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