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