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