Unify the time handling
[fio.git] / options.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <ctype.h>
5 #include <string.h>
6 #include <assert.h>
7 #include <libgen.h>
8 #include <fcntl.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11
12 #include "fio.h"
13 #include "verify.h"
14 #include "parse.h"
15 #include "lib/fls.h"
16 #include "options.h"
17
18 #include "crc/crc32c.h"
19
20 /*
21  * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
22  */
23 static 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
36 static int converthexchartoint(char a)
37 {
38         int base;
39
40         switch (a) {
41         case '0'...'9':
42                 base = '0';
43                 break;
44         case 'A'...'F':
45                 base = 'A' - 10;
46                 break;
47         case 'a'...'f':
48                 base = 'a' - 10;
49                 break;
50         default:
51                 base = 0;
52         }
53         return a - base;
54 }
55
56 static 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
64 static int bssplit_ddir(struct thread_options *o, int ddir, char *str)
65 {
66         struct bssplit *bssplit;
67         unsigned int i, perc, perc_missing;
68         unsigned int max_bs, min_bs;
69         long long val;
70         char *fname;
71
72         o->bssplit_nr[ddir] = 4;
73         bssplit = malloc(4 * sizeof(struct bssplit));
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                  */
87                 if (i == o->bssplit_nr[ddir]) {
88                         o->bssplit_nr[ddir] <<= 1;
89                         bssplit = realloc(bssplit, o->bssplit_nr[ddir]
90                                                   * sizeof(struct bssplit));
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
105                 if (str_to_decimal(fname, &val, 1, o, 0)) {
106                         log_err("fio: bssplit conversion failed\n");
107                         free(bssplit);
108                         return 1;
109                 }
110
111                 if (val > max_bs)
112                         max_bs = val;
113                 if (val < min_bs)
114                         min_bs = val;
115
116                 bssplit[i].bs = val;
117                 bssplit[i].perc = perc;
118                 i++;
119         }
120
121         o->bssplit_nr[ddir] = i;
122
123         /*
124          * Now check if the percentages add up, and how much is missing
125          */
126         perc = perc_missing = 0;
127         for (i = 0; i < o->bssplit_nr[ddir]; i++) {
128                 struct bssplit *bsp = &bssplit[i];
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");
138                 free(bssplit);
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) {
146                 for (i = 0; i < o->bssplit_nr[ddir]; i++) {
147                         struct bssplit *bsp = &bssplit[i];
148
149                         if (bsp->perc == (unsigned char) -1)
150                                 bsp->perc = (100 - perc) / perc_missing;
151                 }
152         }
153
154         o->min_bs[ddir] = min_bs;
155         o->max_bs[ddir] = max_bs;
156
157         /*
158          * now sort based on percentages, for ease of lookup
159          */
160         qsort(bssplit, o->bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161         o->bssplit[ddir] = bssplit;
162         return 0;
163 }
164
165 static int str_bssplit_cb(void *data, const char *input)
166 {
167         struct thread_data *td = data;
168         char *str, *p, *odir, *ddir;
169         int ret = 0;
170
171         if (parse_dryrun())
172                 return 0;
173
174         p = str = strdup(input);
175
176         strip_blank_front(&str);
177         strip_blank_end(str);
178
179         odir = strchr(str, ',');
180         if (odir) {
181                 ddir = strchr(odir + 1, ',');
182                 if (ddir) {
183                         ret = bssplit_ddir(&td->o, DDIR_TRIM, ddir + 1);
184                         if (!ret)
185                                 *ddir = '\0';
186                 } else {
187                         char *op;
188
189                         op = strdup(odir + 1);
190                         ret = bssplit_ddir(&td->o, DDIR_TRIM, op);
191
192                         free(op);
193                 }
194                 if (!ret)
195                         ret = bssplit_ddir(&td->o, DDIR_WRITE, odir + 1);
196                 if (!ret) {
197                         *odir = '\0';
198                         ret = bssplit_ddir(&td->o, DDIR_READ, str);
199                 }
200         } else {
201                 char *op;
202
203                 op = strdup(str);
204                 ret = bssplit_ddir(&td->o, DDIR_WRITE, op);
205                 free(op);
206
207                 if (!ret) {
208                         op = strdup(str);
209                         ret = bssplit_ddir(&td->o, DDIR_TRIM, op);
210                         free(op);
211                 }
212                 ret = bssplit_ddir(&td->o, DDIR_READ, str);
213         }
214
215         free(p);
216         return ret;
217 }
218
219 static int str2error(char *str)
220 {
221         const char *err[] = { "EPERM", "ENOENT", "ESRCH", "EINTR", "EIO",
222                             "ENXIO", "E2BIG", "ENOEXEC", "EBADF",
223                             "ECHILD", "EAGAIN", "ENOMEM", "EACCES",
224                             "EFAULT", "ENOTBLK", "EBUSY", "EEXIST",
225                             "EXDEV", "ENODEV", "ENOTDIR", "EISDIR",
226                             "EINVAL", "ENFILE", "EMFILE", "ENOTTY",
227                             "ETXTBSY","EFBIG", "ENOSPC", "ESPIPE",
228                             "EROFS","EMLINK", "EPIPE", "EDOM", "ERANGE" };
229         int i = 0, num = sizeof(err) / sizeof(void *);
230
231         while (i < num) {
232                 if (!strcmp(err[i], str))
233                         return i + 1;
234                 i++;
235         }
236         return 0;
237 }
238
239 static int ignore_error_type(struct thread_data *td, int etype, char *str)
240 {
241         unsigned int i;
242         int *error;
243         char *fname;
244
245         if (etype >= ERROR_TYPE_CNT) {
246                 log_err("Illegal error type\n");
247                 return 1;
248         }
249
250         td->o.ignore_error_nr[etype] = 4;
251         error = malloc(4 * sizeof(struct bssplit));
252
253         i = 0;
254         while ((fname = strsep(&str, ":")) != NULL) {
255
256                 if (!strlen(fname))
257                         break;
258
259                 /*
260                  * grow struct buffer, if needed
261                  */
262                 if (i == td->o.ignore_error_nr[etype]) {
263                         td->o.ignore_error_nr[etype] <<= 1;
264                         error = realloc(error, td->o.ignore_error_nr[etype]
265                                                   * sizeof(int));
266                 }
267                 if (fname[0] == 'E') {
268                         error[i] = str2error(fname);
269                 } else {
270                         error[i] = atoi(fname);
271                         if (error[i] < 0)
272                                 error[i] = error[i];
273                 }
274                 if (!error[i]) {
275                         log_err("Unknown error %s, please use number value \n",
276                                   fname);
277                         free(error);
278                         return 1;
279                 }
280                 i++;
281         }
282         if (i) {
283                 td->o.continue_on_error |= 1 << etype;
284                 td->o.ignore_error_nr[etype] = i;
285                 td->o.ignore_error[etype] = error;
286         }
287         return 0;
288
289 }
290
291 static int str_ignore_error_cb(void *data, const char *input)
292 {
293         struct thread_data *td = data;
294         char *str, *p, *n;
295         int type = 0, ret = 1;
296
297         if (parse_dryrun())
298                 return 0;
299
300         p = str = strdup(input);
301
302         strip_blank_front(&str);
303         strip_blank_end(str);
304
305         while (p) {
306                 n = strchr(p, ',');
307                 if (n)
308                         *n++ = '\0';
309                 ret = ignore_error_type(td, type, p);
310                 if (ret)
311                         break;
312                 p = n;
313                 type++;
314         }
315         free(str);
316         return ret;
317 }
318
319 static int str_rw_cb(void *data, const char *str)
320 {
321         struct thread_data *td = data;
322         struct thread_options *o = &td->o;
323         char *nr = get_opt_postfix(str);
324
325         if (parse_dryrun())
326                 return 0;
327
328         o->ddir_seq_nr = 1;
329         o->ddir_seq_add = 0;
330
331         if (!nr)
332                 return 0;
333
334         if (td_random(td))
335                 o->ddir_seq_nr = atoi(nr);
336         else {
337                 long long val;
338
339                 if (str_to_decimal(nr, &val, 1, o, 0)) {
340                         log_err("fio: rw postfix parsing failed\n");
341                         free(nr);
342                         return 1;
343                 }
344
345                 o->ddir_seq_add = val;
346         }
347
348         free(nr);
349         return 0;
350 }
351
352 static int str_mem_cb(void *data, const char *mem)
353 {
354         struct thread_data *td = data;
355
356         if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP)
357                 td->o.mmapfile = get_opt_postfix(mem);
358
359         return 0;
360 }
361
362 static int fio_clock_source_cb(void *data, const char *str)
363 {
364         struct thread_data *td = data;
365
366         fio_clock_source = td->o.clocksource;
367         fio_clock_source_set = 1;
368         fio_clock_init();
369         return 0;
370 }
371
372 static int str_rwmix_read_cb(void *data, unsigned long long *val)
373 {
374         struct thread_data *td = data;
375
376         td->o.rwmix[DDIR_READ] = *val;
377         td->o.rwmix[DDIR_WRITE] = 100 - *val;
378         return 0;
379 }
380
381 static int str_rwmix_write_cb(void *data, unsigned long long *val)
382 {
383         struct thread_data *td = data;
384
385         td->o.rwmix[DDIR_WRITE] = *val;
386         td->o.rwmix[DDIR_READ] = 100 - *val;
387         return 0;
388 }
389
390 static int str_exitall_cb(void)
391 {
392         exitall_on_terminate = 1;
393         return 0;
394 }
395
396 #ifdef FIO_HAVE_CPU_AFFINITY
397 static int str_cpumask_cb(void *data, unsigned long long *val)
398 {
399         struct thread_data *td = data;
400         unsigned int i;
401         long max_cpu;
402         int ret;
403
404         if (parse_dryrun())
405                 return 0;
406
407         ret = fio_cpuset_init(&td->o.cpumask);
408         if (ret < 0) {
409                 log_err("fio: cpuset_init failed\n");
410                 td_verror(td, ret, "fio_cpuset_init");
411                 return 1;
412         }
413
414         max_cpu = cpus_online();
415
416         for (i = 0; i < sizeof(int) * 8; i++) {
417                 if ((1 << i) & *val) {
418                         if (i > max_cpu) {
419                                 log_err("fio: CPU %d too large (max=%ld)\n", i,
420                                                                 max_cpu);
421                                 return 1;
422                         }
423                         dprint(FD_PARSE, "set cpu allowed %d\n", i);
424                         fio_cpu_set(&td->o.cpumask, i);
425                 }
426         }
427
428         td->o.cpumask_set = 1;
429         return 0;
430 }
431
432 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
433                             const char *input)
434 {
435         char *cpu, *str, *p;
436         long max_cpu;
437         int ret = 0;
438
439         ret = fio_cpuset_init(mask);
440         if (ret < 0) {
441                 log_err("fio: cpuset_init failed\n");
442                 td_verror(td, ret, "fio_cpuset_init");
443                 return 1;
444         }
445
446         p = str = strdup(input);
447
448         strip_blank_front(&str);
449         strip_blank_end(str);
450
451         max_cpu = cpus_online();
452
453         while ((cpu = strsep(&str, ",")) != NULL) {
454                 char *str2, *cpu2;
455                 int icpu, icpu2;
456
457                 if (!strlen(cpu))
458                         break;
459
460                 str2 = cpu;
461                 icpu2 = -1;
462                 while ((cpu2 = strsep(&str2, "-")) != NULL) {
463                         if (!strlen(cpu2))
464                                 break;
465
466                         icpu2 = atoi(cpu2);
467                 }
468
469                 icpu = atoi(cpu);
470                 if (icpu2 == -1)
471                         icpu2 = icpu;
472                 while (icpu <= icpu2) {
473                         if (icpu >= FIO_MAX_CPUS) {
474                                 log_err("fio: your OS only supports up to"
475                                         " %d CPUs\n", (int) FIO_MAX_CPUS);
476                                 ret = 1;
477                                 break;
478                         }
479                         if (icpu > max_cpu) {
480                                 log_err("fio: CPU %d too large (max=%ld)\n",
481                                                         icpu, max_cpu);
482                                 ret = 1;
483                                 break;
484                         }
485
486                         dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
487                         fio_cpu_set(mask, icpu);
488                         icpu++;
489                 }
490                 if (ret)
491                         break;
492         }
493
494         free(p);
495         if (!ret)
496                 td->o.cpumask_set = 1;
497         return ret;
498 }
499
500 static int str_cpus_allowed_cb(void *data, const char *input)
501 {
502         struct thread_data *td = data;
503         int ret;
504
505         if (parse_dryrun())
506                 return 0;
507
508         ret = set_cpus_allowed(td, &td->o.cpumask, input);
509         if (!ret)
510                 td->o.cpumask_set = 1;
511
512         return ret;
513 }
514
515 static int str_verify_cpus_allowed_cb(void *data, const char *input)
516 {
517         struct thread_data *td = data;
518         int ret;
519
520         ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
521         if (!ret)
522                 td->o.verify_cpumask_set = 1;
523
524         return ret;
525 }
526 #endif
527
528 #ifdef CONFIG_LIBNUMA
529 static int str_numa_cpunodes_cb(void *data, char *input)
530 {
531         struct thread_data *td = data;
532
533         if (parse_dryrun())
534                 return 0;
535
536         /* numa_parse_nodestring() parses a character string list
537          * of nodes into a bit mask. The bit mask is allocated by
538          * numa_allocate_nodemask(), so it should be freed by
539          * numa_free_nodemask().
540          */
541         td->o.numa_cpunodesmask = numa_parse_nodestring(input);
542         if (td->o.numa_cpunodesmask == NULL) {
543                 log_err("fio: numa_parse_nodestring failed\n");
544                 td_verror(td, 1, "str_numa_cpunodes_cb");
545                 return 1;
546         }
547
548         td->o.numa_cpumask_set = 1;
549         return 0;
550 }
551
552 static int str_numa_mpol_cb(void *data, char *input)
553 {
554         struct thread_data *td = data;
555         const char * const policy_types[] =
556                 { "default", "prefer", "bind", "interleave", "local", NULL };
557         int i;
558         char *nodelist;
559
560         if (parse_dryrun())
561                 return 0;
562
563         nodelist = strchr(input, ':');
564         if (nodelist) {
565                 /* NUL-terminate mode */
566                 *nodelist++ = '\0';
567         }
568
569         for (i = 0; i <= MPOL_LOCAL; i++) {
570                 if (!strcmp(input, policy_types[i])) {
571                         td->o.numa_mem_mode = i;
572                         break;
573                 }
574         }
575         if (i > MPOL_LOCAL) {
576                 log_err("fio: memory policy should be: default, prefer, bind, interleave, local\n");
577                 goto out;
578         }
579
580         switch (td->o.numa_mem_mode) {
581         case MPOL_PREFERRED:
582                 /*
583                  * Insist on a nodelist of one node only
584                  */
585                 if (nodelist) {
586                         char *rest = nodelist;
587                         while (isdigit(*rest))
588                                 rest++;
589                         if (*rest) {
590                                 log_err("fio: one node only for \'prefer\'\n");
591                                 goto out;
592                         }
593                 } else {
594                         log_err("fio: one node is needed for \'prefer\'\n");
595                         goto out;
596                 }
597                 break;
598         case MPOL_INTERLEAVE:
599                 /*
600                  * Default to online nodes with memory if no nodelist
601                  */
602                 if (!nodelist)
603                         nodelist = strdup("all");
604                 break;
605         case MPOL_LOCAL:
606         case MPOL_DEFAULT:
607                 /*
608                  * Don't allow a nodelist
609                  */
610                 if (nodelist) {
611                         log_err("fio: NO nodelist for \'local\'\n");
612                         goto out;
613                 }
614                 break;
615         case MPOL_BIND:
616                 /*
617                  * Insist on a nodelist
618                  */
619                 if (!nodelist) {
620                         log_err("fio: a nodelist is needed for \'bind\'\n");
621                         goto out;
622                 }
623                 break;
624         }
625
626
627         /* numa_parse_nodestring() parses a character string list
628          * of nodes into a bit mask. The bit mask is allocated by
629          * numa_allocate_nodemask(), so it should be freed by
630          * numa_free_nodemask().
631          */
632         switch (td->o.numa_mem_mode) {
633         case MPOL_PREFERRED:
634                 td->o.numa_mem_prefer_node = atoi(nodelist);
635                 break;
636         case MPOL_INTERLEAVE:
637         case MPOL_BIND:
638                 td->o.numa_memnodesmask = numa_parse_nodestring(nodelist);
639                 if (td->o.numa_memnodesmask == NULL) {
640                         log_err("fio: numa_parse_nodestring failed\n");
641                         td_verror(td, 1, "str_numa_memnodes_cb");
642                         return 1;
643                 }
644                 break;
645         case MPOL_LOCAL:
646         case MPOL_DEFAULT:
647         default:
648                 break;
649         }
650
651         td->o.numa_memmask_set = 1;
652         return 0;
653
654 out:
655         return 1;
656 }
657 #endif
658
659 static int str_fst_cb(void *data, const char *str)
660 {
661         struct thread_data *td = data;
662         char *nr = get_opt_postfix(str);
663
664         td->file_service_nr = 1;
665         if (nr) {
666                 td->file_service_nr = atoi(nr);
667                 free(nr);
668         }
669
670         return 0;
671 }
672
673 #ifdef CONFIG_SYNC_FILE_RANGE
674 static int str_sfr_cb(void *data, const char *str)
675 {
676         struct thread_data *td = data;
677         char *nr = get_opt_postfix(str);
678
679         td->sync_file_range_nr = 1;
680         if (nr) {
681                 td->sync_file_range_nr = atoi(nr);
682                 free(nr);
683         }
684
685         return 0;
686 }
687 #endif
688
689 static int str_random_distribution_cb(void *data, const char *str)
690 {
691         struct thread_data *td = data;
692         double val;
693         char *nr;
694
695         if (parse_dryrun())
696                 return 0;
697
698         if (td->o.random_distribution == FIO_RAND_DIST_ZIPF)
699                 val = 1.1;
700         else if (td->o.random_distribution == FIO_RAND_DIST_PARETO)
701                 val = 0.2;
702         else
703                 return 0;
704
705         nr = get_opt_postfix(str);
706         if (nr && !str_to_float(nr, &val)) {
707                 log_err("fio: random postfix parsing failed\n");
708                 free(nr);
709                 return 1;
710         }
711
712         free(nr);
713
714         if (td->o.random_distribution == FIO_RAND_DIST_ZIPF) {
715                 if (val == 1.00) {
716                         log_err("fio: zipf theta must different than 1.0\n");
717                         return 1;
718                 }
719                 td->o.zipf_theta.u.f = val;
720         } else {
721                 if (val <= 0.00 || val >= 1.00) {
722                         log_err("fio: pareto input out of range (0 < input < 1.0)\n");
723                         return 1;
724                 }
725                 td->o.pareto_h.u.f = val;
726         }
727
728         return 0;
729 }
730
731 /*
732  * Return next name in the string. Files are separated with ':'. If the ':'
733  * is escaped with a '\', then that ':' is part of the filename and does not
734  * indicate a new file.
735  */
736 static char *get_next_name(char **ptr)
737 {
738         char *str = *ptr;
739         char *p, *start;
740
741         if (!str || !strlen(str))
742                 return NULL;
743
744         start = str;
745         do {
746                 /*
747                  * No colon, we are done
748                  */
749                 p = strchr(str, ':');
750                 if (!p) {
751                         *ptr = NULL;
752                         break;
753                 }
754
755                 /*
756                  * We got a colon, but it's the first character. Skip and
757                  * continue
758                  */
759                 if (p == start) {
760                         str = ++start;
761                         continue;
762                 }
763
764                 if (*(p - 1) != '\\') {
765                         *p = '\0';
766                         *ptr = p + 1;
767                         break;
768                 }
769
770                 memmove(p - 1, p, strlen(p) + 1);
771                 str = p;
772         } while (1);
773
774         return start;
775 }
776
777
778 static int get_max_name_idx(char *input)
779 {
780         unsigned int cur_idx;
781         char *str, *p;
782
783         p = str = strdup(input);
784         for (cur_idx = 0; ; cur_idx++)
785                 if (get_next_name(&str) == NULL)
786                         break;
787
788         free(p);
789         return cur_idx;
790 }
791
792 /*
793  * Returns the directory at the index, indexes > entires will be
794  * assigned via modulo division of the index
795  */
796 int set_name_idx(char *target, char *input, int index)
797 {
798         unsigned int cur_idx;
799         int len;
800         char *fname, *str, *p;
801
802         p = str = strdup(input);
803
804         index %= get_max_name_idx(input);
805         for (cur_idx = 0; cur_idx <= index; cur_idx++)
806                 fname = get_next_name(&str);
807
808         len = sprintf(target, "%s/", fname);
809         free(p);
810
811         return len;
812 }
813
814 static int str_filename_cb(void *data, const char *input)
815 {
816         struct thread_data *td = data;
817         char *fname, *str, *p;
818
819         p = str = strdup(input);
820
821         strip_blank_front(&str);
822         strip_blank_end(str);
823
824         if (!td->files_index)
825                 td->o.nr_files = 0;
826
827         while ((fname = get_next_name(&str)) != NULL) {
828                 if (!strlen(fname))
829                         break;
830                 add_file(td, fname, 0);
831                 td->o.nr_files++;
832         }
833
834         free(p);
835         return 0;
836 }
837
838 static int str_directory_cb(void *data, const char fio_unused *unused)
839 {
840         struct thread_data *td = data;
841         struct stat sb;
842         char *dirname, *str, *p;
843         int ret = 0;
844
845         if (parse_dryrun())
846                 return 0;
847
848         p = str = strdup(td->o.directory);
849         while ((dirname = get_next_name(&str)) != NULL) {
850                 if (lstat(dirname, &sb) < 0) {
851                         ret = errno;
852
853                         log_err("fio: %s is not a directory\n", dirname);
854                         td_verror(td, ret, "lstat");
855                         goto out;
856                 }
857                 if (!S_ISDIR(sb.st_mode)) {
858                         log_err("fio: %s is not a directory\n", dirname);
859                         ret = 1;
860                         goto out;
861                 }
862         }
863
864 out:
865         free(p);
866         return ret;
867 }
868
869 static int str_lockfile_cb(void *data, const char fio_unused *str)
870 {
871         struct thread_data *td = data;
872
873         if (td->files_index) {
874                 log_err("fio: lockfile= option must precede filename=\n");
875                 return 1;
876         }
877
878         return 0;
879 }
880
881 static int str_opendir_cb(void *data, const char fio_unused *str)
882 {
883         struct thread_data *td = data;
884
885         if (parse_dryrun())
886                 return 0;
887
888         if (!td->files_index)
889                 td->o.nr_files = 0;
890
891         return add_dir_files(td, td->o.opendir);
892 }
893
894 static int pattern_cb(char *pattern, unsigned int max_size,
895                       const char *input, unsigned int *pattern_bytes)
896 {
897         long off;
898         int i = 0, j = 0, len, k, base = 10;
899         uint32_t pattern_length;
900         char *loc1, *loc2;
901
902         loc1 = strstr(input, "0x");
903         loc2 = strstr(input, "0X");
904         if (loc1 || loc2)
905                 base = 16;
906         off = strtol(input, NULL, base);
907         if (off != LONG_MAX || errno != ERANGE) {
908                 while (off) {
909                         pattern[i] = off & 0xff;
910                         off >>= 8;
911                         i++;
912                 }
913         } else {
914                 len = strlen(input);
915                 k = len - 1;
916                 if (base == 16) {
917                         if (loc1)
918                                 j = loc1 - input + 2;
919                         else
920                                 j = loc2 - input + 2;
921                 } else
922                         return 1;
923                 if (len - j < max_size * 2) {
924                         while (k >= j) {
925                                 off = converthexchartoint(input[k--]);
926                                 if (k >= j)
927                                         off += (converthexchartoint(input[k--])
928                                                 * 16);
929                                 pattern[i++] = (char) off;
930                         }
931                 }
932         }
933
934         /*
935          * Fill the pattern all the way to the end. This greatly reduces
936          * the number of memcpy's we have to do when verifying the IO.
937          */
938         pattern_length = i;
939         while (i > 1 && i * 2 <= max_size) {
940                 memcpy(&pattern[i], &pattern[0], i);
941                 i *= 2;
942         }
943
944         /*
945          * Fill remainder, if the pattern multiple ends up not being
946          * max_size.
947          */
948         while (i > 1 && i < max_size) {
949                 unsigned int b = min(pattern_length, max_size - i);
950
951                 memcpy(&pattern[i], &pattern[0], b);
952                 i += b;
953         }
954
955         if (i == 1) {
956                 /*
957                  * The code in verify_io_u_pattern assumes a single byte pattern
958                  * fills the whole verify pattern buffer.
959                  */
960                 memset(pattern, pattern[0], max_size);
961         }
962
963         *pattern_bytes = i;
964         return 0;
965 }
966
967 static int str_buffer_pattern_cb(void *data, const char *input)
968 {
969         struct thread_data *td = data;
970         int ret;
971
972         ret = pattern_cb(td->o.buffer_pattern, MAX_PATTERN_SIZE, input,
973                                 &td->o.buffer_pattern_bytes);
974
975         if (!ret) {
976                 td->o.refill_buffers = 0;
977                 td->o.scramble_buffers = 0;
978                 td->o.zero_buffers = 0;
979         }
980
981         return ret;
982 }
983
984 static int str_verify_pattern_cb(void *data, const char *input)
985 {
986         struct thread_data *td = data;
987         int ret;
988
989         ret = pattern_cb(td->o.verify_pattern, MAX_PATTERN_SIZE, input,
990                                 &td->o.verify_pattern_bytes);
991
992         /*
993          * VERIFY_META could already be set
994          */
995         if (!ret && td->o.verify == VERIFY_NONE)
996                 td->o.verify = VERIFY_PATTERN;
997
998         return ret;
999 }
1000
1001 static int str_gtod_reduce_cb(void *data, int *il)
1002 {
1003         struct thread_data *td = data;
1004         int val = *il;
1005
1006         td->o.disable_lat = !!val;
1007         td->o.disable_clat = !!val;
1008         td->o.disable_slat = !!val;
1009         td->o.disable_bw = !!val;
1010         td->o.clat_percentiles = !val;
1011         if (val)
1012                 td->tv_cache_mask = 63;
1013
1014         return 0;
1015 }
1016
1017 static int str_gtod_cpu_cb(void *data, long long *il)
1018 {
1019         struct thread_data *td = data;
1020         int val = *il;
1021
1022         td->o.gtod_cpu = val;
1023         td->o.gtod_offload = 1;
1024         return 0;
1025 }
1026
1027 static int str_size_cb(void *data, unsigned long long *__val)
1028 {
1029         struct thread_data *td = data;
1030         unsigned long long v = *__val;
1031
1032         if (parse_is_percent(v)) {
1033                 td->o.size = 0;
1034                 td->o.size_percent = -1ULL - v;
1035         } else
1036                 td->o.size = v;
1037
1038         return 0;
1039 }
1040
1041 static int rw_verify(struct fio_option *o, void *data)
1042 {
1043         struct thread_data *td = data;
1044
1045         if (read_only && td_write(td)) {
1046                 log_err("fio: job <%s> has write bit set, but fio is in"
1047                         " read-only mode\n", td->o.name);
1048                 return 1;
1049         }
1050
1051         return 0;
1052 }
1053
1054 static int gtod_cpu_verify(struct fio_option *o, void *data)
1055 {
1056 #ifndef FIO_HAVE_CPU_AFFINITY
1057         struct thread_data *td = data;
1058
1059         if (td->o.gtod_cpu) {
1060                 log_err("fio: platform must support CPU affinity for"
1061                         "gettimeofday() offloading\n");
1062                 return 1;
1063         }
1064 #endif
1065
1066         return 0;
1067 }
1068
1069 /*
1070  * Option grouping
1071  */
1072 static struct opt_group fio_opt_groups[] = {
1073         {
1074                 .name   = "General",
1075                 .mask   = FIO_OPT_C_GENERAL,
1076         },
1077         {
1078                 .name   = "I/O",
1079                 .mask   = FIO_OPT_C_IO,
1080         },
1081         {
1082                 .name   = "File",
1083                 .mask   = FIO_OPT_C_FILE,
1084         },
1085         {
1086                 .name   = "Statistics",
1087                 .mask   = FIO_OPT_C_STAT,
1088         },
1089         {
1090                 .name   = "Logging",
1091                 .mask   = FIO_OPT_C_LOG,
1092         },
1093         {
1094                 .name   = "Profiles",
1095                 .mask   = FIO_OPT_C_PROFILE,
1096         },
1097         {
1098                 .name   = NULL,
1099         },
1100 };
1101
1102 static struct opt_group *__opt_group_from_mask(struct opt_group *ogs, unsigned int *mask,
1103                                                unsigned int inv_mask)
1104 {
1105         struct opt_group *og;
1106         int i;
1107
1108         if (*mask == inv_mask || !*mask)
1109                 return NULL;
1110
1111         for (i = 0; ogs[i].name; i++) {
1112                 og = &ogs[i];
1113
1114                 if (*mask & og->mask) {
1115                         *mask &= ~(og->mask);
1116                         return og;
1117                 }
1118         }
1119
1120         return NULL;
1121 }
1122
1123 struct opt_group *opt_group_from_mask(unsigned int *mask)
1124 {
1125         return __opt_group_from_mask(fio_opt_groups, mask, FIO_OPT_C_INVALID);
1126 }
1127
1128 static struct opt_group fio_opt_cat_groups[] = {
1129         {
1130                 .name   = "Latency profiling",
1131                 .mask   = FIO_OPT_G_LATPROF,
1132         },
1133         {
1134                 .name   = "Rate",
1135                 .mask   = FIO_OPT_G_RATE,
1136         },
1137         {
1138                 .name   = "Zone",
1139                 .mask   = FIO_OPT_G_ZONE,
1140         },
1141         {
1142                 .name   = "Read/write mix",
1143                 .mask   = FIO_OPT_G_RWMIX,
1144         },
1145         {
1146                 .name   = "Verify",
1147                 .mask   = FIO_OPT_G_VERIFY,
1148         },
1149         {
1150                 .name   = "Trim",
1151                 .mask   = FIO_OPT_G_TRIM,
1152         },
1153         {
1154                 .name   = "I/O Logging",
1155                 .mask   = FIO_OPT_G_IOLOG,
1156         },
1157         {
1158                 .name   = "I/O Depth",
1159                 .mask   = FIO_OPT_G_IO_DEPTH,
1160         },
1161         {
1162                 .name   = "I/O Flow",
1163                 .mask   = FIO_OPT_G_IO_FLOW,
1164         },
1165         {
1166                 .name   = "Description",
1167                 .mask   = FIO_OPT_G_DESC,
1168         },
1169         {
1170                 .name   = "Filename",
1171                 .mask   = FIO_OPT_G_FILENAME,
1172         },
1173         {
1174                 .name   = "General I/O",
1175                 .mask   = FIO_OPT_G_IO_BASIC,
1176         },
1177         {
1178                 .name   = "Cgroups",
1179                 .mask   = FIO_OPT_G_CGROUP,
1180         },
1181         {
1182                 .name   = "Runtime",
1183                 .mask   = FIO_OPT_G_RUNTIME,
1184         },
1185         {
1186                 .name   = "Process",
1187                 .mask   = FIO_OPT_G_PROCESS,
1188         },
1189         {
1190                 .name   = "Job credentials / priority",
1191                 .mask   = FIO_OPT_G_CRED,
1192         },
1193         {
1194                 .name   = "Clock settings",
1195                 .mask   = FIO_OPT_G_CLOCK,
1196         },
1197         {
1198                 .name   = "I/O Type",
1199                 .mask   = FIO_OPT_G_IO_TYPE,
1200         },
1201         {
1202                 .name   = "I/O Thinktime",
1203                 .mask   = FIO_OPT_G_THINKTIME,
1204         },
1205         {
1206                 .name   = "Randomizations",
1207                 .mask   = FIO_OPT_G_RANDOM,
1208         },
1209         {
1210                 .name   = "I/O buffers",
1211                 .mask   = FIO_OPT_G_IO_BUF,
1212         },
1213         {
1214                 .name   = "Tiobench profile",
1215                 .mask   = FIO_OPT_G_TIOBENCH,
1216         },
1217
1218         {
1219                 .name   = NULL,
1220         }
1221 };
1222
1223 struct opt_group *opt_group_cat_from_mask(unsigned int *mask)
1224 {
1225         return __opt_group_from_mask(fio_opt_cat_groups, mask, FIO_OPT_G_INVALID);
1226 }
1227
1228 /*
1229  * Map of job/command line options
1230  */
1231 struct fio_option fio_options[FIO_MAX_OPTS] = {
1232         {
1233                 .name   = "description",
1234                 .lname  = "Description of job",
1235                 .type   = FIO_OPT_STR_STORE,
1236                 .off1   = td_var_offset(description),
1237                 .help   = "Text job description",
1238                 .category = FIO_OPT_C_GENERAL,
1239                 .group  = FIO_OPT_G_DESC,
1240         },
1241         {
1242                 .name   = "name",
1243                 .lname  = "Job name",
1244                 .type   = FIO_OPT_STR_STORE,
1245                 .off1   = td_var_offset(name),
1246                 .help   = "Name of this job",
1247                 .category = FIO_OPT_C_GENERAL,
1248                 .group  = FIO_OPT_G_DESC,
1249         },
1250         {
1251                 .name   = "filename",
1252                 .lname  = "Filename(s)",
1253                 .type   = FIO_OPT_STR_STORE,
1254                 .off1   = td_var_offset(filename),
1255                 .cb     = str_filename_cb,
1256                 .prio   = -1, /* must come after "directory" */
1257                 .help   = "File(s) to use for the workload",
1258                 .category = FIO_OPT_C_FILE,
1259                 .group  = FIO_OPT_G_FILENAME,
1260         },
1261         {
1262                 .name   = "directory",
1263                 .lname  = "Directory",
1264                 .type   = FIO_OPT_STR_STORE,
1265                 .off1   = td_var_offset(directory),
1266                 .cb     = str_directory_cb,
1267                 .help   = "Directory to store files in",
1268                 .category = FIO_OPT_C_FILE,
1269                 .group  = FIO_OPT_G_FILENAME,
1270         },
1271         {
1272                 .name   = "filename_format",
1273                 .type   = FIO_OPT_STR_STORE,
1274                 .off1   = td_var_offset(filename_format),
1275                 .prio   = -1, /* must come after "directory" */
1276                 .help   = "Override default $jobname.$jobnum.$filenum naming",
1277                 .def    = "$jobname.$jobnum.$filenum",
1278                 .category = FIO_OPT_C_FILE,
1279                 .group  = FIO_OPT_G_FILENAME,
1280         },
1281         {
1282                 .name   = "lockfile",
1283                 .lname  = "Lockfile",
1284                 .type   = FIO_OPT_STR,
1285                 .off1   = td_var_offset(file_lock_mode),
1286                 .help   = "Lock file when doing IO to it",
1287                 .prio   = 1,
1288                 .parent = "filename",
1289                 .hide   = 0,
1290                 .def    = "none",
1291                 .cb     = str_lockfile_cb,
1292                 .category = FIO_OPT_C_FILE,
1293                 .group  = FIO_OPT_G_FILENAME,
1294                 .posval = {
1295                           { .ival = "none",
1296                             .oval = FILE_LOCK_NONE,
1297                             .help = "No file locking",
1298                           },
1299                           { .ival = "exclusive",
1300                             .oval = FILE_LOCK_EXCLUSIVE,
1301                             .help = "Exclusive file lock",
1302                           },
1303                           {
1304                             .ival = "readwrite",
1305                             .oval = FILE_LOCK_READWRITE,
1306                             .help = "Read vs write lock",
1307                           },
1308                 },
1309         },
1310         {
1311                 .name   = "opendir",
1312                 .lname  = "Open directory",
1313                 .type   = FIO_OPT_STR_STORE,
1314                 .off1   = td_var_offset(opendir),
1315                 .cb     = str_opendir_cb,
1316                 .help   = "Recursively add files from this directory and down",
1317                 .category = FIO_OPT_C_FILE,
1318                 .group  = FIO_OPT_G_FILENAME,
1319         },
1320         {
1321                 .name   = "rw",
1322                 .lname  = "Read/write",
1323                 .alias  = "readwrite",
1324                 .type   = FIO_OPT_STR,
1325                 .cb     = str_rw_cb,
1326                 .off1   = td_var_offset(td_ddir),
1327                 .help   = "IO direction",
1328                 .def    = "read",
1329                 .verify = rw_verify,
1330                 .category = FIO_OPT_C_IO,
1331                 .group  = FIO_OPT_G_IO_BASIC,
1332                 .posval = {
1333                           { .ival = "read",
1334                             .oval = TD_DDIR_READ,
1335                             .help = "Sequential read",
1336                           },
1337                           { .ival = "write",
1338                             .oval = TD_DDIR_WRITE,
1339                             .help = "Sequential write",
1340                           },
1341                           { .ival = "trim",
1342                             .oval = TD_DDIR_TRIM,
1343                             .help = "Sequential trim",
1344                           },
1345                           { .ival = "randread",
1346                             .oval = TD_DDIR_RANDREAD,
1347                             .help = "Random read",
1348                           },
1349                           { .ival = "randwrite",
1350                             .oval = TD_DDIR_RANDWRITE,
1351                             .help = "Random write",
1352                           },
1353                           { .ival = "randtrim",
1354                             .oval = TD_DDIR_RANDTRIM,
1355                             .help = "Random trim",
1356                           },
1357                           { .ival = "rw",
1358                             .oval = TD_DDIR_RW,
1359                             .help = "Sequential read and write mix",
1360                           },
1361                           { .ival = "readwrite",
1362                             .oval = TD_DDIR_RW,
1363                             .help = "Sequential read and write mix",
1364                           },
1365                           { .ival = "randrw",
1366                             .oval = TD_DDIR_RANDRW,
1367                             .help = "Random read and write mix"
1368                           },
1369                 },
1370         },
1371         {
1372                 .name   = "rw_sequencer",
1373                 .lname  = "RW Sequencer",
1374                 .type   = FIO_OPT_STR,
1375                 .off1   = td_var_offset(rw_seq),
1376                 .help   = "IO offset generator modifier",
1377                 .def    = "sequential",
1378                 .category = FIO_OPT_C_IO,
1379                 .group  = FIO_OPT_G_IO_BASIC,
1380                 .posval = {
1381                           { .ival = "sequential",
1382                             .oval = RW_SEQ_SEQ,
1383                             .help = "Generate sequential offsets",
1384                           },
1385                           { .ival = "identical",
1386                             .oval = RW_SEQ_IDENT,
1387                             .help = "Generate identical offsets",
1388                           },
1389                 },
1390         },
1391
1392         {
1393                 .name   = "ioengine",
1394                 .lname  = "IO Engine",
1395                 .type   = FIO_OPT_STR_STORE,
1396                 .off1   = td_var_offset(ioengine),
1397                 .help   = "IO engine to use",
1398                 .def    = FIO_PREFERRED_ENGINE,
1399                 .category = FIO_OPT_C_IO,
1400                 .group  = FIO_OPT_G_IO_BASIC,
1401                 .posval = {
1402                           { .ival = "sync",
1403                             .help = "Use read/write",
1404                           },
1405                           { .ival = "psync",
1406                             .help = "Use pread/pwrite",
1407                           },
1408                           { .ival = "vsync",
1409                             .help = "Use readv/writev",
1410                           },
1411 #ifdef CONFIG_PWRITEV
1412                           { .ival = "pvsync",
1413                             .help = "Use preadv/pwritev",
1414                           },
1415 #endif
1416 #ifdef CONFIG_LIBAIO
1417                           { .ival = "libaio",
1418                             .help = "Linux native asynchronous IO",
1419                           },
1420 #endif
1421 #ifdef CONFIG_POSIXAIO
1422                           { .ival = "posixaio",
1423                             .help = "POSIX asynchronous IO",
1424                           },
1425 #endif
1426 #ifdef CONFIG_SOLARISAIO
1427                           { .ival = "solarisaio",
1428                             .help = "Solaris native asynchronous IO",
1429                           },
1430 #endif
1431 #ifdef CONFIG_WINDOWSAIO
1432                           { .ival = "windowsaio",
1433                             .help = "Windows native asynchronous IO"
1434                           },
1435 #endif
1436 #ifdef CONFIG_RBD
1437                           { .ival = "rbd",
1438                             .help = "Rados Block Device asynchronous IO"
1439                           },
1440 #endif
1441                           { .ival = "mmap",
1442                             .help = "Memory mapped IO"
1443                           },
1444 #ifdef CONFIG_LINUX_SPLICE
1445                           { .ival = "splice",
1446                             .help = "splice/vmsplice based IO",
1447                           },
1448                           { .ival = "netsplice",
1449                             .help = "splice/vmsplice to/from the network",
1450                           },
1451 #endif
1452 #ifdef FIO_HAVE_SGIO
1453                           { .ival = "sg",
1454                             .help = "SCSI generic v3 IO",
1455                           },
1456 #endif
1457                           { .ival = "null",
1458                             .help = "Testing engine (no data transfer)",
1459                           },
1460                           { .ival = "net",
1461                             .help = "Network IO",
1462                           },
1463                           { .ival = "cpuio",
1464                             .help = "CPU cycle burner engine",
1465                           },
1466 #ifdef CONFIG_GUASI
1467                           { .ival = "guasi",
1468                             .help = "GUASI IO engine",
1469                           },
1470 #endif
1471 #ifdef FIO_HAVE_BINJECT
1472                           { .ival = "binject",
1473                             .help = "binject direct inject block engine",
1474                           },
1475 #endif
1476 #ifdef CONFIG_RDMA
1477                           { .ival = "rdma",
1478                             .help = "RDMA IO engine",
1479                           },
1480 #endif
1481 #ifdef CONFIG_FUSION_AW
1482                           { .ival = "fusion-aw-sync",
1483                             .help = "Fusion-io atomic write engine",
1484                           },
1485 #endif
1486 #ifdef CONFIG_LINUX_EXT4_MOVE_EXTENT
1487                           { .ival = "e4defrag",
1488                             .help = "ext4 defrag engine",
1489                           },
1490 #endif
1491 #ifdef CONFIG_LINUX_FALLOCATE
1492                           { .ival = "falloc",
1493                             .help = "fallocate() file based engine",
1494                           },
1495 #endif
1496                           { .ival = "external",
1497                             .help = "Load external engine (append name)",
1498                           },
1499                 },
1500         },
1501         {
1502                 .name   = "iodepth",
1503                 .lname  = "IO Depth",
1504                 .type   = FIO_OPT_INT,
1505                 .off1   = td_var_offset(iodepth),
1506                 .help   = "Number of IO buffers to keep in flight",
1507                 .minval = 1,
1508                 .interval = 1,
1509                 .def    = "1",
1510                 .category = FIO_OPT_C_IO,
1511                 .group  = FIO_OPT_G_IO_BASIC,
1512         },
1513         {
1514                 .name   = "iodepth_batch",
1515                 .lname  = "IO Depth batch",
1516                 .alias  = "iodepth_batch_submit",
1517                 .type   = FIO_OPT_INT,
1518                 .off1   = td_var_offset(iodepth_batch),
1519                 .help   = "Number of IO buffers to submit in one go",
1520                 .parent = "iodepth",
1521                 .hide   = 1,
1522                 .minval = 1,
1523                 .interval = 1,
1524                 .def    = "1",
1525                 .category = FIO_OPT_C_IO,
1526                 .group  = FIO_OPT_G_IO_BASIC,
1527         },
1528         {
1529                 .name   = "iodepth_batch_complete",
1530                 .lname  = "IO Depth batch complete",
1531                 .type   = FIO_OPT_INT,
1532                 .off1   = td_var_offset(iodepth_batch_complete),
1533                 .help   = "Number of IO buffers to retrieve in one go",
1534                 .parent = "iodepth",
1535                 .hide   = 1,
1536                 .minval = 0,
1537                 .interval = 1,
1538                 .def    = "1",
1539                 .category = FIO_OPT_C_IO,
1540                 .group  = FIO_OPT_G_IO_BASIC,
1541         },
1542         {
1543                 .name   = "iodepth_low",
1544                 .lname  = "IO Depth batch low",
1545                 .type   = FIO_OPT_INT,
1546                 .off1   = td_var_offset(iodepth_low),
1547                 .help   = "Low water mark for queuing depth",
1548                 .parent = "iodepth",
1549                 .hide   = 1,
1550                 .interval = 1,
1551                 .category = FIO_OPT_C_IO,
1552                 .group  = FIO_OPT_G_IO_BASIC,
1553         },
1554         {
1555                 .name   = "size",
1556                 .lname  = "Size",
1557                 .type   = FIO_OPT_STR_VAL,
1558                 .cb     = str_size_cb,
1559                 .help   = "Total size of device or files",
1560                 .interval = 1024 * 1024,
1561                 .category = FIO_OPT_C_IO,
1562                 .group  = FIO_OPT_G_INVALID,
1563         },
1564         {
1565                 .name   = "fill_device",
1566                 .lname  = "Fill device",
1567                 .alias  = "fill_fs",
1568                 .type   = FIO_OPT_BOOL,
1569                 .off1   = td_var_offset(fill_device),
1570                 .help   = "Write until an ENOSPC error occurs",
1571                 .def    = "0",
1572                 .category = FIO_OPT_C_FILE,
1573                 .group  = FIO_OPT_G_INVALID,
1574         },
1575         {
1576                 .name   = "filesize",
1577                 .lname  = "File size",
1578                 .type   = FIO_OPT_STR_VAL,
1579                 .off1   = td_var_offset(file_size_low),
1580                 .off2   = td_var_offset(file_size_high),
1581                 .minval = 1,
1582                 .help   = "Size of individual files",
1583                 .interval = 1024 * 1024,
1584                 .category = FIO_OPT_C_FILE,
1585                 .group  = FIO_OPT_G_INVALID,
1586         },
1587         {
1588                 .name   = "offset",
1589                 .lname  = "IO offset",
1590                 .alias  = "fileoffset",
1591                 .type   = FIO_OPT_STR_VAL,
1592                 .off1   = td_var_offset(start_offset),
1593                 .help   = "Start IO from this offset",
1594                 .def    = "0",
1595                 .interval = 1024 * 1024,
1596                 .category = FIO_OPT_C_IO,
1597                 .group  = FIO_OPT_G_INVALID,
1598         },
1599         {
1600                 .name   = "offset_increment",
1601                 .lname  = "IO offset increment",
1602                 .type   = FIO_OPT_STR_VAL,
1603                 .off1   = td_var_offset(offset_increment),
1604                 .help   = "What is the increment from one offset to the next",
1605                 .parent = "offset",
1606                 .hide   = 1,
1607                 .def    = "0",
1608                 .interval = 1024 * 1024,
1609                 .category = FIO_OPT_C_IO,
1610                 .group  = FIO_OPT_G_INVALID,
1611         },
1612         {
1613                 .name   = "number_ios",
1614                 .lname  = "Number of IOs to perform",
1615                 .type   = FIO_OPT_STR_VAL,
1616                 .off1   = td_var_offset(number_ios),
1617                 .help   = "Force job completion of this number of IOs",
1618                 .def    = "0",
1619                 .category = FIO_OPT_C_IO,
1620                 .group  = FIO_OPT_G_INVALID,
1621         },
1622         {
1623                 .name   = "bs",
1624                 .lname  = "Block size",
1625                 .alias  = "blocksize",
1626                 .type   = FIO_OPT_INT,
1627                 .off1   = td_var_offset(bs[DDIR_READ]),
1628                 .off2   = td_var_offset(bs[DDIR_WRITE]),
1629                 .off3   = td_var_offset(bs[DDIR_TRIM]),
1630                 .minval = 1,
1631                 .help   = "Block size unit",
1632                 .def    = "4k",
1633                 .parent = "rw",
1634                 .hide   = 1,
1635                 .interval = 512,
1636                 .category = FIO_OPT_C_IO,
1637                 .group  = FIO_OPT_G_INVALID,
1638         },
1639         {
1640                 .name   = "ba",
1641                 .lname  = "Block size align",
1642                 .alias  = "blockalign",
1643                 .type   = FIO_OPT_INT,
1644                 .off1   = td_var_offset(ba[DDIR_READ]),
1645                 .off2   = td_var_offset(ba[DDIR_WRITE]),
1646                 .off3   = td_var_offset(ba[DDIR_TRIM]),
1647                 .minval = 1,
1648                 .help   = "IO block offset alignment",
1649                 .parent = "rw",
1650                 .hide   = 1,
1651                 .interval = 512,
1652                 .category = FIO_OPT_C_IO,
1653                 .group  = FIO_OPT_G_INVALID,
1654         },
1655         {
1656                 .name   = "bsrange",
1657                 .lname  = "Block size range",
1658                 .alias  = "blocksize_range",
1659                 .type   = FIO_OPT_RANGE,
1660                 .off1   = td_var_offset(min_bs[DDIR_READ]),
1661                 .off2   = td_var_offset(max_bs[DDIR_READ]),
1662                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
1663                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
1664                 .off5   = td_var_offset(min_bs[DDIR_TRIM]),
1665                 .off6   = td_var_offset(max_bs[DDIR_TRIM]),
1666                 .minval = 1,
1667                 .help   = "Set block size range (in more detail than bs)",
1668                 .parent = "rw",
1669                 .hide   = 1,
1670                 .interval = 4096,
1671                 .category = FIO_OPT_C_IO,
1672                 .group  = FIO_OPT_G_INVALID,
1673         },
1674         {
1675                 .name   = "bssplit",
1676                 .lname  = "Block size split",
1677                 .type   = FIO_OPT_STR,
1678                 .cb     = str_bssplit_cb,
1679                 .help   = "Set a specific mix of block sizes",
1680                 .parent = "rw",
1681                 .hide   = 1,
1682                 .category = FIO_OPT_C_IO,
1683                 .group  = FIO_OPT_G_INVALID,
1684         },
1685         {
1686                 .name   = "bs_unaligned",
1687                 .lname  = "Block size unaligned",
1688                 .alias  = "blocksize_unaligned",
1689                 .type   = FIO_OPT_STR_SET,
1690                 .off1   = td_var_offset(bs_unaligned),
1691                 .help   = "Don't sector align IO buffer sizes",
1692                 .parent = "rw",
1693                 .hide   = 1,
1694                 .category = FIO_OPT_C_IO,
1695                 .group  = FIO_OPT_G_INVALID,
1696         },
1697         {
1698                 .name   = "bs_is_seq_rand",
1699                 .lname  = "Block size division is seq/random (not read/write)",
1700                 .type   = FIO_OPT_BOOL,
1701                 .off1   = td_var_offset(bs_is_seq_rand),
1702                 .help   = "Consider any blocksize setting to be sequential,ramdom",
1703                 .def    = "0",
1704                 .parent = "blocksize",
1705                 .category = FIO_OPT_C_IO,
1706                 .group  = FIO_OPT_G_INVALID,
1707         },
1708         {
1709                 .name   = "randrepeat",
1710                 .lname  = "Random repeatable",
1711                 .type   = FIO_OPT_BOOL,
1712                 .off1   = td_var_offset(rand_repeatable),
1713                 .help   = "Use repeatable random IO pattern",
1714                 .def    = "1",
1715                 .parent = "rw",
1716                 .hide   = 1,
1717                 .category = FIO_OPT_C_IO,
1718                 .group  = FIO_OPT_G_RANDOM,
1719         },
1720         {
1721                 .name   = "randseed",
1722                 .lname  = "The random generator seed",
1723                 .type   = FIO_OPT_STR_VAL,
1724                 .off1   = td_var_offset(rand_seed),
1725                 .help   = "Set the random generator seed value",
1726                 .parent = "rw",
1727                 .category = FIO_OPT_C_IO,
1728                 .group  = FIO_OPT_G_RANDOM,
1729         },
1730         {
1731                 .name   = "use_os_rand",
1732                 .lname  = "Use OS random",
1733                 .type   = FIO_OPT_BOOL,
1734                 .off1   = td_var_offset(use_os_rand),
1735                 .help   = "Set to use OS random generator",
1736                 .def    = "0",
1737                 .parent = "rw",
1738                 .hide   = 1,
1739                 .category = FIO_OPT_C_IO,
1740                 .group  = FIO_OPT_G_RANDOM,
1741         },
1742         {
1743                 .name   = "norandommap",
1744                 .lname  = "No randommap",
1745                 .type   = FIO_OPT_STR_SET,
1746                 .off1   = td_var_offset(norandommap),
1747                 .help   = "Accept potential duplicate random blocks",
1748                 .parent = "rw",
1749                 .hide   = 1,
1750                 .hide_on_set = 1,
1751                 .category = FIO_OPT_C_IO,
1752                 .group  = FIO_OPT_G_RANDOM,
1753         },
1754         {
1755                 .name   = "softrandommap",
1756                 .lname  = "Soft randommap",
1757                 .type   = FIO_OPT_BOOL,
1758                 .off1   = td_var_offset(softrandommap),
1759                 .help   = "Set norandommap if randommap allocation fails",
1760                 .parent = "norandommap",
1761                 .hide   = 1,
1762                 .def    = "0",
1763                 .category = FIO_OPT_C_IO,
1764                 .group  = FIO_OPT_G_RANDOM,
1765         },
1766         {
1767                 .name   = "random_generator",
1768                 .type   = FIO_OPT_STR,
1769                 .off1   = td_var_offset(random_generator),
1770                 .help   = "Type of random number generator to use",
1771                 .def    = "tausworthe",
1772                 .posval = {
1773                           { .ival = "tausworthe",
1774                             .oval = FIO_RAND_GEN_TAUSWORTHE,
1775                             .help = "Strong Tausworthe generator",
1776                           },
1777                           { .ival = "lfsr",
1778                             .oval = FIO_RAND_GEN_LFSR,
1779                             .help = "Variable length LFSR",
1780                           },
1781                 },
1782                 .category = FIO_OPT_C_IO,
1783                 .group  = FIO_OPT_G_RANDOM,
1784         },
1785         {
1786                 .name   = "random_distribution",
1787                 .type   = FIO_OPT_STR,
1788                 .off1   = td_var_offset(random_distribution),
1789                 .cb     = str_random_distribution_cb,
1790                 .help   = "Random offset distribution generator",
1791                 .def    = "random",
1792                 .posval = {
1793                           { .ival = "random",
1794                             .oval = FIO_RAND_DIST_RANDOM,
1795                             .help = "Completely random",
1796                           },
1797                           { .ival = "zipf",
1798                             .oval = FIO_RAND_DIST_ZIPF,
1799                             .help = "Zipf distribution",
1800                           },
1801                           { .ival = "pareto",
1802                             .oval = FIO_RAND_DIST_PARETO,
1803                             .help = "Pareto distribution",
1804                           },
1805                 },
1806                 .category = FIO_OPT_C_IO,
1807                 .group  = FIO_OPT_G_RANDOM,
1808         },
1809         {
1810                 .name   = "percentage_random",
1811                 .lname  = "Percentage Random",
1812                 .type   = FIO_OPT_INT,
1813                 .off1   = td_var_offset(perc_rand[DDIR_READ]),
1814                 .off2   = td_var_offset(perc_rand[DDIR_WRITE]),
1815                 .off3   = td_var_offset(perc_rand[DDIR_TRIM]),
1816                 .maxval = 100,
1817                 .help   = "Percentage of seq/random mix that should be random",
1818                 .def    = "100,100,100",
1819                 .interval = 5,
1820                 .inverse = "percentage_sequential",
1821                 .category = FIO_OPT_C_IO,
1822                 .group  = FIO_OPT_G_RANDOM,
1823         },
1824         {
1825                 .name   = "percentage_sequential",
1826                 .lname  = "Percentage Sequential",
1827                 .type   = FIO_OPT_DEPRECATED,
1828                 .category = FIO_OPT_C_IO,
1829                 .group  = FIO_OPT_G_RANDOM,
1830         },
1831         {
1832                 .name   = "allrandrepeat",
1833                 .type   = FIO_OPT_BOOL,
1834                 .off1   = td_var_offset(allrand_repeatable),
1835                 .help   = "Use repeatable random numbers for everything",
1836                 .def    = "0",
1837                 .category = FIO_OPT_C_IO,
1838                 .group  = FIO_OPT_G_RANDOM,
1839         },
1840         {
1841                 .name   = "nrfiles",
1842                 .lname  = "Number of files",
1843                 .alias  = "nr_files",
1844                 .type   = FIO_OPT_INT,
1845                 .off1   = td_var_offset(nr_files),
1846                 .help   = "Split job workload between this number of files",
1847                 .def    = "1",
1848                 .interval = 1,
1849                 .category = FIO_OPT_C_FILE,
1850                 .group  = FIO_OPT_G_INVALID,
1851         },
1852         {
1853                 .name   = "openfiles",
1854                 .lname  = "Number of open files",
1855                 .type   = FIO_OPT_INT,
1856                 .off1   = td_var_offset(open_files),
1857                 .help   = "Number of files to keep open at the same time",
1858                 .category = FIO_OPT_C_FILE,
1859                 .group  = FIO_OPT_G_INVALID,
1860         },
1861         {
1862                 .name   = "file_service_type",
1863                 .lname  = "File service type",
1864                 .type   = FIO_OPT_STR,
1865                 .cb     = str_fst_cb,
1866                 .off1   = td_var_offset(file_service_type),
1867                 .help   = "How to select which file to service next",
1868                 .def    = "roundrobin",
1869                 .category = FIO_OPT_C_FILE,
1870                 .group  = FIO_OPT_G_INVALID,
1871                 .posval = {
1872                           { .ival = "random",
1873                             .oval = FIO_FSERVICE_RANDOM,
1874                             .help = "Choose a file at random",
1875                           },
1876                           { .ival = "roundrobin",
1877                             .oval = FIO_FSERVICE_RR,
1878                             .help = "Round robin select files",
1879                           },
1880                           { .ival = "sequential",
1881                             .oval = FIO_FSERVICE_SEQ,
1882                             .help = "Finish one file before moving to the next",
1883                           },
1884                 },
1885                 .parent = "nrfiles",
1886                 .hide   = 1,
1887         },
1888 #ifdef CONFIG_POSIX_FALLOCATE
1889         {
1890                 .name   = "fallocate",
1891                 .lname  = "Fallocate",
1892                 .type   = FIO_OPT_STR,
1893                 .off1   = td_var_offset(fallocate_mode),
1894                 .help   = "Whether pre-allocation is performed when laying out files",
1895                 .def    = "posix",
1896                 .category = FIO_OPT_C_FILE,
1897                 .group  = FIO_OPT_G_INVALID,
1898                 .posval = {
1899                           { .ival = "none",
1900                             .oval = FIO_FALLOCATE_NONE,
1901                             .help = "Do not pre-allocate space",
1902                           },
1903                           { .ival = "posix",
1904                             .oval = FIO_FALLOCATE_POSIX,
1905                             .help = "Use posix_fallocate()",
1906                           },
1907 #ifdef CONFIG_LINUX_FALLOCATE
1908                           { .ival = "keep",
1909                             .oval = FIO_FALLOCATE_KEEP_SIZE,
1910                             .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1911                           },
1912 #endif
1913                           /* Compatibility with former boolean values */
1914                           { .ival = "0",
1915                             .oval = FIO_FALLOCATE_NONE,
1916                             .help = "Alias for 'none'",
1917                           },
1918                           { .ival = "1",
1919                             .oval = FIO_FALLOCATE_POSIX,
1920                             .help = "Alias for 'posix'",
1921                           },
1922                 },
1923         },
1924 #endif  /* CONFIG_POSIX_FALLOCATE */
1925         {
1926                 .name   = "fadvise_hint",
1927                 .lname  = "Fadvise hint",
1928                 .type   = FIO_OPT_BOOL,
1929                 .off1   = td_var_offset(fadvise_hint),
1930                 .help   = "Use fadvise() to advise the kernel on IO pattern",
1931                 .def    = "1",
1932                 .category = FIO_OPT_C_FILE,
1933                 .group  = FIO_OPT_G_INVALID,
1934         },
1935         {
1936                 .name   = "fsync",
1937                 .lname  = "Fsync",
1938                 .type   = FIO_OPT_INT,
1939                 .off1   = td_var_offset(fsync_blocks),
1940                 .help   = "Issue fsync for writes every given number of blocks",
1941                 .def    = "0",
1942                 .interval = 1,
1943                 .category = FIO_OPT_C_FILE,
1944                 .group  = FIO_OPT_G_INVALID,
1945         },
1946         {
1947                 .name   = "fdatasync",
1948                 .lname  = "Fdatasync",
1949                 .type   = FIO_OPT_INT,
1950                 .off1   = td_var_offset(fdatasync_blocks),
1951                 .help   = "Issue fdatasync for writes every given number of blocks",
1952                 .def    = "0",
1953                 .interval = 1,
1954                 .category = FIO_OPT_C_FILE,
1955                 .group  = FIO_OPT_G_INVALID,
1956         },
1957         {
1958                 .name   = "write_barrier",
1959                 .lname  = "Write barrier",
1960                 .type   = FIO_OPT_INT,
1961                 .off1   = td_var_offset(barrier_blocks),
1962                 .help   = "Make every Nth write a barrier write",
1963                 .def    = "0",
1964                 .interval = 1,
1965                 .category = FIO_OPT_C_IO,
1966                 .group  = FIO_OPT_G_INVALID,
1967         },
1968 #ifdef CONFIG_SYNC_FILE_RANGE
1969         {
1970                 .name   = "sync_file_range",
1971                 .lname  = "Sync file range",
1972                 .posval = {
1973                           { .ival = "wait_before",
1974                             .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1975                             .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1976                             .orval  = 1,
1977                           },
1978                           { .ival = "write",
1979                             .oval = SYNC_FILE_RANGE_WRITE,
1980                             .help = "SYNC_FILE_RANGE_WRITE",
1981                             .orval  = 1,
1982                           },
1983                           {
1984                             .ival = "wait_after",
1985                             .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1986                             .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1987                             .orval  = 1,
1988                           },
1989                 },
1990                 .type   = FIO_OPT_STR_MULTI,
1991                 .cb     = str_sfr_cb,
1992                 .off1   = td_var_offset(sync_file_range),
1993                 .help   = "Use sync_file_range()",
1994                 .category = FIO_OPT_C_FILE,
1995                 .group  = FIO_OPT_G_INVALID,
1996         },
1997 #endif
1998         {
1999                 .name   = "direct",
2000                 .lname  = "Direct I/O",
2001                 .type   = FIO_OPT_BOOL,
2002                 .off1   = td_var_offset(odirect),
2003                 .help   = "Use O_DIRECT IO (negates buffered)",
2004                 .def    = "0",
2005                 .inverse = "buffered",
2006                 .category = FIO_OPT_C_IO,
2007                 .group  = FIO_OPT_G_IO_TYPE,
2008         },
2009         {
2010                 .name   = "atomic",
2011                 .lname  = "Atomic I/O",
2012                 .type   = FIO_OPT_BOOL,
2013                 .off1   = td_var_offset(oatomic),
2014                 .help   = "Use Atomic IO with O_DIRECT (implies O_DIRECT)",
2015                 .def    = "0",
2016                 .category = FIO_OPT_C_IO,
2017                 .group  = FIO_OPT_G_IO_TYPE,
2018         },
2019         {
2020                 .name   = "buffered",
2021                 .lname  = "Buffered I/O",
2022                 .type   = FIO_OPT_BOOL,
2023                 .off1   = td_var_offset(odirect),
2024                 .neg    = 1,
2025                 .help   = "Use buffered IO (negates direct)",
2026                 .def    = "1",
2027                 .inverse = "direct",
2028                 .category = FIO_OPT_C_IO,
2029                 .group  = FIO_OPT_G_IO_TYPE,
2030         },
2031         {
2032                 .name   = "overwrite",
2033                 .lname  = "Overwrite",
2034                 .type   = FIO_OPT_BOOL,
2035                 .off1   = td_var_offset(overwrite),
2036                 .help   = "When writing, set whether to overwrite current data",
2037                 .def    = "0",
2038                 .category = FIO_OPT_C_FILE,
2039                 .group  = FIO_OPT_G_INVALID,
2040         },
2041         {
2042                 .name   = "loops",
2043                 .lname  = "Loops",
2044                 .type   = FIO_OPT_INT,
2045                 .off1   = td_var_offset(loops),
2046                 .help   = "Number of times to run the job",
2047                 .def    = "1",
2048                 .interval = 1,
2049                 .category = FIO_OPT_C_GENERAL,
2050                 .group  = FIO_OPT_G_RUNTIME,
2051         },
2052         {
2053                 .name   = "numjobs",
2054                 .lname  = "Number of jobs",
2055                 .type   = FIO_OPT_INT,
2056                 .off1   = td_var_offset(numjobs),
2057                 .help   = "Duplicate this job this many times",
2058                 .def    = "1",
2059                 .interval = 1,
2060                 .category = FIO_OPT_C_GENERAL,
2061                 .group  = FIO_OPT_G_RUNTIME,
2062         },
2063         {
2064                 .name   = "startdelay",
2065                 .lname  = "Start delay",
2066                 .type   = FIO_OPT_STR_VAL_TIME,
2067                 .off1   = td_var_offset(start_delay),
2068                 .off2   = td_var_offset(start_delay_high),
2069                 .help   = "Only start job when this period has passed",
2070                 .def    = "0",
2071                 .is_seconds = 1,
2072                 .category = FIO_OPT_C_GENERAL,
2073                 .group  = FIO_OPT_G_RUNTIME,
2074         },
2075         {
2076                 .name   = "runtime",
2077                 .lname  = "Runtime",
2078                 .alias  = "timeout",
2079                 .type   = FIO_OPT_STR_VAL_TIME,
2080                 .off1   = td_var_offset(timeout),
2081                 .help   = "Stop workload when this amount of time has passed",
2082                 .def    = "0",
2083                 .is_seconds = 1,
2084                 .category = FIO_OPT_C_GENERAL,
2085                 .group  = FIO_OPT_G_RUNTIME,
2086         },
2087         {
2088                 .name   = "time_based",
2089                 .lname  = "Time based",
2090                 .type   = FIO_OPT_STR_SET,
2091                 .off1   = td_var_offset(time_based),
2092                 .help   = "Keep running until runtime/timeout is met",
2093                 .category = FIO_OPT_C_GENERAL,
2094                 .group  = FIO_OPT_G_RUNTIME,
2095         },
2096         {
2097                 .name   = "verify_only",
2098                 .lname  = "Verify only",
2099                 .type   = FIO_OPT_STR_SET,
2100                 .off1   = td_var_offset(verify_only),
2101                 .help   = "Verifies previously written data is still valid",
2102                 .category = FIO_OPT_C_GENERAL,
2103                 .group  = FIO_OPT_G_RUNTIME,
2104         },
2105         {
2106                 .name   = "ramp_time",
2107                 .lname  = "Ramp time",
2108                 .type   = FIO_OPT_STR_VAL_TIME,
2109                 .off1   = td_var_offset(ramp_time),
2110                 .help   = "Ramp up time before measuring performance",
2111                 .is_seconds = 1,
2112                 .category = FIO_OPT_C_GENERAL,
2113                 .group  = FIO_OPT_G_RUNTIME,
2114         },
2115         {
2116                 .name   = "clocksource",
2117                 .lname  = "Clock source",
2118                 .type   = FIO_OPT_STR,
2119                 .cb     = fio_clock_source_cb,
2120                 .off1   = td_var_offset(clocksource),
2121                 .help   = "What type of timing source to use",
2122                 .category = FIO_OPT_C_GENERAL,
2123                 .group  = FIO_OPT_G_CLOCK,
2124                 .posval = {
2125 #ifdef CONFIG_GETTIMEOFDAY
2126                           { .ival = "gettimeofday",
2127                             .oval = CS_GTOD,
2128                             .help = "Use gettimeofday(2) for timing",
2129                           },
2130 #endif
2131 #ifdef CONFIG_CLOCK_GETTIME
2132                           { .ival = "clock_gettime",
2133                             .oval = CS_CGETTIME,
2134                             .help = "Use clock_gettime(2) for timing",
2135                           },
2136 #endif
2137 #ifdef ARCH_HAVE_CPU_CLOCK
2138                           { .ival = "cpu",
2139                             .oval = CS_CPUCLOCK,
2140                             .help = "Use CPU private clock",
2141                           },
2142 #endif
2143                 },
2144         },
2145         {
2146                 .name   = "mem",
2147                 .alias  = "iomem",
2148                 .lname  = "I/O Memory",
2149                 .type   = FIO_OPT_STR,
2150                 .cb     = str_mem_cb,
2151                 .off1   = td_var_offset(mem_type),
2152                 .help   = "Backing type for IO buffers",
2153                 .def    = "malloc",
2154                 .category = FIO_OPT_C_IO,
2155                 .group  = FIO_OPT_G_INVALID,
2156                 .posval = {
2157                           { .ival = "malloc",
2158                             .oval = MEM_MALLOC,
2159                             .help = "Use malloc(3) for IO buffers",
2160                           },
2161                           { .ival = "shm",
2162                             .oval = MEM_SHM,
2163                             .help = "Use shared memory segments for IO buffers",
2164                           },
2165 #ifdef FIO_HAVE_HUGETLB
2166                           { .ival = "shmhuge",
2167                             .oval = MEM_SHMHUGE,
2168                             .help = "Like shm, but use huge pages",
2169                           },
2170 #endif
2171                           { .ival = "mmap",
2172                             .oval = MEM_MMAP,
2173                             .help = "Use mmap(2) (file or anon) for IO buffers",
2174                           },
2175 #ifdef FIO_HAVE_HUGETLB
2176                           { .ival = "mmaphuge",
2177                             .oval = MEM_MMAPHUGE,
2178                             .help = "Like mmap, but use huge pages",
2179                           },
2180 #endif
2181                   },
2182         },
2183         {
2184                 .name   = "iomem_align",
2185                 .alias  = "mem_align",
2186                 .lname  = "I/O memory alignment",
2187                 .type   = FIO_OPT_INT,
2188                 .off1   = td_var_offset(mem_align),
2189                 .minval = 0,
2190                 .help   = "IO memory buffer offset alignment",
2191                 .def    = "0",
2192                 .parent = "iomem",
2193                 .hide   = 1,
2194                 .category = FIO_OPT_C_IO,
2195                 .group  = FIO_OPT_G_INVALID,
2196         },
2197         {
2198                 .name   = "verify",
2199                 .lname  = "Verify",
2200                 .type   = FIO_OPT_STR,
2201                 .off1   = td_var_offset(verify),
2202                 .help   = "Verify data written",
2203                 .def    = "0",
2204                 .category = FIO_OPT_C_IO,
2205                 .group  = FIO_OPT_G_VERIFY,
2206                 .posval = {
2207                           { .ival = "0",
2208                             .oval = VERIFY_NONE,
2209                             .help = "Don't do IO verification",
2210                           },
2211                           { .ival = "md5",
2212                             .oval = VERIFY_MD5,
2213                             .help = "Use md5 checksums for verification",
2214                           },
2215                           { .ival = "crc64",
2216                             .oval = VERIFY_CRC64,
2217                             .help = "Use crc64 checksums for verification",
2218                           },
2219                           { .ival = "crc32",
2220                             .oval = VERIFY_CRC32,
2221                             .help = "Use crc32 checksums for verification",
2222                           },
2223                           { .ival = "crc32c-intel",
2224                             .oval = VERIFY_CRC32C,
2225                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
2226                           },
2227                           { .ival = "crc32c",
2228                             .oval = VERIFY_CRC32C,
2229                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
2230                           },
2231                           { .ival = "crc16",
2232                             .oval = VERIFY_CRC16,
2233                             .help = "Use crc16 checksums for verification",
2234                           },
2235                           { .ival = "crc7",
2236                             .oval = VERIFY_CRC7,
2237                             .help = "Use crc7 checksums for verification",
2238                           },
2239                           { .ival = "sha1",
2240                             .oval = VERIFY_SHA1,
2241                             .help = "Use sha1 checksums for verification",
2242                           },
2243                           { .ival = "sha256",
2244                             .oval = VERIFY_SHA256,
2245                             .help = "Use sha256 checksums for verification",
2246                           },
2247                           { .ival = "sha512",
2248                             .oval = VERIFY_SHA512,
2249                             .help = "Use sha512 checksums for verification",
2250                           },
2251                           { .ival = "xxhash",
2252                             .oval = VERIFY_XXHASH,
2253                             .help = "Use xxhash checksums for verification",
2254                           },
2255                           { .ival = "meta",
2256                             .oval = VERIFY_META,
2257                             .help = "Use io information",
2258                           },
2259                           {
2260                             .ival = "null",
2261                             .oval = VERIFY_NULL,
2262                             .help = "Pretend to verify",
2263                           },
2264                 },
2265         },
2266         {
2267                 .name   = "do_verify",
2268                 .lname  = "Perform verify step",
2269                 .type   = FIO_OPT_BOOL,
2270                 .off1   = td_var_offset(do_verify),
2271                 .help   = "Run verification stage after write",
2272                 .def    = "1",
2273                 .parent = "verify",
2274                 .hide   = 1,
2275                 .category = FIO_OPT_C_IO,
2276                 .group  = FIO_OPT_G_VERIFY,
2277         },
2278         {
2279                 .name   = "verifysort",
2280                 .lname  = "Verify sort",
2281                 .type   = FIO_OPT_BOOL,
2282                 .off1   = td_var_offset(verifysort),
2283                 .help   = "Sort written verify blocks for read back",
2284                 .def    = "1",
2285                 .parent = "verify",
2286                 .hide   = 1,
2287                 .category = FIO_OPT_C_IO,
2288                 .group  = FIO_OPT_G_VERIFY,
2289         },
2290         {
2291                 .name   = "verifysort_nr",
2292                 .type   = FIO_OPT_INT,
2293                 .off1   = td_var_offset(verifysort_nr),
2294                 .help   = "Pre-load and sort verify blocks for a read workload",
2295                 .minval = 0,
2296                 .maxval = 131072,
2297                 .def    = "1024",
2298                 .parent = "verify",
2299                 .category = FIO_OPT_C_IO,
2300                 .group  = FIO_OPT_G_VERIFY,
2301         },
2302         {
2303                 .name   = "verify_interval",
2304                 .lname  = "Verify interval",
2305                 .type   = FIO_OPT_INT,
2306                 .off1   = td_var_offset(verify_interval),
2307                 .minval = 2 * sizeof(struct verify_header),
2308                 .help   = "Store verify buffer header every N bytes",
2309                 .parent = "verify",
2310                 .hide   = 1,
2311                 .interval = 2 * sizeof(struct verify_header),
2312                 .category = FIO_OPT_C_IO,
2313                 .group  = FIO_OPT_G_VERIFY,
2314         },
2315         {
2316                 .name   = "verify_offset",
2317                 .lname  = "Verify offset",
2318                 .type   = FIO_OPT_INT,
2319                 .help   = "Offset verify header location by N bytes",
2320                 .off1   = td_var_offset(verify_offset),
2321                 .minval = sizeof(struct verify_header),
2322                 .parent = "verify",
2323                 .hide   = 1,
2324                 .category = FIO_OPT_C_IO,
2325                 .group  = FIO_OPT_G_VERIFY,
2326         },
2327         {
2328                 .name   = "verify_pattern",
2329                 .lname  = "Verify pattern",
2330                 .type   = FIO_OPT_STR,
2331                 .cb     = str_verify_pattern_cb,
2332                 .help   = "Fill pattern for IO buffers",
2333                 .parent = "verify",
2334                 .hide   = 1,
2335                 .category = FIO_OPT_C_IO,
2336                 .group  = FIO_OPT_G_VERIFY,
2337         },
2338         {
2339                 .name   = "verify_fatal",
2340                 .lname  = "Verify fatal",
2341                 .type   = FIO_OPT_BOOL,
2342                 .off1   = td_var_offset(verify_fatal),
2343                 .def    = "0",
2344                 .help   = "Exit on a single verify failure, don't continue",
2345                 .parent = "verify",
2346                 .hide   = 1,
2347                 .category = FIO_OPT_C_IO,
2348                 .group  = FIO_OPT_G_VERIFY,
2349         },
2350         {
2351                 .name   = "verify_dump",
2352                 .lname  = "Verify dump",
2353                 .type   = FIO_OPT_BOOL,
2354                 .off1   = td_var_offset(verify_dump),
2355                 .def    = "0",
2356                 .help   = "Dump contents of good and bad blocks on failure",
2357                 .parent = "verify",
2358                 .hide   = 1,
2359                 .category = FIO_OPT_C_IO,
2360                 .group  = FIO_OPT_G_VERIFY,
2361         },
2362         {
2363                 .name   = "verify_async",
2364                 .lname  = "Verify asynchronously",
2365                 .type   = FIO_OPT_INT,
2366                 .off1   = td_var_offset(verify_async),
2367                 .def    = "0",
2368                 .help   = "Number of async verifier threads to use",
2369                 .parent = "verify",
2370                 .hide   = 1,
2371                 .category = FIO_OPT_C_IO,
2372                 .group  = FIO_OPT_G_VERIFY,
2373         },
2374         {
2375                 .name   = "verify_backlog",
2376                 .lname  = "Verify backlog",
2377                 .type   = FIO_OPT_STR_VAL,
2378                 .off1   = td_var_offset(verify_backlog),
2379                 .help   = "Verify after this number of blocks are written",
2380                 .parent = "verify",
2381                 .hide   = 1,
2382                 .category = FIO_OPT_C_IO,
2383                 .group  = FIO_OPT_G_VERIFY,
2384         },
2385         {
2386                 .name   = "verify_backlog_batch",
2387                 .lname  = "Verify backlog batch",
2388                 .type   = FIO_OPT_INT,
2389                 .off1   = td_var_offset(verify_batch),
2390                 .help   = "Verify this number of IO blocks",
2391                 .parent = "verify",
2392                 .hide   = 1,
2393                 .category = FIO_OPT_C_IO,
2394                 .group  = FIO_OPT_G_VERIFY,
2395         },
2396 #ifdef FIO_HAVE_CPU_AFFINITY
2397         {
2398                 .name   = "verify_async_cpus",
2399                 .lname  = "Async verify CPUs",
2400                 .type   = FIO_OPT_STR,
2401                 .cb     = str_verify_cpus_allowed_cb,
2402                 .help   = "Set CPUs allowed for async verify threads",
2403                 .parent = "verify_async",
2404                 .hide   = 1,
2405                 .category = FIO_OPT_C_IO,
2406                 .group  = FIO_OPT_G_VERIFY,
2407         },
2408 #endif
2409         {
2410                 .name   = "experimental_verify",
2411                 .off1   = td_var_offset(experimental_verify),
2412                 .type   = FIO_OPT_BOOL,
2413                 .help   = "Enable experimental verification",
2414                 .category = FIO_OPT_C_IO,
2415                 .group  = FIO_OPT_G_VERIFY,
2416         },
2417 #ifdef FIO_HAVE_TRIM
2418         {
2419                 .name   = "trim_percentage",
2420                 .lname  = "Trim percentage",
2421                 .type   = FIO_OPT_INT,
2422                 .off1   = td_var_offset(trim_percentage),
2423                 .minval = 0,
2424                 .maxval = 100,
2425                 .help   = "Number of verify blocks to discard/trim",
2426                 .parent = "verify",
2427                 .def    = "0",
2428                 .interval = 1,
2429                 .hide   = 1,
2430                 .category = FIO_OPT_C_IO,
2431                 .group  = FIO_OPT_G_TRIM,
2432         },
2433         {
2434                 .name   = "trim_verify_zero",
2435                 .lname  = "Verify trim zero",
2436                 .type   = FIO_OPT_BOOL,
2437                 .help   = "Verify that trim/discarded blocks are returned as zeroes",
2438                 .off1   = td_var_offset(trim_zero),
2439                 .parent = "trim_percentage",
2440                 .hide   = 1,
2441                 .def    = "1",
2442                 .category = FIO_OPT_C_IO,
2443                 .group  = FIO_OPT_G_TRIM,
2444         },
2445         {
2446                 .name   = "trim_backlog",
2447                 .lname  = "Trim backlog",
2448                 .type   = FIO_OPT_STR_VAL,
2449                 .off1   = td_var_offset(trim_backlog),
2450                 .help   = "Trim after this number of blocks are written",
2451                 .parent = "trim_percentage",
2452                 .hide   = 1,
2453                 .interval = 1,
2454                 .category = FIO_OPT_C_IO,
2455                 .group  = FIO_OPT_G_TRIM,
2456         },
2457         {
2458                 .name   = "trim_backlog_batch",
2459                 .lname  = "Trim backlog batch",
2460                 .type   = FIO_OPT_INT,
2461                 .off1   = td_var_offset(trim_batch),
2462                 .help   = "Trim this number of IO blocks",
2463                 .parent = "trim_percentage",
2464                 .hide   = 1,
2465                 .interval = 1,
2466                 .category = FIO_OPT_C_IO,
2467                 .group  = FIO_OPT_G_TRIM,
2468         },
2469 #endif
2470         {
2471                 .name   = "write_iolog",
2472                 .lname  = "Write I/O log",
2473                 .type   = FIO_OPT_STR_STORE,
2474                 .off1   = td_var_offset(write_iolog_file),
2475                 .help   = "Store IO pattern to file",
2476                 .category = FIO_OPT_C_IO,
2477                 .group  = FIO_OPT_G_IOLOG,
2478         },
2479         {
2480                 .name   = "read_iolog",
2481                 .lname  = "Read I/O log",
2482                 .type   = FIO_OPT_STR_STORE,
2483                 .off1   = td_var_offset(read_iolog_file),
2484                 .help   = "Playback IO pattern from file",
2485                 .category = FIO_OPT_C_IO,
2486                 .group  = FIO_OPT_G_IOLOG,
2487         },
2488         {
2489                 .name   = "replay_no_stall",
2490                 .lname  = "Don't stall on replay",
2491                 .type   = FIO_OPT_BOOL,
2492                 .off1   = td_var_offset(no_stall),
2493                 .def    = "0",
2494                 .parent = "read_iolog",
2495                 .hide   = 1,
2496                 .help   = "Playback IO pattern file as fast as possible without stalls",
2497                 .category = FIO_OPT_C_IO,
2498                 .group  = FIO_OPT_G_IOLOG,
2499         },
2500         {
2501                 .name   = "replay_redirect",
2502                 .lname  = "Redirect device for replay",
2503                 .type   = FIO_OPT_STR_STORE,
2504                 .off1   = td_var_offset(replay_redirect),
2505                 .parent = "read_iolog",
2506                 .hide   = 1,
2507                 .help   = "Replay all I/O onto this device, regardless of trace device",
2508                 .category = FIO_OPT_C_IO,
2509                 .group  = FIO_OPT_G_IOLOG,
2510         },
2511         {
2512                 .name   = "exec_prerun",
2513                 .lname  = "Pre-execute runnable",
2514                 .type   = FIO_OPT_STR_STORE,
2515                 .off1   = td_var_offset(exec_prerun),
2516                 .help   = "Execute this file prior to running job",
2517                 .category = FIO_OPT_C_GENERAL,
2518                 .group  = FIO_OPT_G_INVALID,
2519         },
2520         {
2521                 .name   = "exec_postrun",
2522                 .lname  = "Post-execute runnable",
2523                 .type   = FIO_OPT_STR_STORE,
2524                 .off1   = td_var_offset(exec_postrun),
2525                 .help   = "Execute this file after running job",
2526                 .category = FIO_OPT_C_GENERAL,
2527                 .group  = FIO_OPT_G_INVALID,
2528         },
2529 #ifdef FIO_HAVE_IOSCHED_SWITCH
2530         {
2531                 .name   = "ioscheduler",
2532                 .lname  = "I/O scheduler",
2533                 .type   = FIO_OPT_STR_STORE,
2534                 .off1   = td_var_offset(ioscheduler),
2535                 .help   = "Use this IO scheduler on the backing device",
2536                 .category = FIO_OPT_C_FILE,
2537                 .group  = FIO_OPT_G_INVALID,
2538         },
2539 #endif
2540         {
2541                 .name   = "zonesize",
2542                 .lname  = "Zone size",
2543                 .type   = FIO_OPT_STR_VAL,
2544                 .off1   = td_var_offset(zone_size),
2545                 .help   = "Amount of data to read per zone",
2546                 .def    = "0",
2547                 .interval = 1024 * 1024,
2548                 .category = FIO_OPT_C_IO,
2549                 .group  = FIO_OPT_G_ZONE,
2550         },
2551         {
2552                 .name   = "zonerange",
2553                 .lname  = "Zone range",
2554                 .type   = FIO_OPT_STR_VAL,
2555                 .off1   = td_var_offset(zone_range),
2556                 .help   = "Give size of an IO zone",
2557                 .def    = "0",
2558                 .interval = 1024 * 1024,
2559                 .category = FIO_OPT_C_IO,
2560                 .group  = FIO_OPT_G_ZONE,
2561         },
2562         {
2563                 .name   = "zoneskip",
2564                 .lname  = "Zone skip",
2565                 .type   = FIO_OPT_STR_VAL,
2566                 .off1   = td_var_offset(zone_skip),
2567                 .help   = "Space between IO zones",
2568                 .def    = "0",
2569                 .interval = 1024 * 1024,
2570                 .category = FIO_OPT_C_IO,
2571                 .group  = FIO_OPT_G_ZONE,
2572         },
2573         {
2574                 .name   = "lockmem",
2575                 .lname  = "Lock memory",
2576                 .type   = FIO_OPT_STR_VAL,
2577                 .off1   = td_var_offset(lockmem),
2578                 .help   = "Lock down this amount of memory (per worker)",
2579                 .def    = "0",
2580                 .interval = 1024 * 1024,
2581                 .category = FIO_OPT_C_GENERAL,
2582                 .group  = FIO_OPT_G_INVALID,
2583         },
2584         {
2585                 .name   = "rwmixread",
2586                 .lname  = "Read/write mix read",
2587                 .type   = FIO_OPT_INT,
2588                 .cb     = str_rwmix_read_cb,
2589                 .maxval = 100,
2590                 .help   = "Percentage of mixed workload that is reads",
2591                 .def    = "50",
2592                 .interval = 5,
2593                 .inverse = "rwmixwrite",
2594                 .category = FIO_OPT_C_IO,
2595                 .group  = FIO_OPT_G_RWMIX,
2596         },
2597         {
2598                 .name   = "rwmixwrite",
2599                 .lname  = "Read/write mix write",
2600                 .type   = FIO_OPT_INT,
2601                 .cb     = str_rwmix_write_cb,
2602                 .maxval = 100,
2603                 .help   = "Percentage of mixed workload that is writes",
2604                 .def    = "50",
2605                 .interval = 5,
2606                 .inverse = "rwmixread",
2607                 .category = FIO_OPT_C_IO,
2608                 .group  = FIO_OPT_G_RWMIX,
2609         },
2610         {
2611                 .name   = "rwmixcycle",
2612                 .lname  = "Read/write mix cycle",
2613                 .type   = FIO_OPT_DEPRECATED,
2614                 .category = FIO_OPT_C_IO,
2615                 .group  = FIO_OPT_G_RWMIX,
2616         },
2617         {
2618                 .name   = "nice",
2619                 .lname  = "Nice",
2620                 .type   = FIO_OPT_INT,
2621                 .off1   = td_var_offset(nice),
2622                 .help   = "Set job CPU nice value",
2623                 .minval = -19,
2624                 .maxval = 20,
2625                 .def    = "0",
2626                 .interval = 1,
2627                 .category = FIO_OPT_C_GENERAL,
2628                 .group  = FIO_OPT_G_CRED,
2629         },
2630 #ifdef FIO_HAVE_IOPRIO
2631         {
2632                 .name   = "prio",
2633                 .lname  = "I/O nice priority",
2634                 .type   = FIO_OPT_INT,
2635                 .off1   = td_var_offset(ioprio),
2636                 .help   = "Set job IO priority value",
2637                 .minval = 0,
2638                 .maxval = 7,
2639                 .interval = 1,
2640                 .category = FIO_OPT_C_GENERAL,
2641                 .group  = FIO_OPT_G_CRED,
2642         },
2643         {
2644                 .name   = "prioclass",
2645                 .lname  = "I/O nice priority class",
2646                 .type   = FIO_OPT_INT,
2647                 .off1   = td_var_offset(ioprio_class),
2648                 .help   = "Set job IO priority class",
2649                 .minval = 0,
2650                 .maxval = 3,
2651                 .interval = 1,
2652                 .category = FIO_OPT_C_GENERAL,
2653                 .group  = FIO_OPT_G_CRED,
2654         },
2655 #endif
2656         {
2657                 .name   = "thinktime",
2658                 .lname  = "Thinktime",
2659                 .type   = FIO_OPT_INT,
2660                 .off1   = td_var_offset(thinktime),
2661                 .help   = "Idle time between IO buffers (usec)",
2662                 .def    = "0",
2663                 .category = FIO_OPT_C_IO,
2664                 .group  = FIO_OPT_G_THINKTIME,
2665         },
2666         {
2667                 .name   = "thinktime_spin",
2668                 .lname  = "Thinktime spin",
2669                 .type   = FIO_OPT_INT,
2670                 .off1   = td_var_offset(thinktime_spin),
2671                 .help   = "Start think time by spinning this amount (usec)",
2672                 .def    = "0",
2673                 .parent = "thinktime",
2674                 .hide   = 1,
2675                 .category = FIO_OPT_C_IO,
2676                 .group  = FIO_OPT_G_THINKTIME,
2677         },
2678         {
2679                 .name   = "thinktime_blocks",
2680                 .lname  = "Thinktime blocks",
2681                 .type   = FIO_OPT_INT,
2682                 .off1   = td_var_offset(thinktime_blocks),
2683                 .help   = "IO buffer period between 'thinktime'",
2684                 .def    = "1",
2685                 .parent = "thinktime",
2686                 .hide   = 1,
2687                 .category = FIO_OPT_C_IO,
2688                 .group  = FIO_OPT_G_THINKTIME,
2689         },
2690         {
2691                 .name   = "rate",
2692                 .lname  = "I/O rate",
2693                 .type   = FIO_OPT_INT,
2694                 .off1   = td_var_offset(rate[DDIR_READ]),
2695                 .off2   = td_var_offset(rate[DDIR_WRITE]),
2696                 .off3   = td_var_offset(rate[DDIR_TRIM]),
2697                 .help   = "Set bandwidth rate",
2698                 .category = FIO_OPT_C_IO,
2699                 .group  = FIO_OPT_G_RATE,
2700         },
2701         {
2702                 .name   = "ratemin",
2703                 .lname  = "I/O min rate",
2704                 .type   = FIO_OPT_INT,
2705                 .off1   = td_var_offset(ratemin[DDIR_READ]),
2706                 .off2   = td_var_offset(ratemin[DDIR_WRITE]),
2707                 .off3   = td_var_offset(ratemin[DDIR_TRIM]),
2708                 .help   = "Job must meet this rate or it will be shutdown",
2709                 .parent = "rate",
2710                 .hide   = 1,
2711                 .category = FIO_OPT_C_IO,
2712                 .group  = FIO_OPT_G_RATE,
2713         },
2714         {
2715                 .name   = "rate_iops",
2716                 .lname  = "I/O rate IOPS",
2717                 .type   = FIO_OPT_INT,
2718                 .off1   = td_var_offset(rate_iops[DDIR_READ]),
2719                 .off2   = td_var_offset(rate_iops[DDIR_WRITE]),
2720                 .off3   = td_var_offset(rate_iops[DDIR_TRIM]),
2721                 .help   = "Limit IO used to this number of IO operations/sec",
2722                 .hide   = 1,
2723                 .category = FIO_OPT_C_IO,
2724                 .group  = FIO_OPT_G_RATE,
2725         },
2726         {
2727                 .name   = "rate_iops_min",
2728                 .lname  = "I/O min rate IOPS",
2729                 .type   = FIO_OPT_INT,
2730                 .off1   = td_var_offset(rate_iops_min[DDIR_READ]),
2731                 .off2   = td_var_offset(rate_iops_min[DDIR_WRITE]),
2732                 .off3   = td_var_offset(rate_iops_min[DDIR_TRIM]),
2733                 .help   = "Job must meet this rate or it will be shut down",
2734                 .parent = "rate_iops",
2735                 .hide   = 1,
2736                 .category = FIO_OPT_C_IO,
2737                 .group  = FIO_OPT_G_RATE,
2738         },
2739         {
2740                 .name   = "ratecycle",
2741                 .lname  = "I/O rate cycle",
2742                 .type   = FIO_OPT_INT,
2743                 .off1   = td_var_offset(ratecycle),
2744                 .help   = "Window average for rate limits (msec)",
2745                 .def    = "1000",
2746                 .parent = "rate",
2747                 .hide   = 1,
2748                 .category = FIO_OPT_C_IO,
2749                 .group  = FIO_OPT_G_RATE,
2750         },
2751         {
2752                 .name   = "max_latency",
2753                 .type   = FIO_OPT_INT,
2754                 .off1   = td_var_offset(max_latency),
2755                 .help   = "Maximum tolerated IO latency (usec)",
2756                 .category = FIO_OPT_C_IO,
2757                 .group = FIO_OPT_G_LATPROF,
2758         },
2759         {
2760                 .name   = "latency_target",
2761                 .lname  = "Latency Target (usec)",
2762                 .type   = FIO_OPT_STR_VAL_TIME,
2763                 .off1   = td_var_offset(latency_target),
2764                 .help   = "Ramp to max queue depth supporting this latency",
2765                 .category = FIO_OPT_C_IO,
2766                 .group  = FIO_OPT_G_LATPROF,
2767         },
2768         {
2769                 .name   = "latency_window",
2770                 .lname  = "Latency Window (usec)",
2771                 .type   = FIO_OPT_STR_VAL_TIME,
2772                 .off1   = td_var_offset(latency_window),
2773                 .help   = "Time to sustain latency_target",
2774                 .category = FIO_OPT_C_IO,
2775                 .group  = FIO_OPT_G_LATPROF,
2776         },
2777         {
2778                 .name   = "latency_percentile",
2779                 .lname  = "Latency Percentile",
2780                 .type   = FIO_OPT_FLOAT_LIST,
2781                 .off1   = td_var_offset(latency_percentile),
2782                 .help   = "Percentile of IOs must be below latency_target",
2783                 .def    = "100",
2784                 .maxlen = 1,
2785                 .minfp  = 0.0,
2786                 .maxfp  = 100.0,
2787                 .category = FIO_OPT_C_IO,
2788                 .group  = FIO_OPT_G_LATPROF,
2789         },
2790         {
2791                 .name   = "invalidate",
2792                 .lname  = "Cache invalidate",
2793                 .type   = FIO_OPT_BOOL,
2794                 .off1   = td_var_offset(invalidate_cache),
2795                 .help   = "Invalidate buffer/page cache prior to running job",
2796                 .def    = "1",
2797                 .category = FIO_OPT_C_IO,
2798                 .group  = FIO_OPT_G_IO_TYPE,
2799         },
2800         {
2801                 .name   = "sync",
2802                 .lname  = "Synchronous I/O",
2803                 .type   = FIO_OPT_BOOL,
2804                 .off1   = td_var_offset(sync_io),
2805                 .help   = "Use O_SYNC for buffered writes",
2806                 .def    = "0",
2807                 .parent = "buffered",
2808                 .hide   = 1,
2809                 .category = FIO_OPT_C_IO,
2810                 .group  = FIO_OPT_G_IO_TYPE,
2811         },
2812         {
2813                 .name   = "create_serialize",
2814                 .lname  = "Create serialize",
2815                 .type   = FIO_OPT_BOOL,
2816                 .off1   = td_var_offset(create_serialize),
2817                 .help   = "Serialize creating of job files",
2818                 .def    = "1",
2819                 .category = FIO_OPT_C_FILE,
2820                 .group  = FIO_OPT_G_INVALID,
2821         },
2822         {
2823                 .name   = "create_fsync",
2824                 .lname  = "Create fsync",
2825                 .type   = FIO_OPT_BOOL,
2826                 .off1   = td_var_offset(create_fsync),
2827                 .help   = "fsync file after creation",
2828                 .def    = "1",
2829                 .category = FIO_OPT_C_FILE,
2830                 .group  = FIO_OPT_G_INVALID,
2831         },
2832         {
2833                 .name   = "create_on_open",
2834                 .lname  = "Create on open",
2835                 .type   = FIO_OPT_BOOL,
2836                 .off1   = td_var_offset(create_on_open),
2837                 .help   = "Create files when they are opened for IO",
2838                 .def    = "0",
2839                 .category = FIO_OPT_C_FILE,
2840                 .group  = FIO_OPT_G_INVALID,
2841         },
2842         {
2843                 .name   = "create_only",
2844                 .type   = FIO_OPT_BOOL,
2845                 .off1   = td_var_offset(create_only),
2846                 .help   = "Only perform file creation phase",
2847                 .category = FIO_OPT_C_FILE,
2848                 .def    = "0",
2849         },
2850         {
2851                 .name   = "pre_read",
2852                 .lname  = "Pre-read files",
2853                 .type   = FIO_OPT_BOOL,
2854                 .off1   = td_var_offset(pre_read),
2855                 .help   = "Pre-read files before starting official testing",
2856                 .def    = "0",
2857                 .category = FIO_OPT_C_FILE,
2858                 .group  = FIO_OPT_G_INVALID,
2859         },
2860 #ifdef FIO_HAVE_CPU_AFFINITY
2861         {
2862                 .name   = "cpumask",
2863                 .lname  = "CPU mask",
2864                 .type   = FIO_OPT_INT,
2865                 .cb     = str_cpumask_cb,
2866                 .help   = "CPU affinity mask",
2867                 .category = FIO_OPT_C_GENERAL,
2868                 .group  = FIO_OPT_G_CRED,
2869         },
2870         {
2871                 .name   = "cpus_allowed",
2872                 .lname  = "CPUs allowed",
2873                 .type   = FIO_OPT_STR,
2874                 .cb     = str_cpus_allowed_cb,
2875                 .help   = "Set CPUs allowed",
2876                 .category = FIO_OPT_C_GENERAL,
2877                 .group  = FIO_OPT_G_CRED,
2878         },
2879 #endif
2880 #ifdef CONFIG_LIBNUMA
2881         {
2882                 .name   = "numa_cpu_nodes",
2883                 .type   = FIO_OPT_STR,
2884                 .cb     = str_numa_cpunodes_cb,
2885                 .help   = "NUMA CPU nodes bind",
2886                 .category = FIO_OPT_C_GENERAL,
2887                 .group  = FIO_OPT_G_INVALID,
2888         },
2889         {
2890                 .name   = "numa_mem_policy",
2891                 .type   = FIO_OPT_STR,
2892                 .cb     = str_numa_mpol_cb,
2893                 .help   = "NUMA memory policy setup",
2894                 .category = FIO_OPT_C_GENERAL,
2895                 .group  = FIO_OPT_G_INVALID,
2896         },
2897 #endif
2898         {
2899                 .name   = "end_fsync",
2900                 .lname  = "End fsync",
2901                 .type   = FIO_OPT_BOOL,
2902                 .off1   = td_var_offset(end_fsync),
2903                 .help   = "Include fsync at the end of job",
2904                 .def    = "0",
2905                 .category = FIO_OPT_C_FILE,
2906                 .group  = FIO_OPT_G_INVALID,
2907         },
2908         {
2909                 .name   = "fsync_on_close",
2910                 .lname  = "Fsync on close",
2911                 .type   = FIO_OPT_BOOL,
2912                 .off1   = td_var_offset(fsync_on_close),
2913                 .help   = "fsync files on close",
2914                 .def    = "0",
2915                 .category = FIO_OPT_C_FILE,
2916                 .group  = FIO_OPT_G_INVALID,
2917         },
2918         {
2919                 .name   = "unlink",
2920                 .lname  = "Unlink file",
2921                 .type   = FIO_OPT_BOOL,
2922                 .off1   = td_var_offset(unlink),
2923                 .help   = "Unlink created files after job has completed",
2924                 .def    = "0",
2925                 .category = FIO_OPT_C_FILE,
2926                 .group  = FIO_OPT_G_INVALID,
2927         },
2928         {
2929                 .name   = "exitall",
2930                 .lname  = "Exit-all on terminate",
2931                 .type   = FIO_OPT_STR_SET,
2932                 .cb     = str_exitall_cb,
2933                 .help   = "Terminate all jobs when one exits",
2934                 .category = FIO_OPT_C_GENERAL,
2935                 .group  = FIO_OPT_G_PROCESS,
2936         },
2937         {
2938                 .name   = "stonewall",
2939                 .lname  = "Wait for previous",
2940                 .alias  = "wait_for_previous",
2941                 .type   = FIO_OPT_STR_SET,
2942                 .off1   = td_var_offset(stonewall),
2943                 .help   = "Insert a hard barrier between this job and previous",
2944                 .category = FIO_OPT_C_GENERAL,
2945                 .group  = FIO_OPT_G_PROCESS,
2946         },
2947         {
2948                 .name   = "new_group",
2949                 .lname  = "New group",
2950                 .type   = FIO_OPT_STR_SET,
2951                 .off1   = td_var_offset(new_group),
2952                 .help   = "Mark the start of a new group (for reporting)",
2953                 .category = FIO_OPT_C_GENERAL,
2954                 .group  = FIO_OPT_G_PROCESS,
2955         },
2956         {
2957                 .name   = "thread",
2958                 .lname  = "Thread",
2959                 .type   = FIO_OPT_STR_SET,
2960                 .off1   = td_var_offset(use_thread),
2961                 .help   = "Use threads instead of processes",
2962                 .category = FIO_OPT_C_GENERAL,
2963                 .group  = FIO_OPT_G_PROCESS,
2964         },
2965         {
2966                 .name   = "write_bw_log",
2967                 .lname  = "Write bandwidth log",
2968                 .type   = FIO_OPT_STR_STORE,
2969                 .off1   = td_var_offset(bw_log_file),
2970                 .help   = "Write log of bandwidth during run",
2971                 .category = FIO_OPT_C_LOG,
2972                 .group  = FIO_OPT_G_INVALID,
2973         },
2974         {
2975                 .name   = "write_lat_log",
2976                 .lname  = "Write latency log",
2977                 .type   = FIO_OPT_STR_STORE,
2978                 .off1   = td_var_offset(lat_log_file),
2979                 .help   = "Write log of latency during run",
2980                 .category = FIO_OPT_C_LOG,
2981                 .group  = FIO_OPT_G_INVALID,
2982         },
2983         {
2984                 .name   = "write_iops_log",
2985                 .lname  = "Write IOPS log",
2986                 .type   = FIO_OPT_STR_STORE,
2987                 .off1   = td_var_offset(iops_log_file),
2988                 .help   = "Write log of IOPS during run",
2989                 .category = FIO_OPT_C_LOG,
2990                 .group  = FIO_OPT_G_INVALID,
2991         },
2992         {
2993                 .name   = "log_avg_msec",
2994                 .lname  = "Log averaging (msec)",
2995                 .type   = FIO_OPT_INT,
2996                 .off1   = td_var_offset(log_avg_msec),
2997                 .help   = "Average bw/iops/lat logs over this period of time",
2998                 .def    = "0",
2999                 .category = FIO_OPT_C_LOG,
3000                 .group  = FIO_OPT_G_INVALID,
3001         },
3002         {
3003                 .name   = "bwavgtime",
3004                 .lname  = "Bandwidth average time",
3005                 .type   = FIO_OPT_INT,
3006                 .off1   = td_var_offset(bw_avg_time),
3007                 .help   = "Time window over which to calculate bandwidth"
3008                           " (msec)",
3009                 .def    = "500",
3010                 .parent = "write_bw_log",
3011                 .hide   = 1,
3012                 .interval = 100,
3013                 .category = FIO_OPT_C_LOG,
3014                 .group  = FIO_OPT_G_INVALID,
3015         },
3016         {
3017                 .name   = "iopsavgtime",
3018                 .lname  = "IOPS average time",
3019                 .type   = FIO_OPT_INT,
3020                 .off1   = td_var_offset(iops_avg_time),
3021                 .help   = "Time window over which to calculate IOPS (msec)",
3022                 .def    = "500",
3023                 .parent = "write_iops_log",
3024                 .hide   = 1,
3025                 .interval = 100,
3026                 .category = FIO_OPT_C_LOG,
3027                 .group  = FIO_OPT_G_INVALID,
3028         },
3029         {
3030                 .name   = "group_reporting",
3031                 .lname  = "Group reporting",
3032                 .type   = FIO_OPT_STR_SET,
3033                 .off1   = td_var_offset(group_reporting),
3034                 .help   = "Do reporting on a per-group basis",
3035                 .category = FIO_OPT_C_STAT,
3036                 .group  = FIO_OPT_G_INVALID,
3037         },
3038         {
3039                 .name   = "zero_buffers",
3040                 .lname  = "Zero I/O buffers",
3041                 .type   = FIO_OPT_STR_SET,
3042                 .off1   = td_var_offset(zero_buffers),
3043                 .help   = "Init IO buffers to all zeroes",
3044                 .category = FIO_OPT_C_IO,
3045                 .group  = FIO_OPT_G_IO_BUF,
3046         },
3047         {
3048                 .name   = "refill_buffers",
3049                 .lname  = "Refill I/O buffers",
3050                 .type   = FIO_OPT_STR_SET,
3051                 .off1   = td_var_offset(refill_buffers),
3052                 .help   = "Refill IO buffers on every IO submit",
3053                 .category = FIO_OPT_C_IO,
3054                 .group  = FIO_OPT_G_IO_BUF,
3055         },
3056         {
3057                 .name   = "scramble_buffers",
3058                 .lname  = "Scramble I/O buffers",
3059                 .type   = FIO_OPT_BOOL,
3060                 .off1   = td_var_offset(scramble_buffers),
3061                 .help   = "Slightly scramble buffers on every IO submit",
3062                 .def    = "1",
3063                 .category = FIO_OPT_C_IO,
3064                 .group  = FIO_OPT_G_IO_BUF,
3065         },
3066         {
3067                 .name   = "buffer_pattern",
3068                 .lname  = "Buffer pattern",
3069                 .type   = FIO_OPT_STR,
3070                 .cb     = str_buffer_pattern_cb,
3071                 .help   = "Fill pattern for IO buffers",
3072                 .category = FIO_OPT_C_IO,
3073                 .group  = FIO_OPT_G_IO_BUF,
3074         },
3075         {
3076                 .name   = "buffer_compress_percentage",
3077                 .lname  = "Buffer compression percentage",
3078                 .type   = FIO_OPT_INT,
3079                 .off1   = td_var_offset(compress_percentage),
3080                 .maxval = 100,
3081                 .minval = 0,
3082                 .help   = "How compressible the buffer is (approximately)",
3083                 .interval = 5,
3084                 .category = FIO_OPT_C_IO,
3085                 .group  = FIO_OPT_G_IO_BUF,
3086         },
3087         {
3088                 .name   = "buffer_compress_chunk",
3089                 .lname  = "Buffer compression chunk size",
3090                 .type   = FIO_OPT_INT,
3091                 .off1   = td_var_offset(compress_chunk),
3092                 .parent = "buffer_compress_percentage",
3093                 .hide   = 1,
3094                 .help   = "Size of compressible region in buffer",
3095                 .interval = 256,
3096                 .category = FIO_OPT_C_IO,
3097                 .group  = FIO_OPT_G_IO_BUF,
3098         },
3099         {
3100                 .name   = "clat_percentiles",
3101                 .lname  = "Completion latency percentiles",
3102                 .type   = FIO_OPT_BOOL,
3103                 .off1   = td_var_offset(clat_percentiles),
3104                 .help   = "Enable the reporting of completion latency percentiles",
3105                 .def    = "1",
3106                 .category = FIO_OPT_C_STAT,
3107                 .group  = FIO_OPT_G_INVALID,
3108         },
3109         {
3110                 .name   = "percentile_list",
3111                 .lname  = "Completion latency percentile list",
3112                 .type   = FIO_OPT_FLOAT_LIST,
3113                 .off1   = td_var_offset(percentile_list),
3114                 .off2   = td_var_offset(percentile_precision),
3115                 .help   = "Specify a custom list of percentiles to report",
3116                 .def    = "1:5:10:20:30:40:50:60:70:80:90:95:99:99.5:99.9:99.95:99.99",
3117                 .maxlen = FIO_IO_U_LIST_MAX_LEN,
3118                 .minfp  = 0.0,
3119                 .maxfp  = 100.0,
3120                 .category = FIO_OPT_C_STAT,
3121                 .group  = FIO_OPT_G_INVALID,
3122         },
3123
3124 #ifdef FIO_HAVE_DISK_UTIL
3125         {
3126                 .name   = "disk_util",
3127                 .lname  = "Disk utilization",
3128                 .type   = FIO_OPT_BOOL,
3129                 .off1   = td_var_offset(do_disk_util),
3130                 .help   = "Log disk utilization statistics",
3131                 .def    = "1",
3132                 .category = FIO_OPT_C_STAT,
3133                 .group  = FIO_OPT_G_INVALID,
3134         },
3135 #endif
3136         {
3137                 .name   = "gtod_reduce",
3138                 .lname  = "Reduce gettimeofday() calls",
3139                 .type   = FIO_OPT_BOOL,
3140                 .help   = "Greatly reduce number of gettimeofday() calls",
3141                 .cb     = str_gtod_reduce_cb,
3142                 .def    = "0",
3143                 .hide_on_set = 1,
3144                 .category = FIO_OPT_C_STAT,
3145                 .group  = FIO_OPT_G_INVALID,
3146         },
3147         {
3148                 .name   = "disable_lat",
3149                 .lname  = "Disable all latency stats",
3150                 .type   = FIO_OPT_BOOL,
3151                 .off1   = td_var_offset(disable_lat),
3152                 .help   = "Disable latency numbers",
3153                 .parent = "gtod_reduce",
3154                 .hide   = 1,
3155                 .def    = "0",
3156                 .category = FIO_OPT_C_STAT,
3157                 .group  = FIO_OPT_G_INVALID,
3158         },
3159         {
3160                 .name   = "disable_clat",
3161                 .lname  = "Disable completion latency stats",
3162                 .type   = FIO_OPT_BOOL,
3163                 .off1   = td_var_offset(disable_clat),
3164                 .help   = "Disable completion latency numbers",
3165                 .parent = "gtod_reduce",
3166                 .hide   = 1,
3167                 .def    = "0",
3168                 .category = FIO_OPT_C_STAT,
3169                 .group  = FIO_OPT_G_INVALID,
3170         },
3171         {
3172                 .name   = "disable_slat",
3173                 .lname  = "Disable submission latency stats",
3174                 .type   = FIO_OPT_BOOL,
3175                 .off1   = td_var_offset(disable_slat),
3176                 .help   = "Disable submission latency numbers",
3177                 .parent = "gtod_reduce",
3178                 .hide   = 1,
3179                 .def    = "0",
3180                 .category = FIO_OPT_C_STAT,
3181                 .group  = FIO_OPT_G_INVALID,
3182         },
3183         {
3184                 .name   = "disable_bw_measurement",
3185                 .lname  = "Disable bandwidth stats",
3186                 .type   = FIO_OPT_BOOL,
3187                 .off1   = td_var_offset(disable_bw),
3188                 .help   = "Disable bandwidth logging",
3189                 .parent = "gtod_reduce",
3190                 .hide   = 1,
3191                 .def    = "0",
3192                 .category = FIO_OPT_C_STAT,
3193                 .group  = FIO_OPT_G_INVALID,
3194         },
3195         {
3196                 .name   = "gtod_cpu",
3197                 .lname  = "Dedicated gettimeofday() CPU",
3198                 .type   = FIO_OPT_INT,
3199                 .cb     = str_gtod_cpu_cb,
3200                 .help   = "Set up dedicated gettimeofday() thread on this CPU",
3201                 .verify = gtod_cpu_verify,
3202                 .category = FIO_OPT_C_GENERAL,
3203                 .group  = FIO_OPT_G_CLOCK,
3204         },
3205         {
3206                 .name   = "unified_rw_reporting",
3207                 .type   = FIO_OPT_BOOL,
3208                 .off1   = td_var_offset(unified_rw_rep),
3209                 .help   = "Unify reporting across data direction",
3210                 .def    = "0",
3211                 .category = FIO_OPT_C_GENERAL,
3212                 .group  = FIO_OPT_G_INVALID,
3213         },
3214         {
3215                 .name   = "continue_on_error",
3216                 .lname  = "Continue on error",
3217                 .type   = FIO_OPT_STR,
3218                 .off1   = td_var_offset(continue_on_error),
3219                 .help   = "Continue on non-fatal errors during IO",
3220                 .def    = "none",
3221                 .category = FIO_OPT_C_GENERAL,
3222                 .group  = FIO_OPT_G_ERR,
3223                 .posval = {
3224                           { .ival = "none",
3225                             .oval = ERROR_TYPE_NONE,
3226                             .help = "Exit when an error is encountered",
3227                           },
3228                           { .ival = "read",
3229                             .oval = ERROR_TYPE_READ,
3230                             .help = "Continue on read errors only",
3231                           },
3232                           { .ival = "write",
3233                             .oval = ERROR_TYPE_WRITE,
3234                             .help = "Continue on write errors only",
3235                           },
3236                           { .ival = "io",
3237                             .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
3238                             .help = "Continue on any IO errors",
3239                           },
3240                           { .ival = "verify",
3241                             .oval = ERROR_TYPE_VERIFY,
3242                             .help = "Continue on verify errors only",
3243                           },
3244                           { .ival = "all",
3245                             .oval = ERROR_TYPE_ANY,
3246                             .help = "Continue on all io and verify errors",
3247                           },
3248                           { .ival = "0",
3249                             .oval = ERROR_TYPE_NONE,
3250                             .help = "Alias for 'none'",
3251                           },
3252                           { .ival = "1",
3253                             .oval = ERROR_TYPE_ANY,
3254                             .help = "Alias for 'all'",
3255                           },
3256                 },
3257         },
3258         {
3259                 .name   = "ignore_error",
3260                 .type   = FIO_OPT_STR,
3261                 .cb     = str_ignore_error_cb,
3262                 .help   = "Set a specific list of errors to ignore",
3263                 .parent = "rw",
3264                 .category = FIO_OPT_C_GENERAL,
3265                 .group  = FIO_OPT_G_ERR,
3266         },
3267         {
3268                 .name   = "error_dump",
3269                 .type   = FIO_OPT_BOOL,
3270                 .off1   = td_var_offset(error_dump),
3271                 .def    = "0",
3272                 .help   = "Dump info on each error",
3273                 .category = FIO_OPT_C_GENERAL,
3274                 .group  = FIO_OPT_G_ERR,
3275         },
3276         {
3277                 .name   = "profile",
3278                 .lname  = "Profile",
3279                 .type   = FIO_OPT_STR_STORE,
3280                 .off1   = td_var_offset(profile),
3281                 .help   = "Select a specific builtin performance test",
3282                 .category = FIO_OPT_C_PROFILE,
3283                 .group  = FIO_OPT_G_INVALID,
3284         },
3285         {
3286                 .name   = "cgroup",
3287                 .lname  = "Cgroup",
3288                 .type   = FIO_OPT_STR_STORE,
3289                 .off1   = td_var_offset(cgroup),
3290                 .help   = "Add job to cgroup of this name",
3291                 .category = FIO_OPT_C_GENERAL,
3292                 .group  = FIO_OPT_G_CGROUP,
3293         },
3294         {
3295                 .name   = "cgroup_nodelete",
3296                 .lname  = "Cgroup no-delete",
3297                 .type   = FIO_OPT_BOOL,
3298                 .off1   = td_var_offset(cgroup_nodelete),
3299                 .help   = "Do not delete cgroups after job completion",
3300                 .def    = "0",
3301                 .parent = "cgroup",
3302                 .category = FIO_OPT_C_GENERAL,
3303                 .group  = FIO_OPT_G_CGROUP,
3304         },
3305         {
3306                 .name   = "cgroup_weight",
3307                 .lname  = "Cgroup weight",
3308                 .type   = FIO_OPT_INT,
3309                 .off1   = td_var_offset(cgroup_weight),
3310                 .help   = "Use given weight for cgroup",
3311                 .minval = 100,
3312                 .maxval = 1000,
3313                 .parent = "cgroup",
3314                 .category = FIO_OPT_C_GENERAL,
3315                 .group  = FIO_OPT_G_CGROUP,
3316         },
3317         {
3318                 .name   = "uid",
3319                 .lname  = "User ID",
3320                 .type   = FIO_OPT_INT,
3321                 .off1   = td_var_offset(uid),
3322                 .help   = "Run job with this user ID",
3323                 .category = FIO_OPT_C_GENERAL,
3324                 .group  = FIO_OPT_G_CRED,
3325         },
3326         {
3327                 .name   = "gid",
3328                 .lname  = "Group ID",
3329                 .type   = FIO_OPT_INT,
3330                 .off1   = td_var_offset(gid),
3331                 .help   = "Run job with this group ID",
3332                 .category = FIO_OPT_C_GENERAL,
3333                 .group  = FIO_OPT_G_CRED,
3334         },
3335         {
3336                 .name   = "kb_base",
3337                 .lname  = "KB Base",
3338                 .type   = FIO_OPT_INT,
3339                 .off1   = td_var_offset(kb_base),
3340                 .prio   = 1,
3341                 .def    = "1024",
3342                 .posval = {
3343                           { .ival = "1024",
3344                             .oval = 1024,
3345                             .help = "Use 1024 as the K base",
3346                           },
3347                           { .ival = "1000",
3348                             .oval = 1000,
3349                             .help = "Use 1000 as the K base",
3350                           },
3351                 },
3352                 .help   = "How many bytes per KB for reporting (1000 or 1024)",
3353                 .category = FIO_OPT_C_GENERAL,
3354                 .group  = FIO_OPT_G_INVALID,
3355         },
3356         {
3357                 .name   = "unit_base",
3358                 .lname  = "Base unit for reporting (Bits or Bytes)",
3359                 .type   = FIO_OPT_INT,
3360                 .off1   = td_var_offset(unit_base),
3361                 .prio   = 1,
3362                 .posval = {
3363                           { .ival = "0",
3364                             .oval = 0,
3365                             .help = "Auto-detect",
3366                           },
3367                           { .ival = "8",
3368                             .oval = 8,
3369                             .help = "Normal (byte based)",
3370                           },
3371                           { .ival = "1",
3372                             .oval = 1,
3373                             .help = "Bit based",
3374                           },
3375                 },
3376                 .help   = "Bit multiple of result summary data (8 for byte, 1 for bit)",
3377                 .category = FIO_OPT_C_GENERAL,
3378                 .group  = FIO_OPT_G_INVALID,
3379         },
3380         {
3381                 .name   = "hugepage-size",
3382                 .lname  = "Hugepage size",
3383                 .type   = FIO_OPT_INT,
3384                 .off1   = td_var_offset(hugepage_size),
3385                 .help   = "When using hugepages, specify size of each page",
3386                 .def    = __fio_stringify(FIO_HUGE_PAGE),
3387                 .interval = 1024 * 1024,
3388                 .category = FIO_OPT_C_GENERAL,
3389                 .group  = FIO_OPT_G_INVALID,
3390         },
3391         {
3392                 .name   = "flow_id",
3393                 .lname  = "I/O flow ID",
3394                 .type   = FIO_OPT_INT,
3395                 .off1   = td_var_offset(flow_id),
3396                 .help   = "The flow index ID to use",
3397                 .def    = "0",
3398                 .category = FIO_OPT_C_IO,
3399                 .group  = FIO_OPT_G_IO_FLOW,
3400         },
3401         {
3402                 .name   = "flow",
3403                 .lname  = "I/O flow weight",
3404                 .type   = FIO_OPT_INT,
3405                 .off1   = td_var_offset(flow),
3406                 .help   = "Weight for flow control of this job",
3407                 .parent = "flow_id",
3408                 .hide   = 1,
3409                 .def    = "0",
3410                 .category = FIO_OPT_C_IO,
3411                 .group  = FIO_OPT_G_IO_FLOW,
3412         },
3413         {
3414                 .name   = "flow_watermark",
3415                 .lname  = "I/O flow watermark",
3416                 .type   = FIO_OPT_INT,
3417                 .off1   = td_var_offset(flow_watermark),
3418                 .help   = "High watermark for flow control. This option"
3419                         " should be set to the same value for all threads"
3420                         " with non-zero flow.",
3421                 .parent = "flow_id",
3422                 .hide   = 1,
3423                 .def    = "1024",
3424                 .category = FIO_OPT_C_IO,
3425                 .group  = FIO_OPT_G_IO_FLOW,
3426         },
3427         {
3428                 .name   = "flow_sleep",
3429                 .lname  = "I/O flow sleep",
3430                 .type   = FIO_OPT_INT,
3431                 .off1   = td_var_offset(flow_sleep),
3432                 .help   = "How many microseconds to sleep after being held"
3433                         " back by the flow control mechanism",
3434                 .parent = "flow_id",
3435                 .hide   = 1,
3436                 .def    = "0",
3437                 .category = FIO_OPT_C_IO,
3438                 .group  = FIO_OPT_G_IO_FLOW,
3439         },
3440         {
3441                 .name = NULL,
3442         },
3443 };
3444
3445 static void add_to_lopt(struct option *lopt, struct fio_option *o,
3446                         const char *name, int val)
3447 {
3448         lopt->name = (char *) name;
3449         lopt->val = val;
3450         if (o->type == FIO_OPT_STR_SET)
3451                 lopt->has_arg = optional_argument;
3452         else
3453                 lopt->has_arg = required_argument;
3454 }
3455
3456 static void options_to_lopts(struct fio_option *opts,
3457                               struct option *long_options,
3458                               int i, int option_type)
3459 {
3460         struct fio_option *o = &opts[0];
3461         while (o->name) {
3462                 add_to_lopt(&long_options[i], o, o->name, option_type);
3463                 if (o->alias) {
3464                         i++;
3465                         add_to_lopt(&long_options[i], o, o->alias, option_type);
3466                 }
3467
3468                 i++;
3469                 o++;
3470                 assert(i < FIO_NR_OPTIONS);
3471         }
3472 }
3473
3474 void fio_options_set_ioengine_opts(struct option *long_options,
3475                                    struct thread_data *td)
3476 {
3477         unsigned int i;
3478
3479         i = 0;
3480         while (long_options[i].name) {
3481                 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
3482                         memset(&long_options[i], 0, sizeof(*long_options));
3483                         break;
3484                 }
3485                 i++;
3486         }
3487
3488         /*
3489          * Just clear out the prior ioengine options.
3490          */
3491         if (!td || !td->eo)
3492                 return;
3493
3494         options_to_lopts(td->io_ops->options, long_options, i,
3495                          FIO_GETOPT_IOENGINE);
3496 }
3497
3498 void fio_options_dup_and_init(struct option *long_options)
3499 {
3500         unsigned int i;
3501
3502         options_init(fio_options);
3503
3504         i = 0;
3505         while (long_options[i].name)
3506                 i++;
3507
3508         options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
3509 }
3510
3511 struct fio_keyword {
3512         const char *word;
3513         const char *desc;
3514         char *replace;
3515 };
3516
3517 static struct fio_keyword fio_keywords[] = {
3518         {
3519                 .word   = "$pagesize",
3520                 .desc   = "Page size in the system",
3521         },
3522         {
3523                 .word   = "$mb_memory",
3524                 .desc   = "Megabytes of memory online",
3525         },
3526         {
3527                 .word   = "$ncpus",
3528                 .desc   = "Number of CPUs online in the system",
3529         },
3530         {
3531                 .word   = NULL,
3532         },
3533 };
3534
3535 void fio_keywords_init(void)
3536 {
3537         unsigned long long mb_memory;
3538         char buf[128];
3539         long l;
3540
3541         sprintf(buf, "%lu", (unsigned long) page_size);
3542         fio_keywords[0].replace = strdup(buf);
3543
3544         mb_memory = os_phys_mem() / (1024 * 1024);
3545         sprintf(buf, "%llu", mb_memory);
3546         fio_keywords[1].replace = strdup(buf);
3547
3548         l = cpus_online();
3549         sprintf(buf, "%lu", l);
3550         fio_keywords[2].replace = strdup(buf);
3551 }
3552
3553 #define BC_APP          "bc"
3554
3555 static char *bc_calc(char *str)
3556 {
3557         char buf[128], *tmp;
3558         FILE *f;
3559         int ret;
3560
3561         /*
3562          * No math, just return string
3563          */
3564         if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
3565              !strchr(str, '/')) || strchr(str, '\''))
3566                 return str;
3567
3568         /*
3569          * Split option from value, we only need to calculate the value
3570          */
3571         tmp = strchr(str, '=');
3572         if (!tmp)
3573                 return str;
3574
3575         tmp++;
3576
3577         /*
3578          * Prevent buffer overflows; such a case isn't reasonable anyway
3579          */
3580         if (strlen(str) >= 128 || strlen(tmp) > 100)
3581                 return str;
3582
3583         sprintf(buf, "which %s > /dev/null", BC_APP);
3584         if (system(buf)) {
3585                 log_err("fio: bc is needed for performing math\n");
3586                 return NULL;
3587         }
3588
3589         sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
3590         f = popen(buf, "r");
3591         if (!f)
3592                 return NULL;
3593
3594         ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
3595         if (ret <= 0)
3596                 return NULL;
3597
3598         pclose(f);
3599         buf[(tmp - str) + ret - 1] = '\0';
3600         memcpy(buf, str, tmp - str);
3601         free(str);
3602         return strdup(buf);
3603 }
3604
3605 /*
3606  * Return a copy of the input string with substrings of the form ${VARNAME}
3607  * substituted with the value of the environment variable VARNAME.  The
3608  * substitution always occurs, even if VARNAME is empty or the corresponding
3609  * environment variable undefined.
3610  */
3611 static char *option_dup_subs(const char *opt)
3612 {
3613         char out[OPT_LEN_MAX+1];
3614         char in[OPT_LEN_MAX+1];
3615         char *outptr = out;
3616         char *inptr = in;
3617         char *ch1, *ch2, *env;
3618         ssize_t nchr = OPT_LEN_MAX;
3619         size_t envlen;
3620
3621         if (strlen(opt) + 1 > OPT_LEN_MAX) {
3622                 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
3623                 return NULL;
3624         }
3625
3626         in[OPT_LEN_MAX] = '\0';
3627         strncpy(in, opt, OPT_LEN_MAX);
3628
3629         while (*inptr && nchr > 0) {
3630                 if (inptr[0] == '$' && inptr[1] == '{') {
3631                         ch2 = strchr(inptr, '}');
3632                         if (ch2 && inptr+1 < ch2) {
3633                                 ch1 = inptr+2;
3634                                 inptr = ch2+1;
3635                                 *ch2 = '\0';
3636
3637                                 env = getenv(ch1);
3638                                 if (env) {
3639                                         envlen = strlen(env);
3640                                         if (envlen <= nchr) {
3641                                                 memcpy(outptr, env, envlen);
3642                                                 outptr += envlen;
3643                                                 nchr -= envlen;
3644                                         }
3645                                 }
3646
3647                                 continue;
3648                         }
3649                 }
3650
3651                 *outptr++ = *inptr++;
3652                 --nchr;
3653         }
3654
3655         *outptr = '\0';
3656         return strdup(out);
3657 }
3658
3659 /*
3660  * Look for reserved variable names and replace them with real values
3661  */
3662 static char *fio_keyword_replace(char *opt)
3663 {
3664         char *s;
3665         int i;
3666         int docalc = 0;
3667
3668         for (i = 0; fio_keywords[i].word != NULL; i++) {
3669                 struct fio_keyword *kw = &fio_keywords[i];
3670
3671                 while ((s = strstr(opt, kw->word)) != NULL) {
3672                         char *new = malloc(strlen(opt) + 1);
3673                         char *o_org = opt;
3674                         int olen = s - opt;
3675                         int len;
3676
3677                         /*
3678                          * Copy part of the string before the keyword and
3679                          * sprintf() the replacement after it.
3680                          */
3681                         memcpy(new, opt, olen);
3682                         len = sprintf(new + olen, "%s", kw->replace);
3683
3684                         /*
3685                          * If there's more in the original string, copy that
3686                          * in too
3687                          */
3688                         opt += strlen(kw->word) + olen;
3689                         if (strlen(opt))
3690                                 memcpy(new + olen + len, opt, opt - o_org - 1);
3691
3692                         /*
3693                          * replace opt and free the old opt
3694                          */
3695                         opt = new;
3696                         free(o_org);
3697
3698                         docalc = 1;
3699                 }
3700         }
3701
3702         /*
3703          * Check for potential math and invoke bc, if possible
3704          */
3705         if (docalc)
3706                 opt = bc_calc(opt);
3707
3708         return opt;
3709 }
3710
3711 static char **dup_and_sub_options(char **opts, int num_opts)
3712 {
3713         int i;
3714         char **opts_copy = malloc(num_opts * sizeof(*opts));
3715         for (i = 0; i < num_opts; i++) {
3716                 opts_copy[i] = option_dup_subs(opts[i]);
3717                 if (!opts_copy[i])
3718                         continue;
3719                 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
3720         }
3721         return opts_copy;
3722 }
3723
3724 int fio_options_parse(struct thread_data *td, char **opts, int num_opts,
3725                         int dump_cmdline)
3726 {
3727         int i, ret, unknown;
3728         char **opts_copy;
3729
3730         sort_options(opts, fio_options, num_opts);
3731         opts_copy = dup_and_sub_options(opts, num_opts);
3732
3733         for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
3734                 struct fio_option *o;
3735                 int newret = parse_option(opts_copy[i], opts[i], fio_options,
3736                                                 &o, td, dump_cmdline);
3737
3738                 if (opts_copy[i]) {
3739                         if (newret && !o) {
3740                                 unknown++;
3741                                 continue;
3742                         }
3743                         free(opts_copy[i]);
3744                         opts_copy[i] = NULL;
3745                 }
3746
3747                 ret |= newret;
3748         }
3749
3750         if (unknown) {
3751                 ret |= ioengine_load(td);
3752                 if (td->eo) {
3753                         sort_options(opts_copy, td->io_ops->options, num_opts);
3754                         opts = opts_copy;
3755                 }
3756                 for (i = 0; i < num_opts; i++) {
3757                         struct fio_option *o = NULL;
3758                         int newret = 1;
3759                         if (!opts_copy[i])
3760                                 continue;
3761
3762                         if (td->eo)
3763                                 newret = parse_option(opts_copy[i], opts[i],
3764                                                       td->io_ops->options, &o,
3765                                                       td->eo, dump_cmdline);
3766
3767                         ret |= newret;
3768                         if (!o)
3769                                 log_err("Bad option <%s>\n", opts[i]);
3770
3771                         free(opts_copy[i]);
3772                         opts_copy[i] = NULL;
3773                 }
3774         }
3775
3776         free(opts_copy);
3777         return ret;
3778 }
3779
3780 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
3781 {
3782         return parse_cmd_option(opt, val, fio_options, td);
3783 }
3784
3785 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
3786                                 char *val)
3787 {
3788         return parse_cmd_option(opt, val, td->io_ops->options, td->eo);
3789 }
3790
3791 void fio_fill_default_options(struct thread_data *td)
3792 {
3793         fill_default_options(td, fio_options);
3794 }
3795
3796 int fio_show_option_help(const char *opt)
3797 {
3798         return show_cmd_help(fio_options, opt);
3799 }
3800
3801 void options_mem_dupe(void *data, struct fio_option *options)
3802 {
3803         struct fio_option *o;
3804         char **ptr;
3805
3806         for (o = &options[0]; o->name; o++) {
3807                 if (o->type != FIO_OPT_STR_STORE)
3808                         continue;
3809
3810                 ptr = td_var(data, o, o->off1);
3811                 if (*ptr)
3812                         *ptr = strdup(*ptr);
3813         }
3814 }
3815
3816 /*
3817  * dupe FIO_OPT_STR_STORE options
3818  */
3819 void fio_options_mem_dupe(struct thread_data *td)
3820 {
3821         options_mem_dupe(&td->o, fio_options);
3822
3823         if (td->eo && td->io_ops) {
3824                 void *oldeo = td->eo;
3825
3826                 td->eo = malloc(td->io_ops->option_struct_size);
3827                 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
3828                 options_mem_dupe(td->eo, td->io_ops->options);
3829         }
3830 }
3831
3832 unsigned int fio_get_kb_base(void *data)
3833 {
3834         struct thread_options *o = data;
3835         unsigned int kb_base = 0;
3836
3837         if (o)
3838                 kb_base = o->kb_base;
3839         if (!kb_base)
3840                 kb_base = 1024;
3841
3842         return kb_base;
3843 }
3844
3845 int add_option(struct fio_option *o)
3846 {
3847         struct fio_option *__o;
3848         int opt_index = 0;
3849
3850         __o = fio_options;
3851         while (__o->name) {
3852                 opt_index++;
3853                 __o++;
3854         }
3855
3856         if (opt_index + 1 == FIO_MAX_OPTS) {
3857                 log_err("fio: FIO_MAX_OPTS is too small\n");
3858                 return 1;
3859         }
3860
3861         memcpy(&fio_options[opt_index], o, sizeof(*o));
3862         fio_options[opt_index + 1].name = NULL;
3863         return 0;
3864 }
3865
3866 void invalidate_profile_options(const char *prof_name)
3867 {
3868         struct fio_option *o;
3869
3870         o = fio_options;
3871         while (o->name) {
3872                 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
3873                         o->type = FIO_OPT_INVALID;
3874                         o->prof_name = NULL;
3875                 }
3876                 o++;
3877         }
3878 }
3879
3880 void add_opt_posval(const char *optname, const char *ival, const char *help)
3881 {
3882         struct fio_option *o;
3883         unsigned int i;
3884
3885         o = find_option(fio_options, optname);
3886         if (!o)
3887                 return;
3888
3889         for (i = 0; i < PARSE_MAX_VP; i++) {
3890                 if (o->posval[i].ival)
3891                         continue;
3892
3893                 o->posval[i].ival = ival;
3894                 o->posval[i].help = help;
3895                 break;
3896         }
3897 }
3898
3899 void del_opt_posval(const char *optname, const char *ival)
3900 {
3901         struct fio_option *o;
3902         unsigned int i;
3903
3904         o = find_option(fio_options, optname);
3905         if (!o)
3906                 return;
3907
3908         for (i = 0; i < PARSE_MAX_VP; i++) {
3909                 if (!o->posval[i].ival)
3910                         continue;
3911                 if (strcmp(o->posval[i].ival, ival))
3912                         continue;
3913
3914                 o->posval[i].ival = NULL;
3915                 o->posval[i].help = NULL;
3916         }
3917 }
3918
3919 void fio_options_free(struct thread_data *td)
3920 {
3921         options_free(fio_options, td);
3922         if (td->eo && td->io_ops && td->io_ops->options) {
3923                 options_free(td->io_ops->options, td->eo);
3924                 free(td->eo);
3925                 td->eo = NULL;
3926         }
3927 }
3928
3929 struct fio_option *fio_option_find(const char *name)
3930 {
3931         return find_option(fio_options, name);
3932 }
3933