blob: ea1ffb13dd8bf95dd0f8c0bb1bbb0a8f257921c0 [file] [log] [blame]
Jens Axboe214e1ec2007-03-15 10:48:13 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <ctype.h>
5#include <string.h>
Jens Axboe214e1ec2007-03-15 10:48:13 +01006#include <assert.h>
Jens Axboe921c7662008-03-26 09:17:55 +01007#include <libgen.h>
Jens Axboe5921e802008-05-30 15:02:38 +02008#include <fcntl.h>
9#include <sys/types.h>
10#include <sys/stat.h>
Jens Axboe214e1ec2007-03-15 10:48:13 +010011
12#include "fio.h"
Jens Axboe4f5af7b2009-06-03 08:45:40 +020013#include "verify.h"
Jens Axboe214e1ec2007-03-15 10:48:13 +010014#include "parse.h"
Jens Axboeeef32352008-06-02 13:31:26 +020015#include "lib/fls.h"
Jens Axboe9f988e22010-03-04 10:42:38 +010016#include "options.h"
Jens Axboe214e1ec2007-03-15 10:48:13 +010017
Jens Axboe5d7c5d32010-06-21 15:08:17 +020018#include "crc/crc32c.h"
19
Jens Axboe214e1ec2007-03-15 10:48:13 +010020/*
21 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
22 */
23static char *get_opt_postfix(const char *str)
24{
25 char *p = strstr(str, ":");
26
27 if (!p)
28 return NULL;
29
30 p++;
31 strip_blank_front(&p);
32 strip_blank_end(p);
33 return strdup(p);
34}
35
Radha Ramachandran0e92f872009-10-27 20:14:27 +010036static int converthexchartoint(char a)
37{
38 int base;
39
40 switch(a) {
41 case '0'...'9':
42 base = '0';
43 break;
44 case 'A'...'F':
45 base = 'A' - 10;
46 break;
47 case 'a'...'f':
48 base = 'a' - 10;
49 break;
50 default:
51 base = 0;
52 }
53 return (a - base);
54}
55
Jens Axboe564ca972007-12-14 12:21:19 +010056static int bs_cmp(const void *p1, const void *p2)
57{
58 const struct bssplit *bsp1 = p1;
59 const struct bssplit *bsp2 = p2;
60
61 return bsp1->perc < bsp2->perc;
62}
63
Jens Axboe720e84a2009-04-21 08:29:55 +020064static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
Jens Axboe564ca972007-12-14 12:21:19 +010065{
Jens Axboe720e84a2009-04-21 08:29:55 +020066 struct bssplit *bssplit;
Jens Axboe564ca972007-12-14 12:21:19 +010067 unsigned int i, perc, perc_missing;
68 unsigned int max_bs, min_bs;
69 long long val;
Jens Axboe720e84a2009-04-21 08:29:55 +020070 char *fname;
Jens Axboe564ca972007-12-14 12:21:19 +010071
Jens Axboe720e84a2009-04-21 08:29:55 +020072 td->o.bssplit_nr[ddir] = 4;
73 bssplit = malloc(4 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010074
75 i = 0;
76 max_bs = 0;
77 min_bs = -1;
78 while ((fname = strsep(&str, ":")) != NULL) {
79 char *perc_str;
80
81 if (!strlen(fname))
82 break;
83
84 /*
85 * grow struct buffer, if needed
86 */
Jens Axboe720e84a2009-04-21 08:29:55 +020087 if (i == td->o.bssplit_nr[ddir]) {
88 td->o.bssplit_nr[ddir] <<= 1;
89 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
Jens Axboe5ec10ea2008-03-06 15:42:00 +010090 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010091 }
92
93 perc_str = strstr(fname, "/");
94 if (perc_str) {
95 *perc_str = '\0';
96 perc_str++;
97 perc = atoi(perc_str);
98 if (perc > 100)
99 perc = 100;
100 else if (!perc)
101 perc = -1;
102 } else
103 perc = -1;
104
Jens Axboe6925dd32011-09-07 22:10:11 +0200105 if (str_to_decimal(fname, &val, 1, td)) {
Jens Axboe564ca972007-12-14 12:21:19 +0100106 log_err("fio: bssplit conversion failed\n");
107 free(td->o.bssplit);
108 return 1;
109 }
110
111 if (val > max_bs)
112 max_bs = val;
113 if (val < min_bs)
114 min_bs = val;
115
Jens Axboe720e84a2009-04-21 08:29:55 +0200116 bssplit[i].bs = val;
117 bssplit[i].perc = perc;
Jens Axboe564ca972007-12-14 12:21:19 +0100118 i++;
119 }
120
Jens Axboe720e84a2009-04-21 08:29:55 +0200121 td->o.bssplit_nr[ddir] = i;
Jens Axboe564ca972007-12-14 12:21:19 +0100122
123 /*
124 * Now check if the percentages add up, and how much is missing
125 */
126 perc = perc_missing = 0;
Jens Axboe720e84a2009-04-21 08:29:55 +0200127 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
128 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100129
130 if (bsp->perc == (unsigned char) -1)
131 perc_missing++;
132 else
133 perc += bsp->perc;
134 }
135
136 if (perc > 100) {
137 log_err("fio: bssplit percentages add to more than 100%%\n");
Jens Axboe720e84a2009-04-21 08:29:55 +0200138 free(bssplit);
Jens Axboe564ca972007-12-14 12:21:19 +0100139 return 1;
140 }
141 /*
142 * If values didn't have a percentage set, divide the remains between
143 * them.
144 */
145 if (perc_missing) {
Jens Axboe720e84a2009-04-21 08:29:55 +0200146 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
147 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100148
149 if (bsp->perc == (unsigned char) -1)
150 bsp->perc = (100 - perc) / perc_missing;
151 }
152 }
153
Jens Axboe720e84a2009-04-21 08:29:55 +0200154 td->o.min_bs[ddir] = min_bs;
155 td->o.max_bs[ddir] = max_bs;
Jens Axboe564ca972007-12-14 12:21:19 +0100156
157 /*
158 * now sort based on percentages, for ease of lookup
159 */
Jens Axboe720e84a2009-04-21 08:29:55 +0200160 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161 td->o.bssplit[ddir] = bssplit;
162 return 0;
163
164}
165
166static int str_bssplit_cb(void *data, const char *input)
167{
168 struct thread_data *td = data;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200169 char *str, *p, *odir, *ddir;
Jens Axboe720e84a2009-04-21 08:29:55 +0200170 int ret = 0;
171
172 p = str = strdup(input);
173
174 strip_blank_front(&str);
175 strip_blank_end(str);
176
177 odir = strchr(str, ',');
178 if (odir) {
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200179 ddir = strchr(odir + 1, ',');
180 if (ddir) {
181 ret = bssplit_ddir(td, DDIR_TRIM, ddir + 1);
182 if (!ret)
183 *ddir = '\0';
184 } else {
185 char *op;
186
187 op = strdup(odir + 1);
188 ret = bssplit_ddir(td, DDIR_TRIM, op);
189
190 free(op);
191 }
192 if (!ret)
193 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
Jens Axboe720e84a2009-04-21 08:29:55 +0200194 if (!ret) {
195 *odir = '\0';
196 ret = bssplit_ddir(td, DDIR_READ, str);
197 }
198 } else {
199 char *op;
200
201 op = strdup(str);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200202 ret = bssplit_ddir(td, DDIR_WRITE, op);
Jens Axboe720e84a2009-04-21 08:29:55 +0200203 free(op);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200204
205 if (!ret) {
206 op = strdup(str);
207 ret = bssplit_ddir(td, DDIR_TRIM, op);
208 free(op);
209 }
210 ret = bssplit_ddir(td, DDIR_READ, str);
Jens Axboe720e84a2009-04-21 08:29:55 +0200211 }
Jens Axboe564ca972007-12-14 12:21:19 +0100212
213 free(p);
Jens Axboe720e84a2009-04-21 08:29:55 +0200214 return ret;
Jens Axboe564ca972007-12-14 12:21:19 +0100215}
216
Dmitry Monakhov8b28bd42012-09-23 15:46:09 +0400217static int str2error(char *str)
218{
219 const char * err[] = {"EPERM", "ENOENT", "ESRCH", "EINTR", "EIO",
220 "ENXIO", "E2BIG", "ENOEXEC", "EBADF",
221 "ECHILD", "EAGAIN", "ENOMEM", "EACCES",
222 "EFAULT", "ENOTBLK", "EBUSY", "EEXIST",
223 "EXDEV", "ENODEV", "ENOTDIR", "EISDIR",
224 "EINVAL", "ENFILE", "EMFILE", "ENOTTY",
225 "ETXTBSY","EFBIG", "ENOSPC", "ESPIPE",
226 "EROFS","EMLINK", "EPIPE", "EDOM", "ERANGE"};
227 int i = 0, num = sizeof(err) / sizeof(void *);
228
229 while( i < num) {
230 if (!strcmp(err[i], str))
231 return i + 1;
232 i++;
233 }
234 return 0;
235}
236
237static int ignore_error_type(struct thread_data *td, int etype, char *str)
238{
239 unsigned int i;
240 int *error;
241 char *fname;
242
243 if (etype >= ERROR_TYPE_CNT) {
244 log_err("Illegal error type\n");
245 return 1;
246 }
247
248 td->o.ignore_error_nr[etype] = 4;
249 error = malloc(4 * sizeof(struct bssplit));
250
251 i = 0;
252 while ((fname = strsep(&str, ":")) != NULL) {
253
254 if (!strlen(fname))
255 break;
256
257 /*
258 * grow struct buffer, if needed
259 */
260 if (i == td->o.ignore_error_nr[etype]) {
261 td->o.ignore_error_nr[etype] <<= 1;
262 error = realloc(error, td->o.ignore_error_nr[etype]
263 * sizeof(int));
264 }
265 if (fname[0] == 'E') {
266 error[i] = str2error(fname);
267 } else {
268 error[i] = atoi(fname);
269 if (error[i] < 0)
270 error[i] = error[i];
271 }
272 if (!error[i]) {
273 log_err("Unknown error %s, please use number value \n",
274 fname);
275 return 1;
276 }
277 i++;
278 }
279 if (i) {
280 td->o.continue_on_error |= 1 << etype;
281 td->o.ignore_error_nr[etype] = i;
282 td->o.ignore_error[etype] = error;
283 }
284 return 0;
285
286}
287
288static int str_ignore_error_cb(void *data, const char *input)
289{
290 struct thread_data *td = data;
291 char *str, *p, *n;
292 int type = 0, ret = 1;
293 p = str = strdup(input);
294
295 strip_blank_front(&str);
296 strip_blank_end(str);
297
298 while (p) {
299 n = strchr(p, ',');
300 if (n)
301 *n++ = '\0';
302 ret = ignore_error_type(td, type, p);
303 if (ret)
304 break;
305 p = n;
306 type++;
307 }
308 free(str);
309 return ret;
310}
311
Jens Axboe211097b2007-03-22 18:56:45 +0100312static int str_rw_cb(void *data, const char *str)
313{
314 struct thread_data *td = data;
315 char *nr = get_opt_postfix(str);
316
Jens Axboe5736c102010-07-20 12:03:25 -0600317 td->o.ddir_seq_nr = 1;
Jens Axboe059b0802011-08-25 09:09:37 +0200318 td->o.ddir_seq_add = 0;
319
320 if (!nr)
321 return 0;
322
323 if (td_random(td))
Jens Axboe5736c102010-07-20 12:03:25 -0600324 td->o.ddir_seq_nr = atoi(nr);
Jens Axboe059b0802011-08-25 09:09:37 +0200325 else {
326 long long val;
327
Jens Axboe6925dd32011-09-07 22:10:11 +0200328 if (str_to_decimal(nr, &val, 1, td)) {
Jens Axboe059b0802011-08-25 09:09:37 +0200329 log_err("fio: rw postfix parsing failed\n");
330 free(nr);
331 return 1;
332 }
333
334 td->o.ddir_seq_add = val;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100335 }
Jens Axboe211097b2007-03-22 18:56:45 +0100336
Jens Axboe059b0802011-08-25 09:09:37 +0200337 free(nr);
Jens Axboe211097b2007-03-22 18:56:45 +0100338 return 0;
339}
340
Jens Axboe214e1ec2007-03-15 10:48:13 +0100341static int str_mem_cb(void *data, const char *mem)
342{
343 struct thread_data *td = data;
344
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100345 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100346 td->mmapfile = get_opt_postfix(mem);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100347 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100348 log_err("fio: mmaphuge:/path/to/file\n");
349 return 1;
350 }
351 }
352
353 return 0;
354}
355
Jens Axboe5d7c5d32010-06-21 15:08:17 +0200356static int str_verify_cb(void *data, const char *mem)
357{
358 struct thread_data *td = data;
359
Jens Axboee3aaafc2012-02-22 20:28:17 +0100360 if (td->o.verify == VERIFY_CRC32C_INTEL ||
361 td->o.verify == VERIFY_CRC32C) {
362 crc32c_intel_probe();
Jens Axboe5d7c5d32010-06-21 15:08:17 +0200363 }
364
365 return 0;
366}
367
Jens Axboec223da82010-03-24 13:23:53 +0100368static int fio_clock_source_cb(void *data, const char *str)
369{
370 struct thread_data *td = data;
371
372 fio_clock_source = td->o.clocksource;
373 fio_time_init();
374 return 0;
375}
376
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400377static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100378{
379 mlock_size = *val;
380 return 0;
381}
382
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400383static int str_rwmix_read_cb(void *data, unsigned long long *val)
Jens Axboecb499fc2008-05-28 10:33:32 +0200384{
385 struct thread_data *td = data;
386
387 td->o.rwmix[DDIR_READ] = *val;
388 td->o.rwmix[DDIR_WRITE] = 100 - *val;
389 return 0;
390}
391
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400392static int str_rwmix_write_cb(void *data, unsigned long long *val)
Jens Axboecb499fc2008-05-28 10:33:32 +0200393{
394 struct thread_data *td = data;
395
396 td->o.rwmix[DDIR_WRITE] = *val;
397 td->o.rwmix[DDIR_READ] = 100 - *val;
398 return 0;
399}
400
Jens Axboe214e1ec2007-03-15 10:48:13 +0100401#ifdef FIO_HAVE_IOPRIO
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400402static int str_prioclass_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100403{
404 struct thread_data *td = data;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200405 unsigned short mask;
406
407 /*
408 * mask off old class bits, str_prio_cb() may have set a default class
409 */
410 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
411 td->ioprio &= mask;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100412
413 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
Jens Axboeac684782007-11-08 08:29:07 +0100414 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100415 return 0;
416}
417
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400418static int str_prio_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100419{
420 struct thread_data *td = data;
421
422 td->ioprio |= *val;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200423
424 /*
425 * If no class is set, assume BE
426 */
427 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
428 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
429
Jens Axboeac684782007-11-08 08:29:07 +0100430 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100431 return 0;
432}
433#endif
434
435static int str_exitall_cb(void)
436{
437 exitall_on_terminate = 1;
438 return 0;
439}
440
Jens Axboe214e1ec2007-03-15 10:48:13 +0100441#ifdef FIO_HAVE_CPU_AFFINITY
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400442static int str_cpumask_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100443{
444 struct thread_data *td = data;
Jens Axboed2e268b2007-06-15 10:33:49 +0200445 unsigned int i;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100446 long max_cpu;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100447 int ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100448
Jens Axboed2ce18b2008-12-12 20:51:40 +0100449 ret = fio_cpuset_init(&td->o.cpumask);
450 if (ret < 0) {
451 log_err("fio: cpuset_init failed\n");
452 td_verror(td, ret, "fio_cpuset_init");
453 return 1;
454 }
455
Jens Axboec00a2282011-07-08 20:56:06 +0200456 max_cpu = cpus_online();
Jens Axboed2e268b2007-06-15 10:33:49 +0200457
Jens Axboe62a72732008-12-08 11:37:01 +0100458 for (i = 0; i < sizeof(int) * 8; i++) {
459 if ((1 << i) & *val) {
Jens Axboeb03daaf2008-12-08 20:31:43 +0100460 if (i > max_cpu) {
461 log_err("fio: CPU %d too large (max=%ld)\n", i,
462 max_cpu);
463 return 1;
464 }
Jens Axboe62a72732008-12-08 11:37:01 +0100465 dprint(FD_PARSE, "set cpu allowed %d\n", i);
Jens Axboe6d459ee2008-12-12 20:02:58 +0100466 fio_cpu_set(&td->o.cpumask, i);
Jens Axboe62a72732008-12-08 11:37:01 +0100467 }
468 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200469
Jens Axboe375b2692007-05-22 09:13:02 +0200470 td->o.cpumask_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100471 return 0;
472}
473
Jens Axboee8462bd2009-07-06 12:59:04 +0200474static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
475 const char *input)
Jens Axboed2e268b2007-06-15 10:33:49 +0200476{
Jens Axboed2e268b2007-06-15 10:33:49 +0200477 char *cpu, *str, *p;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100478 long max_cpu;
Jens Axboe19608d62008-12-08 15:03:12 +0100479 int ret = 0;
Jens Axboed2e268b2007-06-15 10:33:49 +0200480
Jens Axboee8462bd2009-07-06 12:59:04 +0200481 ret = fio_cpuset_init(mask);
Jens Axboed2ce18b2008-12-12 20:51:40 +0100482 if (ret < 0) {
483 log_err("fio: cpuset_init failed\n");
484 td_verror(td, ret, "fio_cpuset_init");
485 return 1;
486 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200487
488 p = str = strdup(input);
489
490 strip_blank_front(&str);
491 strip_blank_end(str);
492
Jens Axboec00a2282011-07-08 20:56:06 +0200493 max_cpu = cpus_online();
Jens Axboeb03daaf2008-12-08 20:31:43 +0100494
Jens Axboed2e268b2007-06-15 10:33:49 +0200495 while ((cpu = strsep(&str, ",")) != NULL) {
Jens Axboe62a72732008-12-08 11:37:01 +0100496 char *str2, *cpu2;
497 int icpu, icpu2;
498
Jens Axboed2e268b2007-06-15 10:33:49 +0200499 if (!strlen(cpu))
500 break;
Jens Axboe62a72732008-12-08 11:37:01 +0100501
502 str2 = cpu;
503 icpu2 = -1;
504 while ((cpu2 = strsep(&str2, "-")) != NULL) {
505 if (!strlen(cpu2))
506 break;
507
508 icpu2 = atoi(cpu2);
509 }
510
511 icpu = atoi(cpu);
512 if (icpu2 == -1)
513 icpu2 = icpu;
514 while (icpu <= icpu2) {
Jens Axboe6d459ee2008-12-12 20:02:58 +0100515 if (icpu >= FIO_MAX_CPUS) {
Jens Axboe19608d62008-12-08 15:03:12 +0100516 log_err("fio: your OS only supports up to"
Jens Axboe6d459ee2008-12-12 20:02:58 +0100517 " %d CPUs\n", (int) FIO_MAX_CPUS);
Jens Axboe19608d62008-12-08 15:03:12 +0100518 ret = 1;
519 break;
520 }
Jens Axboeb03daaf2008-12-08 20:31:43 +0100521 if (icpu > max_cpu) {
522 log_err("fio: CPU %d too large (max=%ld)\n",
523 icpu, max_cpu);
524 ret = 1;
525 break;
526 }
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200527
Jens Axboe62a72732008-12-08 11:37:01 +0100528 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
Jens Axboee8462bd2009-07-06 12:59:04 +0200529 fio_cpu_set(mask, icpu);
Jens Axboe62a72732008-12-08 11:37:01 +0100530 icpu++;
531 }
Jens Axboe19608d62008-12-08 15:03:12 +0100532 if (ret)
533 break;
Jens Axboed2e268b2007-06-15 10:33:49 +0200534 }
535
536 free(p);
Jens Axboe19608d62008-12-08 15:03:12 +0100537 if (!ret)
538 td->o.cpumask_set = 1;
539 return ret;
Jens Axboed2e268b2007-06-15 10:33:49 +0200540}
Jens Axboee8462bd2009-07-06 12:59:04 +0200541
542static int str_cpus_allowed_cb(void *data, const char *input)
543{
544 struct thread_data *td = data;
545 int ret;
546
547 ret = set_cpus_allowed(td, &td->o.cpumask, input);
548 if (!ret)
549 td->o.cpumask_set = 1;
550
551 return ret;
552}
553
554static int str_verify_cpus_allowed_cb(void *data, const char *input)
555{
556 struct thread_data *td = data;
557 int ret;
558
559 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
560 if (!ret)
561 td->o.verify_cpumask_set = 1;
562
563 return ret;
564}
Jens Axboed2e268b2007-06-15 10:33:49 +0200565#endif
566
Yufei Rend0b937e2012-10-19 23:11:52 -0400567#ifdef FIO_HAVE_LIBNUMA
568static int str_numa_cpunodes_cb(void *data, char *input)
569{
570 struct thread_data *td = data;
571
572 /* numa_parse_nodestring() parses a character string list
573 * of nodes into a bit mask. The bit mask is allocated by
574 * numa_allocate_nodemask(), so it should be freed by
575 * numa_free_nodemask().
576 */
577 td->o.numa_cpunodesmask = numa_parse_nodestring(input);
578 if (td->o.numa_cpunodesmask == NULL) {
579 log_err("fio: numa_parse_nodestring failed\n");
580 td_verror(td, 1, "str_numa_cpunodes_cb");
581 return 1;
582 }
583
584 td->o.numa_cpumask_set = 1;
585 return 0;
586}
587
588static int str_numa_mpol_cb(void *data, char *input)
589{
590 struct thread_data *td = data;
591 const char * const policy_types[] =
592 { "default", "prefer", "bind", "interleave", "local" };
593 int i;
594
595 char *nodelist = strchr(input, ':');
596 if (nodelist) {
597 /* NUL-terminate mode */
598 *nodelist++ = '\0';
599 }
600
601 for (i = 0; i <= MPOL_LOCAL; i++) {
602 if (!strcmp(input, policy_types[i])) {
603 td->o.numa_mem_mode = i;
604 break;
605 }
606 }
607 if (i > MPOL_LOCAL) {
608 log_err("fio: memory policy should be: default, prefer, bind, interleave, local\n");
609 goto out;
610 }
611
612 switch (td->o.numa_mem_mode) {
613 case MPOL_PREFERRED:
614 /*
615 * Insist on a nodelist of one node only
616 */
617 if (nodelist) {
618 char *rest = nodelist;
619 while (isdigit(*rest))
620 rest++;
621 if (*rest) {
622 log_err("fio: one node only for \'prefer\'\n");
623 goto out;
624 }
625 } else {
626 log_err("fio: one node is needed for \'prefer\'\n");
627 goto out;
628 }
629 break;
630 case MPOL_INTERLEAVE:
631 /*
632 * Default to online nodes with memory if no nodelist
633 */
634 if (!nodelist)
635 nodelist = strdup("all");
636 break;
637 case MPOL_LOCAL:
638 case MPOL_DEFAULT:
639 /*
640 * Don't allow a nodelist
641 */
642 if (nodelist) {
643 log_err("fio: NO nodelist for \'local\'\n");
644 goto out;
645 }
646 break;
647 case MPOL_BIND:
648 /*
649 * Insist on a nodelist
650 */
651 if (!nodelist) {
652 log_err("fio: a nodelist is needed for \'bind\'\n");
653 goto out;
654 }
655 break;
656 }
657
658
659 /* numa_parse_nodestring() parses a character string list
660 * of nodes into a bit mask. The bit mask is allocated by
661 * numa_allocate_nodemask(), so it should be freed by
662 * numa_free_nodemask().
663 */
664 switch (td->o.numa_mem_mode) {
665 case MPOL_PREFERRED:
666 td->o.numa_mem_prefer_node = atoi(nodelist);
667 break;
668 case MPOL_INTERLEAVE:
669 case MPOL_BIND:
670 td->o.numa_memnodesmask = numa_parse_nodestring(nodelist);
671 if (td->o.numa_memnodesmask == NULL) {
672 log_err("fio: numa_parse_nodestring failed\n");
673 td_verror(td, 1, "str_numa_memnodes_cb");
674 return 1;
675 }
676 break;
677 case MPOL_LOCAL:
678 case MPOL_DEFAULT:
679 default:
680 break;
681 }
682
683 td->o.numa_memmask_set = 1;
684 return 0;
685
686out:
687 return 1;
688}
689#endif
690
Jens Axboe0d29de82010-09-01 13:54:15 +0200691#ifdef FIO_HAVE_TRIM
692static int str_verify_trim_cb(void *data, unsigned long long *val)
693{
694 struct thread_data *td = data;
695
696 td->o.trim_percentage = *val;
697 return 0;
698}
699#endif
700
Jens Axboe214e1ec2007-03-15 10:48:13 +0100701static int str_fst_cb(void *data, const char *str)
702{
703 struct thread_data *td = data;
704 char *nr = get_opt_postfix(str);
705
706 td->file_service_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100707 if (nr) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100708 td->file_service_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100709 free(nr);
710 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100711
712 return 0;
713}
714
Jens Axboe3ae06372010-03-19 19:17:15 +0100715#ifdef FIO_HAVE_SYNC_FILE_RANGE
Jens Axboe44f29692010-03-09 20:09:44 +0100716static int str_sfr_cb(void *data, const char *str)
717{
718 struct thread_data *td = data;
719 char *nr = get_opt_postfix(str);
720
721 td->sync_file_range_nr = 1;
722 if (nr) {
723 td->sync_file_range_nr = atoi(nr);
724 free(nr);
725 }
726
727 return 0;
728}
Jens Axboe3ae06372010-03-19 19:17:15 +0100729#endif
Jens Axboe44f29692010-03-09 20:09:44 +0100730
Jens Axboee25839d2012-11-06 10:49:42 +0100731static int str_random_distribution_cb(void *data, const char *str)
732{
733 struct thread_data *td = data;
734 double val;
735 char *nr;
736
Jens Axboe925fee32012-11-06 13:50:32 +0100737 if (td->o.random_distribution == FIO_RAND_DIST_ZIPF)
738 val = 1.1;
739 else if (td->o.random_distribution == FIO_RAND_DIST_PARETO)
740 val = 0.2;
741 else
Jens Axboee25839d2012-11-06 10:49:42 +0100742 return 0;
743
744 nr = get_opt_postfix(str);
Jens Axboe925fee32012-11-06 13:50:32 +0100745 if (nr && !str_to_float(nr, &val)) {
Jens Axboee25839d2012-11-06 10:49:42 +0100746 log_err("fio: random postfix parsing failed\n");
747 free(nr);
748 return 1;
749 }
750
Jens Axboe925fee32012-11-06 13:50:32 +0100751 if (td->o.random_distribution == FIO_RAND_DIST_ZIPF)
752 td->o.zipf_theta = val;
753 else
754 td->o.pareto_h = val;
755
Jens Axboee25839d2012-11-06 10:49:42 +0100756 free(nr);
757 return 0;
758}
759
Jens Axboe921c7662008-03-26 09:17:55 +0100760static int check_dir(struct thread_data *td, char *fname)
761{
Jens Axboe3f0ca9b2011-05-24 21:36:24 +0200762#if 0
Jens Axboe921c7662008-03-26 09:17:55 +0100763 char file[PATH_MAX], *dir;
Jens Axboebc838912008-04-07 09:00:54 +0200764 int elen = 0;
Jens Axboe921c7662008-03-26 09:17:55 +0100765
Jens Axboebc838912008-04-07 09:00:54 +0200766 if (td->o.directory) {
767 strcpy(file, td->o.directory);
Jens Axboefcef0b32008-05-26 14:53:24 +0200768 strcat(file, "/");
Jens Axboebc838912008-04-07 09:00:54 +0200769 elen = strlen(file);
770 }
771
Jens Axboefcef0b32008-05-26 14:53:24 +0200772 sprintf(file + elen, "%s", fname);
Jens Axboe921c7662008-03-26 09:17:55 +0100773 dir = dirname(file);
774
Jens Axboefcef0b32008-05-26 14:53:24 +0200775 {
776 struct stat sb;
777 /*
778 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
779 * yet, so we can't do this check right here...
780 */
Jens Axboe921c7662008-03-26 09:17:55 +0100781 if (lstat(dir, &sb) < 0) {
782 int ret = errno;
783
784 log_err("fio: %s is not a directory\n", dir);
785 td_verror(td, ret, "lstat");
786 return 1;
787 }
788
789 if (!S_ISDIR(sb.st_mode)) {
790 log_err("fio: %s is not a directory\n", dir);
791 return 1;
792 }
Jens Axboefcef0b32008-05-26 14:53:24 +0200793 }
794#endif
Jens Axboe921c7662008-03-26 09:17:55 +0100795
796 return 0;
797}
798
Jens Axboe8e827d32009-08-04 09:51:48 +0200799/*
800 * Return next file in the string. Files are separated with ':'. If the ':'
801 * is escaped with a '\', then that ':' is part of the filename and does not
802 * indicate a new file.
803 */
804static char *get_next_file_name(char **ptr)
805{
806 char *str = *ptr;
807 char *p, *start;
808
809 if (!str || !strlen(str))
810 return NULL;
811
812 start = str;
813 do {
814 /*
815 * No colon, we are done
816 */
817 p = strchr(str, ':');
818 if (!p) {
819 *ptr = NULL;
820 break;
821 }
822
823 /*
824 * We got a colon, but it's the first character. Skip and
825 * continue
826 */
827 if (p == start) {
828 str = ++start;
829 continue;
830 }
831
832 if (*(p - 1) != '\\') {
833 *p = '\0';
834 *ptr = p + 1;
835 break;
836 }
837
838 memmove(p - 1, p, strlen(p) + 1);
839 str = p;
840 } while (1);
841
842 return start;
843}
844
Jens Axboe214e1ec2007-03-15 10:48:13 +0100845static int str_filename_cb(void *data, const char *input)
846{
847 struct thread_data *td = data;
848 char *fname, *str, *p;
849
850 p = str = strdup(input);
851
852 strip_blank_front(&str);
853 strip_blank_end(str);
854
855 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100856 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100857
Jens Axboe8e827d32009-08-04 09:51:48 +0200858 while ((fname = get_next_file_name(&str)) != NULL) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100859 if (!strlen(fname))
860 break;
Jens Axboe921c7662008-03-26 09:17:55 +0100861 if (check_dir(td, fname)) {
862 free(p);
863 return 1;
864 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100865 add_file(td, fname);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100866 td->o.nr_files++;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100867 }
868
869 free(p);
870 return 0;
871}
872
873static int str_directory_cb(void *data, const char fio_unused *str)
874{
875 struct thread_data *td = data;
876 struct stat sb;
877
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100878 if (lstat(td->o.directory, &sb) < 0) {
Jens Axboe921c7662008-03-26 09:17:55 +0100879 int ret = errno;
880
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100881 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe921c7662008-03-26 09:17:55 +0100882 td_verror(td, ret, "lstat");
Jens Axboe214e1ec2007-03-15 10:48:13 +0100883 return 1;
884 }
885 if (!S_ISDIR(sb.st_mode)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100886 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100887 return 1;
888 }
889
890 return 0;
891}
892
893static int str_opendir_cb(void *data, const char fio_unused *str)
894{
895 struct thread_data *td = data;
896
897 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100898 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100899
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100900 return add_dir_files(td, td->o.opendir);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100901}
902
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400903static int str_verify_offset_cb(void *data, unsigned long long *off)
Shawn Lewis546a9142007-07-28 21:11:37 +0200904{
905 struct thread_data *td = data;
Jens Axboea59e1702007-07-30 08:53:27 +0200906
Shawn Lewis546a9142007-07-28 21:11:37 +0200907 if (*off && *off < sizeof(struct verify_header)) {
Jens Axboea59e1702007-07-30 08:53:27 +0200908 log_err("fio: verify_offset too small\n");
Shawn Lewis546a9142007-07-28 21:11:37 +0200909 return 1;
910 }
Jens Axboea59e1702007-07-30 08:53:27 +0200911
912 td->o.verify_offset = *off;
Shawn Lewis546a9142007-07-28 21:11:37 +0200913 return 0;
914}
915
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100916static int str_verify_pattern_cb(void *data, const char *input)
Jens Axboe90059d62007-07-30 09:33:12 +0200917{
918 struct thread_data *td = data;
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100919 long off;
920 int i = 0, j = 0, len, k, base = 10;
921 char* loc1, * loc2;
Jens Axboe90059d62007-07-30 09:33:12 +0200922
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100923 loc1 = strstr(input, "0x");
924 loc2 = strstr(input, "0X");
925 if (loc1 || loc2)
926 base = 16;
927 off = strtol(input, NULL, base);
928 if (off != LONG_MAX || errno != ERANGE) {
929 while (off) {
930 td->o.verify_pattern[i] = off & 0xff;
931 off >>= 8;
932 i++;
933 }
934 } else {
935 len = strlen(input);
936 k = len - 1;
937 if (base == 16) {
938 if (loc1)
939 j = loc1 - input + 2;
940 else
941 j = loc2 - input + 2;
942 } else
943 return 1;
944 if (len - j < MAX_PATTERN_SIZE * 2) {
945 while (k >= j) {
946 off = converthexchartoint(input[k--]);
947 if (k >= j)
948 off += (converthexchartoint(input[k--])
949 * 16);
950 td->o.verify_pattern[i++] = (char) off;
951 }
952 }
953 }
Steven Langefcd9dc2012-02-02 20:22:04 +0100954
955 /*
956 * Fill the pattern all the way to the end. This greatly reduces
957 * the number of memcpy's we have to do when verifying the IO.
958 */
959 while (i > 1 && i * 2 <= MAX_PATTERN_SIZE) {
960 memcpy(&td->o.verify_pattern[i], &td->o.verify_pattern[0], i);
961 i *= 2;
962 }
Steven Lang9a2a86d2012-02-07 09:42:59 +0100963 if (i == 1) {
964 /*
965 * The code in verify_io_u_pattern assumes a single byte pattern
966 * fills the whole verify pattern buffer.
967 */
968 memset(td->o.verify_pattern, td->o.verify_pattern[0],
969 MAX_PATTERN_SIZE);
970 }
Steven Langefcd9dc2012-02-02 20:22:04 +0100971
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100972 td->o.verify_pattern_bytes = i;
Steven Langefcd9dc2012-02-02 20:22:04 +0100973
Jens Axboe92bf48d2011-01-14 21:20:42 +0100974 /*
975 * VERIFY_META could already be set
976 */
977 if (td->o.verify == VERIFY_NONE)
978 td->o.verify = VERIFY_PATTERN;
Steven Langefcd9dc2012-02-02 20:22:04 +0100979
Jens Axboe90059d62007-07-30 09:33:12 +0200980 return 0;
981}
Jens Axboe214e1ec2007-03-15 10:48:13 +0100982
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100983static int str_lockfile_cb(void *data, const char *str)
984{
985 struct thread_data *td = data;
986 char *nr = get_opt_postfix(str);
987
988 td->o.lockfile_batch = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100989 if (nr) {
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100990 td->o.lockfile_batch = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100991 free(nr);
992 }
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100993
994 return 0;
995}
996
Jens Axboee3cedca2008-11-19 19:57:52 +0100997static int str_write_bw_log_cb(void *data, const char *str)
998{
999 struct thread_data *td = data;
1000
1001 if (str)
1002 td->o.bw_log_file = strdup(str);
1003
1004 td->o.write_bw_log = 1;
1005 return 0;
1006}
1007
1008static int str_write_lat_log_cb(void *data, const char *str)
1009{
1010 struct thread_data *td = data;
1011
1012 if (str)
1013 td->o.lat_log_file = strdup(str);
1014
1015 td->o.write_lat_log = 1;
1016 return 0;
1017}
1018
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001019static int str_write_iops_log_cb(void *data, const char *str)
1020{
1021 struct thread_data *td = data;
1022
1023 if (str)
1024 td->o.iops_log_file = strdup(str);
1025
1026 td->o.write_iops_log = 1;
1027 return 0;
1028}
1029
Jens Axboe993bf482008-11-14 13:04:53 +01001030static int str_gtod_reduce_cb(void *data, int *il)
1031{
1032 struct thread_data *td = data;
1033 int val = *il;
1034
Jens Axboe02af0982010-06-24 09:59:34 +02001035 td->o.disable_lat = !!val;
Jens Axboe993bf482008-11-14 13:04:53 +01001036 td->o.disable_clat = !!val;
1037 td->o.disable_slat = !!val;
1038 td->o.disable_bw = !!val;
Jens Axboe0dc1bc02011-10-13 08:55:29 +02001039 td->o.clat_percentiles = !val;
Jens Axboe993bf482008-11-14 13:04:53 +01001040 if (val)
1041 td->tv_cache_mask = 63;
1042
1043 return 0;
1044}
1045
Cigy Cyriac85bc8332010-08-10 19:21:09 -04001046static int str_gtod_cpu_cb(void *data, long long *il)
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001047{
1048 struct thread_data *td = data;
1049 int val = *il;
1050
1051 td->o.gtod_cpu = val;
1052 td->o.gtod_offload = 1;
1053 return 0;
1054}
1055
Jens Axboe7bb59102011-07-12 19:47:03 +02001056static int str_size_cb(void *data, unsigned long long *__val)
1057{
1058 struct thread_data *td = data;
1059 unsigned long long v = *__val;
1060
1061 if (parse_is_percent(v)) {
1062 td->o.size = 0;
1063 td->o.size_percent = -1ULL - v;
1064 } else
1065 td->o.size = v;
1066
1067 return 0;
1068}
1069
Jens Axboe896cac22009-07-01 10:38:35 +02001070static int rw_verify(struct fio_option *o, void *data)
1071{
1072 struct thread_data *td = data;
1073
1074 if (read_only && td_write(td)) {
1075 log_err("fio: job <%s> has write bit set, but fio is in"
1076 " read-only mode\n", td->o.name);
1077 return 1;
1078 }
1079
1080 return 0;
1081}
1082
Jens Axboe276ca4f2009-07-01 10:43:05 +02001083static int gtod_cpu_verify(struct fio_option *o, void *data)
Jens Axboe29d43ff2009-07-01 10:42:18 +02001084{
Jens Axboe276ca4f2009-07-01 10:43:05 +02001085#ifndef FIO_HAVE_CPU_AFFINITY
Jens Axboe29d43ff2009-07-01 10:42:18 +02001086 struct thread_data *td = data;
1087
Jens Axboe29d43ff2009-07-01 10:42:18 +02001088 if (td->o.gtod_cpu) {
1089 log_err("fio: platform must support CPU affinity for"
1090 "gettimeofday() offloading\n");
1091 return 1;
1092 }
1093#endif
1094
1095 return 0;
1096}
1097
Jens Axboe90fef2d2009-07-17 22:33:32 +02001098static int kb_base_verify(struct fio_option *o, void *data)
1099{
1100 struct thread_data *td = data;
1101
1102 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
1103 log_err("fio: kb_base set to nonsensical value: %u\n",
1104 td->o.kb_base);
1105 return 1;
1106 }
1107
1108 return 0;
1109}
1110
Jens Axboe214e1ec2007-03-15 10:48:13 +01001111/*
1112 * Map of job/command line options
1113 */
Jens Axboe07b32322010-03-05 09:48:44 +01001114static struct fio_option options[FIO_MAX_OPTS] = {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001115 {
1116 .name = "description",
1117 .type = FIO_OPT_STR_STORE,
1118 .off1 = td_var_offset(description),
1119 .help = "Text job description",
1120 },
1121 {
1122 .name = "name",
1123 .type = FIO_OPT_STR_STORE,
1124 .off1 = td_var_offset(name),
1125 .help = "Name of this job",
1126 },
1127 {
1128 .name = "directory",
1129 .type = FIO_OPT_STR_STORE,
1130 .off1 = td_var_offset(directory),
1131 .cb = str_directory_cb,
1132 .help = "Directory to store files in",
1133 },
1134 {
1135 .name = "filename",
1136 .type = FIO_OPT_STR_STORE,
1137 .off1 = td_var_offset(filename),
1138 .cb = str_filename_cb,
Jens Axboef0d524b2009-04-27 08:00:48 +02001139 .prio = -1, /* must come after "directory" */
Jens Axboe214e1ec2007-03-15 10:48:13 +01001140 .help = "File(s) to use for the workload",
1141 },
1142 {
Jens Axboe90fef2d2009-07-17 22:33:32 +02001143 .name = "kb_base",
1144 .type = FIO_OPT_INT,
1145 .off1 = td_var_offset(kb_base),
Jens Axboe90fef2d2009-07-17 22:33:32 +02001146 .verify = kb_base_verify,
Jens Axboea639f0b2009-07-18 08:25:35 +02001147 .prio = 1,
Jens Axboe90fef2d2009-07-17 22:33:32 +02001148 .def = "1024",
Jens Axboea639f0b2009-07-18 08:25:35 +02001149 .help = "How many bytes per KB for reporting (1000 or 1024)",
Jens Axboe90fef2d2009-07-17 22:33:32 +02001150 },
1151 {
Jens Axboe29c13492008-03-01 19:25:20 +01001152 .name = "lockfile",
Jens Axboe4d4e80f2008-03-04 10:18:56 +01001153 .type = FIO_OPT_STR,
1154 .cb = str_lockfile_cb,
1155 .off1 = td_var_offset(file_lock_mode),
Jens Axboe29c13492008-03-01 19:25:20 +01001156 .help = "Lock file when doing IO to it",
1157 .parent = "filename",
Jens Axboe4d4e80f2008-03-04 10:18:56 +01001158 .def = "none",
1159 .posval = {
1160 { .ival = "none",
1161 .oval = FILE_LOCK_NONE,
1162 .help = "No file locking",
1163 },
1164 { .ival = "exclusive",
1165 .oval = FILE_LOCK_EXCLUSIVE,
1166 .help = "Exclusive file lock",
1167 },
1168 {
1169 .ival = "readwrite",
1170 .oval = FILE_LOCK_READWRITE,
1171 .help = "Read vs write lock",
1172 },
1173 },
Jens Axboe29c13492008-03-01 19:25:20 +01001174 },
1175 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001176 .name = "opendir",
1177 .type = FIO_OPT_STR_STORE,
1178 .off1 = td_var_offset(opendir),
1179 .cb = str_opendir_cb,
1180 .help = "Recursively add files from this directory and down",
1181 },
1182 {
1183 .name = "rw",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001184 .alias = "readwrite",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001185 .type = FIO_OPT_STR,
Jens Axboe211097b2007-03-22 18:56:45 +01001186 .cb = str_rw_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001187 .off1 = td_var_offset(td_ddir),
1188 .help = "IO direction",
1189 .def = "read",
Jens Axboe896cac22009-07-01 10:38:35 +02001190 .verify = rw_verify,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001191 .posval = {
1192 { .ival = "read",
1193 .oval = TD_DDIR_READ,
1194 .help = "Sequential read",
1195 },
1196 { .ival = "write",
1197 .oval = TD_DDIR_WRITE,
1198 .help = "Sequential write",
1199 },
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001200 { .ival = "trim",
1201 .oval = TD_DDIR_TRIM,
1202 .help = "Sequential trim",
1203 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001204 { .ival = "randread",
1205 .oval = TD_DDIR_RANDREAD,
1206 .help = "Random read",
1207 },
1208 { .ival = "randwrite",
1209 .oval = TD_DDIR_RANDWRITE,
1210 .help = "Random write",
1211 },
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001212 { .ival = "randtrim",
1213 .oval = TD_DDIR_RANDTRIM,
1214 .help = "Random trim",
1215 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001216 { .ival = "rw",
1217 .oval = TD_DDIR_RW,
1218 .help = "Sequential read and write mix",
1219 },
Jens Axboe10b023d2012-03-23 13:40:06 +01001220 { .ival = "readwrite",
1221 .oval = TD_DDIR_RW,
1222 .help = "Sequential read and write mix",
1223 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001224 { .ival = "randrw",
1225 .oval = TD_DDIR_RANDRW,
1226 .help = "Random read and write mix"
1227 },
1228 },
1229 },
1230 {
Jens Axboe38dad622010-07-20 14:46:00 -06001231 .name = "rw_sequencer",
1232 .type = FIO_OPT_STR,
1233 .off1 = td_var_offset(rw_seq),
1234 .help = "IO offset generator modifier",
1235 .def = "sequential",
1236 .posval = {
1237 { .ival = "sequential",
1238 .oval = RW_SEQ_SEQ,
1239 .help = "Generate sequential offsets",
1240 },
1241 { .ival = "identical",
1242 .oval = RW_SEQ_IDENT,
1243 .help = "Generate identical offsets",
1244 },
1245 },
1246 },
1247
1248 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001249 .name = "ioengine",
1250 .type = FIO_OPT_STR_STORE,
1251 .off1 = td_var_offset(ioengine),
1252 .help = "IO engine to use",
Jens Axboe58483fa2011-01-19 11:09:58 -07001253 .def = FIO_PREFERRED_ENGINE,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001254 .posval = {
1255 { .ival = "sync",
1256 .help = "Use read/write",
1257 },
gurudas paia31041e2007-10-23 15:12:30 +02001258 { .ival = "psync",
1259 .help = "Use pread/pwrite",
1260 },
Jens Axboe1d2af022008-02-04 10:59:07 +01001261 { .ival = "vsync",
Bruce Cran03e20d62011-01-02 20:14:54 +01001262 .help = "Use readv/writev",
Jens Axboe1d2af022008-02-04 10:59:07 +01001263 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001264#ifdef FIO_HAVE_LIBAIO
1265 { .ival = "libaio",
1266 .help = "Linux native asynchronous IO",
1267 },
1268#endif
1269#ifdef FIO_HAVE_POSIXAIO
1270 { .ival = "posixaio",
1271 .help = "POSIX asynchronous IO",
1272 },
1273#endif
Jens Axboe417f0062008-06-02 11:59:30 +02001274#ifdef FIO_HAVE_SOLARISAIO
1275 { .ival = "solarisaio",
1276 .help = "Solaris native asynchronous IO",
1277 },
1278#endif
Bruce Cran03e20d62011-01-02 20:14:54 +01001279#ifdef FIO_HAVE_WINDOWSAIO
1280 { .ival = "windowsaio",
Jens Axboe3be80072011-01-19 11:07:28 -07001281 .help = "Windows native asynchronous IO"
Steven Langde890a12011-11-09 14:03:34 +01001282 },
Jens Axboe3be80072011-01-19 11:07:28 -07001283#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001284 { .ival = "mmap",
Bruce Cran03e20d62011-01-02 20:14:54 +01001285 .help = "Memory mapped IO"
Jens Axboe214e1ec2007-03-15 10:48:13 +01001286 },
1287#ifdef FIO_HAVE_SPLICE
1288 { .ival = "splice",
1289 .help = "splice/vmsplice based IO",
1290 },
Jens Axboe9cce02e2007-06-22 15:42:21 +02001291 { .ival = "netsplice",
1292 .help = "splice/vmsplice to/from the network",
1293 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001294#endif
1295#ifdef FIO_HAVE_SGIO
1296 { .ival = "sg",
1297 .help = "SCSI generic v3 IO",
1298 },
1299#endif
1300 { .ival = "null",
1301 .help = "Testing engine (no data transfer)",
1302 },
1303 { .ival = "net",
1304 .help = "Network IO",
1305 },
1306#ifdef FIO_HAVE_SYSLET
1307 { .ival = "syslet-rw",
1308 .help = "syslet enabled async pread/pwrite IO",
1309 },
1310#endif
1311 { .ival = "cpuio",
Bruce Cran03e20d62011-01-02 20:14:54 +01001312 .help = "CPU cycle burner engine",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001313 },
Jens Axboeb8c82a42007-03-21 08:48:26 +01001314#ifdef FIO_HAVE_GUASI
1315 { .ival = "guasi",
1316 .help = "GUASI IO engine",
1317 },
1318#endif
Jens Axboe79a43182010-09-07 13:28:58 +02001319#ifdef FIO_HAVE_BINJECT
1320 { .ival = "binject",
1321 .help = "binject direct inject block engine",
1322 },
1323#endif
ren yufei21b8aee2011-08-01 10:01:57 +02001324#ifdef FIO_HAVE_RDMA
1325 { .ival = "rdma",
1326 .help = "RDMA IO engine",
1327 },
1328#endif
Jens Axboe8200b8c2012-09-18 23:55:43 +02001329#ifdef FIO_HAVE_FUSION_AW
1330 { .ival = "fusion-aw-sync",
1331 .help = "Fusion-io atomic write engine",
1332 },
1333#endif
Jens Axboe1ecc95c2012-09-20 13:46:34 +02001334#ifdef FIO_HAVE_E4_ENG
1335 { .ival = "e4defrag",
1336 .help = "ext4 defrag engine",
1337 },
1338#endif
1339#ifdef FIO_HAVE_FALLOC_ENG
1340 { .ival = "falloc",
1341 .help = "fallocate() file based engine",
1342 },
1343#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001344 { .ival = "external",
1345 .help = "Load external engine (append name)",
1346 },
1347 },
1348 },
1349 {
1350 .name = "iodepth",
1351 .type = FIO_OPT_INT,
1352 .off1 = td_var_offset(iodepth),
Bruce Cran03e20d62011-01-02 20:14:54 +01001353 .help = "Number of IO buffers to keep in flight",
Jens Axboe757aff42007-12-12 19:42:13 +01001354 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001355 .def = "1",
1356 },
1357 {
1358 .name = "iodepth_batch",
Jens Axboe49504212008-06-05 09:03:30 +02001359 .alias = "iodepth_batch_submit",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001360 .type = FIO_OPT_INT,
1361 .off1 = td_var_offset(iodepth_batch),
Jens Axboed65db442009-01-16 19:15:33 +01001362 .help = "Number of IO buffers to submit in one go",
Jens Axboeafdf9352007-07-31 16:14:34 +02001363 .parent = "iodepth",
Jens Axboea2e6f8a2008-01-18 10:28:11 +01001364 .minval = 1,
1365 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001366 },
1367 {
Jens Axboe49504212008-06-05 09:03:30 +02001368 .name = "iodepth_batch_complete",
1369 .type = FIO_OPT_INT,
1370 .off1 = td_var_offset(iodepth_batch_complete),
Jens Axboed65db442009-01-16 19:15:33 +01001371 .help = "Number of IO buffers to retrieve in one go",
Jens Axboe49504212008-06-05 09:03:30 +02001372 .parent = "iodepth",
1373 .minval = 0,
1374 .def = "1",
1375 },
1376 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001377 .name = "iodepth_low",
1378 .type = FIO_OPT_INT,
1379 .off1 = td_var_offset(iodepth_low),
1380 .help = "Low water mark for queuing depth",
Jens Axboeafdf9352007-07-31 16:14:34 +02001381 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001382 },
1383 {
1384 .name = "size",
1385 .type = FIO_OPT_STR_VAL,
Jens Axboe7bb59102011-07-12 19:47:03 +02001386 .cb = str_size_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001387 .help = "Total size of device or files",
1388 },
1389 {
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001390 .name = "fill_device",
Jens Axboe74586c12011-01-20 10:16:03 -07001391 .alias = "fill_fs",
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001392 .type = FIO_OPT_BOOL,
1393 .off1 = td_var_offset(fill_device),
1394 .help = "Write until an ENOSPC error occurs",
1395 .def = "0",
1396 },
1397 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001398 .name = "filesize",
1399 .type = FIO_OPT_STR_VAL,
1400 .off1 = td_var_offset(file_size_low),
1401 .off2 = td_var_offset(file_size_high),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001402 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001403 .help = "Size of individual files",
1404 },
1405 {
Jens Axboe67a10002007-07-31 23:12:16 +02001406 .name = "offset",
1407 .alias = "fileoffset",
1408 .type = FIO_OPT_STR_VAL,
1409 .off1 = td_var_offset(start_offset),
1410 .help = "Start IO from this offset",
1411 .def = "0",
1412 },
1413 {
Jens Axboe2d7cd862012-03-15 14:53:38 +01001414 .name = "offset_increment",
1415 .type = FIO_OPT_STR_VAL,
1416 .off1 = td_var_offset(offset_increment),
1417 .help = "What is the increment from one offset to the next",
1418 .parent = "offset",
1419 .def = "0",
1420 },
1421 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001422 .name = "bs",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001423 .alias = "blocksize",
Jens Axboee01b22b2009-06-09 15:43:25 +02001424 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001425 .off1 = td_var_offset(bs[DDIR_READ]),
1426 .off2 = td_var_offset(bs[DDIR_WRITE]),
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001427 .off3 = td_var_offset(bs[DDIR_TRIM]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001428 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001429 .help = "Block size unit",
1430 .def = "4k",
Jens Axboe67a10002007-07-31 23:12:16 +02001431 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001432 },
1433 {
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001434 .name = "ba",
1435 .alias = "blockalign",
Jens Axboee01b22b2009-06-09 15:43:25 +02001436 .type = FIO_OPT_INT,
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001437 .off1 = td_var_offset(ba[DDIR_READ]),
1438 .off2 = td_var_offset(ba[DDIR_WRITE]),
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001439 .off3 = td_var_offset(ba[DDIR_TRIM]),
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001440 .minval = 1,
1441 .help = "IO block offset alignment",
1442 .parent = "rw",
1443 },
1444 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001445 .name = "bsrange",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001446 .alias = "blocksize_range",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001447 .type = FIO_OPT_RANGE,
1448 .off1 = td_var_offset(min_bs[DDIR_READ]),
1449 .off2 = td_var_offset(max_bs[DDIR_READ]),
1450 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1451 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001452 .off5 = td_var_offset(min_bs[DDIR_TRIM]),
1453 .off6 = td_var_offset(max_bs[DDIR_TRIM]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001454 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001455 .help = "Set block size range (in more detail than bs)",
Jens Axboe67a10002007-07-31 23:12:16 +02001456 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001457 },
1458 {
Jens Axboe564ca972007-12-14 12:21:19 +01001459 .name = "bssplit",
1460 .type = FIO_OPT_STR,
1461 .cb = str_bssplit_cb,
1462 .help = "Set a specific mix of block sizes",
1463 .parent = "rw",
1464 },
1465 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001466 .name = "bs_unaligned",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001467 .alias = "blocksize_unaligned",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001468 .type = FIO_OPT_STR_SET,
1469 .off1 = td_var_offset(bs_unaligned),
1470 .help = "Don't sector align IO buffer sizes",
Jens Axboe67a10002007-07-31 23:12:16 +02001471 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001472 },
1473 {
1474 .name = "randrepeat",
1475 .type = FIO_OPT_BOOL,
1476 .off1 = td_var_offset(rand_repeatable),
1477 .help = "Use repeatable random IO pattern",
1478 .def = "1",
Jens Axboe67a10002007-07-31 23:12:16 +02001479 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001480 },
1481 {
Jens Axboe2615cc42011-03-28 09:35:09 +02001482 .name = "use_os_rand",
1483 .type = FIO_OPT_BOOL,
1484 .off1 = td_var_offset(use_os_rand),
1485 .help = "Set to use OS random generator",
1486 .def = "0",
1487 .parent = "rw",
1488 },
1489 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001490 .name = "norandommap",
1491 .type = FIO_OPT_STR_SET,
1492 .off1 = td_var_offset(norandommap),
1493 .help = "Accept potential duplicate random blocks",
Jens Axboe67a10002007-07-31 23:12:16 +02001494 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001495 },
1496 {
Jens Axboe2b386d22008-03-26 10:32:57 +01001497 .name = "softrandommap",
1498 .type = FIO_OPT_BOOL,
1499 .off1 = td_var_offset(softrandommap),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001500 .help = "Set norandommap if randommap allocation fails",
Jens Axboe2b386d22008-03-26 10:32:57 +01001501 .parent = "norandommap",
1502 .def = "0",
1503 },
1504 {
Jens Axboee25839d2012-11-06 10:49:42 +01001505 .name = "random_distribution",
1506 .type = FIO_OPT_STR,
1507 .off1 = td_var_offset(random_distribution),
1508 .cb = str_random_distribution_cb,
1509 .help = "Random offset distribution generator",
1510 .def = "random",
1511 .posval = {
1512 { .ival = "random",
1513 .oval = FIO_RAND_DIST_RANDOM,
1514 .help = "Completely random",
1515 },
1516 { .ival = "zipf",
1517 .oval = FIO_RAND_DIST_ZIPF,
1518 .help = "Zipf distribution",
1519 },
Jens Axboe925fee32012-11-06 13:50:32 +01001520 { .ival = "pareto",
1521 .oval = FIO_RAND_DIST_PARETO,
1522 .help = "Pareto distribution",
1523 },
Jens Axboee25839d2012-11-06 10:49:42 +01001524 },
1525 },
1526 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001527 .name = "nrfiles",
Jens Axboed7c8be02010-11-25 08:21:39 +01001528 .alias = "nr_files",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001529 .type = FIO_OPT_INT,
1530 .off1 = td_var_offset(nr_files),
1531 .help = "Split job workload between this number of files",
1532 .def = "1",
1533 },
1534 {
1535 .name = "openfiles",
1536 .type = FIO_OPT_INT,
1537 .off1 = td_var_offset(open_files),
1538 .help = "Number of files to keep open at the same time",
1539 },
1540 {
1541 .name = "file_service_type",
1542 .type = FIO_OPT_STR,
1543 .cb = str_fst_cb,
1544 .off1 = td_var_offset(file_service_type),
1545 .help = "How to select which file to service next",
1546 .def = "roundrobin",
1547 .posval = {
1548 { .ival = "random",
1549 .oval = FIO_FSERVICE_RANDOM,
1550 .help = "Choose a file at random",
1551 },
1552 { .ival = "roundrobin",
1553 .oval = FIO_FSERVICE_RR,
1554 .help = "Round robin select files",
1555 },
Jens Axboea086c252009-03-04 08:27:37 +01001556 { .ival = "sequential",
1557 .oval = FIO_FSERVICE_SEQ,
1558 .help = "Finish one file before moving to the next",
1559 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001560 },
Jens Axboe67a10002007-07-31 23:12:16 +02001561 .parent = "nrfiles",
1562 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001563#ifdef FIO_HAVE_FALLOCATE
1564 {
1565 .name = "fallocate",
Eric Gourioua596f042011-06-17 09:11:45 +02001566 .type = FIO_OPT_STR,
1567 .off1 = td_var_offset(fallocate_mode),
1568 .help = "Whether pre-allocation is performed when laying out files",
1569 .def = "posix",
1570 .posval = {
1571 { .ival = "none",
1572 .oval = FIO_FALLOCATE_NONE,
1573 .help = "Do not pre-allocate space",
1574 },
1575 { .ival = "posix",
1576 .oval = FIO_FALLOCATE_POSIX,
1577 .help = "Use posix_fallocate()",
1578 },
1579#ifdef FIO_HAVE_LINUX_FALLOCATE
1580 { .ival = "keep",
1581 .oval = FIO_FALLOCATE_KEEP_SIZE,
1582 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1583 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001584#endif
Eric Gourioua596f042011-06-17 09:11:45 +02001585 /* Compatibility with former boolean values */
1586 { .ival = "0",
1587 .oval = FIO_FALLOCATE_NONE,
1588 .help = "Alias for 'none'",
1589 },
1590 { .ival = "1",
1591 .oval = FIO_FALLOCATE_POSIX,
1592 .help = "Alias for 'posix'",
1593 },
1594 },
1595 },
1596#endif /* FIO_HAVE_FALLOCATE */
Jens Axboe67a10002007-07-31 23:12:16 +02001597 {
1598 .name = "fadvise_hint",
1599 .type = FIO_OPT_BOOL,
1600 .off1 = td_var_offset(fadvise_hint),
1601 .help = "Use fadvise() to advise the kernel on IO pattern",
1602 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001603 },
1604 {
1605 .name = "fsync",
1606 .type = FIO_OPT_INT,
1607 .off1 = td_var_offset(fsync_blocks),
1608 .help = "Issue fsync for writes every given number of blocks",
1609 .def = "0",
1610 },
1611 {
Jens Axboe5f9099e2009-06-16 22:40:26 +02001612 .name = "fdatasync",
1613 .type = FIO_OPT_INT,
1614 .off1 = td_var_offset(fdatasync_blocks),
1615 .help = "Issue fdatasync for writes every given number of blocks",
1616 .def = "0",
1617 },
Jens Axboe1ef2b6b2010-10-08 15:07:01 +02001618 {
1619 .name = "write_barrier",
1620 .type = FIO_OPT_INT,
1621 .off1 = td_var_offset(barrier_blocks),
1622 .help = "Make every Nth write a barrier write",
1623 .def = "0",
1624 },
Jens Axboe44f29692010-03-09 20:09:44 +01001625#ifdef FIO_HAVE_SYNC_FILE_RANGE
1626 {
1627 .name = "sync_file_range",
1628 .posval = {
1629 { .ival = "wait_before",
1630 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1631 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001632 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001633 },
1634 { .ival = "write",
1635 .oval = SYNC_FILE_RANGE_WRITE,
1636 .help = "SYNC_FILE_RANGE_WRITE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001637 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001638 },
1639 {
1640 .ival = "wait_after",
1641 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1642 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
Jens Axboe3843deb2010-03-09 20:41:15 +01001643 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001644 },
1645 },
Jens Axboe3843deb2010-03-09 20:41:15 +01001646 .type = FIO_OPT_STR_MULTI,
Jens Axboe44f29692010-03-09 20:09:44 +01001647 .cb = str_sfr_cb,
1648 .off1 = td_var_offset(sync_file_range),
1649 .help = "Use sync_file_range()",
1650 },
1651#endif
Jens Axboe5f9099e2009-06-16 22:40:26 +02001652 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001653 .name = "direct",
1654 .type = FIO_OPT_BOOL,
1655 .off1 = td_var_offset(odirect),
1656 .help = "Use O_DIRECT IO (negates buffered)",
1657 .def = "0",
1658 },
1659 {
1660 .name = "buffered",
1661 .type = FIO_OPT_BOOL,
1662 .off1 = td_var_offset(odirect),
1663 .neg = 1,
1664 .help = "Use buffered IO (negates direct)",
1665 .def = "1",
1666 },
1667 {
1668 .name = "overwrite",
1669 .type = FIO_OPT_BOOL,
1670 .off1 = td_var_offset(overwrite),
1671 .help = "When writing, set whether to overwrite current data",
1672 .def = "0",
1673 },
1674 {
1675 .name = "loops",
1676 .type = FIO_OPT_INT,
1677 .off1 = td_var_offset(loops),
1678 .help = "Number of times to run the job",
1679 .def = "1",
1680 },
1681 {
1682 .name = "numjobs",
1683 .type = FIO_OPT_INT,
1684 .off1 = td_var_offset(numjobs),
1685 .help = "Duplicate this job this many times",
1686 .def = "1",
1687 },
1688 {
1689 .name = "startdelay",
Jens Axboea5737c92010-06-29 10:40:30 +02001690 .type = FIO_OPT_STR_VAL_TIME,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001691 .off1 = td_var_offset(start_delay),
1692 .help = "Only start job when this period has passed",
1693 .def = "0",
1694 },
1695 {
1696 .name = "runtime",
1697 .alias = "timeout",
1698 .type = FIO_OPT_STR_VAL_TIME,
1699 .off1 = td_var_offset(timeout),
1700 .help = "Stop workload when this amount of time has passed",
1701 .def = "0",
1702 },
1703 {
Jens Axboecf4464c2007-04-17 20:14:42 +02001704 .name = "time_based",
1705 .type = FIO_OPT_STR_SET,
1706 .off1 = td_var_offset(time_based),
1707 .help = "Keep running until runtime/timeout is met",
1708 },
1709 {
Jens Axboe721938a2008-09-10 09:46:16 +02001710 .name = "ramp_time",
1711 .type = FIO_OPT_STR_VAL_TIME,
1712 .off1 = td_var_offset(ramp_time),
1713 .help = "Ramp up time before measuring performance",
1714 },
1715 {
Jens Axboec223da82010-03-24 13:23:53 +01001716 .name = "clocksource",
1717 .type = FIO_OPT_STR,
1718 .cb = fio_clock_source_cb,
1719 .off1 = td_var_offset(clocksource),
1720 .help = "What type of timing source to use",
Jens Axboec223da82010-03-24 13:23:53 +01001721 .posval = {
1722 { .ival = "gettimeofday",
1723 .oval = CS_GTOD,
1724 .help = "Use gettimeofday(2) for timing",
1725 },
1726 { .ival = "clock_gettime",
1727 .oval = CS_CGETTIME,
1728 .help = "Use clock_gettime(2) for timing",
1729 },
1730#ifdef ARCH_HAVE_CPU_CLOCK
1731 { .ival = "cpu",
1732 .oval = CS_CPUCLOCK,
1733 .help = "Use CPU private clock",
1734 },
1735#endif
1736 },
1737 },
1738 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001739 .name = "mem",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001740 .alias = "iomem",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001741 .type = FIO_OPT_STR,
1742 .cb = str_mem_cb,
1743 .off1 = td_var_offset(mem_type),
1744 .help = "Backing type for IO buffers",
1745 .def = "malloc",
1746 .posval = {
1747 { .ival = "malloc",
1748 .oval = MEM_MALLOC,
1749 .help = "Use malloc(3) for IO buffers",
1750 },
Jens Axboeb370e462007-03-19 10:51:49 +01001751 { .ival = "shm",
1752 .oval = MEM_SHM,
1753 .help = "Use shared memory segments for IO buffers",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001754 },
1755#ifdef FIO_HAVE_HUGETLB
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001756 { .ival = "shmhuge",
1757 .oval = MEM_SHMHUGE,
1758 .help = "Like shm, but use huge pages",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001759 },
1760#endif
Jens Axboeb370e462007-03-19 10:51:49 +01001761 { .ival = "mmap",
1762 .oval = MEM_MMAP,
1763 .help = "Use mmap(2) (file or anon) for IO buffers",
1764 },
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001765#ifdef FIO_HAVE_HUGETLB
1766 { .ival = "mmaphuge",
1767 .oval = MEM_MMAPHUGE,
1768 .help = "Like mmap, but use huge pages",
1769 },
1770#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001771 },
1772 },
1773 {
Jens Axboed529ee12009-07-01 10:33:03 +02001774 .name = "iomem_align",
1775 .alias = "mem_align",
1776 .type = FIO_OPT_INT,
1777 .off1 = td_var_offset(mem_align),
1778 .minval = 0,
1779 .help = "IO memory buffer offset alignment",
1780 .def = "0",
1781 .parent = "iomem",
1782 },
1783 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001784 .name = "verify",
1785 .type = FIO_OPT_STR,
1786 .off1 = td_var_offset(verify),
1787 .help = "Verify data written",
Jens Axboe5d7c5d32010-06-21 15:08:17 +02001788 .cb = str_verify_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001789 .def = "0",
1790 .posval = {
1791 { .ival = "0",
1792 .oval = VERIFY_NONE,
1793 .help = "Don't do IO verification",
1794 },
Jens Axboefcca4b52007-07-27 15:42:00 +02001795 { .ival = "md5",
1796 .oval = VERIFY_MD5,
1797 .help = "Use md5 checksums for verification",
1798 },
Jens Axboed77a7af2007-07-27 15:35:06 +02001799 { .ival = "crc64",
1800 .oval = VERIFY_CRC64,
1801 .help = "Use crc64 checksums for verification",
1802 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001803 { .ival = "crc32",
1804 .oval = VERIFY_CRC32,
1805 .help = "Use crc32 checksums for verification",
1806 },
Jens Axboeaf497e62008-08-04 15:40:35 +02001807 { .ival = "crc32c-intel",
Jens Axboee3aaafc2012-02-22 20:28:17 +01001808 .oval = VERIFY_CRC32C,
1809 .help = "Use crc32c checksums for verification (hw assisted, if available)",
Jens Axboeaf497e62008-08-04 15:40:35 +02001810 },
Jens Axboebac39e02008-06-11 20:46:19 +02001811 { .ival = "crc32c",
1812 .oval = VERIFY_CRC32C,
Jens Axboee3aaafc2012-02-22 20:28:17 +01001813 .help = "Use crc32c checksums for verification (hw assisted, if available)",
Jens Axboebac39e02008-06-11 20:46:19 +02001814 },
Jens Axboe969f7ed2007-07-27 09:07:17 +02001815 { .ival = "crc16",
1816 .oval = VERIFY_CRC16,
1817 .help = "Use crc16 checksums for verification",
1818 },
Jens Axboe1e154bd2007-07-27 09:52:40 +02001819 { .ival = "crc7",
1820 .oval = VERIFY_CRC7,
1821 .help = "Use crc7 checksums for verification",
1822 },
Jens Axboe7c353ce2009-08-09 22:40:33 +02001823 { .ival = "sha1",
1824 .oval = VERIFY_SHA1,
1825 .help = "Use sha1 checksums for verification",
1826 },
Jens Axboecd14cc12007-07-30 10:59:33 +02001827 { .ival = "sha256",
1828 .oval = VERIFY_SHA256,
1829 .help = "Use sha256 checksums for verification",
1830 },
1831 { .ival = "sha512",
1832 .oval = VERIFY_SHA512,
1833 .help = "Use sha512 checksums for verification",
1834 },
Shawn Lewis7437ee82007-08-02 21:05:58 +02001835 { .ival = "meta",
1836 .oval = VERIFY_META,
1837 .help = "Use io information",
1838 },
Jens Axboe36690c92007-03-26 10:23:34 +02001839 {
1840 .ival = "null",
1841 .oval = VERIFY_NULL,
1842 .help = "Pretend to verify",
1843 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001844 },
1845 },
1846 {
Jens Axboe005c5652007-08-02 22:21:36 +02001847 .name = "do_verify",
Jens Axboe68e1f292007-08-10 10:32:14 +02001848 .type = FIO_OPT_BOOL,
Jens Axboe005c5652007-08-02 22:21:36 +02001849 .off1 = td_var_offset(do_verify),
1850 .help = "Run verification stage after write",
1851 .def = "1",
1852 .parent = "verify",
1853 },
1854 {
Jens Axboe160b9662007-03-27 10:59:49 +02001855 .name = "verifysort",
1856 .type = FIO_OPT_BOOL,
1857 .off1 = td_var_offset(verifysort),
1858 .help = "Sort written verify blocks for read back",
1859 .def = "1",
Jens Axboec83f2df2007-07-31 22:51:47 +02001860 .parent = "verify",
Jens Axboe160b9662007-03-27 10:59:49 +02001861 },
1862 {
Jens Axboea59e1702007-07-30 08:53:27 +02001863 .name = "verify_interval",
Jens Axboee01b22b2009-06-09 15:43:25 +02001864 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001865 .off1 = td_var_offset(verify_interval),
Jens Axboe819a9682007-07-28 21:30:31 +02001866 .minval = 2 * sizeof(struct verify_header),
Jens Axboea59e1702007-07-30 08:53:27 +02001867 .help = "Store verify buffer header every N bytes",
Jens Axboeafdf9352007-07-31 16:14:34 +02001868 .parent = "verify",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +02001869 },
1870 {
Jens Axboea59e1702007-07-30 08:53:27 +02001871 .name = "verify_offset",
Jens Axboee01b22b2009-06-09 15:43:25 +02001872 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001873 .help = "Offset verify header location by N bytes",
Shawn Lewis546a9142007-07-28 21:11:37 +02001874 .def = "0",
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001875 .cb = str_verify_offset_cb,
Jens Axboeafdf9352007-07-31 16:14:34 +02001876 .parent = "verify",
Shawn Lewis546a9142007-07-28 21:11:37 +02001877 },
1878 {
Shawn Lewise28218f2008-01-16 11:01:33 +01001879 .name = "verify_pattern",
Radha Ramachandran0e92f872009-10-27 20:14:27 +01001880 .type = FIO_OPT_STR,
Shawn Lewise28218f2008-01-16 11:01:33 +01001881 .cb = str_verify_pattern_cb,
1882 .help = "Fill pattern for IO buffers",
1883 .parent = "verify",
1884 },
1885 {
Jens Axboea12a3b42007-08-09 10:20:54 +02001886 .name = "verify_fatal",
Jens Axboe68e1f292007-08-10 10:32:14 +02001887 .type = FIO_OPT_BOOL,
Jens Axboea12a3b42007-08-09 10:20:54 +02001888 .off1 = td_var_offset(verify_fatal),
1889 .def = "0",
1890 .help = "Exit on a single verify failure, don't continue",
1891 .parent = "verify",
1892 },
1893 {
Jens Axboeb463e932011-01-12 09:03:23 +01001894 .name = "verify_dump",
1895 .type = FIO_OPT_BOOL,
1896 .off1 = td_var_offset(verify_dump),
Jens Axboeef71e312011-10-25 22:43:36 +02001897 .def = "0",
Jens Axboeb463e932011-01-12 09:03:23 +01001898 .help = "Dump contents of good and bad blocks on failure",
1899 .parent = "verify",
1900 },
1901 {
Jens Axboee8462bd2009-07-06 12:59:04 +02001902 .name = "verify_async",
1903 .type = FIO_OPT_INT,
1904 .off1 = td_var_offset(verify_async),
1905 .def = "0",
1906 .help = "Number of async verifier threads to use",
1907 .parent = "verify",
1908 },
Jens Axboe9e144182010-06-15 14:25:36 +02001909 {
1910 .name = "verify_backlog",
1911 .type = FIO_OPT_STR_VAL,
1912 .off1 = td_var_offset(verify_backlog),
1913 .help = "Verify after this number of blocks are written",
1914 .parent = "verify",
1915 },
1916 {
1917 .name = "verify_backlog_batch",
1918 .type = FIO_OPT_INT,
1919 .off1 = td_var_offset(verify_batch),
1920 .help = "Verify this number of IO blocks",
Jens Axboe0d29de82010-09-01 13:54:15 +02001921 .parent = "verify",
Jens Axboe9e144182010-06-15 14:25:36 +02001922 },
Jens Axboee8462bd2009-07-06 12:59:04 +02001923#ifdef FIO_HAVE_CPU_AFFINITY
1924 {
1925 .name = "verify_async_cpus",
1926 .type = FIO_OPT_STR,
1927 .cb = str_verify_cpus_allowed_cb,
1928 .help = "Set CPUs allowed for async verify threads",
1929 .parent = "verify_async",
1930 },
1931#endif
Jens Axboe0d29de82010-09-01 13:54:15 +02001932#ifdef FIO_HAVE_TRIM
1933 {
1934 .name = "trim_percentage",
1935 .type = FIO_OPT_INT,
1936 .cb = str_verify_trim_cb,
1937 .maxval = 100,
1938 .help = "Number of verify blocks to discard/trim",
1939 .parent = "verify",
1940 .def = "0",
1941 },
1942 {
1943 .name = "trim_verify_zero",
1944 .type = FIO_OPT_INT,
1945 .help = "Verify that trim/discarded blocks are returned as zeroes",
1946 .off1 = td_var_offset(trim_zero),
1947 .parent = "trim_percentage",
1948 .def = "1",
1949 },
1950 {
1951 .name = "trim_backlog",
1952 .type = FIO_OPT_STR_VAL,
1953 .off1 = td_var_offset(trim_backlog),
1954 .help = "Trim after this number of blocks are written",
1955 .parent = "trim_percentage",
1956 },
1957 {
1958 .name = "trim_backlog_batch",
1959 .type = FIO_OPT_INT,
1960 .off1 = td_var_offset(trim_batch),
1961 .help = "Trim this number of IO blocks",
1962 .parent = "trim_percentage",
1963 },
1964#endif
Jens Axboee8462bd2009-07-06 12:59:04 +02001965 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001966 .name = "write_iolog",
1967 .type = FIO_OPT_STR_STORE,
1968 .off1 = td_var_offset(write_iolog_file),
1969 .help = "Store IO pattern to file",
1970 },
1971 {
1972 .name = "read_iolog",
1973 .type = FIO_OPT_STR_STORE,
1974 .off1 = td_var_offset(read_iolog_file),
1975 .help = "Playback IO pattern from file",
1976 },
1977 {
David Nellans64bbb862010-08-24 22:13:30 +02001978 .name = "replay_no_stall",
1979 .type = FIO_OPT_INT,
1980 .off1 = td_var_offset(no_stall),
1981 .def = "0",
Jens Axboe87e7a972010-08-25 09:01:25 +02001982 .parent = "read_iolog",
David Nellans64bbb862010-08-24 22:13:30 +02001983 .help = "Playback IO pattern file as fast as possible without stalls",
1984 },
1985 {
David Nellansd1c46c02010-08-31 21:20:47 +02001986 .name = "replay_redirect",
1987 .type = FIO_OPT_STR_STORE,
1988 .off1 = td_var_offset(replay_redirect),
1989 .parent = "read_iolog",
1990 .help = "Replay all I/O onto this device, regardless of trace device",
1991 },
1992 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001993 .name = "exec_prerun",
1994 .type = FIO_OPT_STR_STORE,
1995 .off1 = td_var_offset(exec_prerun),
1996 .help = "Execute this file prior to running job",
1997 },
1998 {
1999 .name = "exec_postrun",
2000 .type = FIO_OPT_STR_STORE,
2001 .off1 = td_var_offset(exec_postrun),
2002 .help = "Execute this file after running job",
2003 },
2004#ifdef FIO_HAVE_IOSCHED_SWITCH
2005 {
2006 .name = "ioscheduler",
2007 .type = FIO_OPT_STR_STORE,
2008 .off1 = td_var_offset(ioscheduler),
2009 .help = "Use this IO scheduler on the backing device",
2010 },
2011#endif
2012 {
2013 .name = "zonesize",
2014 .type = FIO_OPT_STR_VAL,
2015 .off1 = td_var_offset(zone_size),
Steven Noonaned335852012-01-31 13:58:00 +01002016 .help = "Amount of data to read per zone",
2017 .def = "0",
2018 },
2019 {
2020 .name = "zonerange",
2021 .type = FIO_OPT_STR_VAL,
2022 .off1 = td_var_offset(zone_range),
Jens Axboe214e1ec2007-03-15 10:48:13 +01002023 .help = "Give size of an IO zone",
2024 .def = "0",
2025 },
2026 {
2027 .name = "zoneskip",
2028 .type = FIO_OPT_STR_VAL,
2029 .off1 = td_var_offset(zone_skip),
2030 .help = "Space between IO zones",
2031 .def = "0",
2032 },
2033 {
2034 .name = "lockmem",
2035 .type = FIO_OPT_STR_VAL,
2036 .cb = str_lockmem_cb,
2037 .help = "Lock down this amount of memory",
2038 .def = "0",
2039 },
2040 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002041 .name = "rwmixread",
2042 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02002043 .cb = str_rwmix_read_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002044 .maxval = 100,
2045 .help = "Percentage of mixed workload that is reads",
2046 .def = "50",
2047 },
2048 {
2049 .name = "rwmixwrite",
2050 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02002051 .cb = str_rwmix_write_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002052 .maxval = 100,
2053 .help = "Percentage of mixed workload that is writes",
2054 .def = "50",
2055 },
2056 {
Jens Axboeafdf9352007-07-31 16:14:34 +02002057 .name = "rwmixcycle",
Jens Axboe15ca1502008-04-07 09:26:02 +02002058 .type = FIO_OPT_DEPRECATED,
Jens Axboeafdf9352007-07-31 16:14:34 +02002059 },
2060 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002061 .name = "nice",
2062 .type = FIO_OPT_INT,
2063 .off1 = td_var_offset(nice),
2064 .help = "Set job CPU nice value",
2065 .minval = -19,
2066 .maxval = 20,
2067 .def = "0",
2068 },
2069#ifdef FIO_HAVE_IOPRIO
2070 {
2071 .name = "prio",
2072 .type = FIO_OPT_INT,
2073 .cb = str_prio_cb,
2074 .help = "Set job IO priority value",
2075 .minval = 0,
2076 .maxval = 7,
2077 },
2078 {
2079 .name = "prioclass",
2080 .type = FIO_OPT_INT,
2081 .cb = str_prioclass_cb,
2082 .help = "Set job IO priority class",
2083 .minval = 0,
2084 .maxval = 3,
2085 },
2086#endif
2087 {
2088 .name = "thinktime",
2089 .type = FIO_OPT_INT,
2090 .off1 = td_var_offset(thinktime),
2091 .help = "Idle time between IO buffers (usec)",
2092 .def = "0",
2093 },
2094 {
2095 .name = "thinktime_spin",
2096 .type = FIO_OPT_INT,
2097 .off1 = td_var_offset(thinktime_spin),
2098 .help = "Start think time by spinning this amount (usec)",
2099 .def = "0",
Jens Axboeafdf9352007-07-31 16:14:34 +02002100 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002101 },
2102 {
2103 .name = "thinktime_blocks",
2104 .type = FIO_OPT_INT,
2105 .off1 = td_var_offset(thinktime_blocks),
2106 .help = "IO buffer period between 'thinktime'",
2107 .def = "1",
Jens Axboeafdf9352007-07-31 16:14:34 +02002108 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002109 },
2110 {
2111 .name = "rate",
Jens Axboee01b22b2009-06-09 15:43:25 +02002112 .type = FIO_OPT_INT,
Shaohua Li6eaf09d2012-09-14 08:49:43 +02002113 .off1 = td_var_offset(rate[DDIR_READ]),
2114 .off2 = td_var_offset(rate[DDIR_WRITE]),
2115 .off3 = td_var_offset(rate[DDIR_TRIM]),
Jens Axboe214e1ec2007-03-15 10:48:13 +01002116 .help = "Set bandwidth rate",
2117 },
2118 {
2119 .name = "ratemin",
Jens Axboee01b22b2009-06-09 15:43:25 +02002120 .type = FIO_OPT_INT,
Shaohua Li6eaf09d2012-09-14 08:49:43 +02002121 .off1 = td_var_offset(ratemin[DDIR_READ]),
2122 .off2 = td_var_offset(ratemin[DDIR_WRITE]),
2123 .off3 = td_var_offset(ratemin[DDIR_TRIM]),
Jens Axboe4e991c22007-03-15 11:41:11 +01002124 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02002125 .parent = "rate",
Jens Axboe4e991c22007-03-15 11:41:11 +01002126 },
2127 {
2128 .name = "rate_iops",
Jens Axboee01b22b2009-06-09 15:43:25 +02002129 .type = FIO_OPT_INT,
Shaohua Li6eaf09d2012-09-14 08:49:43 +02002130 .off1 = td_var_offset(rate_iops[DDIR_READ]),
2131 .off2 = td_var_offset(rate_iops[DDIR_WRITE]),
2132 .off3 = td_var_offset(rate_iops[DDIR_TRIM]),
Jens Axboe4e991c22007-03-15 11:41:11 +01002133 .help = "Limit IO used to this number of IO operations/sec",
2134 },
2135 {
2136 .name = "rate_iops_min",
Jens Axboee01b22b2009-06-09 15:43:25 +02002137 .type = FIO_OPT_INT,
Shaohua Li6eaf09d2012-09-14 08:49:43 +02002138 .off1 = td_var_offset(rate_iops_min[DDIR_READ]),
2139 .off2 = td_var_offset(rate_iops_min[DDIR_WRITE]),
2140 .off3 = td_var_offset(rate_iops_min[DDIR_TRIM]),
Bruce Cran03e20d62011-01-02 20:14:54 +01002141 .help = "Job must meet this rate or it will be shut down",
Jens Axboeafdf9352007-07-31 16:14:34 +02002142 .parent = "rate_iops",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002143 },
2144 {
2145 .name = "ratecycle",
2146 .type = FIO_OPT_INT,
2147 .off1 = td_var_offset(ratecycle),
2148 .help = "Window average for rate limits (msec)",
2149 .def = "1000",
Jens Axboeafdf9352007-07-31 16:14:34 +02002150 .parent = "rate",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002151 },
2152 {
Jens Axboe15501532012-10-24 16:37:45 +02002153 .name = "max_latency",
2154 .type = FIO_OPT_INT,
2155 .off1 = td_var_offset(max_latency),
2156 .help = "Maximum tolerated IO latency (usec)",
2157 },
2158 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002159 .name = "invalidate",
2160 .type = FIO_OPT_BOOL,
2161 .off1 = td_var_offset(invalidate_cache),
2162 .help = "Invalidate buffer/page cache prior to running job",
2163 .def = "1",
2164 },
2165 {
2166 .name = "sync",
2167 .type = FIO_OPT_BOOL,
2168 .off1 = td_var_offset(sync_io),
2169 .help = "Use O_SYNC for buffered writes",
2170 .def = "0",
Jens Axboe67a10002007-07-31 23:12:16 +02002171 .parent = "buffered",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002172 },
2173 {
2174 .name = "bwavgtime",
2175 .type = FIO_OPT_INT,
2176 .off1 = td_var_offset(bw_avg_time),
Jens Axboe5ec10ea2008-03-06 15:42:00 +01002177 .help = "Time window over which to calculate bandwidth"
2178 " (msec)",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002179 .def = "500",
Jens Axboec8eeb9d2011-10-05 14:02:22 +02002180 .parent = "write_bw_log",
2181 },
2182 {
2183 .name = "iopsavgtime",
2184 .type = FIO_OPT_INT,
2185 .off1 = td_var_offset(iops_avg_time),
2186 .help = "Time window over which to calculate IOPS (msec)",
2187 .def = "500",
2188 .parent = "write_iops_log",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002189 },
2190 {
2191 .name = "create_serialize",
2192 .type = FIO_OPT_BOOL,
2193 .off1 = td_var_offset(create_serialize),
2194 .help = "Serialize creating of job files",
2195 .def = "1",
2196 },
2197 {
2198 .name = "create_fsync",
2199 .type = FIO_OPT_BOOL,
2200 .off1 = td_var_offset(create_fsync),
Bruce Cran03e20d62011-01-02 20:14:54 +01002201 .help = "fsync file after creation",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002202 .def = "1",
2203 },
2204 {
Jens Axboe814452b2009-03-04 12:53:13 +01002205 .name = "create_on_open",
2206 .type = FIO_OPT_BOOL,
2207 .off1 = td_var_offset(create_on_open),
2208 .help = "Create files when they are opened for IO",
2209 .def = "0",
2210 },
Jens Axboe0b9d69e2009-09-11 22:29:54 +02002211 {
Jens Axboe25460cf2012-05-02 13:58:02 +02002212 .name = "create_only",
2213 .type = FIO_OPT_BOOL,
2214 .off1 = td_var_offset(create_only),
2215 .help = "Only perform file creation phase",
2216 .def = "0",
2217 },
2218 {
Zhang, Yanminafad68f2009-05-20 11:30:55 +02002219 .name = "pre_read",
2220 .type = FIO_OPT_BOOL,
2221 .off1 = td_var_offset(pre_read),
Bruce Cran03e20d62011-01-02 20:14:54 +01002222 .help = "Pre-read files before starting official testing",
Zhang, Yanminafad68f2009-05-20 11:30:55 +02002223 .def = "0",
2224 },
Jens Axboe814452b2009-03-04 12:53:13 +01002225 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002226 .name = "cpuload",
2227 .type = FIO_OPT_INT,
2228 .off1 = td_var_offset(cpuload),
2229 .help = "Use this percentage of CPU",
2230 },
2231 {
2232 .name = "cpuchunks",
2233 .type = FIO_OPT_INT,
2234 .off1 = td_var_offset(cpucycle),
2235 .help = "Length of the CPU burn cycles (usecs)",
2236 .def = "50000",
Jens Axboe67a10002007-07-31 23:12:16 +02002237 .parent = "cpuload",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002238 },
2239#ifdef FIO_HAVE_CPU_AFFINITY
2240 {
2241 .name = "cpumask",
2242 .type = FIO_OPT_INT,
2243 .cb = str_cpumask_cb,
2244 .help = "CPU affinity mask",
2245 },
Jens Axboed2e268b2007-06-15 10:33:49 +02002246 {
2247 .name = "cpus_allowed",
2248 .type = FIO_OPT_STR,
2249 .cb = str_cpus_allowed_cb,
2250 .help = "Set CPUs allowed",
2251 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01002252#endif
Yufei Rend0b937e2012-10-19 23:11:52 -04002253#ifdef FIO_HAVE_LIBNUMA
2254 {
2255 .name = "numa_cpu_nodes",
2256 .type = FIO_OPT_STR,
2257 .cb = str_numa_cpunodes_cb,
2258 .help = "NUMA CPU nodes bind",
2259 },
2260 {
2261 .name = "numa_mem_policy",
2262 .type = FIO_OPT_STR,
2263 .cb = str_numa_mpol_cb,
2264 .help = "NUMA memory policy setup",
2265 },
2266#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01002267 {
2268 .name = "end_fsync",
2269 .type = FIO_OPT_BOOL,
2270 .off1 = td_var_offset(end_fsync),
2271 .help = "Include fsync at the end of job",
2272 .def = "0",
2273 },
2274 {
2275 .name = "fsync_on_close",
2276 .type = FIO_OPT_BOOL,
2277 .off1 = td_var_offset(fsync_on_close),
2278 .help = "fsync files on close",
2279 .def = "0",
2280 },
2281 {
2282 .name = "unlink",
2283 .type = FIO_OPT_BOOL,
2284 .off1 = td_var_offset(unlink),
2285 .help = "Unlink created files after job has completed",
2286 .def = "0",
2287 },
2288 {
2289 .name = "exitall",
2290 .type = FIO_OPT_STR_SET,
2291 .cb = str_exitall_cb,
2292 .help = "Terminate all jobs when one exits",
2293 },
2294 {
2295 .name = "stonewall",
Jens Axboed3923652011-08-03 12:38:39 +02002296 .alias = "wait_for_previous",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002297 .type = FIO_OPT_STR_SET,
2298 .off1 = td_var_offset(stonewall),
2299 .help = "Insert a hard barrier between this job and previous",
2300 },
2301 {
Jens Axboeb3d62a72007-03-20 14:23:26 +01002302 .name = "new_group",
2303 .type = FIO_OPT_STR_SET,
2304 .off1 = td_var_offset(new_group),
2305 .help = "Mark the start of a new group (for reporting)",
2306 },
2307 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002308 .name = "thread",
2309 .type = FIO_OPT_STR_SET,
2310 .off1 = td_var_offset(use_thread),
2311 .help = "Use threads instead of forks",
2312 },
2313 {
2314 .name = "write_bw_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01002315 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002316 .off1 = td_var_offset(write_bw_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01002317 .cb = str_write_bw_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002318 .help = "Write log of bandwidth during run",
2319 },
2320 {
2321 .name = "write_lat_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01002322 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002323 .off1 = td_var_offset(write_lat_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01002324 .cb = str_write_lat_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002325 .help = "Write log of latency during run",
2326 },
2327 {
Jens Axboec8eeb9d2011-10-05 14:02:22 +02002328 .name = "write_iops_log",
2329 .type = FIO_OPT_STR,
2330 .off1 = td_var_offset(write_iops_log),
2331 .cb = str_write_iops_log_cb,
2332 .help = "Write log of IOPS during run",
2333 },
2334 {
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01002335 .name = "log_avg_msec",
2336 .type = FIO_OPT_INT,
2337 .off1 = td_var_offset(log_avg_msec),
2338 .help = "Average bw/iops/lat logs over this period of time",
2339 .def = "0",
2340 },
2341 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002342 .name = "hugepage-size",
Jens Axboee01b22b2009-06-09 15:43:25 +02002343 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002344 .off1 = td_var_offset(hugepage_size),
2345 .help = "When using hugepages, specify size of each page",
Jens Axboe81179ee2011-10-04 12:42:06 +02002346 .def = __fio_stringify(FIO_HUGE_PAGE),
Jens Axboe214e1ec2007-03-15 10:48:13 +01002347 },
2348 {
2349 .name = "group_reporting",
2350 .type = FIO_OPT_STR_SET,
2351 .off1 = td_var_offset(group_reporting),
2352 .help = "Do reporting on a per-group basis",
2353 },
2354 {
Jens Axboee9459e52007-04-17 15:46:32 +02002355 .name = "zero_buffers",
2356 .type = FIO_OPT_STR_SET,
2357 .off1 = td_var_offset(zero_buffers),
2358 .help = "Init IO buffers to all zeroes",
2359 },
Jens Axboe5973caf2008-05-21 19:52:35 +02002360 {
2361 .name = "refill_buffers",
2362 .type = FIO_OPT_STR_SET,
2363 .off1 = td_var_offset(refill_buffers),
2364 .help = "Refill IO buffers on every IO submit",
2365 },
Yu-ju Hong83349192011-08-13 00:53:44 +02002366 {
Jens Axboefd684182011-09-19 09:24:44 +02002367 .name = "scramble_buffers",
2368 .type = FIO_OPT_BOOL,
2369 .off1 = td_var_offset(scramble_buffers),
2370 .help = "Slightly scramble buffers on every IO submit",
2371 .def = "1",
2372 },
2373 {
Jens Axboe9c426842012-03-02 21:02:12 +01002374 .name = "buffer_compress_percentage",
2375 .type = FIO_OPT_INT,
2376 .off1 = td_var_offset(compress_percentage),
2377 .maxval = 100,
2378 .minval = 1,
2379 .help = "How compressible the buffer is (approximately)",
2380 },
2381 {
Jens Axboef97a43a2012-03-09 19:06:24 +01002382 .name = "buffer_compress_chunk",
2383 .type = FIO_OPT_INT,
2384 .off1 = td_var_offset(compress_chunk),
Jens Axboe207b18e2012-03-09 19:11:25 +01002385 .parent = "buffer_compress_percentage",
Jens Axboef97a43a2012-03-09 19:06:24 +01002386 .help = "Size of compressible region in buffer",
2387 },
2388 {
Yu-ju Hong83349192011-08-13 00:53:44 +02002389 .name = "clat_percentiles",
2390 .type = FIO_OPT_BOOL,
2391 .off1 = td_var_offset(clat_percentiles),
2392 .help = "Enable the reporting of completion latency percentiles",
Jens Axboe467b35e2011-10-13 08:53:24 +02002393 .def = "1",
Yu-ju Hong83349192011-08-13 00:53:44 +02002394 },
2395 {
2396 .name = "percentile_list",
2397 .type = FIO_OPT_FLOAT_LIST,
2398 .off1 = td_var_offset(percentile_list),
2399 .off2 = td_var_offset(overwrite_plist),
2400 .help = "Specify a custom list of percentiles to report",
2401 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2402 .minfp = 0.0,
2403 .maxfp = 100.0,
2404 },
2405
Jens Axboe0a839f32007-04-26 09:02:34 +02002406#ifdef FIO_HAVE_DISK_UTIL
2407 {
2408 .name = "disk_util",
2409 .type = FIO_OPT_BOOL,
2410 .off1 = td_var_offset(do_disk_util),
Jens Axboef66ab3c2008-06-05 11:48:22 +02002411 .help = "Log disk utilization statistics",
Jens Axboe0a839f32007-04-26 09:02:34 +02002412 .def = "1",
2413 },
2414#endif
Jens Axboee9459e52007-04-17 15:46:32 +02002415 {
Jens Axboe993bf482008-11-14 13:04:53 +01002416 .name = "gtod_reduce",
2417 .type = FIO_OPT_BOOL,
2418 .help = "Greatly reduce number of gettimeofday() calls",
2419 .cb = str_gtod_reduce_cb,
2420 .def = "0",
2421 },
2422 {
Jens Axboe02af0982010-06-24 09:59:34 +02002423 .name = "disable_lat",
2424 .type = FIO_OPT_BOOL,
2425 .off1 = td_var_offset(disable_lat),
2426 .help = "Disable latency numbers",
2427 .parent = "gtod_reduce",
2428 .def = "0",
2429 },
2430 {
Jens Axboe9520ebb2008-10-16 21:03:27 +02002431 .name = "disable_clat",
2432 .type = FIO_OPT_BOOL,
2433 .off1 = td_var_offset(disable_clat),
2434 .help = "Disable completion latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01002435 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002436 .def = "0",
2437 },
2438 {
2439 .name = "disable_slat",
2440 .type = FIO_OPT_BOOL,
2441 .off1 = td_var_offset(disable_slat),
Bruce Cran03e20d62011-01-02 20:14:54 +01002442 .help = "Disable submission latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01002443 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002444 .def = "0",
2445 },
2446 {
2447 .name = "disable_bw_measurement",
2448 .type = FIO_OPT_BOOL,
2449 .off1 = td_var_offset(disable_bw),
2450 .help = "Disable bandwidth logging",
Jens Axboe993bf482008-11-14 13:04:53 +01002451 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002452 .def = "0",
2453 },
2454 {
Jens Axboebe4ecfd2008-12-08 14:10:52 +01002455 .name = "gtod_cpu",
2456 .type = FIO_OPT_INT,
2457 .cb = str_gtod_cpu_cb,
Bruce Cran03e20d62011-01-02 20:14:54 +01002458 .help = "Set up dedicated gettimeofday() thread on this CPU",
Jens Axboe29d43ff2009-07-01 10:42:18 +02002459 .verify = gtod_cpu_verify,
Jens Axboebe4ecfd2008-12-08 14:10:52 +01002460 },
2461 {
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002462 .name = "continue_on_error",
Steven Lang06842022011-11-17 09:45:17 +01002463 .type = FIO_OPT_STR,
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002464 .off1 = td_var_offset(continue_on_error),
Bruce Cran03e20d62011-01-02 20:14:54 +01002465 .help = "Continue on non-fatal errors during IO",
Steven Lang06842022011-11-17 09:45:17 +01002466 .def = "none",
2467 .posval = {
2468 { .ival = "none",
2469 .oval = ERROR_TYPE_NONE,
2470 .help = "Exit when an error is encountered",
2471 },
2472 { .ival = "read",
2473 .oval = ERROR_TYPE_READ,
2474 .help = "Continue on read errors only",
2475 },
2476 { .ival = "write",
2477 .oval = ERROR_TYPE_WRITE,
2478 .help = "Continue on write errors only",
2479 },
2480 { .ival = "io",
2481 .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2482 .help = "Continue on any IO errors",
2483 },
2484 { .ival = "verify",
2485 .oval = ERROR_TYPE_VERIFY,
2486 .help = "Continue on verify errors only",
2487 },
2488 { .ival = "all",
2489 .oval = ERROR_TYPE_ANY,
2490 .help = "Continue on all io and verify errors",
2491 },
2492 { .ival = "0",
2493 .oval = ERROR_TYPE_NONE,
2494 .help = "Alias for 'none'",
2495 },
2496 { .ival = "1",
2497 .oval = ERROR_TYPE_ANY,
2498 .help = "Alias for 'all'",
2499 },
2500 },
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002501 },
2502 {
Dmitry Monakhov8b28bd42012-09-23 15:46:09 +04002503 .name = "ignore_error",
2504 .type = FIO_OPT_STR,
2505 .cb = str_ignore_error_cb,
2506 .help = "Set a specific list of errors to ignore",
2507 .parent = "rw",
2508 },
2509 {
2510 .name = "error_dump",
2511 .type = FIO_OPT_BOOL,
2512 .off1 = td_var_offset(error_dump),
2513 .def = "0",
2514 .help = "Dump info on each error",
2515 },
2516
2517 {
Jens Axboe9ac8a792009-11-13 21:23:07 +01002518 .name = "profile",
Jens Axboe79d16312010-03-04 12:43:20 +01002519 .type = FIO_OPT_STR_STORE,
Jens Axboe9ac8a792009-11-13 21:23:07 +01002520 .off1 = td_var_offset(profile),
Jens Axboe9ac8a792009-11-13 21:23:07 +01002521 .help = "Select a specific builtin performance test",
2522 },
2523 {
Jens Axboea696fa22009-12-04 10:05:02 +01002524 .name = "cgroup",
2525 .type = FIO_OPT_STR_STORE,
2526 .off1 = td_var_offset(cgroup),
2527 .help = "Add job to cgroup of this name",
2528 },
2529 {
2530 .name = "cgroup_weight",
2531 .type = FIO_OPT_INT,
2532 .off1 = td_var_offset(cgroup_weight),
2533 .help = "Use given weight for cgroup",
2534 .minval = 100,
2535 .maxval = 1000,
Jens Axboea696fa22009-12-04 10:05:02 +01002536 },
2537 {
Vivek Goyal7de87092010-03-31 22:55:15 +02002538 .name = "cgroup_nodelete",
2539 .type = FIO_OPT_BOOL,
2540 .off1 = td_var_offset(cgroup_nodelete),
2541 .help = "Do not delete cgroups after job completion",
2542 .def = "0",
2543 },
2544 {
Jens Axboee0b0d892009-12-08 10:10:14 +01002545 .name = "uid",
2546 .type = FIO_OPT_INT,
2547 .off1 = td_var_offset(uid),
2548 .help = "Run job with this user ID",
2549 },
2550 {
2551 .name = "gid",
2552 .type = FIO_OPT_INT,
2553 .off1 = td_var_offset(gid),
2554 .help = "Run job with this group ID",
2555 },
2556 {
Dan Ehrenberg9e684a42012-02-20 11:05:14 +01002557 .name = "flow_id",
2558 .type = FIO_OPT_INT,
2559 .off1 = td_var_offset(flow_id),
2560 .help = "The flow index ID to use",
2561 .def = "0",
2562 },
2563 {
2564 .name = "flow",
2565 .type = FIO_OPT_INT,
2566 .off1 = td_var_offset(flow),
2567 .help = "Weight for flow control of this job",
2568 .parent = "flow_id",
2569 .def = "0",
2570 },
2571 {
2572 .name = "flow_watermark",
2573 .type = FIO_OPT_INT,
2574 .off1 = td_var_offset(flow_watermark),
2575 .help = "High watermark for flow control. This option"
2576 " should be set to the same value for all threads"
2577 " with non-zero flow.",
2578 .parent = "flow_id",
2579 .def = "1024",
2580 },
2581 {
2582 .name = "flow_sleep",
2583 .type = FIO_OPT_INT,
2584 .off1 = td_var_offset(flow_sleep),
2585 .help = "How many microseconds to sleep after being held"
2586 " back by the flow control mechanism",
2587 .parent = "flow_id",
2588 .def = "0",
2589 },
2590 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002591 .name = NULL,
2592 },
2593};
2594
Jens Axboe17af15d2010-04-13 10:38:16 +02002595static void add_to_lopt(struct option *lopt, struct fio_option *o,
Steven Langde890a12011-11-09 14:03:34 +01002596 const char *name, int val)
Jens Axboe9f817362010-03-04 14:38:10 +01002597{
Jens Axboe17af15d2010-04-13 10:38:16 +02002598 lopt->name = (char *) name;
Steven Langde890a12011-11-09 14:03:34 +01002599 lopt->val = val;
Jens Axboe9f817362010-03-04 14:38:10 +01002600 if (o->type == FIO_OPT_STR_SET)
2601 lopt->has_arg = no_argument;
2602 else
2603 lopt->has_arg = required_argument;
2604}
2605
Steven Langde890a12011-11-09 14:03:34 +01002606static void options_to_lopts(struct fio_option *opts,
2607 struct option *long_options,
2608 int i, int option_type)
2609{
2610 struct fio_option *o = &opts[0];
2611 while (o->name) {
2612 add_to_lopt(&long_options[i], o, o->name, option_type);
2613 if (o->alias) {
2614 i++;
2615 add_to_lopt(&long_options[i], o, o->alias, option_type);
2616 }
2617
2618 i++;
2619 o++;
2620 assert(i < FIO_NR_OPTIONS);
2621 }
2622}
2623
2624void fio_options_set_ioengine_opts(struct option *long_options,
2625 struct thread_data *td)
2626{
2627 unsigned int i;
2628
2629 i = 0;
2630 while (long_options[i].name) {
2631 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2632 memset(&long_options[i], 0, sizeof(*long_options));
2633 break;
2634 }
2635 i++;
2636 }
2637
2638 /*
2639 * Just clear out the prior ioengine options.
2640 */
2641 if (!td || !td->eo)
2642 return;
2643
2644 options_to_lopts(td->io_ops->options, long_options, i,
2645 FIO_GETOPT_IOENGINE);
2646}
2647
Jens Axboe214e1ec2007-03-15 10:48:13 +01002648void fio_options_dup_and_init(struct option *long_options)
2649{
Jens Axboe214e1ec2007-03-15 10:48:13 +01002650 unsigned int i;
2651
2652 options_init(options);
2653
2654 i = 0;
2655 while (long_options[i].name)
2656 i++;
2657
Steven Langde890a12011-11-09 14:03:34 +01002658 options_to_lopts(options, long_options, i, FIO_GETOPT_JOB);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002659}
2660
Jens Axboe74929ac2009-08-05 11:42:37 +02002661struct fio_keyword {
2662 const char *word;
2663 const char *desc;
2664 char *replace;
2665};
2666
2667static struct fio_keyword fio_keywords[] = {
2668 {
2669 .word = "$pagesize",
2670 .desc = "Page size in the system",
2671 },
2672 {
2673 .word = "$mb_memory",
2674 .desc = "Megabytes of memory online",
2675 },
2676 {
2677 .word = "$ncpus",
2678 .desc = "Number of CPUs online in the system",
2679 },
2680 {
2681 .word = NULL,
2682 },
2683};
2684
2685void fio_keywords_init(void)
2686{
Jens Axboe3b2e1462009-12-15 08:58:10 +01002687 unsigned long long mb_memory;
Jens Axboe74929ac2009-08-05 11:42:37 +02002688 char buf[128];
2689 long l;
2690
Jens Axboea4cfc472012-10-09 10:30:48 -06002691 sprintf(buf, "%lu", (unsigned long) page_size);
Jens Axboe74929ac2009-08-05 11:42:37 +02002692 fio_keywords[0].replace = strdup(buf);
2693
Jens Axboe8eb016d2011-07-11 10:24:20 +02002694 mb_memory = os_phys_mem() / (1024 * 1024);
Jens Axboe3b2e1462009-12-15 08:58:10 +01002695 sprintf(buf, "%llu", mb_memory);
Jens Axboe74929ac2009-08-05 11:42:37 +02002696 fio_keywords[1].replace = strdup(buf);
2697
Jens Axboec00a2282011-07-08 20:56:06 +02002698 l = cpus_online();
Jens Axboe74929ac2009-08-05 11:42:37 +02002699 sprintf(buf, "%lu", l);
2700 fio_keywords[2].replace = strdup(buf);
2701}
2702
Jens Axboe892a6ff2009-11-13 12:19:49 +01002703#define BC_APP "bc"
2704
2705static char *bc_calc(char *str)
2706{
Steven Langd0c814e2011-10-28 08:37:13 +02002707 char buf[128], *tmp;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002708 FILE *f;
2709 int ret;
2710
2711 /*
2712 * No math, just return string
2713 */
Steven Langd0c814e2011-10-28 08:37:13 +02002714 if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2715 !strchr(str, '/')) || strchr(str, '\''))
Jens Axboe892a6ff2009-11-13 12:19:49 +01002716 return str;
2717
2718 /*
2719 * Split option from value, we only need to calculate the value
2720 */
2721 tmp = strchr(str, '=');
2722 if (!tmp)
2723 return str;
2724
2725 tmp++;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002726
Steven Langd0c814e2011-10-28 08:37:13 +02002727 /*
2728 * Prevent buffer overflows; such a case isn't reasonable anyway
2729 */
2730 if (strlen(str) >= 128 || strlen(tmp) > 100)
2731 return str;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002732
2733 sprintf(buf, "which %s > /dev/null", BC_APP);
2734 if (system(buf)) {
2735 log_err("fio: bc is needed for performing math\n");
Jens Axboe892a6ff2009-11-13 12:19:49 +01002736 return NULL;
2737 }
2738
Steven Langd0c814e2011-10-28 08:37:13 +02002739 sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002740 f = popen(buf, "r");
2741 if (!f) {
Jens Axboe892a6ff2009-11-13 12:19:49 +01002742 return NULL;
2743 }
2744
Steven Langd0c814e2011-10-28 08:37:13 +02002745 ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002746 if (ret <= 0) {
Jens Axboe892a6ff2009-11-13 12:19:49 +01002747 return NULL;
2748 }
2749
Jens Axboe892a6ff2009-11-13 12:19:49 +01002750 pclose(f);
Steven Langd0c814e2011-10-28 08:37:13 +02002751 buf[(tmp - str) + ret - 1] = '\0';
2752 memcpy(buf, str, tmp - str);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002753 free(str);
Steven Langd0c814e2011-10-28 08:37:13 +02002754 return strdup(buf);
2755}
2756
2757/*
2758 * Return a copy of the input string with substrings of the form ${VARNAME}
2759 * substituted with the value of the environment variable VARNAME. The
2760 * substitution always occurs, even if VARNAME is empty or the corresponding
2761 * environment variable undefined.
2762 */
2763static char *option_dup_subs(const char *opt)
2764{
2765 char out[OPT_LEN_MAX+1];
2766 char in[OPT_LEN_MAX+1];
2767 char *outptr = out;
2768 char *inptr = in;
2769 char *ch1, *ch2, *env;
2770 ssize_t nchr = OPT_LEN_MAX;
2771 size_t envlen;
2772
2773 if (strlen(opt) + 1 > OPT_LEN_MAX) {
2774 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2775 return NULL;
2776 }
2777
2778 in[OPT_LEN_MAX] = '\0';
2779 strncpy(in, opt, OPT_LEN_MAX);
2780
2781 while (*inptr && nchr > 0) {
2782 if (inptr[0] == '$' && inptr[1] == '{') {
2783 ch2 = strchr(inptr, '}');
2784 if (ch2 && inptr+1 < ch2) {
2785 ch1 = inptr+2;
2786 inptr = ch2+1;
2787 *ch2 = '\0';
2788
2789 env = getenv(ch1);
2790 if (env) {
2791 envlen = strlen(env);
2792 if (envlen <= nchr) {
2793 memcpy(outptr, env, envlen);
2794 outptr += envlen;
2795 nchr -= envlen;
2796 }
2797 }
2798
2799 continue;
2800 }
2801 }
2802
2803 *outptr++ = *inptr++;
2804 --nchr;
2805 }
2806
2807 *outptr = '\0';
2808 return strdup(out);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002809}
2810
Jens Axboe74929ac2009-08-05 11:42:37 +02002811/*
2812 * Look for reserved variable names and replace them with real values
2813 */
2814static char *fio_keyword_replace(char *opt)
2815{
2816 char *s;
2817 int i;
Steven Langd0c814e2011-10-28 08:37:13 +02002818 int docalc = 0;
Jens Axboe74929ac2009-08-05 11:42:37 +02002819
2820 for (i = 0; fio_keywords[i].word != NULL; i++) {
2821 struct fio_keyword *kw = &fio_keywords[i];
2822
2823 while ((s = strstr(opt, kw->word)) != NULL) {
2824 char *new = malloc(strlen(opt) + 1);
2825 char *o_org = opt;
2826 int olen = s - opt;
2827 int len;
2828
2829 /*
2830 * Copy part of the string before the keyword and
2831 * sprintf() the replacement after it.
2832 */
2833 memcpy(new, opt, olen);
2834 len = sprintf(new + olen, "%s", kw->replace);
2835
2836 /*
2837 * If there's more in the original string, copy that
2838 * in too
2839 */
2840 opt += strlen(kw->word) + olen;
2841 if (strlen(opt))
2842 memcpy(new + olen + len, opt, opt - o_org - 1);
2843
2844 /*
2845 * replace opt and free the old opt
2846 */
2847 opt = new;
Steven Langd0c814e2011-10-28 08:37:13 +02002848 free(o_org);
Jens Axboe7a958bd2009-11-13 12:33:54 +01002849
Steven Langd0c814e2011-10-28 08:37:13 +02002850 docalc = 1;
Jens Axboe74929ac2009-08-05 11:42:37 +02002851 }
2852 }
2853
Steven Langd0c814e2011-10-28 08:37:13 +02002854 /*
2855 * Check for potential math and invoke bc, if possible
2856 */
2857 if (docalc)
2858 opt = bc_calc(opt);
2859
Jens Axboe7a958bd2009-11-13 12:33:54 +01002860 return opt;
Jens Axboe74929ac2009-08-05 11:42:37 +02002861}
2862
Steven Langd0c814e2011-10-28 08:37:13 +02002863static char **dup_and_sub_options(char **opts, int num_opts)
2864{
2865 int i;
2866 char **opts_copy = malloc(num_opts * sizeof(*opts));
2867 for (i = 0; i < num_opts; i++) {
2868 opts_copy[i] = option_dup_subs(opts[i]);
2869 if (!opts_copy[i])
2870 continue;
2871 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2872 }
2873 return opts_copy;
2874}
2875
Jens Axboe3b8b7132008-06-10 19:46:23 +02002876int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
Jens Axboe214e1ec2007-03-15 10:48:13 +01002877{
Steven Langde890a12011-11-09 14:03:34 +01002878 int i, ret, unknown;
Steven Langd0c814e2011-10-28 08:37:13 +02002879 char **opts_copy;
Jens Axboe3b8b7132008-06-10 19:46:23 +02002880
2881 sort_options(opts, options, num_opts);
Steven Langd0c814e2011-10-28 08:37:13 +02002882 opts_copy = dup_and_sub_options(opts, num_opts);
Jens Axboe3b8b7132008-06-10 19:46:23 +02002883
Steven Langde890a12011-11-09 14:03:34 +01002884 for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
2885 struct fio_option *o;
2886 int newret = parse_option(opts_copy[i], opts[i], options, &o,
2887 td);
Steven Langd0c814e2011-10-28 08:37:13 +02002888
Steven Langde890a12011-11-09 14:03:34 +01002889 if (opts_copy[i]) {
2890 if (newret && !o) {
2891 unknown++;
2892 continue;
2893 }
Steven Langd0c814e2011-10-28 08:37:13 +02002894 free(opts_copy[i]);
Steven Langde890a12011-11-09 14:03:34 +01002895 opts_copy[i] = NULL;
2896 }
2897
2898 ret |= newret;
2899 }
2900
2901 if (unknown) {
2902 ret |= ioengine_load(td);
2903 if (td->eo) {
2904 sort_options(opts_copy, td->io_ops->options, num_opts);
2905 opts = opts_copy;
2906 }
2907 for (i = 0; i < num_opts; i++) {
2908 struct fio_option *o = NULL;
2909 int newret = 1;
2910 if (!opts_copy[i])
2911 continue;
2912
2913 if (td->eo)
2914 newret = parse_option(opts_copy[i], opts[i],
2915 td->io_ops->options, &o,
2916 td->eo);
2917
2918 ret |= newret;
2919 if (!o)
2920 log_err("Bad option <%s>\n", opts[i]);
2921
2922 free(opts_copy[i]);
2923 opts_copy[i] = NULL;
2924 }
Jens Axboe74929ac2009-08-05 11:42:37 +02002925 }
Jens Axboe3b8b7132008-06-10 19:46:23 +02002926
Steven Langd0c814e2011-10-28 08:37:13 +02002927 free(opts_copy);
Jens Axboe3b8b7132008-06-10 19:46:23 +02002928 return ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +01002929}
2930
2931int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2932{
Jens Axboe07b32322010-03-05 09:48:44 +01002933 return parse_cmd_option(opt, val, options, td);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002934}
2935
Steven Langde890a12011-11-09 14:03:34 +01002936int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
2937 char *val)
2938{
2939 return parse_cmd_option(opt, val, td->io_ops->options, td);
2940}
2941
Jens Axboe214e1ec2007-03-15 10:48:13 +01002942void fio_fill_default_options(struct thread_data *td)
2943{
2944 fill_default_options(td, options);
2945}
2946
2947int fio_show_option_help(const char *opt)
2948{
Jens Axboe07b32322010-03-05 09:48:44 +01002949 return show_cmd_help(options, opt);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002950}
Jens Axboed23bb322007-03-23 15:57:56 +01002951
Steven Langde890a12011-11-09 14:03:34 +01002952void options_mem_dupe(void *data, struct fio_option *options)
2953{
2954 struct fio_option *o;
2955 char **ptr;
2956
2957 for (o = &options[0]; o->name; o++) {
2958 if (o->type != FIO_OPT_STR_STORE)
2959 continue;
2960
2961 ptr = td_var(data, o->off1);
2962 if (*ptr)
2963 *ptr = strdup(*ptr);
2964 }
2965}
2966
Jens Axboe7e356b22011-10-14 10:55:16 +02002967/*
2968 * dupe FIO_OPT_STR_STORE options
2969 */
Steven Langde890a12011-11-09 14:03:34 +01002970void fio_options_mem_dupe(struct thread_data *td)
Jens Axboed23bb322007-03-23 15:57:56 +01002971{
Steven Langde890a12011-11-09 14:03:34 +01002972 options_mem_dupe(&td->o, options);
Jens Axboe1647f592011-11-09 20:25:21 +01002973
2974 if (td->eo && td->io_ops) {
Steven Langde890a12011-11-09 14:03:34 +01002975 void *oldeo = td->eo;
Jens Axboe1647f592011-11-09 20:25:21 +01002976
Steven Langde890a12011-11-09 14:03:34 +01002977 td->eo = malloc(td->io_ops->option_struct_size);
2978 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
2979 options_mem_dupe(td->eo, td->io_ops->options);
Jens Axboed23bb322007-03-23 15:57:56 +01002980 }
2981}
2982
Jens Axboed6978a32009-07-18 21:04:09 +02002983unsigned int fio_get_kb_base(void *data)
2984{
2985 struct thread_data *td = data;
2986 unsigned int kb_base = 0;
2987
2988 if (td)
2989 kb_base = td->o.kb_base;
2990 if (!kb_base)
2991 kb_base = 1024;
2992
2993 return kb_base;
2994}
Jens Axboe9f988e22010-03-04 10:42:38 +01002995
Jens Axboe07b32322010-03-05 09:48:44 +01002996int add_option(struct fio_option *o)
Jens Axboe9f988e22010-03-04 10:42:38 +01002997{
Jens Axboe07b32322010-03-05 09:48:44 +01002998 struct fio_option *__o;
2999 int opt_index = 0;
3000
3001 __o = options;
3002 while (__o->name) {
3003 opt_index++;
3004 __o++;
3005 }
3006
3007 memcpy(&options[opt_index], o, sizeof(*o));
3008 return 0;
Jens Axboe9f988e22010-03-04 10:42:38 +01003009}
Jens Axboee2de69d2010-03-04 14:05:48 +01003010
Jens Axboe07b32322010-03-05 09:48:44 +01003011void invalidate_profile_options(const char *prof_name)
Jens Axboee2de69d2010-03-04 14:05:48 +01003012{
Jens Axboe07b32322010-03-05 09:48:44 +01003013 struct fio_option *o;
Jens Axboee2de69d2010-03-04 14:05:48 +01003014
Jens Axboe07b32322010-03-05 09:48:44 +01003015 o = options;
3016 while (o->name) {
3017 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
3018 o->type = FIO_OPT_INVALID;
3019 o->prof_name = NULL;
3020 }
3021 o++;
Jens Axboee2de69d2010-03-04 14:05:48 +01003022 }
3023}
Jens Axboef5b6bb82010-03-05 10:09:59 +01003024
3025void add_opt_posval(const char *optname, const char *ival, const char *help)
3026{
3027 struct fio_option *o;
3028 unsigned int i;
3029
3030 o = find_option(options, optname);
3031 if (!o)
3032 return;
3033
3034 for (i = 0; i < PARSE_MAX_VP; i++) {
3035 if (o->posval[i].ival)
3036 continue;
3037
3038 o->posval[i].ival = ival;
3039 o->posval[i].help = help;
3040 break;
3041 }
3042}
3043
3044void del_opt_posval(const char *optname, const char *ival)
3045{
3046 struct fio_option *o;
3047 unsigned int i;
3048
3049 o = find_option(options, optname);
3050 if (!o)
3051 return;
3052
3053 for (i = 0; i < PARSE_MAX_VP; i++) {
3054 if (!o->posval[i].ival)
3055 continue;
3056 if (strcmp(o->posval[i].ival, ival))
3057 continue;
3058
3059 o->posval[i].ival = NULL;
3060 o->posval[i].help = NULL;
3061 }
3062}
Jens Axboe7e356b22011-10-14 10:55:16 +02003063
3064void fio_options_free(struct thread_data *td)
3065{
3066 options_free(options, td);
Steven Langde890a12011-11-09 14:03:34 +01003067 if (td->eo && td->io_ops && td->io_ops->options) {
3068 options_free(td->io_ops->options, td->eo);
3069 free(td->eo);
3070 td->eo = NULL;
3071 }
Jens Axboe7e356b22011-10-14 10:55:16 +02003072}