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