server: include number of CPUs in probe reply
[fio.git] / options.c
CommitLineData
214e1eca
JA
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <ctype.h>
5#include <string.h>
214e1eca 6#include <assert.h>
921c766f 7#include <libgen.h>
5921e80c
JA
8#include <fcntl.h>
9#include <sys/types.h>
10#include <sys/stat.h>
214e1eca
JA
11
12#include "fio.h"
4f5af7b2 13#include "verify.h"
214e1eca 14#include "parse.h"
eef32359 15#include "lib/fls.h"
9f988e2e 16#include "options.h"
214e1eca 17
5d7c5d34
JA
18#include "crc/crc32c.h"
19
214e1eca
JA
20/*
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
0e92f873
RR
36static int converthexchartoint(char a)
37{
38 int base;
39
3c3ed070 40 switch (a) {
0e92f873
RR
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 }
3c3ed070 53 return a - base;
0e92f873
RR
54}
55
564ca972
JA
56static 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
83ea422a 64static int bssplit_ddir(struct thread_options *o, int ddir, char *str)
564ca972 65{
720e84ad 66 struct bssplit *bssplit;
564ca972
JA
67 unsigned int i, perc, perc_missing;
68 unsigned int max_bs, min_bs;
69 long long val;
720e84ad 70 char *fname;
564ca972 71
83ea422a 72 o->bssplit_nr[ddir] = 4;
720e84ad 73 bssplit = malloc(4 * sizeof(struct bssplit));
564ca972
JA
74
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 */
83ea422a
JA
87 if (i == o->bssplit_nr[ddir]) {
88 o->bssplit_nr[ddir] <<= 1;
89 bssplit = realloc(bssplit, o->bssplit_nr[ddir]
5ec10eaa 90 * sizeof(struct bssplit));
564ca972
JA
91 }
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
83ea422a 105 if (str_to_decimal(fname, &val, 1, o)) {
564ca972 106 log_err("fio: bssplit conversion failed\n");
83ea422a 107 free(o->bssplit);
564ca972
JA
108 return 1;
109 }
110
111 if (val > max_bs)
112 max_bs = val;
113 if (val < min_bs)
114 min_bs = val;
115
720e84ad
JA
116 bssplit[i].bs = val;
117 bssplit[i].perc = perc;
564ca972
JA
118 i++;
119 }
120
83ea422a 121 o->bssplit_nr[ddir] = i;
564ca972
JA
122
123 /*
124 * Now check if the percentages add up, and how much is missing
125 */
126 perc = perc_missing = 0;
83ea422a 127 for (i = 0; i < o->bssplit_nr[ddir]; i++) {
720e84ad 128 struct bssplit *bsp = &bssplit[i];
564ca972
JA
129
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");
720e84ad 138 free(bssplit);
564ca972
JA
139 return 1;
140 }
141 /*
142 * If values didn't have a percentage set, divide the remains between
143 * them.
144 */
145 if (perc_missing) {
83ea422a 146 for (i = 0; i < o->bssplit_nr[ddir]; i++) {
720e84ad 147 struct bssplit *bsp = &bssplit[i];
564ca972
JA
148
149 if (bsp->perc == (unsigned char) -1)
150 bsp->perc = (100 - perc) / perc_missing;
151 }
152 }
153
83ea422a
JA
154 o->min_bs[ddir] = min_bs;
155 o->max_bs[ddir] = max_bs;
564ca972
JA
156
157 /*
158 * now sort based on percentages, for ease of lookup
159 */
83ea422a
JA
160 qsort(bssplit, o->bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161 o->bssplit[ddir] = bssplit;
720e84ad 162 return 0;
720e84ad
JA
163}
164
165static int str_bssplit_cb(void *data, const char *input)
166{
167 struct thread_data *td = data;
168 char *str, *p, *odir;
169 int ret = 0;
170
171 p = str = strdup(input);
172
173 strip_blank_front(&str);
174 strip_blank_end(str);
175
176 odir = strchr(str, ',');
177 if (odir) {
83ea422a 178 ret = bssplit_ddir(&td->o, DDIR_WRITE, odir + 1);
720e84ad
JA
179 if (!ret) {
180 *odir = '\0';
83ea422a 181 ret = bssplit_ddir(&td->o, DDIR_READ, str);
720e84ad
JA
182 }
183 } else {
184 char *op;
185
186 op = strdup(str);
187
83ea422a 188 ret = bssplit_ddir(&td->o, DDIR_READ, str);
720e84ad 189 if (!ret)
83ea422a 190 ret = bssplit_ddir(&td->o, DDIR_WRITE, op);
720e84ad
JA
191
192 free(op);
193 }
564ca972
JA
194
195 free(p);
720e84ad 196 return ret;
564ca972
JA
197}
198
211097b2
JA
199static int str_rw_cb(void *data, const char *str)
200{
201 struct thread_data *td = data;
83ea422a 202 struct thread_options *o = &td->o;
211097b2
JA
203 char *nr = get_opt_postfix(str);
204
83ea422a
JA
205 o->ddir_seq_nr = 1;
206 o->ddir_seq_add = 0;
059b0802
JA
207
208 if (!nr)
209 return 0;
210
211 if (td_random(td))
83ea422a 212 o->ddir_seq_nr = atoi(nr);
059b0802
JA
213 else {
214 long long val;
215
83ea422a 216 if (str_to_decimal(nr, &val, 1, o)) {
059b0802
JA
217 log_err("fio: rw postfix parsing failed\n");
218 free(nr);
219 return 1;
220 }
221
83ea422a 222 o->ddir_seq_add = val;
182ec6ee 223 }
211097b2 224
059b0802 225 free(nr);
211097b2
JA
226 return 0;
227}
228
214e1eca
JA
229static int str_mem_cb(void *data, const char *mem)
230{
231 struct thread_data *td = data;
83ea422a 232 struct thread_options *o = &td->o;
214e1eca 233
83ea422a
JA
234 if (o->mem_type == MEM_MMAPHUGE || o->mem_type == MEM_MMAP) {
235 o->mmapfile = get_opt_postfix(mem);
236 if (o->mem_type == MEM_MMAPHUGE && !o->mmapfile) {
214e1eca
JA
237 log_err("fio: mmaphuge:/path/to/file\n");
238 return 1;
239 }
240 }
241
242 return 0;
243}
244
c223da83
JA
245static int fio_clock_source_cb(void *data, const char *str)
246{
247 struct thread_data *td = data;
248
249 fio_clock_source = td->o.clocksource;
250 fio_time_init();
251 return 0;
252}
253
85bc833b 254static int str_rwmix_read_cb(void *data, unsigned long long *val)
cb499fc4
JA
255{
256 struct thread_data *td = data;
257
258 td->o.rwmix[DDIR_READ] = *val;
259 td->o.rwmix[DDIR_WRITE] = 100 - *val;
260 return 0;
261}
262
85bc833b 263static int str_rwmix_write_cb(void *data, unsigned long long *val)
cb499fc4
JA
264{
265 struct thread_data *td = data;
266
267 td->o.rwmix[DDIR_WRITE] = *val;
268 td->o.rwmix[DDIR_READ] = 100 - *val;
269 return 0;
270}
271
214e1eca 272#ifdef FIO_HAVE_IOPRIO
85bc833b 273static int str_prioclass_cb(void *data, unsigned long long *val)
214e1eca
JA
274{
275 struct thread_data *td = data;
6cefbe33
JA
276 unsigned short mask;
277
278 /*
279 * mask off old class bits, str_prio_cb() may have set a default class
280 */
281 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
282 td->ioprio &= mask;
214e1eca
JA
283
284 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
ac684785 285 td->ioprio_set = 1;
214e1eca
JA
286 return 0;
287}
288
85bc833b 289static int str_prio_cb(void *data, unsigned long long *val)
214e1eca
JA
290{
291 struct thread_data *td = data;
292
293 td->ioprio |= *val;
6cefbe33
JA
294
295 /*
296 * If no class is set, assume BE
297 */
298 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
299 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
300
ac684785 301 td->ioprio_set = 1;
214e1eca
JA
302 return 0;
303}
304#endif
305
306static int str_exitall_cb(void)
307{
308 exitall_on_terminate = 1;
309 return 0;
310}
311
214e1eca 312#ifdef FIO_HAVE_CPU_AFFINITY
85bc833b 313static int str_cpumask_cb(void *data, unsigned long long *val)
d2e268b0
JA
314{
315 struct thread_data *td = data;
214e1eca 316 unsigned int i;
b03daafb 317 long max_cpu;
d2ce18b5
JA
318 int ret;
319
320 ret = fio_cpuset_init(&td->o.cpumask);
321 if (ret < 0) {
322 log_err("fio: cpuset_init failed\n");
323 td_verror(td, ret, "fio_cpuset_init");
324 return 1;
325 }
214e1eca 326
c00a2289 327 max_cpu = cpus_online();
214e1eca 328
62a7273d
JA
329 for (i = 0; i < sizeof(int) * 8; i++) {
330 if ((1 << i) & *val) {
b03daafb
JA
331 if (i > max_cpu) {
332 log_err("fio: CPU %d too large (max=%ld)\n", i,
333 max_cpu);
334 return 1;
335 }
62a7273d 336 dprint(FD_PARSE, "set cpu allowed %d\n", i);
6d459ee7 337 fio_cpu_set(&td->o.cpumask, i);
62a7273d
JA
338 }
339 }
d2e268b0
JA
340
341 td->o.cpumask_set = 1;
342 return 0;
214e1eca
JA
343}
344
e8462bd8
JA
345static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
346 const char *input)
214e1eca 347{
d2e268b0 348 char *cpu, *str, *p;
b03daafb 349 long max_cpu;
19608d6c 350 int ret = 0;
d2e268b0 351
e8462bd8 352 ret = fio_cpuset_init(mask);
d2ce18b5
JA
353 if (ret < 0) {
354 log_err("fio: cpuset_init failed\n");
355 td_verror(td, ret, "fio_cpuset_init");
356 return 1;
357 }
d2e268b0
JA
358
359 p = str = strdup(input);
214e1eca 360
d2e268b0
JA
361 strip_blank_front(&str);
362 strip_blank_end(str);
363
c00a2289 364 max_cpu = cpus_online();
b03daafb 365
d2e268b0 366 while ((cpu = strsep(&str, ",")) != NULL) {
62a7273d
JA
367 char *str2, *cpu2;
368 int icpu, icpu2;
369
d2e268b0
JA
370 if (!strlen(cpu))
371 break;
62a7273d
JA
372
373 str2 = cpu;
374 icpu2 = -1;
375 while ((cpu2 = strsep(&str2, "-")) != NULL) {
376 if (!strlen(cpu2))
377 break;
378
379 icpu2 = atoi(cpu2);
380 }
381
382 icpu = atoi(cpu);
383 if (icpu2 == -1)
384 icpu2 = icpu;
385 while (icpu <= icpu2) {
6d459ee7 386 if (icpu >= FIO_MAX_CPUS) {
19608d6c 387 log_err("fio: your OS only supports up to"
6d459ee7 388 " %d CPUs\n", (int) FIO_MAX_CPUS);
19608d6c
JA
389 ret = 1;
390 break;
391 }
b03daafb
JA
392 if (icpu > max_cpu) {
393 log_err("fio: CPU %d too large (max=%ld)\n",
394 icpu, max_cpu);
395 ret = 1;
396 break;
397 }
0b9d69ec 398
62a7273d 399 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
e8462bd8 400 fio_cpu_set(mask, icpu);
62a7273d
JA
401 icpu++;
402 }
19608d6c
JA
403 if (ret)
404 break;
d2e268b0
JA
405 }
406
407 free(p);
19608d6c
JA
408 if (!ret)
409 td->o.cpumask_set = 1;
410 return ret;
214e1eca 411}
e8462bd8
JA
412
413static int str_cpus_allowed_cb(void *data, const char *input)
414{
415 struct thread_data *td = data;
416 int ret;
417
418 ret = set_cpus_allowed(td, &td->o.cpumask, input);
419 if (!ret)
420 td->o.cpumask_set = 1;
421
422 return ret;
423}
424
425static int str_verify_cpus_allowed_cb(void *data, const char *input)
426{
427 struct thread_data *td = data;
428 int ret;
429
430 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
431 if (!ret)
432 td->o.verify_cpumask_set = 1;
433
434 return ret;
435}
d2e268b0 436#endif
214e1eca 437
0d29de83
JA
438#ifdef FIO_HAVE_TRIM
439static int str_verify_trim_cb(void *data, unsigned long long *val)
440{
441 struct thread_data *td = data;
442
443 td->o.trim_percentage = *val;
444 return 0;
445}
446#endif
447
214e1eca
JA
448static int str_fst_cb(void *data, const char *str)
449{
450 struct thread_data *td = data;
451 char *nr = get_opt_postfix(str);
452
453 td->file_service_nr = 1;
182ec6ee 454 if (nr) {
214e1eca 455 td->file_service_nr = atoi(nr);
182ec6ee
JA
456 free(nr);
457 }
214e1eca
JA
458
459 return 0;
460}
461
3ae06371 462#ifdef FIO_HAVE_SYNC_FILE_RANGE
44f29692
JA
463static int str_sfr_cb(void *data, const char *str)
464{
465 struct thread_data *td = data;
466 char *nr = get_opt_postfix(str);
467
468 td->sync_file_range_nr = 1;
469 if (nr) {
470 td->sync_file_range_nr = atoi(nr);
471 free(nr);
472 }
473
474 return 0;
475}
3ae06371 476#endif
44f29692 477
921c766f
JA
478static int check_dir(struct thread_data *td, char *fname)
479{
3f0ca9b9 480#if 0
921c766f 481 char file[PATH_MAX], *dir;
bc838919 482 int elen = 0;
921c766f 483
bc838919
JA
484 if (td->o.directory) {
485 strcpy(file, td->o.directory);
fcef0b35 486 strcat(file, "/");
bc838919
JA
487 elen = strlen(file);
488 }
489
fcef0b35 490 sprintf(file + elen, "%s", fname);
921c766f
JA
491 dir = dirname(file);
492
fcef0b35
JA
493 {
494 struct stat sb;
495 /*
496 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
497 * yet, so we can't do this check right here...
498 */
921c766f
JA
499 if (lstat(dir, &sb) < 0) {
500 int ret = errno;
501
502 log_err("fio: %s is not a directory\n", dir);
503 td_verror(td, ret, "lstat");
504 return 1;
505 }
506
507 if (!S_ISDIR(sb.st_mode)) {
508 log_err("fio: %s is not a directory\n", dir);
509 return 1;
510 }
fcef0b35
JA
511 }
512#endif
921c766f
JA
513
514 return 0;
515}
516
8e827d35
JA
517/*
518 * Return next file in the string. Files are separated with ':'. If the ':'
519 * is escaped with a '\', then that ':' is part of the filename and does not
520 * indicate a new file.
521 */
522static char *get_next_file_name(char **ptr)
523{
524 char *str = *ptr;
525 char *p, *start;
526
527 if (!str || !strlen(str))
528 return NULL;
529
530 start = str;
531 do {
532 /*
533 * No colon, we are done
534 */
535 p = strchr(str, ':');
536 if (!p) {
537 *ptr = NULL;
538 break;
539 }
540
541 /*
542 * We got a colon, but it's the first character. Skip and
543 * continue
544 */
545 if (p == start) {
546 str = ++start;
547 continue;
548 }
549
550 if (*(p - 1) != '\\') {
551 *p = '\0';
552 *ptr = p + 1;
553 break;
554 }
555
556 memmove(p - 1, p, strlen(p) + 1);
557 str = p;
558 } while (1);
559
560 return start;
561}
562
214e1eca
JA
563static int str_filename_cb(void *data, const char *input)
564{
565 struct thread_data *td = data;
566 char *fname, *str, *p;
567
568 p = str = strdup(input);
569
570 strip_blank_front(&str);
571 strip_blank_end(str);
572
573 if (!td->files_index)
2dc1bbeb 574 td->o.nr_files = 0;
214e1eca 575
8e827d35 576 while ((fname = get_next_file_name(&str)) != NULL) {
214e1eca
JA
577 if (!strlen(fname))
578 break;
921c766f
JA
579 if (check_dir(td, fname)) {
580 free(p);
581 return 1;
582 }
214e1eca 583 add_file(td, fname);
2dc1bbeb 584 td->o.nr_files++;
214e1eca
JA
585 }
586
587 free(p);
588 return 0;
589}
590
591static int str_directory_cb(void *data, const char fio_unused *str)
592{
593 struct thread_data *td = data;
594 struct stat sb;
595
2dc1bbeb 596 if (lstat(td->o.directory, &sb) < 0) {
921c766f
JA
597 int ret = errno;
598
2dc1bbeb 599 log_err("fio: %s is not a directory\n", td->o.directory);
921c766f 600 td_verror(td, ret, "lstat");
214e1eca
JA
601 return 1;
602 }
603 if (!S_ISDIR(sb.st_mode)) {
2dc1bbeb 604 log_err("fio: %s is not a directory\n", td->o.directory);
214e1eca
JA
605 return 1;
606 }
607
608 return 0;
609}
610
611static int str_opendir_cb(void *data, const char fio_unused *str)
612{
613 struct thread_data *td = data;
614
615 if (!td->files_index)
2dc1bbeb 616 td->o.nr_files = 0;
214e1eca 617
2dc1bbeb 618 return add_dir_files(td, td->o.opendir);
214e1eca
JA
619}
620
85bc833b 621static int str_verify_offset_cb(void *data, unsigned long long *off)
546a9142
SL
622{
623 struct thread_data *td = data;
a59e170d 624
546a9142 625 if (*off && *off < sizeof(struct verify_header)) {
a59e170d 626 log_err("fio: verify_offset too small\n");
546a9142
SL
627 return 1;
628 }
a59e170d
JA
629
630 td->o.verify_offset = *off;
546a9142
SL
631 return 0;
632}
633
0e92f873 634static int str_verify_pattern_cb(void *data, const char *input)
90059d65
JA
635{
636 struct thread_data *td = data;
0e92f873
RR
637 long off;
638 int i = 0, j = 0, len, k, base = 10;
3c3ed070 639 char *loc1, *loc2;
0e92f873
RR
640
641 loc1 = strstr(input, "0x");
642 loc2 = strstr(input, "0X");
643 if (loc1 || loc2)
644 base = 16;
645 off = strtol(input, NULL, base);
646 if (off != LONG_MAX || errno != ERANGE) {
647 while (off) {
648 td->o.verify_pattern[i] = off & 0xff;
649 off >>= 8;
650 i++;
651 }
652 } else {
653 len = strlen(input);
654 k = len - 1;
655 if (base == 16) {
656 if (loc1)
657 j = loc1 - input + 2;
658 else
659 j = loc2 - input + 2;
660 } else
661 return 1;
662 if (len - j < MAX_PATTERN_SIZE * 2) {
663 while (k >= j) {
664 off = converthexchartoint(input[k--]);
665 if (k >= j)
666 off += (converthexchartoint(input[k--])
667 * 16);
668 td->o.verify_pattern[i++] = (char) off;
669 }
670 }
671 }
efcd9dcc
SL
672
673 /*
674 * Fill the pattern all the way to the end. This greatly reduces
675 * the number of memcpy's we have to do when verifying the IO.
676 */
677 while (i > 1 && i * 2 <= MAX_PATTERN_SIZE) {
678 memcpy(&td->o.verify_pattern[i], &td->o.verify_pattern[0], i);
679 i *= 2;
680 }
9a2a86d0
SL
681 if (i == 1) {
682 /*
683 * The code in verify_io_u_pattern assumes a single byte pattern
684 * fills the whole verify pattern buffer.
685 */
686 memset(td->o.verify_pattern, td->o.verify_pattern[0],
687 MAX_PATTERN_SIZE);
688 }
efcd9dcc 689
0e92f873 690 td->o.verify_pattern_bytes = i;
efcd9dcc 691
92bf48d5
JA
692 /*
693 * VERIFY_META could already be set
694 */
695 if (td->o.verify == VERIFY_NONE)
696 td->o.verify = VERIFY_PATTERN;
efcd9dcc 697
90059d65
JA
698 return 0;
699}
214e1eca 700
4d4e80f2
JA
701static int str_lockfile_cb(void *data, const char *str)
702{
703 struct thread_data *td = data;
704 char *nr = get_opt_postfix(str);
705
706 td->o.lockfile_batch = 1;
182ec6ee 707 if (nr) {
4d4e80f2 708 td->o.lockfile_batch = atoi(nr);
182ec6ee
JA
709 free(nr);
710 }
4d4e80f2
JA
711
712 return 0;
713}
714
e3cedca7
JA
715static int str_write_bw_log_cb(void *data, const char *str)
716{
717 struct thread_data *td = data;
718
719 if (str)
720 td->o.bw_log_file = strdup(str);
721
722 td->o.write_bw_log = 1;
723 return 0;
724}
725
726static int str_write_lat_log_cb(void *data, const char *str)
727{
728 struct thread_data *td = data;
729
730 if (str)
731 td->o.lat_log_file = strdup(str);
732
733 td->o.write_lat_log = 1;
734 return 0;
735}
736
c8eeb9df
JA
737static int str_write_iops_log_cb(void *data, const char *str)
738{
739 struct thread_data *td = data;
740
741 if (str)
742 td->o.iops_log_file = strdup(str);
743
744 td->o.write_iops_log = 1;
745 return 0;
746}
747
993bf48b
JA
748static int str_gtod_reduce_cb(void *data, int *il)
749{
750 struct thread_data *td = data;
751 int val = *il;
752
02af0988 753 td->o.disable_lat = !!val;
993bf48b
JA
754 td->o.disable_clat = !!val;
755 td->o.disable_slat = !!val;
756 td->o.disable_bw = !!val;
0dc1bc03 757 td->o.clat_percentiles = !val;
993bf48b
JA
758 if (val)
759 td->tv_cache_mask = 63;
760
761 return 0;
762}
763
85bc833b 764static int str_gtod_cpu_cb(void *data, long long *il)
be4ecfdf
JA
765{
766 struct thread_data *td = data;
767 int val = *il;
768
769 td->o.gtod_cpu = val;
770 td->o.gtod_offload = 1;
771 return 0;
772}
773
7bb59102
JA
774static int str_size_cb(void *data, unsigned long long *__val)
775{
776 struct thread_data *td = data;
777 unsigned long long v = *__val;
778
779 if (parse_is_percent(v)) {
780 td->o.size = 0;
781 td->o.size_percent = -1ULL - v;
782 } else
783 td->o.size = v;
784
785 return 0;
786}
787
896cac2a
JA
788static int rw_verify(struct fio_option *o, void *data)
789{
790 struct thread_data *td = data;
791
792 if (read_only && td_write(td)) {
793 log_err("fio: job <%s> has write bit set, but fio is in"
794 " read-only mode\n", td->o.name);
795 return 1;
796 }
797
798 return 0;
799}
800
276ca4f7 801static int gtod_cpu_verify(struct fio_option *o, void *data)
29d43ff9 802{
276ca4f7 803#ifndef FIO_HAVE_CPU_AFFINITY
29d43ff9
JA
804 struct thread_data *td = data;
805
29d43ff9
JA
806 if (td->o.gtod_cpu) {
807 log_err("fio: platform must support CPU affinity for"
808 "gettimeofday() offloading\n");
809 return 1;
810 }
811#endif
812
813 return 0;
814}
815
90fef2d1
JA
816static int kb_base_verify(struct fio_option *o, void *data)
817{
818 struct thread_data *td = data;
819
820 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
821 log_err("fio: kb_base set to nonsensical value: %u\n",
822 td->o.kb_base);
823 return 1;
824 }
825
826 return 0;
827}
828
9af4a244
JA
829/*
830 * Option grouping
831 */
832static struct opt_group fio_opt_groups[] = {
833 {
e8b0e958
JA
834 .name = "General",
835 .mask = FIO_OPT_C_GENERAL,
9af4a244
JA
836 },
837 {
e8b0e958
JA
838 .name = "I/O",
839 .mask = FIO_OPT_C_IO,
9af4a244
JA
840 },
841 {
e8b0e958
JA
842 .name = "File",
843 .mask = FIO_OPT_C_FILE,
9af4a244
JA
844 },
845 {
e8b0e958
JA
846 .name = "Statistics",
847 .mask = FIO_OPT_C_STAT,
9af4a244
JA
848 },
849 {
e8b0e958
JA
850 .name = "Logging",
851 .mask = FIO_OPT_C_LOG,
9af4a244 852 },
e231bbe6 853 {
e8b0e958 854 .name = NULL,
e231bbe6 855 },
e8b0e958
JA
856};
857
858static struct opt_group *__opt_group_from_mask(struct opt_group *ogs, unsigned int *mask,
859 unsigned int inv_mask)
860{
861 struct opt_group *og;
862 int i;
863
864 if (*mask == inv_mask || !*mask)
865 return NULL;
866
867 for (i = 0; ogs[i].name; i++) {
868 og = &ogs[i];
869
870 if (*mask & og->mask) {
871 *mask &= ~(og->mask);
872 return og;
873 }
874 }
875
876 return NULL;
877}
878
879struct opt_group *opt_group_from_mask(unsigned int *mask)
880{
881 return __opt_group_from_mask(fio_opt_groups, mask, FIO_OPT_C_INVALID);
882}
883
884static struct opt_group fio_opt_cat_groups[] = {
9af4a244 885 {
e8b0e958
JA
886 .name = "Rate",
887 .mask = FIO_OPT_G_RATE,
9af4a244
JA
888 },
889 {
e8b0e958
JA
890 .name = "Zone",
891 .mask = FIO_OPT_G_ZONE,
9af4a244
JA
892 },
893 {
e8b0e958
JA
894 .name = "Read/write mix",
895 .mask = FIO_OPT_G_RWMIX,
9af4a244
JA
896 },
897 {
898 .name = "Verify",
899 .mask = FIO_OPT_G_VERIFY,
900 },
901 {
e8b0e958
JA
902 .name = "Trim",
903 .mask = FIO_OPT_G_TRIM,
9af4a244
JA
904 },
905 {
e8b0e958
JA
906 .name = "I/O Logging",
907 .mask = FIO_OPT_G_IOLOG,
9af4a244
JA
908 },
909 {
e8b0e958
JA
910 .name = "I/O Depth",
911 .mask = FIO_OPT_G_IO_DEPTH,
9af4a244
JA
912 },
913 {
e8b0e958
JA
914 .name = "I/O Flow",
915 .mask = FIO_OPT_G_IO_FLOW,
9af4a244 916 },
0626037e
JA
917 {
918 .name = "Description",
919 .mask = FIO_OPT_G_DESC,
920 },
921 {
922 .name = "Filename",
923 .mask = FIO_OPT_G_FILENAME,
924 },
925 {
926 .name = "General I/O",
927 .mask = FIO_OPT_G_IO_BASIC,
928 },
a1f6afec
JA
929 {
930 .name = "Cgroups",
931 .mask = FIO_OPT_G_CGROUP,
932 },
933 {
934 .name = "Runtime",
935 .mask = FIO_OPT_G_RUNTIME,
936 },
10860056
JA
937 {
938 .name = "Process",
939 .mask = FIO_OPT_G_PROCESS,
940 },
941 {
942 .name = "Job credentials / priority",
943 .mask = FIO_OPT_G_CRED,
944 },
945 {
946 .name = "Clock settings",
947 .mask = FIO_OPT_G_CLOCK,
948 },
3ceb458f
JA
949 {
950 .name = "I/O Type",
951 .mask = FIO_OPT_G_IO_TYPE,
952 },
953 {
954 .name = "I/O Thinktime",
955 .mask = FIO_OPT_G_THINKTIME,
956 },
957 {
958 .name = "Randomizations",
959 .mask = FIO_OPT_G_RANDOM,
960 },
961 {
962 .name = "I/O buffers",
963 .mask = FIO_OPT_G_IO_BUF,
964 },
9af4a244
JA
965 {
966 .name = NULL,
e8b0e958 967 }
9af4a244
JA
968};
969
e8b0e958 970struct opt_group *opt_group_cat_from_mask(unsigned int *mask)
9af4a244 971{
e8b0e958 972 return __opt_group_from_mask(fio_opt_cat_groups, mask, FIO_OPT_G_INVALID);
9af4a244
JA
973}
974
214e1eca
JA
975/*
976 * Map of job/command line options
977 */
9af4a244 978struct fio_option fio_options[FIO_MAX_OPTS] = {
214e1eca
JA
979 {
980 .name = "description",
e8b0e958 981 .lname = "Description of job",
214e1eca
JA
982 .type = FIO_OPT_STR_STORE,
983 .off1 = td_var_offset(description),
984 .help = "Text job description",
e8b0e958 985 .category = FIO_OPT_C_GENERAL,
0626037e 986 .group = FIO_OPT_G_DESC,
214e1eca
JA
987 },
988 {
989 .name = "name",
e8b0e958 990 .lname = "Job name",
214e1eca
JA
991 .type = FIO_OPT_STR_STORE,
992 .off1 = td_var_offset(name),
993 .help = "Name of this job",
e8b0e958 994 .category = FIO_OPT_C_GENERAL,
0626037e 995 .group = FIO_OPT_G_DESC,
214e1eca 996 },
214e1eca
JA
997 {
998 .name = "filename",
e8b0e958 999 .lname = "Filename(s)",
214e1eca
JA
1000 .type = FIO_OPT_STR_STORE,
1001 .off1 = td_var_offset(filename),
1002 .cb = str_filename_cb,
f0d524b0 1003 .prio = -1, /* must come after "directory" */
214e1eca 1004 .help = "File(s) to use for the workload",
e8b0e958 1005 .category = FIO_OPT_C_FILE,
0626037e 1006 .group = FIO_OPT_G_FILENAME,
214e1eca 1007 },
90fef2d1 1008 {
e8b0e958
JA
1009 .name = "directory",
1010 .lname = "Directory",
1011 .type = FIO_OPT_STR_STORE,
1012 .off1 = td_var_offset(directory),
1013 .cb = str_directory_cb,
1014 .help = "Directory to store files in",
1015 .category = FIO_OPT_C_FILE,
0626037e 1016 .group = FIO_OPT_G_FILENAME,
90fef2d1 1017 },
29c1349f
JA
1018 {
1019 .name = "lockfile",
e8b0e958 1020 .lname = "Lockfile",
4d4e80f2
JA
1021 .type = FIO_OPT_STR,
1022 .cb = str_lockfile_cb,
1023 .off1 = td_var_offset(file_lock_mode),
29c1349f
JA
1024 .help = "Lock file when doing IO to it",
1025 .parent = "filename",
d71c154c 1026 .hide = 0,
4d4e80f2 1027 .def = "none",
e8b0e958 1028 .category = FIO_OPT_C_FILE,
0626037e 1029 .group = FIO_OPT_G_FILENAME,
4d4e80f2
JA
1030 .posval = {
1031 { .ival = "none",
1032 .oval = FILE_LOCK_NONE,
1033 .help = "No file locking",
1034 },
1035 { .ival = "exclusive",
1036 .oval = FILE_LOCK_EXCLUSIVE,
1037 .help = "Exclusive file lock",
1038 },
1039 {
1040 .ival = "readwrite",
1041 .oval = FILE_LOCK_READWRITE,
1042 .help = "Read vs write lock",
1043 },
1044 },
29c1349f 1045 },
214e1eca
JA
1046 {
1047 .name = "opendir",
e8b0e958 1048 .lname = "Open directory",
214e1eca
JA
1049 .type = FIO_OPT_STR_STORE,
1050 .off1 = td_var_offset(opendir),
1051 .cb = str_opendir_cb,
1052 .help = "Recursively add files from this directory and down",
e8b0e958 1053 .category = FIO_OPT_C_FILE,
0626037e 1054 .group = FIO_OPT_G_FILENAME,
214e1eca
JA
1055 },
1056 {
1057 .name = "rw",
e8b0e958 1058 .lname = "Read/write",
d3aad8f2 1059 .alias = "readwrite",
214e1eca 1060 .type = FIO_OPT_STR,
211097b2 1061 .cb = str_rw_cb,
214e1eca
JA
1062 .off1 = td_var_offset(td_ddir),
1063 .help = "IO direction",
1064 .def = "read",
896cac2a 1065 .verify = rw_verify,
e8b0e958 1066 .category = FIO_OPT_C_IO,
0626037e 1067 .group = FIO_OPT_G_IO_BASIC,
214e1eca
JA
1068 .posval = {
1069 { .ival = "read",
1070 .oval = TD_DDIR_READ,
1071 .help = "Sequential read",
1072 },
1073 { .ival = "write",
1074 .oval = TD_DDIR_WRITE,
1075 .help = "Sequential write",
1076 },
1077 { .ival = "randread",
1078 .oval = TD_DDIR_RANDREAD,
1079 .help = "Random read",
1080 },
1081 { .ival = "randwrite",
1082 .oval = TD_DDIR_RANDWRITE,
1083 .help = "Random write",
1084 },
1085 { .ival = "rw",
1086 .oval = TD_DDIR_RW,
1087 .help = "Sequential read and write mix",
1088 },
1089 { .ival = "randrw",
1090 .oval = TD_DDIR_RANDRW,
1091 .help = "Random read and write mix"
1092 },
1093 },
1094 },
38dad62d
JA
1095 {
1096 .name = "rw_sequencer",
e8b0e958 1097 .lname = "RW Sequencer",
38dad62d
JA
1098 .type = FIO_OPT_STR,
1099 .off1 = td_var_offset(rw_seq),
1100 .help = "IO offset generator modifier",
1101 .def = "sequential",
e8b0e958 1102 .category = FIO_OPT_C_IO,
0626037e 1103 .group = FIO_OPT_G_IO_BASIC,
38dad62d
JA
1104 .posval = {
1105 { .ival = "sequential",
1106 .oval = RW_SEQ_SEQ,
1107 .help = "Generate sequential offsets",
1108 },
1109 { .ival = "identical",
1110 .oval = RW_SEQ_IDENT,
1111 .help = "Generate identical offsets",
1112 },
1113 },
1114 },
1115
214e1eca
JA
1116 {
1117 .name = "ioengine",
e8b0e958 1118 .lname = "IO Engine",
214e1eca
JA
1119 .type = FIO_OPT_STR_STORE,
1120 .off1 = td_var_offset(ioengine),
1121 .help = "IO engine to use",
58483fa4 1122 .def = FIO_PREFERRED_ENGINE,
e8b0e958 1123 .category = FIO_OPT_C_IO,
0626037e 1124 .group = FIO_OPT_G_IO_BASIC,
214e1eca
JA
1125 .posval = {
1126 { .ival = "sync",
1127 .help = "Use read/write",
1128 },
a31041ea 1129 { .ival = "psync",
1130 .help = "Use pread/pwrite",
1131 },
1d2af02a 1132 { .ival = "vsync",
03e20d68 1133 .help = "Use readv/writev",
1d2af02a 1134 },
214e1eca
JA
1135#ifdef FIO_HAVE_LIBAIO
1136 { .ival = "libaio",
1137 .help = "Linux native asynchronous IO",
1138 },
1139#endif
1140#ifdef FIO_HAVE_POSIXAIO
1141 { .ival = "posixaio",
1142 .help = "POSIX asynchronous IO",
1143 },
417f0068
JA
1144#endif
1145#ifdef FIO_HAVE_SOLARISAIO
1146 { .ival = "solarisaio",
1147 .help = "Solaris native asynchronous IO",
1148 },
214e1eca 1149#endif
03e20d68
BC
1150#ifdef FIO_HAVE_WINDOWSAIO
1151 { .ival = "windowsaio",
3be80071 1152 .help = "Windows native asynchronous IO"
de890a1e 1153 },
3be80071 1154#endif
214e1eca 1155 { .ival = "mmap",
03e20d68 1156 .help = "Memory mapped IO"
214e1eca
JA
1157 },
1158#ifdef FIO_HAVE_SPLICE
1159 { .ival = "splice",
1160 .help = "splice/vmsplice based IO",
1161 },
9cce02e8
JA
1162 { .ival = "netsplice",
1163 .help = "splice/vmsplice to/from the network",
1164 },
214e1eca
JA
1165#endif
1166#ifdef FIO_HAVE_SGIO
1167 { .ival = "sg",
1168 .help = "SCSI generic v3 IO",
1169 },
1170#endif
1171 { .ival = "null",
1172 .help = "Testing engine (no data transfer)",
1173 },
1174 { .ival = "net",
1175 .help = "Network IO",
1176 },
1177#ifdef FIO_HAVE_SYSLET
1178 { .ival = "syslet-rw",
1179 .help = "syslet enabled async pread/pwrite IO",
1180 },
1181#endif
1182 { .ival = "cpuio",
03e20d68 1183 .help = "CPU cycle burner engine",
214e1eca 1184 },
b8c82a46
JA
1185#ifdef FIO_HAVE_GUASI
1186 { .ival = "guasi",
1187 .help = "GUASI IO engine",
1188 },
79a43187
JA
1189#endif
1190#ifdef FIO_HAVE_BINJECT
1191 { .ival = "binject",
1192 .help = "binject direct inject block engine",
1193 },
21b8aee8 1194#endif
1195#ifdef FIO_HAVE_RDMA
1196 { .ival = "rdma",
1197 .help = "RDMA IO engine",
1198 },
b8c82a46 1199#endif
214e1eca
JA
1200 { .ival = "external",
1201 .help = "Load external engine (append name)",
1202 },
1203 },
1204 },
1205 {
1206 .name = "iodepth",
e8b0e958 1207 .lname = "IO Depth",
214e1eca
JA
1208 .type = FIO_OPT_INT,
1209 .off1 = td_var_offset(iodepth),
03e20d68 1210 .help = "Number of IO buffers to keep in flight",
757aff4f 1211 .minval = 1,
20eb06bd 1212 .interval = 1,
214e1eca 1213 .def = "1",
e8b0e958 1214 .category = FIO_OPT_C_IO,
0626037e 1215 .group = FIO_OPT_G_IO_BASIC,
214e1eca
JA
1216 },
1217 {
1218 .name = "iodepth_batch",
e8b0e958 1219 .lname = "IO Depth batch",
4950421a 1220 .alias = "iodepth_batch_submit",
214e1eca
JA
1221 .type = FIO_OPT_INT,
1222 .off1 = td_var_offset(iodepth_batch),
d65db441 1223 .help = "Number of IO buffers to submit in one go",
afdf9352 1224 .parent = "iodepth",
d71c154c 1225 .hide = 1,
a2e6f8ac 1226 .minval = 1,
20eb06bd 1227 .interval = 1,
a2e6f8ac 1228 .def = "1",
e8b0e958 1229 .category = FIO_OPT_C_IO,
0626037e 1230 .group = FIO_OPT_G_IO_BASIC,
4950421a
JA
1231 },
1232 {
1233 .name = "iodepth_batch_complete",
e8b0e958 1234 .lname = "IO Depth batch complete",
4950421a
JA
1235 .type = FIO_OPT_INT,
1236 .off1 = td_var_offset(iodepth_batch_complete),
d65db441 1237 .help = "Number of IO buffers to retrieve in one go",
4950421a 1238 .parent = "iodepth",
d71c154c 1239 .hide = 1,
4950421a 1240 .minval = 0,
20eb06bd 1241 .interval = 1,
4950421a 1242 .def = "1",
e8b0e958 1243 .category = FIO_OPT_C_IO,
0626037e 1244 .group = FIO_OPT_G_IO_BASIC,
214e1eca
JA
1245 },
1246 {
1247 .name = "iodepth_low",
e8b0e958 1248 .lname = "IO Depth batch low",
214e1eca
JA
1249 .type = FIO_OPT_INT,
1250 .off1 = td_var_offset(iodepth_low),
1251 .help = "Low water mark for queuing depth",
afdf9352 1252 .parent = "iodepth",
d71c154c 1253 .hide = 1,
20eb06bd 1254 .interval = 1,
e8b0e958 1255 .category = FIO_OPT_C_IO,
0626037e 1256 .group = FIO_OPT_G_IO_BASIC,
214e1eca
JA
1257 },
1258 {
1259 .name = "size",
e8b0e958 1260 .lname = "Size",
214e1eca 1261 .type = FIO_OPT_STR_VAL,
7bb59102 1262 .cb = str_size_cb,
214e1eca 1263 .help = "Total size of device or files",
20eb06bd 1264 .interval = 1024 * 1024,
e8b0e958
JA
1265 .category = FIO_OPT_C_IO,
1266 .group = FIO_OPT_G_INVALID,
214e1eca 1267 },
aa31f1f1
SL
1268 {
1269 .name = "fill_device",
e8b0e958 1270 .lname = "Fill device",
74586c1e 1271 .alias = "fill_fs",
aa31f1f1
SL
1272 .type = FIO_OPT_BOOL,
1273 .off1 = td_var_offset(fill_device),
1274 .help = "Write until an ENOSPC error occurs",
1275 .def = "0",
e8b0e958
JA
1276 .category = FIO_OPT_C_FILE,
1277 .group = FIO_OPT_G_INVALID,
aa31f1f1 1278 },
214e1eca
JA
1279 {
1280 .name = "filesize",
e8b0e958 1281 .lname = "File size",
214e1eca
JA
1282 .type = FIO_OPT_STR_VAL,
1283 .off1 = td_var_offset(file_size_low),
1284 .off2 = td_var_offset(file_size_high),
c3edbdba 1285 .minval = 1,
214e1eca 1286 .help = "Size of individual files",
20eb06bd 1287 .interval = 1024 * 1024,
e8b0e958
JA
1288 .category = FIO_OPT_C_FILE,
1289 .group = FIO_OPT_G_INVALID,
214e1eca 1290 },
67a1000f
JA
1291 {
1292 .name = "offset",
e8b0e958 1293 .lname = "IO offset",
67a1000f
JA
1294 .alias = "fileoffset",
1295 .type = FIO_OPT_STR_VAL,
1296 .off1 = td_var_offset(start_offset),
1297 .help = "Start IO from this offset",
1298 .def = "0",
20eb06bd 1299 .interval = 1024 * 1024,
e8b0e958
JA
1300 .category = FIO_OPT_C_IO,
1301 .group = FIO_OPT_G_INVALID,
67a1000f 1302 },
2d7cd868
JA
1303 {
1304 .name = "offset_increment",
e8b0e958 1305 .lname = "IO offset increment",
2d7cd868
JA
1306 .type = FIO_OPT_STR_VAL,
1307 .off1 = td_var_offset(offset_increment),
1308 .help = "What is the increment from one offset to the next",
1309 .parent = "offset",
d71c154c 1310 .hide = 1,
2d7cd868 1311 .def = "0",
20eb06bd 1312 .interval = 1024 * 1024,
e8b0e958
JA
1313 .category = FIO_OPT_C_IO,
1314 .group = FIO_OPT_G_INVALID,
2d7cd868 1315 },
214e1eca
JA
1316 {
1317 .name = "bs",
e8b0e958 1318 .lname = "Block size",
d3aad8f2 1319 .alias = "blocksize",
e01b22b8 1320 .type = FIO_OPT_INT,
214e1eca
JA
1321 .off1 = td_var_offset(bs[DDIR_READ]),
1322 .off2 = td_var_offset(bs[DDIR_WRITE]),
c3edbdba 1323 .minval = 1,
214e1eca
JA
1324 .help = "Block size unit",
1325 .def = "4k",
67a1000f 1326 .parent = "rw",
d71c154c 1327 .hide = 1,
20eb06bd 1328 .interval = 512,
e8b0e958
JA
1329 .category = FIO_OPT_C_IO,
1330 .group = FIO_OPT_G_INVALID,
214e1eca 1331 },
2b7a01d0
JA
1332 {
1333 .name = "ba",
e8b0e958 1334 .lname = "Block size align",
2b7a01d0 1335 .alias = "blockalign",
e01b22b8 1336 .type = FIO_OPT_INT,
2b7a01d0
JA
1337 .off1 = td_var_offset(ba[DDIR_READ]),
1338 .off2 = td_var_offset(ba[DDIR_WRITE]),
1339 .minval = 1,
1340 .help = "IO block offset alignment",
1341 .parent = "rw",
d71c154c 1342 .hide = 1,
20eb06bd 1343 .interval = 512,
e8b0e958
JA
1344 .category = FIO_OPT_C_IO,
1345 .group = FIO_OPT_G_INVALID,
2b7a01d0 1346 },
214e1eca
JA
1347 {
1348 .name = "bsrange",
e8b0e958 1349 .lname = "Block size range",
d3aad8f2 1350 .alias = "blocksize_range",
214e1eca
JA
1351 .type = FIO_OPT_RANGE,
1352 .off1 = td_var_offset(min_bs[DDIR_READ]),
1353 .off2 = td_var_offset(max_bs[DDIR_READ]),
1354 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1355 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
c3edbdba 1356 .minval = 1,
214e1eca 1357 .help = "Set block size range (in more detail than bs)",
67a1000f 1358 .parent = "rw",
d71c154c 1359 .hide = 1,
20eb06bd 1360 .interval = 4096,
e8b0e958
JA
1361 .category = FIO_OPT_C_IO,
1362 .group = FIO_OPT_G_INVALID,
214e1eca 1363 },
564ca972
JA
1364 {
1365 .name = "bssplit",
e8b0e958 1366 .lname = "Block size split",
564ca972
JA
1367 .type = FIO_OPT_STR,
1368 .cb = str_bssplit_cb,
1369 .help = "Set a specific mix of block sizes",
1370 .parent = "rw",
d71c154c 1371 .hide = 1,
e8b0e958
JA
1372 .category = FIO_OPT_C_IO,
1373 .group = FIO_OPT_G_INVALID,
564ca972 1374 },
214e1eca
JA
1375 {
1376 .name = "bs_unaligned",
e8b0e958 1377 .lname = "Block size unaligned",
d3aad8f2 1378 .alias = "blocksize_unaligned",
214e1eca
JA
1379 .type = FIO_OPT_STR_SET,
1380 .off1 = td_var_offset(bs_unaligned),
1381 .help = "Don't sector align IO buffer sizes",
67a1000f 1382 .parent = "rw",
d71c154c 1383 .hide = 1,
e8b0e958
JA
1384 .category = FIO_OPT_C_IO,
1385 .group = FIO_OPT_G_INVALID,
214e1eca
JA
1386 },
1387 {
1388 .name = "randrepeat",
e8b0e958 1389 .lname = "Random repeatable",
214e1eca
JA
1390 .type = FIO_OPT_BOOL,
1391 .off1 = td_var_offset(rand_repeatable),
1392 .help = "Use repeatable random IO pattern",
1393 .def = "1",
67a1000f 1394 .parent = "rw",
d71c154c 1395 .hide = 1,
e8b0e958 1396 .category = FIO_OPT_C_IO,
3ceb458f 1397 .group = FIO_OPT_G_RANDOM,
214e1eca 1398 },
2615cc4b
JA
1399 {
1400 .name = "use_os_rand",
e8b0e958 1401 .lname = "Use OS random",
2615cc4b
JA
1402 .type = FIO_OPT_BOOL,
1403 .off1 = td_var_offset(use_os_rand),
1404 .help = "Set to use OS random generator",
1405 .def = "0",
1406 .parent = "rw",
d71c154c 1407 .hide = 1,
e8b0e958 1408 .category = FIO_OPT_C_IO,
3ceb458f 1409 .group = FIO_OPT_G_RANDOM,
2615cc4b 1410 },
214e1eca
JA
1411 {
1412 .name = "norandommap",
e8b0e958 1413 .lname = "No randommap",
214e1eca
JA
1414 .type = FIO_OPT_STR_SET,
1415 .off1 = td_var_offset(norandommap),
1416 .help = "Accept potential duplicate random blocks",
67a1000f 1417 .parent = "rw",
d71c154c 1418 .hide = 1,
b2452a43 1419 .hide_on_set = 1,
e8b0e958 1420 .category = FIO_OPT_C_IO,
3ceb458f 1421 .group = FIO_OPT_G_RANDOM,
214e1eca 1422 },
2b386d25
JA
1423 {
1424 .name = "softrandommap",
e8b0e958 1425 .lname = "Soft randommap",
2b386d25
JA
1426 .type = FIO_OPT_BOOL,
1427 .off1 = td_var_offset(softrandommap),
f66ab3c8 1428 .help = "Set norandommap if randommap allocation fails",
2b386d25 1429 .parent = "norandommap",
d71c154c 1430 .hide = 1,
2b386d25 1431 .def = "0",
e8b0e958 1432 .category = FIO_OPT_C_IO,
3ceb458f 1433 .group = FIO_OPT_G_RANDOM,
2b386d25 1434 },
214e1eca
JA
1435 {
1436 .name = "nrfiles",
e8b0e958 1437 .lname = "Number of files",
d7c8be03 1438 .alias = "nr_files",
214e1eca
JA
1439 .type = FIO_OPT_INT,
1440 .off1 = td_var_offset(nr_files),
1441 .help = "Split job workload between this number of files",
1442 .def = "1",
20eb06bd 1443 .interval = 1,
e8b0e958
JA
1444 .category = FIO_OPT_C_FILE,
1445 .group = FIO_OPT_G_INVALID,
214e1eca
JA
1446 },
1447 {
1448 .name = "openfiles",
e8b0e958 1449 .lname = "Number of open files",
214e1eca
JA
1450 .type = FIO_OPT_INT,
1451 .off1 = td_var_offset(open_files),
1452 .help = "Number of files to keep open at the same time",
e8b0e958
JA
1453 .category = FIO_OPT_C_FILE,
1454 .group = FIO_OPT_G_INVALID,
214e1eca
JA
1455 },
1456 {
1457 .name = "file_service_type",
e8b0e958 1458 .lname = "File service type",
214e1eca
JA
1459 .type = FIO_OPT_STR,
1460 .cb = str_fst_cb,
1461 .off1 = td_var_offset(file_service_type),
1462 .help = "How to select which file to service next",
1463 .def = "roundrobin",
e8b0e958
JA
1464 .category = FIO_OPT_C_FILE,
1465 .group = FIO_OPT_G_INVALID,
214e1eca
JA
1466 .posval = {
1467 { .ival = "random",
1468 .oval = FIO_FSERVICE_RANDOM,
1469 .help = "Choose a file at random",
1470 },
1471 { .ival = "roundrobin",
1472 .oval = FIO_FSERVICE_RR,
1473 .help = "Round robin select files",
1474 },
a086c257
JA
1475 { .ival = "sequential",
1476 .oval = FIO_FSERVICE_SEQ,
1477 .help = "Finish one file before moving to the next",
1478 },
214e1eca 1479 },
67a1000f 1480 .parent = "nrfiles",
d71c154c 1481 .hide = 1,
67a1000f 1482 },
7bc8c2cf
JA
1483#ifdef FIO_HAVE_FALLOCATE
1484 {
1485 .name = "fallocate",
e8b0e958 1486 .lname = "Fallocate",
a596f047
EG
1487 .type = FIO_OPT_STR,
1488 .off1 = td_var_offset(fallocate_mode),
1489 .help = "Whether pre-allocation is performed when laying out files",
1490 .def = "posix",
e8b0e958
JA
1491 .category = FIO_OPT_C_FILE,
1492 .group = FIO_OPT_G_INVALID,
a596f047
EG
1493 .posval = {
1494 { .ival = "none",
1495 .oval = FIO_FALLOCATE_NONE,
1496 .help = "Do not pre-allocate space",
1497 },
1498 { .ival = "posix",
1499 .oval = FIO_FALLOCATE_POSIX,
1500 .help = "Use posix_fallocate()",
1501 },
1502#ifdef FIO_HAVE_LINUX_FALLOCATE
1503 { .ival = "keep",
1504 .oval = FIO_FALLOCATE_KEEP_SIZE,
1505 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1506 },
7bc8c2cf 1507#endif
a596f047
EG
1508 /* Compatibility with former boolean values */
1509 { .ival = "0",
1510 .oval = FIO_FALLOCATE_NONE,
1511 .help = "Alias for 'none'",
1512 },
1513 { .ival = "1",
1514 .oval = FIO_FALLOCATE_POSIX,
1515 .help = "Alias for 'posix'",
1516 },
1517 },
1518 },
1519#endif /* FIO_HAVE_FALLOCATE */
67a1000f
JA
1520 {
1521 .name = "fadvise_hint",
e8b0e958 1522 .lname = "Fadvise hint",
67a1000f
JA
1523 .type = FIO_OPT_BOOL,
1524 .off1 = td_var_offset(fadvise_hint),
1525 .help = "Use fadvise() to advise the kernel on IO pattern",
1526 .def = "1",
e8b0e958
JA
1527 .category = FIO_OPT_C_FILE,
1528 .group = FIO_OPT_G_INVALID,
214e1eca
JA
1529 },
1530 {
1531 .name = "fsync",
e8b0e958 1532 .lname = "Fsync",
214e1eca
JA
1533 .type = FIO_OPT_INT,
1534 .off1 = td_var_offset(fsync_blocks),
1535 .help = "Issue fsync for writes every given number of blocks",
1536 .def = "0",
20eb06bd 1537 .interval = 1,
e8b0e958
JA
1538 .category = FIO_OPT_C_FILE,
1539 .group = FIO_OPT_G_INVALID,
214e1eca 1540 },
5f9099ea
JA
1541 {
1542 .name = "fdatasync",
e8b0e958 1543 .lname = "Fdatasync",
5f9099ea
JA
1544 .type = FIO_OPT_INT,
1545 .off1 = td_var_offset(fdatasync_blocks),
1546 .help = "Issue fdatasync for writes every given number of blocks",
1547 .def = "0",
20eb06bd 1548 .interval = 1,
e8b0e958
JA
1549 .category = FIO_OPT_C_FILE,
1550 .group = FIO_OPT_G_INVALID,
5f9099ea 1551 },
1ef2b6be
JA
1552 {
1553 .name = "write_barrier",
e8b0e958 1554 .lname = "Write barrier",
1ef2b6be
JA
1555 .type = FIO_OPT_INT,
1556 .off1 = td_var_offset(barrier_blocks),
1557 .help = "Make every Nth write a barrier write",
1558 .def = "0",
20eb06bd 1559 .interval = 1,
e8b0e958
JA
1560 .category = FIO_OPT_C_IO,
1561 .group = FIO_OPT_G_INVALID,
1ef2b6be 1562 },
44f29692
JA
1563#ifdef FIO_HAVE_SYNC_FILE_RANGE
1564 {
1565 .name = "sync_file_range",
e8b0e958 1566 .lname = "Sync file range",
44f29692
JA
1567 .posval = {
1568 { .ival = "wait_before",
1569 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1570 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
3843deb3 1571 .or = 1,
44f29692
JA
1572 },
1573 { .ival = "write",
1574 .oval = SYNC_FILE_RANGE_WRITE,
1575 .help = "SYNC_FILE_RANGE_WRITE",
3843deb3 1576 .or = 1,
44f29692
JA
1577 },
1578 {
1579 .ival = "wait_after",
1580 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1581 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
3843deb3 1582 .or = 1,
44f29692
JA
1583 },
1584 },
3843deb3 1585 .type = FIO_OPT_STR_MULTI,
44f29692
JA
1586 .cb = str_sfr_cb,
1587 .off1 = td_var_offset(sync_file_range),
1588 .help = "Use sync_file_range()",
e8b0e958
JA
1589 .category = FIO_OPT_C_FILE,
1590 .group = FIO_OPT_G_INVALID,
44f29692
JA
1591 },
1592#endif
214e1eca
JA
1593 {
1594 .name = "direct",
e8b0e958 1595 .lname = "Direct I/O",
214e1eca
JA
1596 .type = FIO_OPT_BOOL,
1597 .off1 = td_var_offset(odirect),
1598 .help = "Use O_DIRECT IO (negates buffered)",
1599 .def = "0",
a01a1bc5 1600 .inverse = "buffered",
e8b0e958 1601 .category = FIO_OPT_C_IO,
3ceb458f 1602 .group = FIO_OPT_G_IO_TYPE,
214e1eca
JA
1603 },
1604 {
1605 .name = "buffered",
e8b0e958 1606 .lname = "Buffered I/O",
214e1eca
JA
1607 .type = FIO_OPT_BOOL,
1608 .off1 = td_var_offset(odirect),
1609 .neg = 1,
1610 .help = "Use buffered IO (negates direct)",
1611 .def = "1",
a01a1bc5 1612 .inverse = "direct",
e8b0e958 1613 .category = FIO_OPT_C_IO,
3ceb458f 1614 .group = FIO_OPT_G_IO_TYPE,
214e1eca
JA
1615 },
1616 {
1617 .name = "overwrite",
e8b0e958 1618 .lname = "Overwrite",
214e1eca
JA
1619 .type = FIO_OPT_BOOL,
1620 .off1 = td_var_offset(overwrite),
1621 .help = "When writing, set whether to overwrite current data",
1622 .def = "0",
e8b0e958
JA
1623 .category = FIO_OPT_C_FILE,
1624 .group = FIO_OPT_G_INVALID,
214e1eca
JA
1625 },
1626 {
1627 .name = "loops",
e8b0e958 1628 .lname = "Loops",
214e1eca
JA
1629 .type = FIO_OPT_INT,
1630 .off1 = td_var_offset(loops),
1631 .help = "Number of times to run the job",
1632 .def = "1",
20eb06bd 1633 .interval = 1,
e8b0e958 1634 .category = FIO_OPT_C_GENERAL,
a1f6afec 1635 .group = FIO_OPT_G_RUNTIME,
214e1eca
JA
1636 },
1637 {
1638 .name = "numjobs",
e8b0e958 1639 .lname = "Number of jobs",
214e1eca
JA
1640 .type = FIO_OPT_INT,
1641 .off1 = td_var_offset(numjobs),
1642 .help = "Duplicate this job this many times",
1643 .def = "1",
20eb06bd 1644 .interval = 1,
e8b0e958 1645 .category = FIO_OPT_C_GENERAL,
a1f6afec 1646 .group = FIO_OPT_G_RUNTIME,
214e1eca
JA
1647 },
1648 {
1649 .name = "startdelay",
e8b0e958 1650 .lname = "Start delay",
a5737c93 1651 .type = FIO_OPT_STR_VAL_TIME,
214e1eca
JA
1652 .off1 = td_var_offset(start_delay),
1653 .help = "Only start job when this period has passed",
1654 .def = "0",
e8b0e958 1655 .category = FIO_OPT_C_GENERAL,
a1f6afec 1656 .group = FIO_OPT_G_RUNTIME,
214e1eca
JA
1657 },
1658 {
1659 .name = "runtime",
e8b0e958 1660 .lname = "Runtime",
214e1eca
JA
1661 .alias = "timeout",
1662 .type = FIO_OPT_STR_VAL_TIME,
1663 .off1 = td_var_offset(timeout),
1664 .help = "Stop workload when this amount of time has passed",
1665 .def = "0",
e8b0e958 1666 .category = FIO_OPT_C_GENERAL,
a1f6afec 1667 .group = FIO_OPT_G_RUNTIME,
214e1eca 1668 },
cf4464ca
JA
1669 {
1670 .name = "time_based",
e8b0e958 1671 .lname = "Time based",
cf4464ca
JA
1672 .type = FIO_OPT_STR_SET,
1673 .off1 = td_var_offset(time_based),
1674 .help = "Keep running until runtime/timeout is met",
e8b0e958 1675 .category = FIO_OPT_C_GENERAL,
a1f6afec 1676 .group = FIO_OPT_G_RUNTIME,
cf4464ca 1677 },
721938ae
JA
1678 {
1679 .name = "ramp_time",
e8b0e958 1680 .lname = "Ramp time",
721938ae
JA
1681 .type = FIO_OPT_STR_VAL_TIME,
1682 .off1 = td_var_offset(ramp_time),
1683 .help = "Ramp up time before measuring performance",
e8b0e958 1684 .category = FIO_OPT_C_GENERAL,
a1f6afec 1685 .group = FIO_OPT_G_RUNTIME,
721938ae 1686 },
c223da83
JA
1687 {
1688 .name = "clocksource",
e8b0e958 1689 .lname = "Clock source",
c223da83
JA
1690 .type = FIO_OPT_STR,
1691 .cb = fio_clock_source_cb,
1692 .off1 = td_var_offset(clocksource),
1693 .help = "What type of timing source to use",
e8b0e958 1694 .category = FIO_OPT_C_GENERAL,
10860056 1695 .group = FIO_OPT_G_CLOCK,
c223da83
JA
1696 .posval = {
1697 { .ival = "gettimeofday",
1698 .oval = CS_GTOD,
1699 .help = "Use gettimeofday(2) for timing",
1700 },
1701 { .ival = "clock_gettime",
1702 .oval = CS_CGETTIME,
1703 .help = "Use clock_gettime(2) for timing",
1704 },
1705#ifdef ARCH_HAVE_CPU_CLOCK
1706 { .ival = "cpu",
1707 .oval = CS_CPUCLOCK,
1708 .help = "Use CPU private clock",
1709 },
1710#endif
1711 },
1712 },
214e1eca
JA
1713 {
1714 .name = "mem",
d3aad8f2 1715 .alias = "iomem",
e8b0e958 1716 .lname = "I/O Memory",
214e1eca
JA
1717 .type = FIO_OPT_STR,
1718 .cb = str_mem_cb,
1719 .off1 = td_var_offset(mem_type),
1720 .help = "Backing type for IO buffers",
1721 .def = "malloc",
e8b0e958
JA
1722 .category = FIO_OPT_C_IO,
1723 .group = FIO_OPT_G_INVALID,
214e1eca
JA
1724 .posval = {
1725 { .ival = "malloc",
1726 .oval = MEM_MALLOC,
1727 .help = "Use malloc(3) for IO buffers",
1728 },
37c8cdfe
JA
1729 { .ival = "shm",
1730 .oval = MEM_SHM,
1731 .help = "Use shared memory segments for IO buffers",
1732 },
214e1eca
JA
1733#ifdef FIO_HAVE_HUGETLB
1734 { .ival = "shmhuge",
1735 .oval = MEM_SHMHUGE,
1736 .help = "Like shm, but use huge pages",
1737 },
b370e46a 1738#endif
37c8cdfe
JA
1739 { .ival = "mmap",
1740 .oval = MEM_MMAP,
1741 .help = "Use mmap(2) (file or anon) for IO buffers",
1742 },
214e1eca
JA
1743#ifdef FIO_HAVE_HUGETLB
1744 { .ival = "mmaphuge",
1745 .oval = MEM_MMAPHUGE,
1746 .help = "Like mmap, but use huge pages",
1747 },
1748#endif
1749 },
1750 },
d529ee19
JA
1751 {
1752 .name = "iomem_align",
1753 .alias = "mem_align",
e8b0e958 1754 .lname = "I/O memory alignment",
d529ee19
JA
1755 .type = FIO_OPT_INT,
1756 .off1 = td_var_offset(mem_align),
1757 .minval = 0,
1758 .help = "IO memory buffer offset alignment",
1759 .def = "0",
1760 .parent = "iomem",
d71c154c 1761 .hide = 1,
e8b0e958
JA
1762 .category = FIO_OPT_C_IO,
1763 .group = FIO_OPT_G_INVALID,
d529ee19 1764 },
214e1eca
JA
1765 {
1766 .name = "verify",
e8b0e958 1767 .lname = "Verify",
214e1eca
JA
1768 .type = FIO_OPT_STR,
1769 .off1 = td_var_offset(verify),
1770 .help = "Verify data written",
1771 .def = "0",
e8b0e958 1772 .category = FIO_OPT_C_IO,
3ceb458f 1773 .group = FIO_OPT_G_VERIFY,
214e1eca
JA
1774 .posval = {
1775 { .ival = "0",
1776 .oval = VERIFY_NONE,
1777 .help = "Don't do IO verification",
1778 },
fcca4b58
JA
1779 { .ival = "md5",
1780 .oval = VERIFY_MD5,
1781 .help = "Use md5 checksums for verification",
1782 },
d77a7af3
JA
1783 { .ival = "crc64",
1784 .oval = VERIFY_CRC64,
1785 .help = "Use crc64 checksums for verification",
1786 },
214e1eca
JA
1787 { .ival = "crc32",
1788 .oval = VERIFY_CRC32,
1789 .help = "Use crc32 checksums for verification",
1790 },
af497e6a 1791 { .ival = "crc32c-intel",
e3aaafc4
JA
1792 .oval = VERIFY_CRC32C,
1793 .help = "Use crc32c checksums for verification (hw assisted, if available)",
af497e6a 1794 },
bac39e0e
JA
1795 { .ival = "crc32c",
1796 .oval = VERIFY_CRC32C,
e3aaafc4 1797 .help = "Use crc32c checksums for verification (hw assisted, if available)",
bac39e0e 1798 },
969f7ed3
JA
1799 { .ival = "crc16",
1800 .oval = VERIFY_CRC16,
1801 .help = "Use crc16 checksums for verification",
1802 },
1e154bdb
JA
1803 { .ival = "crc7",
1804 .oval = VERIFY_CRC7,
1805 .help = "Use crc7 checksums for verification",
1806 },
7c353ceb
JA
1807 { .ival = "sha1",
1808 .oval = VERIFY_SHA1,
1809 .help = "Use sha1 checksums for verification",
1810 },
cd14cc10
JA
1811 { .ival = "sha256",
1812 .oval = VERIFY_SHA256,
1813 .help = "Use sha256 checksums for verification",
1814 },
1815 { .ival = "sha512",
1816 .oval = VERIFY_SHA512,
1817 .help = "Use sha512 checksums for verification",
1818 },
7437ee87
SL
1819 { .ival = "meta",
1820 .oval = VERIFY_META,
1821 .help = "Use io information",
1822 },
36690c9b
JA
1823 {
1824 .ival = "null",
1825 .oval = VERIFY_NULL,
1826 .help = "Pretend to verify",
1827 },
214e1eca
JA
1828 },
1829 },
005c565a
JA
1830 {
1831 .name = "do_verify",
e8b0e958 1832 .lname = "Perform verify step",
68e1f29a 1833 .type = FIO_OPT_BOOL,
005c565a
JA
1834 .off1 = td_var_offset(do_verify),
1835 .help = "Run verification stage after write",
1836 .def = "1",
1837 .parent = "verify",
d71c154c 1838 .hide = 1,
e8b0e958
JA
1839 .category = FIO_OPT_C_IO,
1840 .group = FIO_OPT_G_VERIFY,
005c565a 1841 },
160b966d
JA
1842 {
1843 .name = "verifysort",
e8b0e958 1844 .lname = "Verify sort",
160b966d
JA
1845 .type = FIO_OPT_BOOL,
1846 .off1 = td_var_offset(verifysort),
1847 .help = "Sort written verify blocks for read back",
1848 .def = "1",
c83f2df1 1849 .parent = "verify",
d71c154c 1850 .hide = 1,
e8b0e958
JA
1851 .category = FIO_OPT_C_IO,
1852 .group = FIO_OPT_G_VERIFY,
160b966d 1853 },
3f9f4e26 1854 {
a59e170d 1855 .name = "verify_interval",
e8b0e958 1856 .lname = "Verify interval",
e01b22b8 1857 .type = FIO_OPT_INT,
a59e170d 1858 .off1 = td_var_offset(verify_interval),
819a9680 1859 .minval = 2 * sizeof(struct verify_header),
a59e170d 1860 .help = "Store verify buffer header every N bytes",
afdf9352 1861 .parent = "verify",
d71c154c 1862 .hide = 1,
20eb06bd 1863 .interval = 2 * sizeof(struct verify_header),
e8b0e958
JA
1864 .category = FIO_OPT_C_IO,
1865 .group = FIO_OPT_G_VERIFY,
3f9f4e26 1866 },
546a9142 1867 {
a59e170d 1868 .name = "verify_offset",
e8b0e958 1869 .lname = "Verify offset",
e01b22b8 1870 .type = FIO_OPT_INT,
a59e170d 1871 .help = "Offset verify header location by N bytes",
546a9142 1872 .def = "0",
5ec10eaa 1873 .cb = str_verify_offset_cb,
afdf9352 1874 .parent = "verify",
d71c154c 1875 .hide = 1,
e8b0e958
JA
1876 .category = FIO_OPT_C_IO,
1877 .group = FIO_OPT_G_VERIFY,
546a9142 1878 },
e28218f3
SL
1879 {
1880 .name = "verify_pattern",
e8b0e958 1881 .lname = "Verify pattern",
0e92f873 1882 .type = FIO_OPT_STR,
e28218f3
SL
1883 .cb = str_verify_pattern_cb,
1884 .help = "Fill pattern for IO buffers",
1885 .parent = "verify",
d71c154c 1886 .hide = 1,
e8b0e958
JA
1887 .category = FIO_OPT_C_IO,
1888 .group = FIO_OPT_G_VERIFY,
e28218f3 1889 },
a12a3b4d
JA
1890 {
1891 .name = "verify_fatal",
e8b0e958 1892 .lname = "Verify fatal",
68e1f29a 1893 .type = FIO_OPT_BOOL,
a12a3b4d
JA
1894 .off1 = td_var_offset(verify_fatal),
1895 .def = "0",
1896 .help = "Exit on a single verify failure, don't continue",
1897 .parent = "verify",
d71c154c 1898 .hide = 1,
e8b0e958
JA
1899 .category = FIO_OPT_C_IO,
1900 .group = FIO_OPT_G_VERIFY,
a12a3b4d 1901 },
b463e936
JA
1902 {
1903 .name = "verify_dump",
e8b0e958 1904 .lname = "Verify dump",
b463e936
JA
1905 .type = FIO_OPT_BOOL,
1906 .off1 = td_var_offset(verify_dump),
ef71e317 1907 .def = "0",
b463e936
JA
1908 .help = "Dump contents of good and bad blocks on failure",
1909 .parent = "verify",
d71c154c 1910 .hide = 1,
e8b0e958
JA
1911 .category = FIO_OPT_C_IO,
1912 .group = FIO_OPT_G_VERIFY,
b463e936 1913 },
e8462bd8
JA
1914 {
1915 .name = "verify_async",
e8b0e958 1916 .lname = "Verify asynchronously",
e8462bd8
JA
1917 .type = FIO_OPT_INT,
1918 .off1 = td_var_offset(verify_async),
1919 .def = "0",
1920 .help = "Number of async verifier threads to use",
1921 .parent = "verify",
d71c154c 1922 .hide = 1,
e8b0e958
JA
1923 .category = FIO_OPT_C_IO,
1924 .group = FIO_OPT_G_VERIFY,
e8462bd8 1925 },
9e144189
JA
1926 {
1927 .name = "verify_backlog",
e8b0e958 1928 .lname = "Verify backlog",
9e144189
JA
1929 .type = FIO_OPT_STR_VAL,
1930 .off1 = td_var_offset(verify_backlog),
1931 .help = "Verify after this number of blocks are written",
1932 .parent = "verify",
d71c154c 1933 .hide = 1,
e8b0e958
JA
1934 .category = FIO_OPT_C_IO,
1935 .group = FIO_OPT_G_VERIFY,
9e144189
JA
1936 },
1937 {
1938 .name = "verify_backlog_batch",
e8b0e958 1939 .lname = "Verify backlog batch",
9e144189
JA
1940 .type = FIO_OPT_INT,
1941 .off1 = td_var_offset(verify_batch),
1942 .help = "Verify this number of IO blocks",
0d29de83 1943 .parent = "verify",
d71c154c 1944 .hide = 1,
e8b0e958
JA
1945 .category = FIO_OPT_C_IO,
1946 .group = FIO_OPT_G_VERIFY,
9e144189 1947 },
e8462bd8
JA
1948#ifdef FIO_HAVE_CPU_AFFINITY
1949 {
1950 .name = "verify_async_cpus",
e8b0e958 1951 .lname = "Async verify CPUs",
e8462bd8
JA
1952 .type = FIO_OPT_STR,
1953 .cb = str_verify_cpus_allowed_cb,
1954 .help = "Set CPUs allowed for async verify threads",
1955 .parent = "verify_async",
d71c154c 1956 .hide = 1,
e8b0e958
JA
1957 .category = FIO_OPT_C_IO,
1958 .group = FIO_OPT_G_VERIFY,
e8462bd8 1959 },
0d29de83
JA
1960#endif
1961#ifdef FIO_HAVE_TRIM
1962 {
1963 .name = "trim_percentage",
e8b0e958 1964 .lname = "Trim percentage",
0d29de83
JA
1965 .type = FIO_OPT_INT,
1966 .cb = str_verify_trim_cb,
20eb06bd 1967 .minval = 0,
0d29de83
JA
1968 .maxval = 100,
1969 .help = "Number of verify blocks to discard/trim",
1970 .parent = "verify",
1971 .def = "0",
20eb06bd 1972 .interval = 1,
d71c154c 1973 .hide = 1,
e8b0e958
JA
1974 .category = FIO_OPT_C_IO,
1975 .group = FIO_OPT_G_TRIM,
0d29de83
JA
1976 },
1977 {
1978 .name = "trim_verify_zero",
e8b0e958 1979 .lname = "Verify trim zero",
20eb06bd 1980 .type = FIO_OPT_BOOL,
0d29de83
JA
1981 .help = "Verify that trim/discarded blocks are returned as zeroes",
1982 .off1 = td_var_offset(trim_zero),
1983 .parent = "trim_percentage",
d71c154c 1984 .hide = 1,
0d29de83 1985 .def = "1",
e8b0e958
JA
1986 .category = FIO_OPT_C_IO,
1987 .group = FIO_OPT_G_TRIM,
0d29de83
JA
1988 },
1989 {
1990 .name = "trim_backlog",
e8b0e958 1991 .lname = "Trim backlog",
0d29de83
JA
1992 .type = FIO_OPT_STR_VAL,
1993 .off1 = td_var_offset(trim_backlog),
1994 .help = "Trim after this number of blocks are written",
1995 .parent = "trim_percentage",
d71c154c 1996 .hide = 1,
20eb06bd 1997 .interval = 1,
e8b0e958
JA
1998 .category = FIO_OPT_C_IO,
1999 .group = FIO_OPT_G_TRIM,
0d29de83
JA
2000 },
2001 {
2002 .name = "trim_backlog_batch",
e8b0e958 2003 .lname = "Trim backlog batch",
0d29de83
JA
2004 .type = FIO_OPT_INT,
2005 .off1 = td_var_offset(trim_batch),
2006 .help = "Trim this number of IO blocks",
2007 .parent = "trim_percentage",
d71c154c 2008 .hide = 1,
20eb06bd 2009 .interval = 1,
e8b0e958
JA
2010 .category = FIO_OPT_C_IO,
2011 .group = FIO_OPT_G_TRIM,
0d29de83 2012 },
e8462bd8 2013#endif
214e1eca
JA
2014 {
2015 .name = "write_iolog",
e8b0e958 2016 .lname = "Write I/O log",
214e1eca
JA
2017 .type = FIO_OPT_STR_STORE,
2018 .off1 = td_var_offset(write_iolog_file),
2019 .help = "Store IO pattern to file",
e8b0e958
JA
2020 .category = FIO_OPT_C_IO,
2021 .group = FIO_OPT_G_IOLOG,
214e1eca
JA
2022 },
2023 {
2024 .name = "read_iolog",
e8b0e958 2025 .lname = "Read I/O log",
214e1eca
JA
2026 .type = FIO_OPT_STR_STORE,
2027 .off1 = td_var_offset(read_iolog_file),
2028 .help = "Playback IO pattern from file",
e8b0e958
JA
2029 .category = FIO_OPT_C_IO,
2030 .group = FIO_OPT_G_IOLOG,
214e1eca 2031 },
64bbb865
DN
2032 {
2033 .name = "replay_no_stall",
e8b0e958 2034 .lname = "Don't stall on replay",
20eb06bd 2035 .type = FIO_OPT_BOOL,
64bbb865
DN
2036 .off1 = td_var_offset(no_stall),
2037 .def = "0",
87e7a972 2038 .parent = "read_iolog",
d71c154c 2039 .hide = 1,
64bbb865 2040 .help = "Playback IO pattern file as fast as possible without stalls",
e8b0e958
JA
2041 .category = FIO_OPT_C_IO,
2042 .group = FIO_OPT_G_IOLOG,
64bbb865 2043 },
d1c46c04
DN
2044 {
2045 .name = "replay_redirect",
e8b0e958 2046 .lname = "Redirect device for replay",
d1c46c04
DN
2047 .type = FIO_OPT_STR_STORE,
2048 .off1 = td_var_offset(replay_redirect),
2049 .parent = "read_iolog",
d71c154c 2050 .hide = 1,
d1c46c04 2051 .help = "Replay all I/O onto this device, regardless of trace device",
e8b0e958
JA
2052 .category = FIO_OPT_C_IO,
2053 .group = FIO_OPT_G_IOLOG,
d1c46c04 2054 },
214e1eca
JA
2055 {
2056 .name = "exec_prerun",
e8b0e958 2057 .lname = "Pre-execute runnable",
214e1eca
JA
2058 .type = FIO_OPT_STR_STORE,
2059 .off1 = td_var_offset(exec_prerun),
2060 .help = "Execute this file prior to running job",
e8b0e958
JA
2061 .category = FIO_OPT_C_GENERAL,
2062 .group = FIO_OPT_G_INVALID,
214e1eca
JA
2063 },
2064 {
2065 .name = "exec_postrun",
e8b0e958 2066 .lname = "Post-execute runnable",
214e1eca
JA
2067 .type = FIO_OPT_STR_STORE,
2068 .off1 = td_var_offset(exec_postrun),
2069 .help = "Execute this file after running job",
e8b0e958
JA
2070 .category = FIO_OPT_C_GENERAL,
2071 .group = FIO_OPT_G_INVALID,
214e1eca
JA
2072 },
2073#ifdef FIO_HAVE_IOSCHED_SWITCH
2074 {
2075 .name = "ioscheduler",
e8b0e958 2076 .lname = "I/O scheduler",
214e1eca
JA
2077 .type = FIO_OPT_STR_STORE,
2078 .off1 = td_var_offset(ioscheduler),
2079 .help = "Use this IO scheduler on the backing device",
e8b0e958
JA
2080 .category = FIO_OPT_C_FILE,
2081 .group = FIO_OPT_G_INVALID,
214e1eca
JA
2082 },
2083#endif
2084 {
2085 .name = "zonesize",
e8b0e958 2086 .lname = "Zone size",
214e1eca
JA
2087 .type = FIO_OPT_STR_VAL,
2088 .off1 = td_var_offset(zone_size),
ed335855
SN
2089 .help = "Amount of data to read per zone",
2090 .def = "0",
20eb06bd 2091 .interval = 1024 * 1024,
e8b0e958
JA
2092 .category = FIO_OPT_C_IO,
2093 .group = FIO_OPT_G_ZONE,
ed335855
SN
2094 },
2095 {
2096 .name = "zonerange",
e8b0e958 2097 .lname = "Zone range",
ed335855
SN
2098 .type = FIO_OPT_STR_VAL,
2099 .off1 = td_var_offset(zone_range),
214e1eca
JA
2100 .help = "Give size of an IO zone",
2101 .def = "0",
20eb06bd 2102 .interval = 1024 * 1024,
e8b0e958
JA
2103 .category = FIO_OPT_C_IO,
2104 .group = FIO_OPT_G_ZONE,
214e1eca
JA
2105 },
2106 {
2107 .name = "zoneskip",
e8b0e958 2108 .lname = "Zone skip",
214e1eca
JA
2109 .type = FIO_OPT_STR_VAL,
2110 .off1 = td_var_offset(zone_skip),
2111 .help = "Space between IO zones",
2112 .def = "0",
20eb06bd 2113 .interval = 1024 * 1024,
e8b0e958
JA
2114 .category = FIO_OPT_C_IO,
2115 .group = FIO_OPT_G_ZONE,
214e1eca
JA
2116 },
2117 {
2118 .name = "lockmem",
e8b0e958 2119 .lname = "Lock memory",
214e1eca 2120 .type = FIO_OPT_STR_VAL,
1b79a070 2121 .off1 = td_var_offset(lockmem),
214e1eca
JA
2122 .help = "Lock down this amount of memory",
2123 .def = "0",
20eb06bd 2124 .interval = 1024 * 1024,
e8b0e958
JA
2125 .category = FIO_OPT_C_GENERAL,
2126 .group = FIO_OPT_G_INVALID,
214e1eca 2127 },
214e1eca
JA
2128 {
2129 .name = "rwmixread",
e8b0e958 2130 .lname = "Read/write mix read",
214e1eca 2131 .type = FIO_OPT_INT,
cb499fc4 2132 .cb = str_rwmix_read_cb,
214e1eca
JA
2133 .maxval = 100,
2134 .help = "Percentage of mixed workload that is reads",
2135 .def = "50",
20eb06bd 2136 .interval = 5,
90265353 2137 .inverse = "rwmixwrite",
e8b0e958
JA
2138 .category = FIO_OPT_C_IO,
2139 .group = FIO_OPT_G_RWMIX,
214e1eca
JA
2140 },
2141 {
2142 .name = "rwmixwrite",
e8b0e958 2143 .lname = "Read/write mix write",
214e1eca 2144 .type = FIO_OPT_INT,
cb499fc4 2145 .cb = str_rwmix_write_cb,
214e1eca
JA
2146 .maxval = 100,
2147 .help = "Percentage of mixed workload that is writes",
2148 .def = "50",
20eb06bd 2149 .interval = 5,
90265353 2150 .inverse = "rwmixread",
e8b0e958
JA
2151 .category = FIO_OPT_C_IO,
2152 .group = FIO_OPT_G_RWMIX,
214e1eca 2153 },
afdf9352
JA
2154 {
2155 .name = "rwmixcycle",
e8b0e958 2156 .lname = "Read/write mix cycle",
15ca150e 2157 .type = FIO_OPT_DEPRECATED,
e8b0e958
JA
2158 .category = FIO_OPT_C_IO,
2159 .group = FIO_OPT_G_RWMIX,
afdf9352 2160 },
214e1eca
JA
2161 {
2162 .name = "nice",
e8b0e958 2163 .lname = "Nice",
214e1eca
JA
2164 .type = FIO_OPT_INT,
2165 .off1 = td_var_offset(nice),
2166 .help = "Set job CPU nice value",
2167 .minval = -19,
2168 .maxval = 20,
2169 .def = "0",
20eb06bd 2170 .interval = 1,
e8b0e958 2171 .category = FIO_OPT_C_GENERAL,
10860056 2172 .group = FIO_OPT_G_CRED,
214e1eca
JA
2173 },
2174#ifdef FIO_HAVE_IOPRIO
2175 {
2176 .name = "prio",
e8b0e958 2177 .lname = "I/O nice priority",
214e1eca
JA
2178 .type = FIO_OPT_INT,
2179 .cb = str_prio_cb,
2180 .help = "Set job IO priority value",
2181 .minval = 0,
2182 .maxval = 7,
20eb06bd 2183 .interval = 1,
e8b0e958 2184 .category = FIO_OPT_C_GENERAL,
10860056 2185 .group = FIO_OPT_G_CRED,
214e1eca
JA
2186 },
2187 {
2188 .name = "prioclass",
e8b0e958 2189 .lname = "I/O nice priority class",
214e1eca
JA
2190 .type = FIO_OPT_INT,
2191 .cb = str_prioclass_cb,
2192 .help = "Set job IO priority class",
2193 .minval = 0,
2194 .maxval = 3,
20eb06bd 2195 .interval = 1,
e8b0e958 2196 .category = FIO_OPT_C_GENERAL,
10860056 2197 .group = FIO_OPT_G_CRED,
214e1eca
JA
2198 },
2199#endif
2200 {
2201 .name = "thinktime",
e8b0e958 2202 .lname = "Thinktime",
214e1eca
JA
2203 .type = FIO_OPT_INT,
2204 .off1 = td_var_offset(thinktime),
2205 .help = "Idle time between IO buffers (usec)",
2206 .def = "0",
e8b0e958 2207 .category = FIO_OPT_C_IO,
3ceb458f 2208 .group = FIO_OPT_G_THINKTIME,
214e1eca
JA
2209 },
2210 {
2211 .name = "thinktime_spin",
e8b0e958 2212 .lname = "Thinktime spin",
214e1eca
JA
2213 .type = FIO_OPT_INT,
2214 .off1 = td_var_offset(thinktime_spin),
2215 .help = "Start think time by spinning this amount (usec)",
2216 .def = "0",
afdf9352 2217 .parent = "thinktime",
d71c154c 2218 .hide = 1,
e8b0e958 2219 .category = FIO_OPT_C_IO,
3ceb458f 2220 .group = FIO_OPT_G_THINKTIME,
214e1eca
JA
2221 },
2222 {
2223 .name = "thinktime_blocks",
e8b0e958 2224 .lname = "Thinktime blocks",
214e1eca
JA
2225 .type = FIO_OPT_INT,
2226 .off1 = td_var_offset(thinktime_blocks),
2227 .help = "IO buffer period between 'thinktime'",
2228 .def = "1",
afdf9352 2229 .parent = "thinktime",
d71c154c 2230 .hide = 1,
e8b0e958 2231 .category = FIO_OPT_C_IO,
3ceb458f 2232 .group = FIO_OPT_G_THINKTIME,
214e1eca
JA
2233 },
2234 {
2235 .name = "rate",
e8b0e958 2236 .lname = "I/O rate",
e01b22b8 2237 .type = FIO_OPT_INT,
581e7141
JA
2238 .off1 = td_var_offset(rate[0]),
2239 .off2 = td_var_offset(rate[1]),
214e1eca 2240 .help = "Set bandwidth rate",
e8b0e958
JA
2241 .category = FIO_OPT_C_IO,
2242 .group = FIO_OPT_G_RATE,
214e1eca
JA
2243 },
2244 {
2245 .name = "ratemin",
e8b0e958 2246 .lname = "I/O min rate",
e01b22b8 2247 .type = FIO_OPT_INT,
581e7141
JA
2248 .off1 = td_var_offset(ratemin[0]),
2249 .off2 = td_var_offset(ratemin[1]),
4e991c23 2250 .help = "Job must meet this rate or it will be shutdown",
afdf9352 2251 .parent = "rate",
d71c154c 2252 .hide = 1,
e8b0e958
JA
2253 .category = FIO_OPT_C_IO,
2254 .group = FIO_OPT_G_RATE,
4e991c23
JA
2255 },
2256 {
2257 .name = "rate_iops",
e8b0e958 2258 .lname = "I/O rate IOPS",
e01b22b8 2259 .type = FIO_OPT_INT,
581e7141
JA
2260 .off1 = td_var_offset(rate_iops[0]),
2261 .off2 = td_var_offset(rate_iops[1]),
4e991c23 2262 .help = "Limit IO used to this number of IO operations/sec",
d71c154c 2263 .hide = 1,
e8b0e958
JA
2264 .category = FIO_OPT_C_IO,
2265 .group = FIO_OPT_G_RATE,
4e991c23
JA
2266 },
2267 {
2268 .name = "rate_iops_min",
e8b0e958 2269 .lname = "I/O min rate IOPS",
e01b22b8 2270 .type = FIO_OPT_INT,
581e7141
JA
2271 .off1 = td_var_offset(rate_iops_min[0]),
2272 .off2 = td_var_offset(rate_iops_min[1]),
03e20d68 2273 .help = "Job must meet this rate or it will be shut down",
afdf9352 2274 .parent = "rate_iops",
d71c154c 2275 .hide = 1,
e8b0e958
JA
2276 .category = FIO_OPT_C_IO,
2277 .group = FIO_OPT_G_RATE,
214e1eca
JA
2278 },
2279 {
2280 .name = "ratecycle",
e8b0e958 2281 .lname = "I/O rate cycle",
214e1eca
JA
2282 .type = FIO_OPT_INT,
2283 .off1 = td_var_offset(ratecycle),
2284 .help = "Window average for rate limits (msec)",
2285 .def = "1000",
afdf9352 2286 .parent = "rate",
d71c154c 2287 .hide = 1,
e8b0e958
JA
2288 .category = FIO_OPT_C_IO,
2289 .group = FIO_OPT_G_RATE,
214e1eca
JA
2290 },
2291 {
2292 .name = "invalidate",
e8b0e958 2293 .lname = "Cache invalidate",
214e1eca
JA
2294 .type = FIO_OPT_BOOL,
2295 .off1 = td_var_offset(invalidate_cache),
2296 .help = "Invalidate buffer/page cache prior to running job",
2297 .def = "1",
e8b0e958 2298 .category = FIO_OPT_C_IO,
3ceb458f 2299 .group = FIO_OPT_G_IO_TYPE,
214e1eca
JA
2300 },
2301 {
2302 .name = "sync",
e8b0e958 2303 .lname = "Synchronous I/O",
214e1eca
JA
2304 .type = FIO_OPT_BOOL,
2305 .off1 = td_var_offset(sync_io),
2306 .help = "Use O_SYNC for buffered writes",
2307 .def = "0",
67a1000f 2308 .parent = "buffered",
d71c154c 2309 .hide = 1,
e8b0e958 2310 .category = FIO_OPT_C_IO,
3ceb458f 2311 .group = FIO_OPT_G_IO_TYPE,
214e1eca 2312 },
214e1eca
JA
2313 {
2314 .name = "create_serialize",
e8b0e958 2315 .lname = "Create serialize",
214e1eca
JA
2316 .type = FIO_OPT_BOOL,
2317 .off1 = td_var_offset(create_serialize),
2318 .help = "Serialize creating of job files",
2319 .def = "1",
e8b0e958
JA
2320 .category = FIO_OPT_C_FILE,
2321 .group = FIO_OPT_G_INVALID,
214e1eca
JA
2322 },
2323 {
2324 .name = "create_fsync",
e8b0e958 2325 .lname = "Create fsync",
214e1eca
JA
2326 .type = FIO_OPT_BOOL,
2327 .off1 = td_var_offset(create_fsync),
03e20d68 2328 .help = "fsync file after creation",
214e1eca 2329 .def = "1",
e8b0e958
JA
2330 .category = FIO_OPT_C_FILE,
2331 .group = FIO_OPT_G_INVALID,
214e1eca 2332 },
814452bd
JA
2333 {
2334 .name = "create_on_open",
e8b0e958 2335 .lname = "Create on open",
814452bd
JA
2336 .type = FIO_OPT_BOOL,
2337 .off1 = td_var_offset(create_on_open),
2338 .help = "Create files when they are opened for IO",
2339 .def = "0",
e8b0e958
JA
2340 .category = FIO_OPT_C_FILE,
2341 .group = FIO_OPT_G_INVALID,
814452bd 2342 },
0b9d69ec 2343 {
afad68f7 2344 .name = "pre_read",
e8b0e958 2345 .lname = "Pre-read files",
afad68f7
ZY
2346 .type = FIO_OPT_BOOL,
2347 .off1 = td_var_offset(pre_read),
03e20d68 2348 .help = "Pre-read files before starting official testing",
afad68f7 2349 .def = "0",
e8b0e958
JA
2350 .category = FIO_OPT_C_FILE,
2351 .group = FIO_OPT_G_INVALID,
afad68f7 2352 },
214e1eca
JA
2353#ifdef FIO_HAVE_CPU_AFFINITY
2354 {
2355 .name = "cpumask",
e8b0e958 2356 .lname = "CPU mask",
214e1eca
JA
2357 .type = FIO_OPT_INT,
2358 .cb = str_cpumask_cb,
2359 .help = "CPU affinity mask",
e8b0e958 2360 .category = FIO_OPT_C_GENERAL,
10860056 2361 .group = FIO_OPT_G_CRED,
214e1eca 2362 },
d2e268b0
JA
2363 {
2364 .name = "cpus_allowed",
e8b0e958 2365 .lname = "CPUs allowed",
d2e268b0
JA
2366 .type = FIO_OPT_STR,
2367 .cb = str_cpus_allowed_cb,
2368 .help = "Set CPUs allowed",
e8b0e958 2369 .category = FIO_OPT_C_GENERAL,
10860056 2370 .group = FIO_OPT_G_CRED,
d2e268b0 2371 },
214e1eca
JA
2372#endif
2373 {
2374 .name = "end_fsync",
e8b0e958 2375 .lname = "End fsync",
214e1eca
JA
2376 .type = FIO_OPT_BOOL,
2377 .off1 = td_var_offset(end_fsync),
2378 .help = "Include fsync at the end of job",
2379 .def = "0",
e8b0e958
JA
2380 .category = FIO_OPT_C_FILE,
2381 .group = FIO_OPT_G_INVALID,
214e1eca
JA
2382 },
2383 {
2384 .name = "fsync_on_close",
e8b0e958 2385 .lname = "Fsync on close",
214e1eca
JA
2386 .type = FIO_OPT_BOOL,
2387 .off1 = td_var_offset(fsync_on_close),
2388 .help = "fsync files on close",
2389 .def = "0",
e8b0e958
JA
2390 .category = FIO_OPT_C_FILE,
2391 .group = FIO_OPT_G_INVALID,
214e1eca
JA
2392 },
2393 {
2394 .name = "unlink",
e8b0e958 2395 .lname = "Unlink file",
214e1eca
JA
2396 .type = FIO_OPT_BOOL,
2397 .off1 = td_var_offset(unlink),
2398 .help = "Unlink created files after job has completed",
2399 .def = "0",
e8b0e958
JA
2400 .category = FIO_OPT_C_FILE,
2401 .group = FIO_OPT_G_INVALID,
214e1eca
JA
2402 },
2403 {
2404 .name = "exitall",
e8b0e958 2405 .lname = "Exit-all on terminate",
214e1eca
JA
2406 .type = FIO_OPT_STR_SET,
2407 .cb = str_exitall_cb,
2408 .help = "Terminate all jobs when one exits",
e8b0e958 2409 .category = FIO_OPT_C_GENERAL,
a1f6afec 2410 .group = FIO_OPT_G_PROCESS,
214e1eca
JA
2411 },
2412 {
2413 .name = "stonewall",
e8b0e958 2414 .lname = "Wait for previous",
d392365e 2415 .alias = "wait_for_previous",
214e1eca
JA
2416 .type = FIO_OPT_STR_SET,
2417 .off1 = td_var_offset(stonewall),
2418 .help = "Insert a hard barrier between this job and previous",
e8b0e958 2419 .category = FIO_OPT_C_GENERAL,
a1f6afec 2420 .group = FIO_OPT_G_PROCESS,
214e1eca 2421 },
b3d62a75
JA
2422 {
2423 .name = "new_group",
e8b0e958 2424 .lname = "New group",
b3d62a75
JA
2425 .type = FIO_OPT_STR_SET,
2426 .off1 = td_var_offset(new_group),
2427 .help = "Mark the start of a new group (for reporting)",
e8b0e958 2428 .category = FIO_OPT_C_GENERAL,
a1f6afec 2429 .group = FIO_OPT_G_PROCESS,
b3d62a75 2430 },
214e1eca
JA
2431 {
2432 .name = "thread",
e8b0e958 2433 .lname = "Thread",
214e1eca
JA
2434 .type = FIO_OPT_STR_SET,
2435 .off1 = td_var_offset(use_thread),
20eb06bd 2436 .help = "Use threads instead of processes",
e8b0e958 2437 .category = FIO_OPT_C_GENERAL,
a1f6afec 2438 .group = FIO_OPT_G_PROCESS,
214e1eca
JA
2439 },
2440 {
2441 .name = "write_bw_log",
e8b0e958 2442 .lname = "Write bandwidth log",
e3cedca7 2443 .type = FIO_OPT_STR,
214e1eca 2444 .off1 = td_var_offset(write_bw_log),
e3cedca7 2445 .cb = str_write_bw_log_cb,
214e1eca 2446 .help = "Write log of bandwidth during run",
e8b0e958
JA
2447 .category = FIO_OPT_C_LOG,
2448 .group = FIO_OPT_G_INVALID,
214e1eca
JA
2449 },
2450 {
2451 .name = "write_lat_log",
e8b0e958 2452 .lname = "Write latency log",
e3cedca7 2453 .type = FIO_OPT_STR,
214e1eca 2454 .off1 = td_var_offset(write_lat_log),
e3cedca7 2455 .cb = str_write_lat_log_cb,
214e1eca 2456 .help = "Write log of latency during run",
e8b0e958
JA
2457 .category = FIO_OPT_C_LOG,
2458 .group = FIO_OPT_G_INVALID,
214e1eca 2459 },
c8eeb9df
JA
2460 {
2461 .name = "write_iops_log",
e8b0e958 2462 .lname = "Write IOPS log",
c8eeb9df
JA
2463 .type = FIO_OPT_STR,
2464 .off1 = td_var_offset(write_iops_log),
2465 .cb = str_write_iops_log_cb,
2466 .help = "Write log of IOPS during run",
e8b0e958
JA
2467 .category = FIO_OPT_C_LOG,
2468 .group = FIO_OPT_G_INVALID,
c8eeb9df 2469 },
b8bc8cba
JA
2470 {
2471 .name = "log_avg_msec",
e8b0e958 2472 .lname = "Log averaging (msec)",
b8bc8cba
JA
2473 .type = FIO_OPT_INT,
2474 .off1 = td_var_offset(log_avg_msec),
2475 .help = "Average bw/iops/lat logs over this period of time",
2476 .def = "0",
e8b0e958
JA
2477 .category = FIO_OPT_C_LOG,
2478 .group = FIO_OPT_G_INVALID,
b8bc8cba 2479 },
c504ee55
JA
2480 {
2481 .name = "bwavgtime",
2482 .lname = "Bandwidth average time",
2483 .type = FIO_OPT_INT,
2484 .off1 = td_var_offset(bw_avg_time),
2485 .help = "Time window over which to calculate bandwidth"
2486 " (msec)",
2487 .def = "500",
2488 .parent = "write_bw_log",
2489 .hide = 1,
2490 .interval = 100,
2491 .category = FIO_OPT_C_LOG,
2492 .group = FIO_OPT_G_INVALID,
2493 },
2494 {
2495 .name = "iopsavgtime",
2496 .lname = "IOPS average time",
2497 .type = FIO_OPT_INT,
2498 .off1 = td_var_offset(iops_avg_time),
2499 .help = "Time window over which to calculate IOPS (msec)",
2500 .def = "500",
2501 .parent = "write_iops_log",
2502 .hide = 1,
2503 .interval = 100,
2504 .category = FIO_OPT_C_LOG,
2505 .group = FIO_OPT_G_INVALID,
2506 },
214e1eca
JA
2507 {
2508 .name = "group_reporting",
e8b0e958
JA
2509 .lname = "Group reporting",
2510 .type = FIO_OPT_BOOL,
214e1eca
JA
2511 .off1 = td_var_offset(group_reporting),
2512 .help = "Do reporting on a per-group basis",
e8b0e958 2513 .def = "1",
10860056 2514 .category = FIO_OPT_C_STAT,
e8b0e958 2515 .group = FIO_OPT_G_INVALID,
214e1eca 2516 },
e9459e5a
JA
2517 {
2518 .name = "zero_buffers",
e8b0e958 2519 .lname = "Zero I/O buffers",
e9459e5a
JA
2520 .type = FIO_OPT_STR_SET,
2521 .off1 = td_var_offset(zero_buffers),
2522 .help = "Init IO buffers to all zeroes",
e8b0e958 2523 .category = FIO_OPT_C_IO,
3ceb458f 2524 .group = FIO_OPT_G_IO_BUF,
e9459e5a 2525 },
5973cafb
JA
2526 {
2527 .name = "refill_buffers",
e8b0e958 2528 .lname = "Refill I/O buffers",
5973cafb
JA
2529 .type = FIO_OPT_STR_SET,
2530 .off1 = td_var_offset(refill_buffers),
2531 .help = "Refill IO buffers on every IO submit",
e8b0e958 2532 .category = FIO_OPT_C_IO,
3ceb458f 2533 .group = FIO_OPT_G_IO_BUF,
5973cafb 2534 },
fd68418e
JA
2535 {
2536 .name = "scramble_buffers",
e8b0e958 2537 .lname = "Scramble I/O buffers",
fd68418e
JA
2538 .type = FIO_OPT_BOOL,
2539 .off1 = td_var_offset(scramble_buffers),
2540 .help = "Slightly scramble buffers on every IO submit",
2541 .def = "1",
e8b0e958 2542 .category = FIO_OPT_C_IO,
3ceb458f 2543 .group = FIO_OPT_G_IO_BUF,
fd68418e 2544 },
9c42684e
JA
2545 {
2546 .name = "buffer_compress_percentage",
e8b0e958 2547 .lname = "Buffer compression percentage",
9c42684e
JA
2548 .type = FIO_OPT_INT,
2549 .off1 = td_var_offset(compress_percentage),
2550 .maxval = 100,
2551 .minval = 1,
2552 .help = "How compressible the buffer is (approximately)",
20eb06bd 2553 .interval = 5,
e8b0e958 2554 .category = FIO_OPT_C_IO,
3ceb458f 2555 .group = FIO_OPT_G_IO_BUF,
9c42684e 2556 },
f97a43a1
JA
2557 {
2558 .name = "buffer_compress_chunk",
e8b0e958 2559 .lname = "Buffer compression chunk size",
f97a43a1
JA
2560 .type = FIO_OPT_INT,
2561 .off1 = td_var_offset(compress_chunk),
207b18e4 2562 .parent = "buffer_compress_percentage",
d71c154c 2563 .hide = 1,
f97a43a1 2564 .help = "Size of compressible region in buffer",
20eb06bd 2565 .interval = 256,
e8b0e958 2566 .category = FIO_OPT_C_IO,
3ceb458f 2567 .group = FIO_OPT_G_IO_BUF,
f97a43a1 2568 },
83349190
YH
2569 {
2570 .name = "clat_percentiles",
e8b0e958 2571 .lname = "Completion latency percentiles",
83349190
YH
2572 .type = FIO_OPT_BOOL,
2573 .off1 = td_var_offset(clat_percentiles),
2574 .help = "Enable the reporting of completion latency percentiles",
467b35ed 2575 .def = "1",
e8b0e958
JA
2576 .category = FIO_OPT_C_STAT,
2577 .group = FIO_OPT_G_INVALID,
83349190
YH
2578 },
2579 {
2580 .name = "percentile_list",
e8b0e958 2581 .lname = "Completion latency percentile list",
83349190
YH
2582 .type = FIO_OPT_FLOAT_LIST,
2583 .off1 = td_var_offset(percentile_list),
2584 .off2 = td_var_offset(overwrite_plist),
2585 .help = "Specify a custom list of percentiles to report",
2586 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2587 .minfp = 0.0,
2588 .maxfp = 100.0,
e8b0e958
JA
2589 .category = FIO_OPT_C_STAT,
2590 .group = FIO_OPT_G_INVALID,
83349190
YH
2591 },
2592
0a839f30
JA
2593#ifdef FIO_HAVE_DISK_UTIL
2594 {
2595 .name = "disk_util",
e8b0e958 2596 .lname = "Disk utilization",
0a839f30
JA
2597 .type = FIO_OPT_BOOL,
2598 .off1 = td_var_offset(do_disk_util),
f66ab3c8 2599 .help = "Log disk utilization statistics",
0a839f30 2600 .def = "1",
e8b0e958
JA
2601 .category = FIO_OPT_C_STAT,
2602 .group = FIO_OPT_G_INVALID,
0a839f30
JA
2603 },
2604#endif
993bf48b
JA
2605 {
2606 .name = "gtod_reduce",
e8b0e958 2607 .lname = "Reduce gettimeofday() calls",
993bf48b
JA
2608 .type = FIO_OPT_BOOL,
2609 .help = "Greatly reduce number of gettimeofday() calls",
2610 .cb = str_gtod_reduce_cb,
2611 .def = "0",
a4ed77fe 2612 .hide_on_set = 1,
e8b0e958
JA
2613 .category = FIO_OPT_C_STAT,
2614 .group = FIO_OPT_G_INVALID,
993bf48b 2615 },
02af0988
JA
2616 {
2617 .name = "disable_lat",
e8b0e958 2618 .lname = "Disable all latency stats",
02af0988
JA
2619 .type = FIO_OPT_BOOL,
2620 .off1 = td_var_offset(disable_lat),
2621 .help = "Disable latency numbers",
2622 .parent = "gtod_reduce",
d71c154c 2623 .hide = 1,
02af0988 2624 .def = "0",
e8b0e958
JA
2625 .category = FIO_OPT_C_STAT,
2626 .group = FIO_OPT_G_INVALID,
02af0988 2627 },
9520ebb9
JA
2628 {
2629 .name = "disable_clat",
e8b0e958 2630 .lname = "Disable completion latency stats",
9520ebb9
JA
2631 .type = FIO_OPT_BOOL,
2632 .off1 = td_var_offset(disable_clat),
2633 .help = "Disable completion latency numbers",
993bf48b 2634 .parent = "gtod_reduce",
d71c154c 2635 .hide = 1,
9520ebb9 2636 .def = "0",
e8b0e958
JA
2637 .category = FIO_OPT_C_STAT,
2638 .group = FIO_OPT_G_INVALID,
9520ebb9
JA
2639 },
2640 {
2641 .name = "disable_slat",
e8b0e958 2642 .lname = "Disable submission latency stats",
9520ebb9
JA
2643 .type = FIO_OPT_BOOL,
2644 .off1 = td_var_offset(disable_slat),
03e20d68 2645 .help = "Disable submission latency numbers",
993bf48b 2646 .parent = "gtod_reduce",
d71c154c 2647 .hide = 1,
9520ebb9 2648 .def = "0",
e8b0e958
JA
2649 .category = FIO_OPT_C_STAT,
2650 .group = FIO_OPT_G_INVALID,
9520ebb9
JA
2651 },
2652 {
2653 .name = "disable_bw_measurement",
e8b0e958 2654 .lname = "Disable bandwidth stats",
9520ebb9
JA
2655 .type = FIO_OPT_BOOL,
2656 .off1 = td_var_offset(disable_bw),
2657 .help = "Disable bandwidth logging",
993bf48b 2658 .parent = "gtod_reduce",
d71c154c 2659 .hide = 1,
9520ebb9 2660 .def = "0",
e8b0e958
JA
2661 .category = FIO_OPT_C_STAT,
2662 .group = FIO_OPT_G_INVALID,
9520ebb9 2663 },
be4ecfdf
JA
2664 {
2665 .name = "gtod_cpu",
e8b0e958 2666 .lname = "Dedicated gettimeofday() CPU",
be4ecfdf
JA
2667 .type = FIO_OPT_INT,
2668 .cb = str_gtod_cpu_cb,
03e20d68 2669 .help = "Set up dedicated gettimeofday() thread on this CPU",
29d43ff9 2670 .verify = gtod_cpu_verify,
e8b0e958 2671 .category = FIO_OPT_C_GENERAL,
10860056 2672 .group = FIO_OPT_G_CLOCK,
be4ecfdf 2673 },
f2bba182
RR
2674 {
2675 .name = "continue_on_error",
e8b0e958 2676 .lname = "Continue on error",
06842027 2677 .type = FIO_OPT_STR,
f2bba182 2678 .off1 = td_var_offset(continue_on_error),
03e20d68 2679 .help = "Continue on non-fatal errors during IO",
06842027 2680 .def = "none",
e8b0e958
JA
2681 .category = FIO_OPT_C_GENERAL,
2682 .group = FIO_OPT_G_INVALID,
06842027
SL
2683 .posval = {
2684 { .ival = "none",
2685 .oval = ERROR_TYPE_NONE,
2686 .help = "Exit when an error is encountered",
2687 },
2688 { .ival = "read",
2689 .oval = ERROR_TYPE_READ,
2690 .help = "Continue on read errors only",
2691 },
2692 { .ival = "write",
2693 .oval = ERROR_TYPE_WRITE,
2694 .help = "Continue on write errors only",
2695 },
2696 { .ival = "io",
2697 .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2698 .help = "Continue on any IO errors",
2699 },
2700 { .ival = "verify",
2701 .oval = ERROR_TYPE_VERIFY,
2702 .help = "Continue on verify errors only",
2703 },
2704 { .ival = "all",
2705 .oval = ERROR_TYPE_ANY,
2706 .help = "Continue on all io and verify errors",
2707 },
2708 { .ival = "0",
2709 .oval = ERROR_TYPE_NONE,
2710 .help = "Alias for 'none'",
2711 },
2712 { .ival = "1",
2713 .oval = ERROR_TYPE_ANY,
2714 .help = "Alias for 'all'",
2715 },
2716 },
f2bba182 2717 },
9ac8a797
JA
2718 {
2719 .name = "profile",
e8b0e958 2720 .lname = "Profile",
79d16311 2721 .type = FIO_OPT_STR_STORE,
9ac8a797 2722 .off1 = td_var_offset(profile),
9ac8a797 2723 .help = "Select a specific builtin performance test",
e8b0e958
JA
2724 .category = FIO_OPT_C_GENERAL,
2725 .group = FIO_OPT_G_INVALID,
9ac8a797 2726 },
a696fa2a
JA
2727 {
2728 .name = "cgroup",
e8b0e958 2729 .lname = "Cgroup",
a696fa2a
JA
2730 .type = FIO_OPT_STR_STORE,
2731 .off1 = td_var_offset(cgroup),
2732 .help = "Add job to cgroup of this name",
e8b0e958 2733 .category = FIO_OPT_C_GENERAL,
a1f6afec
JA
2734 .group = FIO_OPT_G_CGROUP,
2735 },
2736 {
2737 .name = "cgroup_nodelete",
2738 .lname = "Cgroup no-delete",
2739 .type = FIO_OPT_BOOL,
2740 .off1 = td_var_offset(cgroup_nodelete),
2741 .help = "Do not delete cgroups after job completion",
2742 .def = "0",
2743 .parent = "cgroup",
2744 .category = FIO_OPT_C_GENERAL,
2745 .group = FIO_OPT_G_CGROUP,
a696fa2a
JA
2746 },
2747 {
2748 .name = "cgroup_weight",
e8b0e958 2749 .lname = "Cgroup weight",
a696fa2a
JA
2750 .type = FIO_OPT_INT,
2751 .off1 = td_var_offset(cgroup_weight),
2752 .help = "Use given weight for cgroup",
2753 .minval = 100,
2754 .maxval = 1000,
a1f6afec 2755 .parent = "cgroup",
e8b0e958 2756 .category = FIO_OPT_C_GENERAL,
a1f6afec 2757 .group = FIO_OPT_G_CGROUP,
7de87099 2758 },
e0b0d892
JA
2759 {
2760 .name = "uid",
e8b0e958 2761 .lname = "User ID",
e0b0d892
JA
2762 .type = FIO_OPT_INT,
2763 .off1 = td_var_offset(uid),
2764 .help = "Run job with this user ID",
e8b0e958 2765 .category = FIO_OPT_C_GENERAL,
10860056 2766 .group = FIO_OPT_G_CRED,
e0b0d892
JA
2767 },
2768 {
2769 .name = "gid",
e8b0e958 2770 .lname = "Group ID",
e0b0d892
JA
2771 .type = FIO_OPT_INT,
2772 .off1 = td_var_offset(gid),
2773 .help = "Run job with this group ID",
e8b0e958 2774 .category = FIO_OPT_C_GENERAL,
10860056 2775 .group = FIO_OPT_G_CRED,
e0b0d892 2776 },
a1f6afec
JA
2777 {
2778 .name = "kb_base",
2779 .lname = "KB Base",
2780 .type = FIO_OPT_INT,
2781 .off1 = td_var_offset(kb_base),
2782 .verify = kb_base_verify,
2783 .prio = 1,
2784 .def = "1024",
2785 .help = "How many bytes per KB for reporting (1000 or 1024)",
2786 .category = FIO_OPT_C_GENERAL,
2787 .group = FIO_OPT_G_INVALID,
2788 },
3ceb458f
JA
2789 {
2790 .name = "hugepage-size",
2791 .lname = "Hugepage size",
2792 .type = FIO_OPT_INT,
2793 .off1 = td_var_offset(hugepage_size),
2794 .help = "When using hugepages, specify size of each page",
2795 .def = __fio_stringify(FIO_HUGE_PAGE),
2796 .interval = 1024 * 1024,
2797 .category = FIO_OPT_C_GENERAL,
2798 .group = FIO_OPT_G_INVALID,
2799 },
9e684a49
DE
2800 {
2801 .name = "flow_id",
e8b0e958 2802 .lname = "I/O flow ID",
9e684a49
DE
2803 .type = FIO_OPT_INT,
2804 .off1 = td_var_offset(flow_id),
2805 .help = "The flow index ID to use",
2806 .def = "0",
e8b0e958
JA
2807 .category = FIO_OPT_C_IO,
2808 .group = FIO_OPT_G_IO_FLOW,
9e684a49
DE
2809 },
2810 {
2811 .name = "flow",
e8b0e958 2812 .lname = "I/O flow weight",
9e684a49
DE
2813 .type = FIO_OPT_INT,
2814 .off1 = td_var_offset(flow),
2815 .help = "Weight for flow control of this job",
2816 .parent = "flow_id",
d71c154c 2817 .hide = 1,
9e684a49 2818 .def = "0",
e8b0e958
JA
2819 .category = FIO_OPT_C_IO,
2820 .group = FIO_OPT_G_IO_FLOW,
9e684a49
DE
2821 },
2822 {
2823 .name = "flow_watermark",
e8b0e958 2824 .lname = "I/O flow watermark",
9e684a49
DE
2825 .type = FIO_OPT_INT,
2826 .off1 = td_var_offset(flow_watermark),
2827 .help = "High watermark for flow control. This option"
2828 " should be set to the same value for all threads"
2829 " with non-zero flow.",
2830 .parent = "flow_id",
d71c154c 2831 .hide = 1,
9e684a49 2832 .def = "1024",
e8b0e958
JA
2833 .category = FIO_OPT_C_IO,
2834 .group = FIO_OPT_G_IO_FLOW,
9e684a49
DE
2835 },
2836 {
2837 .name = "flow_sleep",
e8b0e958 2838 .lname = "I/O flow sleep",
9e684a49
DE
2839 .type = FIO_OPT_INT,
2840 .off1 = td_var_offset(flow_sleep),
2841 .help = "How many microseconds to sleep after being held"
2842 " back by the flow control mechanism",
2843 .parent = "flow_id",
d71c154c 2844 .hide = 1,
9e684a49 2845 .def = "0",
e8b0e958
JA
2846 .category = FIO_OPT_C_IO,
2847 .group = FIO_OPT_G_IO_FLOW,
9e684a49 2848 },
214e1eca
JA
2849 {
2850 .name = NULL,
2851 },
2852};
2853
17af15d4 2854static void add_to_lopt(struct option *lopt, struct fio_option *o,
de890a1e 2855 const char *name, int val)
9f81736c 2856{
17af15d4 2857 lopt->name = (char *) name;
de890a1e 2858 lopt->val = val;
9f81736c
JA
2859 if (o->type == FIO_OPT_STR_SET)
2860 lopt->has_arg = no_argument;
2861 else
2862 lopt->has_arg = required_argument;
2863}
2864
de890a1e
SL
2865static void options_to_lopts(struct fio_option *opts,
2866 struct option *long_options,
2867 int i, int option_type)
214e1eca 2868{
de890a1e 2869 struct fio_option *o = &opts[0];
214e1eca 2870 while (o->name) {
de890a1e 2871 add_to_lopt(&long_options[i], o, o->name, option_type);
17af15d4
JA
2872 if (o->alias) {
2873 i++;
de890a1e 2874 add_to_lopt(&long_options[i], o, o->alias, option_type);
17af15d4 2875 }
214e1eca
JA
2876
2877 i++;
2878 o++;
2879 assert(i < FIO_NR_OPTIONS);
2880 }
2881}
2882
de890a1e
SL
2883void fio_options_set_ioengine_opts(struct option *long_options,
2884 struct thread_data *td)
2885{
2886 unsigned int i;
2887
2888 i = 0;
2889 while (long_options[i].name) {
2890 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2891 memset(&long_options[i], 0, sizeof(*long_options));
2892 break;
2893 }
2894 i++;
2895 }
2896
2897 /*
2898 * Just clear out the prior ioengine options.
2899 */
2900 if (!td || !td->eo)
2901 return;
2902
2903 options_to_lopts(td->io_ops->options, long_options, i,
2904 FIO_GETOPT_IOENGINE);
2905}
2906
2907void fio_options_dup_and_init(struct option *long_options)
2908{
2909 unsigned int i;
2910
9af4a244 2911 options_init(fio_options);
de890a1e
SL
2912
2913 i = 0;
2914 while (long_options[i].name)
2915 i++;
2916
9af4a244 2917 options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
de890a1e
SL
2918}
2919
74929ac2
JA
2920struct fio_keyword {
2921 const char *word;
2922 const char *desc;
2923 char *replace;
2924};
2925
2926static struct fio_keyword fio_keywords[] = {
2927 {
2928 .word = "$pagesize",
2929 .desc = "Page size in the system",
2930 },
2931 {
2932 .word = "$mb_memory",
2933 .desc = "Megabytes of memory online",
2934 },
2935 {
2936 .word = "$ncpus",
2937 .desc = "Number of CPUs online in the system",
2938 },
2939 {
2940 .word = NULL,
2941 },
2942};
2943
2944void fio_keywords_init(void)
2945{
3b2e1464 2946 unsigned long long mb_memory;
74929ac2
JA
2947 char buf[128];
2948 long l;
2949
2950 sprintf(buf, "%lu", page_size);
2951 fio_keywords[0].replace = strdup(buf);
2952
8eb016d3 2953 mb_memory = os_phys_mem() / (1024 * 1024);
3b2e1464 2954 sprintf(buf, "%llu", mb_memory);
74929ac2
JA
2955 fio_keywords[1].replace = strdup(buf);
2956
c00a2289 2957 l = cpus_online();
74929ac2
JA
2958 sprintf(buf, "%lu", l);
2959 fio_keywords[2].replace = strdup(buf);
2960}
2961
892a6ffc
JA
2962#define BC_APP "bc"
2963
2964static char *bc_calc(char *str)
2965{
d0c814ec 2966 char buf[128], *tmp;
892a6ffc
JA
2967 FILE *f;
2968 int ret;
2969
2970 /*
2971 * No math, just return string
2972 */
d0c814ec
SL
2973 if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2974 !strchr(str, '/')) || strchr(str, '\''))
892a6ffc
JA
2975 return str;
2976
2977 /*
2978 * Split option from value, we only need to calculate the value
2979 */
2980 tmp = strchr(str, '=');
2981 if (!tmp)
2982 return str;
2983
2984 tmp++;
892a6ffc 2985
d0c814ec
SL
2986 /*
2987 * Prevent buffer overflows; such a case isn't reasonable anyway
2988 */
2989 if (strlen(str) >= 128 || strlen(tmp) > 100)
2990 return str;
892a6ffc
JA
2991
2992 sprintf(buf, "which %s > /dev/null", BC_APP);
2993 if (system(buf)) {
2994 log_err("fio: bc is needed for performing math\n");
892a6ffc
JA
2995 return NULL;
2996 }
2997
d0c814ec 2998 sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
892a6ffc 2999 f = popen(buf, "r");
3c3ed070 3000 if (!f)
892a6ffc 3001 return NULL;
892a6ffc 3002
d0c814ec 3003 ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
3c3ed070 3004 if (ret <= 0)
892a6ffc 3005 return NULL;
892a6ffc 3006
892a6ffc 3007 pclose(f);
d0c814ec
SL
3008 buf[(tmp - str) + ret - 1] = '\0';
3009 memcpy(buf, str, tmp - str);
892a6ffc 3010 free(str);
d0c814ec
SL
3011 return strdup(buf);
3012}
3013
3014/*
3015 * Return a copy of the input string with substrings of the form ${VARNAME}
3016 * substituted with the value of the environment variable VARNAME. The
3017 * substitution always occurs, even if VARNAME is empty or the corresponding
3018 * environment variable undefined.
3019 */
3020static char *option_dup_subs(const char *opt)
3021{
3022 char out[OPT_LEN_MAX+1];
3023 char in[OPT_LEN_MAX+1];
3024 char *outptr = out;
3025 char *inptr = in;
3026 char *ch1, *ch2, *env;
3027 ssize_t nchr = OPT_LEN_MAX;
3028 size_t envlen;
3029
3030 if (strlen(opt) + 1 > OPT_LEN_MAX) {
3031 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
3032 return NULL;
3033 }
3034
3035 in[OPT_LEN_MAX] = '\0';
3036 strncpy(in, opt, OPT_LEN_MAX);
3037
3038 while (*inptr && nchr > 0) {
3039 if (inptr[0] == '$' && inptr[1] == '{') {
3040 ch2 = strchr(inptr, '}');
3041 if (ch2 && inptr+1 < ch2) {
3042 ch1 = inptr+2;
3043 inptr = ch2+1;
3044 *ch2 = '\0';
3045
3046 env = getenv(ch1);
3047 if (env) {
3048 envlen = strlen(env);
3049 if (envlen <= nchr) {
3050 memcpy(outptr, env, envlen);
3051 outptr += envlen;
3052 nchr -= envlen;
3053 }
3054 }
3055
3056 continue;
3057 }
3058 }
3059
3060 *outptr++ = *inptr++;
3061 --nchr;
3062 }
3063
3064 *outptr = '\0';
3065 return strdup(out);
892a6ffc
JA
3066}
3067
74929ac2
JA
3068/*
3069 * Look for reserved variable names and replace them with real values
3070 */
3071static char *fio_keyword_replace(char *opt)
3072{
3073 char *s;
3074 int i;
d0c814ec 3075 int docalc = 0;
74929ac2
JA
3076
3077 for (i = 0; fio_keywords[i].word != NULL; i++) {
3078 struct fio_keyword *kw = &fio_keywords[i];
3079
3080 while ((s = strstr(opt, kw->word)) != NULL) {
3081 char *new = malloc(strlen(opt) + 1);
3082 char *o_org = opt;
3083 int olen = s - opt;
3084 int len;
3085
3086 /*
3087 * Copy part of the string before the keyword and
3088 * sprintf() the replacement after it.
3089 */
3090 memcpy(new, opt, olen);
3091 len = sprintf(new + olen, "%s", kw->replace);
3092
3093 /*
3094 * If there's more in the original string, copy that
3095 * in too
3096 */
3097 opt += strlen(kw->word) + olen;
3098 if (strlen(opt))
3099 memcpy(new + olen + len, opt, opt - o_org - 1);
3100
3101 /*
3102 * replace opt and free the old opt
3103 */
3104 opt = new;
d0c814ec 3105 free(o_org);
7a958bd5 3106
d0c814ec 3107 docalc = 1;
74929ac2
JA
3108 }
3109 }
3110
d0c814ec
SL
3111 /*
3112 * Check for potential math and invoke bc, if possible
3113 */
3114 if (docalc)
3115 opt = bc_calc(opt);
3116
7a958bd5 3117 return opt;
74929ac2
JA
3118}
3119
d0c814ec
SL
3120static char **dup_and_sub_options(char **opts, int num_opts)
3121{
3122 int i;
3123 char **opts_copy = malloc(num_opts * sizeof(*opts));
3124 for (i = 0; i < num_opts; i++) {
3125 opts_copy[i] = option_dup_subs(opts[i]);
3126 if (!opts_copy[i])
3127 continue;
3128 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
3129 }
3130 return opts_copy;
3131}
3132
3b8b7135 3133int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
214e1eca 3134{
de890a1e 3135 int i, ret, unknown;
d0c814ec 3136 char **opts_copy;
3b8b7135 3137
9af4a244 3138 sort_options(opts, fio_options, num_opts);
d0c814ec 3139 opts_copy = dup_and_sub_options(opts, num_opts);
3b8b7135 3140
de890a1e
SL
3141 for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
3142 struct fio_option *o;
9af4a244
JA
3143 int newret = parse_option(opts_copy[i], opts[i], fio_options,
3144 &o, td);
d0c814ec 3145
de890a1e
SL
3146 if (opts_copy[i]) {
3147 if (newret && !o) {
3148 unknown++;
3149 continue;
3150 }
d0c814ec 3151 free(opts_copy[i]);
de890a1e
SL
3152 opts_copy[i] = NULL;
3153 }
3154
3155 ret |= newret;
3156 }
3157
3158 if (unknown) {
3159 ret |= ioengine_load(td);
3160 if (td->eo) {
3161 sort_options(opts_copy, td->io_ops->options, num_opts);
3162 opts = opts_copy;
3163 }
3164 for (i = 0; i < num_opts; i++) {
3165 struct fio_option *o = NULL;
3166 int newret = 1;
3167 if (!opts_copy[i])
3168 continue;
3169
3170 if (td->eo)
3171 newret = parse_option(opts_copy[i], opts[i],
3172 td->io_ops->options, &o,
3173 td->eo);
3174
3175 ret |= newret;
3176 if (!o)
3177 log_err("Bad option <%s>\n", opts[i]);
3178
3179 free(opts_copy[i]);
3180 opts_copy[i] = NULL;
3181 }
74929ac2 3182 }
3b8b7135 3183
d0c814ec 3184 free(opts_copy);
3b8b7135 3185 return ret;
214e1eca
JA
3186}
3187
3188int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
3189{
9af4a244 3190 return parse_cmd_option(opt, val, fio_options, td);
214e1eca
JA
3191}
3192
de890a1e
SL
3193int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
3194 char *val)
3195{
3196 return parse_cmd_option(opt, val, td->io_ops->options, td);
3197}
3198
214e1eca
JA
3199void fio_fill_default_options(struct thread_data *td)
3200{
9af4a244 3201 fill_default_options(td, fio_options);
214e1eca
JA
3202}
3203
3204int fio_show_option_help(const char *opt)
3205{
9af4a244 3206 return show_cmd_help(fio_options, opt);
214e1eca 3207}
d23bb327 3208
de890a1e 3209void options_mem_dupe(void *data, struct fio_option *options)
d23bb327 3210{
de890a1e 3211 struct fio_option *o;
d23bb327 3212 char **ptr;
d23bb327 3213
de890a1e
SL
3214 for (o = &options[0]; o->name; o++) {
3215 if (o->type != FIO_OPT_STR_STORE)
d23bb327
JA
3216 continue;
3217
de890a1e 3218 ptr = td_var(data, o->off1);
7e356b2d
JA
3219 if (*ptr)
3220 *ptr = strdup(*ptr);
d23bb327
JA
3221 }
3222}
3223
de890a1e
SL
3224/*
3225 * dupe FIO_OPT_STR_STORE options
3226 */
3227void fio_options_mem_dupe(struct thread_data *td)
3228{
9af4a244 3229 options_mem_dupe(&td->o, fio_options);
1647f592
JA
3230
3231 if (td->eo && td->io_ops) {
de890a1e 3232 void *oldeo = td->eo;
1647f592 3233
de890a1e
SL
3234 td->eo = malloc(td->io_ops->option_struct_size);
3235 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
3236 options_mem_dupe(td->eo, td->io_ops->options);
3237 }
3238}
3239
d6978a32
JA
3240unsigned int fio_get_kb_base(void *data)
3241{
83ea422a 3242 struct thread_options *o = data;
d6978a32
JA
3243 unsigned int kb_base = 0;
3244
83ea422a
JA
3245 if (o)
3246 kb_base = o->kb_base;
d6978a32
JA
3247 if (!kb_base)
3248 kb_base = 1024;
3249
3250 return kb_base;
3251}
9f988e2e 3252
07b3232d 3253int add_option(struct fio_option *o)
9f988e2e 3254{
07b3232d
JA
3255 struct fio_option *__o;
3256 int opt_index = 0;
3257
9af4a244 3258 __o = fio_options;
07b3232d
JA
3259 while (__o->name) {
3260 opt_index++;
3261 __o++;
3262 }
3263
9af4a244 3264 memcpy(&fio_options[opt_index], o, sizeof(*o));
07b3232d 3265 return 0;
9f988e2e 3266}
e2de69da 3267
07b3232d 3268void invalidate_profile_options(const char *prof_name)
e2de69da 3269{
07b3232d 3270 struct fio_option *o;
e2de69da 3271
9af4a244 3272 o = fio_options;
07b3232d
JA
3273 while (o->name) {
3274 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
3275 o->type = FIO_OPT_INVALID;
3276 o->prof_name = NULL;
3277 }
3278 o++;
e2de69da
JA
3279 }
3280}
f5b6bb85
JA
3281
3282void add_opt_posval(const char *optname, const char *ival, const char *help)
3283{
3284 struct fio_option *o;
3285 unsigned int i;
3286
9af4a244 3287 o = find_option(fio_options, optname);
f5b6bb85
JA
3288 if (!o)
3289 return;
3290
3291 for (i = 0; i < PARSE_MAX_VP; i++) {
3292 if (o->posval[i].ival)
3293 continue;
3294
3295 o->posval[i].ival = ival;
3296 o->posval[i].help = help;
3297 break;
3298 }
3299}
3300
3301void del_opt_posval(const char *optname, const char *ival)
3302{
3303 struct fio_option *o;
3304 unsigned int i;
3305
9af4a244 3306 o = find_option(fio_options, optname);
f5b6bb85
JA
3307 if (!o)
3308 return;
3309
3310 for (i = 0; i < PARSE_MAX_VP; i++) {
3311 if (!o->posval[i].ival)
3312 continue;
3313 if (strcmp(o->posval[i].ival, ival))
3314 continue;
3315
3316 o->posval[i].ival = NULL;
3317 o->posval[i].help = NULL;
3318 }
3319}
7e356b2d
JA
3320
3321void fio_options_free(struct thread_data *td)
3322{
9af4a244 3323 options_free(fio_options, td);
de890a1e
SL
3324 if (td->eo && td->io_ops && td->io_ops->options) {
3325 options_free(td->io_ops->options, td->eo);
3326 free(td->eo);
3327 td->eo = NULL;
3328 }
7e356b2d 3329}
c504ee55
JA
3330
3331struct fio_option *fio_option_find(const char *name)
3332{
3333 return find_option(fio_options, name);
3334}
3335