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