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