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