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