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