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 /*
940  * Option grouping
941  */
942 static struct opt_group fio_opt_groups[] = {
943         {
944                 .name   = "General",
945                 .mask   = FIO_OPT_C_GENERAL,
946         },
947         {
948                 .name   = "I/O",
949                 .mask   = FIO_OPT_C_IO,
950         },
951         {
952                 .name   = "File",
953                 .mask   = FIO_OPT_C_FILE,
954         },
955         {
956                 .name   = "Statistics",
957                 .mask   = FIO_OPT_C_STAT,
958         },
959         {
960                 .name   = "Logging",
961                 .mask   = FIO_OPT_C_LOG,
962         },
963         {
964                 .name   = "Profiles",
965                 .mask   = FIO_OPT_C_PROFILE,
966         },
967         {
968                 .name   = NULL,
969         },
970 };
971
972 static struct opt_group *__opt_group_from_mask(struct opt_group *ogs, unsigned int *mask,
973                                                unsigned int inv_mask)
974 {
975         struct opt_group *og;
976         int i;
977
978         if (*mask == inv_mask || !*mask)
979                 return NULL;
980
981         for (i = 0; ogs[i].name; i++) {
982                 og = &ogs[i];
983
984                 if (*mask & og->mask) {
985                         *mask &= ~(og->mask);
986                         return og;
987                 }
988         }
989
990         return NULL;
991 }
992
993 struct opt_group *opt_group_from_mask(unsigned int *mask)
994 {
995         return __opt_group_from_mask(fio_opt_groups, mask, FIO_OPT_C_INVALID);
996 }
997
998 static struct opt_group fio_opt_cat_groups[] = {
999         {
1000                 .name   = "Rate",
1001                 .mask   = FIO_OPT_G_RATE,
1002         },
1003         {
1004                 .name   = "Zone",
1005                 .mask   = FIO_OPT_G_ZONE,
1006         },
1007         {
1008                 .name   = "Read/write mix",
1009                 .mask   = FIO_OPT_G_RWMIX,
1010         },
1011         {
1012                 .name   = "Verify",
1013                 .mask   = FIO_OPT_G_VERIFY,
1014         },
1015         {
1016                 .name   = "Trim",
1017                 .mask   = FIO_OPT_G_TRIM,
1018         },
1019         {
1020                 .name   = "I/O Logging",
1021                 .mask   = FIO_OPT_G_IOLOG,
1022         },
1023         {
1024                 .name   = "I/O Depth",
1025                 .mask   = FIO_OPT_G_IO_DEPTH,
1026         },
1027         {
1028                 .name   = "I/O Flow",
1029                 .mask   = FIO_OPT_G_IO_FLOW,
1030         },
1031         {
1032                 .name   = "Description",
1033                 .mask   = FIO_OPT_G_DESC,
1034         },
1035         {
1036                 .name   = "Filename",
1037                 .mask   = FIO_OPT_G_FILENAME,
1038         },
1039         {
1040                 .name   = "General I/O",
1041                 .mask   = FIO_OPT_G_IO_BASIC,
1042         },
1043         {
1044                 .name   = "Cgroups",
1045                 .mask   = FIO_OPT_G_CGROUP,
1046         },
1047         {
1048                 .name   = "Runtime",
1049                 .mask   = FIO_OPT_G_RUNTIME,
1050         },
1051         {
1052                 .name   = "Process",
1053                 .mask   = FIO_OPT_G_PROCESS,
1054         },
1055         {
1056                 .name   = "Job credentials / priority",
1057                 .mask   = FIO_OPT_G_CRED,
1058         },
1059         {
1060                 .name   = "Clock settings",
1061                 .mask   = FIO_OPT_G_CLOCK,
1062         },
1063         {
1064                 .name   = "I/O Type",
1065                 .mask   = FIO_OPT_G_IO_TYPE,
1066         },
1067         {
1068                 .name   = "I/O Thinktime",
1069                 .mask   = FIO_OPT_G_THINKTIME,
1070         },
1071         {
1072                 .name   = "Randomizations",
1073                 .mask   = FIO_OPT_G_RANDOM,
1074         },
1075         {
1076                 .name   = "I/O buffers",
1077                 .mask   = FIO_OPT_G_IO_BUF,
1078         },
1079         {
1080                 .name   = "Tiobench profile",
1081                 .mask   = FIO_OPT_G_TIOBENCH,
1082         },
1083
1084         {
1085                 .name   = NULL,
1086         }
1087 };
1088
1089 struct opt_group *opt_group_cat_from_mask(unsigned int *mask)
1090 {
1091         return __opt_group_from_mask(fio_opt_cat_groups, mask, FIO_OPT_G_INVALID);
1092 }
1093
1094 /*
1095  * Map of job/command line options
1096  */
1097 struct fio_option fio_options[FIO_MAX_OPTS] = {
1098         {
1099                 .name   = "description",
1100                 .lname  = "Description of job",
1101                 .type   = FIO_OPT_STR_STORE,
1102                 .off1   = td_var_offset(description),
1103                 .help   = "Text job description",
1104                 .category = FIO_OPT_C_GENERAL,
1105                 .group  = FIO_OPT_G_DESC,
1106         },
1107         {
1108                 .name   = "name",
1109                 .lname  = "Job name",
1110                 .type   = FIO_OPT_STR_STORE,
1111                 .off1   = td_var_offset(name),
1112                 .help   = "Name of this job",
1113                 .category = FIO_OPT_C_GENERAL,
1114                 .group  = FIO_OPT_G_DESC,
1115         },
1116         {
1117                 .name   = "filename",
1118                 .lname  = "Filename(s)",
1119                 .type   = FIO_OPT_STR_STORE,
1120                 .off1   = td_var_offset(filename),
1121                 .cb     = str_filename_cb,
1122                 .prio   = -1, /* must come after "directory" */
1123                 .help   = "File(s) to use for the workload",
1124                 .category = FIO_OPT_C_FILE,
1125                 .group  = FIO_OPT_G_FILENAME,
1126         },
1127         {
1128                 .name   = "directory",
1129                 .lname  = "Directory",
1130                 .type   = FIO_OPT_STR_STORE,
1131                 .off1   = td_var_offset(directory),
1132                 .cb     = str_directory_cb,
1133                 .help   = "Directory to store files in",
1134                 .category = FIO_OPT_C_FILE,
1135                 .group  = FIO_OPT_G_FILENAME,
1136         },
1137         {
1138                 .name   = "filename_format",
1139                 .type   = FIO_OPT_STR_STORE,
1140                 .off1   = td_var_offset(filename_format),
1141                 .prio   = -1, /* must come after "directory" */
1142                 .help   = "Override default $jobname.$jobnum.$filenum naming",
1143                 .def    = "$jobname.$jobnum.$filenum",
1144         },
1145         {
1146                 .name   = "lockfile",
1147                 .lname  = "Lockfile",
1148                 .type   = FIO_OPT_STR,
1149                 .off1   = td_var_offset(file_lock_mode),
1150                 .help   = "Lock file when doing IO to it",
1151                 .parent = "filename",
1152                 .hide   = 0,
1153                 .def    = "none",
1154                 .category = FIO_OPT_C_FILE,
1155                 .group  = FIO_OPT_G_FILENAME,
1156                 .posval = {
1157                           { .ival = "none",
1158                             .oval = FILE_LOCK_NONE,
1159                             .help = "No file locking",
1160                           },
1161                           { .ival = "exclusive",
1162                             .oval = FILE_LOCK_EXCLUSIVE,
1163                             .help = "Exclusive file lock",
1164                           },
1165                           {
1166                             .ival = "readwrite",
1167                             .oval = FILE_LOCK_READWRITE,
1168                             .help = "Read vs write lock",
1169                           },
1170                 },
1171         },
1172         {
1173                 .name   = "opendir",
1174                 .lname  = "Open directory",
1175                 .type   = FIO_OPT_STR_STORE,
1176                 .off1   = td_var_offset(opendir),
1177                 .cb     = str_opendir_cb,
1178                 .help   = "Recursively add files from this directory and down",
1179                 .category = FIO_OPT_C_FILE,
1180                 .group  = FIO_OPT_G_FILENAME,
1181         },
1182         {
1183                 .name   = "rw",
1184                 .lname  = "Read/write",
1185                 .alias  = "readwrite",
1186                 .type   = FIO_OPT_STR,
1187                 .cb     = str_rw_cb,
1188                 .off1   = td_var_offset(td_ddir),
1189                 .help   = "IO direction",
1190                 .def    = "read",
1191                 .verify = rw_verify,
1192                 .category = FIO_OPT_C_IO,
1193                 .group  = FIO_OPT_G_IO_BASIC,
1194                 .posval = {
1195                           { .ival = "read",
1196                             .oval = TD_DDIR_READ,
1197                             .help = "Sequential read",
1198                           },
1199                           { .ival = "write",
1200                             .oval = TD_DDIR_WRITE,
1201                             .help = "Sequential write",
1202                           },
1203                           { .ival = "trim",
1204                             .oval = TD_DDIR_TRIM,
1205                             .help = "Sequential trim",
1206                           },
1207                           { .ival = "randread",
1208                             .oval = TD_DDIR_RANDREAD,
1209                             .help = "Random read",
1210                           },
1211                           { .ival = "randwrite",
1212                             .oval = TD_DDIR_RANDWRITE,
1213                             .help = "Random write",
1214                           },
1215                           { .ival = "randtrim",
1216                             .oval = TD_DDIR_RANDTRIM,
1217                             .help = "Random trim",
1218                           },
1219                           { .ival = "rw",
1220                             .oval = TD_DDIR_RW,
1221                             .help = "Sequential read and write mix",
1222                           },
1223                           { .ival = "readwrite",
1224                             .oval = TD_DDIR_RW,
1225                             .help = "Sequential read and write mix",
1226                           },
1227                           { .ival = "randrw",
1228                             .oval = TD_DDIR_RANDRW,
1229                             .help = "Random read and write mix"
1230                           },
1231                 },
1232         },
1233         {
1234                 .name   = "rw_sequencer",
1235                 .lname  = "RW Sequencer",
1236                 .type   = FIO_OPT_STR,
1237                 .off1   = td_var_offset(rw_seq),
1238                 .help   = "IO offset generator modifier",
1239                 .def    = "sequential",
1240                 .category = FIO_OPT_C_IO,
1241                 .group  = FIO_OPT_G_IO_BASIC,
1242                 .posval = {
1243                           { .ival = "sequential",
1244                             .oval = RW_SEQ_SEQ,
1245                             .help = "Generate sequential offsets",
1246                           },
1247                           { .ival = "identical",
1248                             .oval = RW_SEQ_IDENT,
1249                             .help = "Generate identical offsets",
1250                           },
1251                 },
1252         },
1253
1254         {
1255                 .name   = "ioengine",
1256                 .lname  = "IO Engine",
1257                 .type   = FIO_OPT_STR_STORE,
1258                 .off1   = td_var_offset(ioengine),
1259                 .help   = "IO engine to use",
1260                 .def    = FIO_PREFERRED_ENGINE,
1261                 .category = FIO_OPT_C_IO,
1262                 .group  = FIO_OPT_G_IO_BASIC,
1263                 .posval = {
1264                           { .ival = "sync",
1265                             .help = "Use read/write",
1266                           },
1267                           { .ival = "psync",
1268                             .help = "Use pread/pwrite",
1269                           },
1270                           { .ival = "vsync",
1271                             .help = "Use readv/writev",
1272                           },
1273 #ifdef CONFIG_LIBAIO
1274                           { .ival = "libaio",
1275                             .help = "Linux native asynchronous IO",
1276                           },
1277 #endif
1278 #ifdef CONFIG_POSIXAIO
1279                           { .ival = "posixaio",
1280                             .help = "POSIX asynchronous IO",
1281                           },
1282 #endif
1283 #ifdef CONFIG_SOLARISAIO
1284                           { .ival = "solarisaio",
1285                             .help = "Solaris native asynchronous IO",
1286                           },
1287 #endif
1288 #ifdef CONFIG_WINDOWSAIO
1289                           { .ival = "windowsaio",
1290                             .help = "Windows native asynchronous IO"
1291                           },
1292 #endif
1293                           { .ival = "mmap",
1294                             .help = "Memory mapped IO"
1295                           },
1296 #ifdef CONFIG_LINUX_SPLICE
1297                           { .ival = "splice",
1298                             .help = "splice/vmsplice based IO",
1299                           },
1300                           { .ival = "netsplice",
1301                             .help = "splice/vmsplice to/from the network",
1302                           },
1303 #endif
1304 #ifdef FIO_HAVE_SGIO
1305                           { .ival = "sg",
1306                             .help = "SCSI generic v3 IO",
1307                           },
1308 #endif
1309                           { .ival = "null",
1310                             .help = "Testing engine (no data transfer)",
1311                           },
1312                           { .ival = "net",
1313                             .help = "Network IO",
1314                           },
1315                           { .ival = "cpuio",
1316                             .help = "CPU cycle burner engine",
1317                           },
1318 #ifdef CONFIG_GUASI
1319                           { .ival = "guasi",
1320                             .help = "GUASI IO engine",
1321                           },
1322 #endif
1323 #ifdef FIO_HAVE_BINJECT
1324                           { .ival = "binject",
1325                             .help = "binject direct inject block engine",
1326                           },
1327 #endif
1328 #ifdef CONFIG_RDMA
1329                           { .ival = "rdma",
1330                             .help = "RDMA IO engine",
1331                           },
1332 #endif
1333 #ifdef CONFIG_FUSION_AW
1334                           { .ival = "fusion-aw-sync",
1335                             .help = "Fusion-io atomic write engine",
1336                           },
1337 #endif
1338 #ifdef CONFIG_LINUX_EXT4_MOVE_EXTENT
1339                           { .ival = "e4defrag",
1340                             .help = "ext4 defrag engine",
1341                           },
1342 #endif
1343 #ifdef CONFIG_LINUX_FALLOCATE
1344                           { .ival = "falloc",
1345                             .help = "fallocate() file based engine",
1346                           },
1347 #endif
1348                           { .ival = "external",
1349                             .help = "Load external engine (append name)",
1350                           },
1351                 },
1352         },
1353         {
1354                 .name   = "iodepth",
1355                 .lname  = "IO Depth",
1356                 .type   = FIO_OPT_INT,
1357                 .off1   = td_var_offset(iodepth),
1358                 .help   = "Number of IO buffers to keep in flight",
1359                 .minval = 1,
1360                 .interval = 1,
1361                 .def    = "1",
1362                 .category = FIO_OPT_C_IO,
1363                 .group  = FIO_OPT_G_IO_BASIC,
1364         },
1365         {
1366                 .name   = "iodepth_batch",
1367                 .lname  = "IO Depth batch",
1368                 .alias  = "iodepth_batch_submit",
1369                 .type   = FIO_OPT_INT,
1370                 .off1   = td_var_offset(iodepth_batch),
1371                 .help   = "Number of IO buffers to submit in one go",
1372                 .parent = "iodepth",
1373                 .hide   = 1,
1374                 .minval = 1,
1375                 .interval = 1,
1376                 .def    = "1",
1377                 .category = FIO_OPT_C_IO,
1378                 .group  = FIO_OPT_G_IO_BASIC,
1379         },
1380         {
1381                 .name   = "iodepth_batch_complete",
1382                 .lname  = "IO Depth batch complete",
1383                 .type   = FIO_OPT_INT,
1384                 .off1   = td_var_offset(iodepth_batch_complete),
1385                 .help   = "Number of IO buffers to retrieve in one go",
1386                 .parent = "iodepth",
1387                 .hide   = 1,
1388                 .minval = 0,
1389                 .interval = 1,
1390                 .def    = "1",
1391                 .category = FIO_OPT_C_IO,
1392                 .group  = FIO_OPT_G_IO_BASIC,
1393         },
1394         {
1395                 .name   = "iodepth_low",
1396                 .lname  = "IO Depth batch low",
1397                 .type   = FIO_OPT_INT,
1398                 .off1   = td_var_offset(iodepth_low),
1399                 .help   = "Low water mark for queuing depth",
1400                 .parent = "iodepth",
1401                 .hide   = 1,
1402                 .interval = 1,
1403                 .category = FIO_OPT_C_IO,
1404                 .group  = FIO_OPT_G_IO_BASIC,
1405         },
1406         {
1407                 .name   = "size",
1408                 .lname  = "Size",
1409                 .type   = FIO_OPT_STR_VAL,
1410                 .cb     = str_size_cb,
1411                 .help   = "Total size of device or files",
1412                 .interval = 1024 * 1024,
1413                 .category = FIO_OPT_C_IO,
1414                 .group  = FIO_OPT_G_INVALID,
1415         },
1416         {
1417                 .name   = "fill_device",
1418                 .lname  = "Fill device",
1419                 .alias  = "fill_fs",
1420                 .type   = FIO_OPT_BOOL,
1421                 .off1   = td_var_offset(fill_device),
1422                 .help   = "Write until an ENOSPC error occurs",
1423                 .def    = "0",
1424                 .category = FIO_OPT_C_FILE,
1425                 .group  = FIO_OPT_G_INVALID,
1426         },
1427         {
1428                 .name   = "filesize",
1429                 .lname  = "File size",
1430                 .type   = FIO_OPT_STR_VAL,
1431                 .off1   = td_var_offset(file_size_low),
1432                 .off2   = td_var_offset(file_size_high),
1433                 .minval = 1,
1434                 .help   = "Size of individual files",
1435                 .interval = 1024 * 1024,
1436                 .category = FIO_OPT_C_FILE,
1437                 .group  = FIO_OPT_G_INVALID,
1438         },
1439         {
1440                 .name   = "offset",
1441                 .lname  = "IO offset",
1442                 .alias  = "fileoffset",
1443                 .type   = FIO_OPT_STR_VAL,
1444                 .off1   = td_var_offset(start_offset),
1445                 .help   = "Start IO from this offset",
1446                 .def    = "0",
1447                 .interval = 1024 * 1024,
1448                 .category = FIO_OPT_C_IO,
1449                 .group  = FIO_OPT_G_INVALID,
1450         },
1451         {
1452                 .name   = "offset_increment",
1453                 .lname  = "IO offset increment",
1454                 .type   = FIO_OPT_STR_VAL,
1455                 .off1   = td_var_offset(offset_increment),
1456                 .help   = "What is the increment from one offset to the next",
1457                 .parent = "offset",
1458                 .hide   = 1,
1459                 .def    = "0",
1460                 .interval = 1024 * 1024,
1461                 .category = FIO_OPT_C_IO,
1462                 .group  = FIO_OPT_G_INVALID,
1463         },
1464         {
1465                 .name   = "bs",
1466                 .lname  = "Block size",
1467                 .alias  = "blocksize",
1468                 .type   = FIO_OPT_INT,
1469                 .off1   = td_var_offset(bs[DDIR_READ]),
1470                 .off2   = td_var_offset(bs[DDIR_WRITE]),
1471                 .off3   = td_var_offset(bs[DDIR_TRIM]),
1472                 .minval = 1,
1473                 .help   = "Block size unit",
1474                 .def    = "4k",
1475                 .parent = "rw",
1476                 .hide   = 1,
1477                 .interval = 512,
1478                 .category = FIO_OPT_C_IO,
1479                 .group  = FIO_OPT_G_INVALID,
1480         },
1481         {
1482                 .name   = "ba",
1483                 .lname  = "Block size align",
1484                 .alias  = "blockalign",
1485                 .type   = FIO_OPT_INT,
1486                 .off1   = td_var_offset(ba[DDIR_READ]),
1487                 .off2   = td_var_offset(ba[DDIR_WRITE]),
1488                 .off3   = td_var_offset(ba[DDIR_TRIM]),
1489                 .minval = 1,
1490                 .help   = "IO block offset alignment",
1491                 .parent = "rw",
1492                 .hide   = 1,
1493                 .interval = 512,
1494                 .category = FIO_OPT_C_IO,
1495                 .group  = FIO_OPT_G_INVALID,
1496         },
1497         {
1498                 .name   = "bsrange",
1499                 .lname  = "Block size range",
1500                 .alias  = "blocksize_range",
1501                 .type   = FIO_OPT_RANGE,
1502                 .off1   = td_var_offset(min_bs[DDIR_READ]),
1503                 .off2   = td_var_offset(max_bs[DDIR_READ]),
1504                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
1505                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
1506                 .off5   = td_var_offset(min_bs[DDIR_TRIM]),
1507                 .off6   = td_var_offset(max_bs[DDIR_TRIM]),
1508                 .minval = 1,
1509                 .help   = "Set block size range (in more detail than bs)",
1510                 .parent = "rw",
1511                 .hide   = 1,
1512                 .interval = 4096,
1513                 .category = FIO_OPT_C_IO,
1514                 .group  = FIO_OPT_G_INVALID,
1515         },
1516         {
1517                 .name   = "bssplit",
1518                 .lname  = "Block size split",
1519                 .type   = FIO_OPT_STR,
1520                 .cb     = str_bssplit_cb,
1521                 .help   = "Set a specific mix of block sizes",
1522                 .parent = "rw",
1523                 .hide   = 1,
1524                 .category = FIO_OPT_C_IO,
1525                 .group  = FIO_OPT_G_INVALID,
1526         },
1527         {
1528                 .name   = "bs_unaligned",
1529                 .lname  = "Block size unaligned",
1530                 .alias  = "blocksize_unaligned",
1531                 .type   = FIO_OPT_STR_SET,
1532                 .off1   = td_var_offset(bs_unaligned),
1533                 .help   = "Don't sector align IO buffer sizes",
1534                 .parent = "rw",
1535                 .hide   = 1,
1536                 .category = FIO_OPT_C_IO,
1537                 .group  = FIO_OPT_G_INVALID,
1538         },
1539         {
1540                 .name   = "randrepeat",
1541                 .lname  = "Random repeatable",
1542                 .type   = FIO_OPT_BOOL,
1543                 .off1   = td_var_offset(rand_repeatable),
1544                 .help   = "Use repeatable random IO pattern",
1545                 .def    = "1",
1546                 .parent = "rw",
1547                 .hide   = 1,
1548                 .category = FIO_OPT_C_IO,
1549                 .group  = FIO_OPT_G_RANDOM,
1550         },
1551         {
1552                 .name   = "use_os_rand",
1553                 .lname  = "Use OS random",
1554                 .type   = FIO_OPT_BOOL,
1555                 .off1   = td_var_offset(use_os_rand),
1556                 .help   = "Set to use OS random generator",
1557                 .def    = "0",
1558                 .parent = "rw",
1559                 .hide   = 1,
1560                 .category = FIO_OPT_C_IO,
1561                 .group  = FIO_OPT_G_RANDOM,
1562         },
1563         {
1564                 .name   = "norandommap",
1565                 .lname  = "No randommap",
1566                 .type   = FIO_OPT_STR_SET,
1567                 .off1   = td_var_offset(norandommap),
1568                 .help   = "Accept potential duplicate random blocks",
1569                 .parent = "rw",
1570                 .hide   = 1,
1571                 .hide_on_set = 1,
1572                 .category = FIO_OPT_C_IO,
1573                 .group  = FIO_OPT_G_RANDOM,
1574         },
1575         {
1576                 .name   = "softrandommap",
1577                 .lname  = "Soft randommap",
1578                 .type   = FIO_OPT_BOOL,
1579                 .off1   = td_var_offset(softrandommap),
1580                 .help   = "Set norandommap if randommap allocation fails",
1581                 .parent = "norandommap",
1582                 .hide   = 1,
1583                 .def    = "0",
1584                 .category = FIO_OPT_C_IO,
1585                 .group  = FIO_OPT_G_RANDOM,
1586         },
1587         {
1588                 .name   = "random_generator",
1589                 .type   = FIO_OPT_STR,
1590                 .off1   = td_var_offset(random_generator),
1591                 .help   = "Type of random number generator to use",
1592                 .def    = "tausworthe",
1593                 .posval = {
1594                           { .ival = "tausworthe",
1595                             .oval = FIO_RAND_GEN_TAUSWORTHE,
1596                             .help = "Strong Tausworthe generator",
1597                           },
1598                           { .ival = "lfsr",
1599                             .oval = FIO_RAND_GEN_LFSR,
1600                             .help = "Variable length LFSR",
1601                           },
1602                 },
1603                 .category = FIO_OPT_C_IO,
1604                 .group  = FIO_OPT_G_RANDOM,
1605         },
1606         {
1607                 .name   = "random_distribution",
1608                 .type   = FIO_OPT_STR,
1609                 .off1   = td_var_offset(random_distribution),
1610                 .cb     = str_random_distribution_cb,
1611                 .help   = "Random offset distribution generator",
1612                 .def    = "random",
1613                 .posval = {
1614                           { .ival = "random",
1615                             .oval = FIO_RAND_DIST_RANDOM,
1616                             .help = "Completely random",
1617                           },
1618                           { .ival = "zipf",
1619                             .oval = FIO_RAND_DIST_ZIPF,
1620                             .help = "Zipf distribution",
1621                           },
1622                           { .ival = "pareto",
1623                             .oval = FIO_RAND_DIST_PARETO,
1624                             .help = "Pareto distribution",
1625                           },
1626                 },
1627                 .category = FIO_OPT_C_IO,
1628                 .group  = FIO_OPT_G_RANDOM,
1629         },
1630         {
1631                 .name   = "nrfiles",
1632                 .lname  = "Number of files",
1633                 .alias  = "nr_files",
1634                 .type   = FIO_OPT_INT,
1635                 .off1   = td_var_offset(nr_files),
1636                 .help   = "Split job workload between this number of files",
1637                 .def    = "1",
1638                 .interval = 1,
1639                 .category = FIO_OPT_C_FILE,
1640                 .group  = FIO_OPT_G_INVALID,
1641         },
1642         {
1643                 .name   = "openfiles",
1644                 .lname  = "Number of open files",
1645                 .type   = FIO_OPT_INT,
1646                 .off1   = td_var_offset(open_files),
1647                 .help   = "Number of files to keep open at the same time",
1648                 .category = FIO_OPT_C_FILE,
1649                 .group  = FIO_OPT_G_INVALID,
1650         },
1651         {
1652                 .name   = "file_service_type",
1653                 .lname  = "File service type",
1654                 .type   = FIO_OPT_STR,
1655                 .cb     = str_fst_cb,
1656                 .off1   = td_var_offset(file_service_type),
1657                 .help   = "How to select which file to service next",
1658                 .def    = "roundrobin",
1659                 .category = FIO_OPT_C_FILE,
1660                 .group  = FIO_OPT_G_INVALID,
1661                 .posval = {
1662                           { .ival = "random",
1663                             .oval = FIO_FSERVICE_RANDOM,
1664                             .help = "Choose a file at random",
1665                           },
1666                           { .ival = "roundrobin",
1667                             .oval = FIO_FSERVICE_RR,
1668                             .help = "Round robin select files",
1669                           },
1670                           { .ival = "sequential",
1671                             .oval = FIO_FSERVICE_SEQ,
1672                             .help = "Finish one file before moving to the next",
1673                           },
1674                 },
1675                 .parent = "nrfiles",
1676                 .hide   = 1,
1677         },
1678 #ifdef CONFIG_POSIX_FALLOCATE
1679         {
1680                 .name   = "fallocate",
1681                 .lname  = "Fallocate",
1682                 .type   = FIO_OPT_STR,
1683                 .off1   = td_var_offset(fallocate_mode),
1684                 .help   = "Whether pre-allocation is performed when laying out files",
1685                 .def    = "posix",
1686                 .category = FIO_OPT_C_FILE,
1687                 .group  = FIO_OPT_G_INVALID,
1688                 .posval = {
1689                           { .ival = "none",
1690                             .oval = FIO_FALLOCATE_NONE,
1691                             .help = "Do not pre-allocate space",
1692                           },
1693                           { .ival = "posix",
1694                             .oval = FIO_FALLOCATE_POSIX,
1695                             .help = "Use posix_fallocate()",
1696                           },
1697 #ifdef CONFIG_LINUX_FALLOCATE
1698                           { .ival = "keep",
1699                             .oval = FIO_FALLOCATE_KEEP_SIZE,
1700                             .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1701                           },
1702 #endif
1703                           /* Compatibility with former boolean values */
1704                           { .ival = "0",
1705                             .oval = FIO_FALLOCATE_NONE,
1706                             .help = "Alias for 'none'",
1707                           },
1708                           { .ival = "1",
1709                             .oval = FIO_FALLOCATE_POSIX,
1710                             .help = "Alias for 'posix'",
1711                           },
1712                 },
1713         },
1714 #endif  /* CONFIG_POSIX_FALLOCATE */
1715         {
1716                 .name   = "fadvise_hint",
1717                 .lname  = "Fadvise hint",
1718                 .type   = FIO_OPT_BOOL,
1719                 .off1   = td_var_offset(fadvise_hint),
1720                 .help   = "Use fadvise() to advise the kernel on IO pattern",
1721                 .def    = "1",
1722                 .category = FIO_OPT_C_FILE,
1723                 .group  = FIO_OPT_G_INVALID,
1724         },
1725         {
1726                 .name   = "fsync",
1727                 .lname  = "Fsync",
1728                 .type   = FIO_OPT_INT,
1729                 .off1   = td_var_offset(fsync_blocks),
1730                 .help   = "Issue fsync for writes every given number of blocks",
1731                 .def    = "0",
1732                 .interval = 1,
1733                 .category = FIO_OPT_C_FILE,
1734                 .group  = FIO_OPT_G_INVALID,
1735         },
1736         {
1737                 .name   = "fdatasync",
1738                 .lname  = "Fdatasync",
1739                 .type   = FIO_OPT_INT,
1740                 .off1   = td_var_offset(fdatasync_blocks),
1741                 .help   = "Issue fdatasync for writes every given number of blocks",
1742                 .def    = "0",
1743                 .interval = 1,
1744                 .category = FIO_OPT_C_FILE,
1745                 .group  = FIO_OPT_G_INVALID,
1746         },
1747         {
1748                 .name   = "write_barrier",
1749                 .lname  = "Write barrier",
1750                 .type   = FIO_OPT_INT,
1751                 .off1   = td_var_offset(barrier_blocks),
1752                 .help   = "Make every Nth write a barrier write",
1753                 .def    = "0",
1754                 .interval = 1,
1755                 .category = FIO_OPT_C_IO,
1756                 .group  = FIO_OPT_G_INVALID,
1757         },
1758 #ifdef CONFIG_SYNC_FILE_RANGE
1759         {
1760                 .name   = "sync_file_range",
1761                 .lname  = "Sync file range",
1762                 .posval = {
1763                           { .ival = "wait_before",
1764                             .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1765                             .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1766                             .or   = 1,
1767                           },
1768                           { .ival = "write",
1769                             .oval = SYNC_FILE_RANGE_WRITE,
1770                             .help = "SYNC_FILE_RANGE_WRITE",
1771                             .or   = 1,
1772                           },
1773                           {
1774                             .ival = "wait_after",
1775                             .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1776                             .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1777                             .or   = 1,
1778                           },
1779                 },
1780                 .type   = FIO_OPT_STR_MULTI,
1781                 .cb     = str_sfr_cb,
1782                 .off1   = td_var_offset(sync_file_range),
1783                 .help   = "Use sync_file_range()",
1784                 .category = FIO_OPT_C_FILE,
1785                 .group  = FIO_OPT_G_INVALID,
1786         },
1787 #endif
1788         {
1789                 .name   = "direct",
1790                 .lname  = "Direct I/O",
1791                 .type   = FIO_OPT_BOOL,
1792                 .off1   = td_var_offset(odirect),
1793                 .help   = "Use O_DIRECT IO (negates buffered)",
1794                 .def    = "0",
1795                 .inverse = "buffered",
1796                 .category = FIO_OPT_C_IO,
1797                 .group  = FIO_OPT_G_IO_TYPE,
1798         },
1799         {
1800                 .name   = "buffered",
1801                 .lname  = "Buffered I/O",
1802                 .type   = FIO_OPT_BOOL,
1803                 .off1   = td_var_offset(odirect),
1804                 .neg    = 1,
1805                 .help   = "Use buffered IO (negates direct)",
1806                 .def    = "1",
1807                 .inverse = "direct",
1808                 .category = FIO_OPT_C_IO,
1809                 .group  = FIO_OPT_G_IO_TYPE,
1810         },
1811         {
1812                 .name   = "overwrite",
1813                 .lname  = "Overwrite",
1814                 .type   = FIO_OPT_BOOL,
1815                 .off1   = td_var_offset(overwrite),
1816                 .help   = "When writing, set whether to overwrite current data",
1817                 .def    = "0",
1818                 .category = FIO_OPT_C_FILE,
1819                 .group  = FIO_OPT_G_INVALID,
1820         },
1821         {
1822                 .name   = "loops",
1823                 .lname  = "Loops",
1824                 .type   = FIO_OPT_INT,
1825                 .off1   = td_var_offset(loops),
1826                 .help   = "Number of times to run the job",
1827                 .def    = "1",
1828                 .interval = 1,
1829                 .category = FIO_OPT_C_GENERAL,
1830                 .group  = FIO_OPT_G_RUNTIME,
1831         },
1832         {
1833                 .name   = "numjobs",
1834                 .lname  = "Number of jobs",
1835                 .type   = FIO_OPT_INT,
1836                 .off1   = td_var_offset(numjobs),
1837                 .help   = "Duplicate this job this many times",
1838                 .def    = "1",
1839                 .interval = 1,
1840                 .category = FIO_OPT_C_GENERAL,
1841                 .group  = FIO_OPT_G_RUNTIME,
1842         },
1843         {
1844                 .name   = "startdelay",
1845                 .lname  = "Start delay",
1846                 .type   = FIO_OPT_STR_VAL_TIME,
1847                 .off1   = td_var_offset(start_delay),
1848                 .help   = "Only start job when this period has passed",
1849                 .def    = "0",
1850                 .category = FIO_OPT_C_GENERAL,
1851                 .group  = FIO_OPT_G_RUNTIME,
1852         },
1853         {
1854                 .name   = "runtime",
1855                 .lname  = "Runtime",
1856                 .alias  = "timeout",
1857                 .type   = FIO_OPT_STR_VAL_TIME,
1858                 .off1   = td_var_offset(timeout),
1859                 .help   = "Stop workload when this amount of time has passed",
1860                 .def    = "0",
1861                 .category = FIO_OPT_C_GENERAL,
1862                 .group  = FIO_OPT_G_RUNTIME,
1863         },
1864         {
1865                 .name   = "time_based",
1866                 .lname  = "Time based",
1867                 .type   = FIO_OPT_STR_SET,
1868                 .off1   = td_var_offset(time_based),
1869                 .help   = "Keep running until runtime/timeout is met",
1870                 .category = FIO_OPT_C_GENERAL,
1871                 .group  = FIO_OPT_G_RUNTIME,
1872         },
1873         {
1874                 .name   = "ramp_time",
1875                 .lname  = "Ramp time",
1876                 .type   = FIO_OPT_STR_VAL_TIME,
1877                 .off1   = td_var_offset(ramp_time),
1878                 .help   = "Ramp up time before measuring performance",
1879                 .category = FIO_OPT_C_GENERAL,
1880                 .group  = FIO_OPT_G_RUNTIME,
1881         },
1882         {
1883                 .name   = "clocksource",
1884                 .lname  = "Clock source",
1885                 .type   = FIO_OPT_STR,
1886                 .cb     = fio_clock_source_cb,
1887                 .off1   = td_var_offset(clocksource),
1888                 .help   = "What type of timing source to use",
1889                 .category = FIO_OPT_C_GENERAL,
1890                 .group  = FIO_OPT_G_CLOCK,
1891                 .posval = {
1892 #ifdef CONFIG_GETTIMEOFDAY
1893                           { .ival = "gettimeofday",
1894                             .oval = CS_GTOD,
1895                             .help = "Use gettimeofday(2) for timing",
1896                           },
1897 #endif
1898 #ifdef CONFIG_CLOCK_GETTIME
1899                           { .ival = "clock_gettime",
1900                             .oval = CS_CGETTIME,
1901                             .help = "Use clock_gettime(2) for timing",
1902                           },
1903 #endif
1904 #ifdef ARCH_HAVE_CPU_CLOCK
1905                           { .ival = "cpu",
1906                             .oval = CS_CPUCLOCK,
1907                             .help = "Use CPU private clock",
1908                           },
1909 #endif
1910                 },
1911         },
1912         {
1913                 .name   = "mem",
1914                 .alias  = "iomem",
1915                 .lname  = "I/O Memory",
1916                 .type   = FIO_OPT_STR,
1917                 .cb     = str_mem_cb,
1918                 .off1   = td_var_offset(mem_type),
1919                 .help   = "Backing type for IO buffers",
1920                 .def    = "malloc",
1921                 .category = FIO_OPT_C_IO,
1922                 .group  = FIO_OPT_G_INVALID,
1923                 .posval = {
1924                           { .ival = "malloc",
1925                             .oval = MEM_MALLOC,
1926                             .help = "Use malloc(3) for IO buffers",
1927                           },
1928                           { .ival = "shm",
1929                             .oval = MEM_SHM,
1930                             .help = "Use shared memory segments for IO buffers",
1931                           },
1932 #ifdef FIO_HAVE_HUGETLB
1933                           { .ival = "shmhuge",
1934                             .oval = MEM_SHMHUGE,
1935                             .help = "Like shm, but use huge pages",
1936                           },
1937 #endif
1938                           { .ival = "mmap",
1939                             .oval = MEM_MMAP,
1940                             .help = "Use mmap(2) (file or anon) for IO buffers",
1941                           },
1942 #ifdef FIO_HAVE_HUGETLB
1943                           { .ival = "mmaphuge",
1944                             .oval = MEM_MMAPHUGE,
1945                             .help = "Like mmap, but use huge pages",
1946                           },
1947 #endif
1948                   },
1949         },
1950         {
1951                 .name   = "iomem_align",
1952                 .alias  = "mem_align",
1953                 .lname  = "I/O memory alignment",
1954                 .type   = FIO_OPT_INT,
1955                 .off1   = td_var_offset(mem_align),
1956                 .minval = 0,
1957                 .help   = "IO memory buffer offset alignment",
1958                 .def    = "0",
1959                 .parent = "iomem",
1960                 .hide   = 1,
1961                 .category = FIO_OPT_C_IO,
1962                 .group  = FIO_OPT_G_INVALID,
1963         },
1964         {
1965                 .name   = "verify",
1966                 .lname  = "Verify",
1967                 .type   = FIO_OPT_STR,
1968                 .off1   = td_var_offset(verify),
1969                 .help   = "Verify data written",
1970                 .def    = "0",
1971                 .category = FIO_OPT_C_IO,
1972                 .group  = FIO_OPT_G_VERIFY,
1973                 .posval = {
1974                           { .ival = "0",
1975                             .oval = VERIFY_NONE,
1976                             .help = "Don't do IO verification",
1977                           },
1978                           { .ival = "md5",
1979                             .oval = VERIFY_MD5,
1980                             .help = "Use md5 checksums for verification",
1981                           },
1982                           { .ival = "crc64",
1983                             .oval = VERIFY_CRC64,
1984                             .help = "Use crc64 checksums for verification",
1985                           },
1986                           { .ival = "crc32",
1987                             .oval = VERIFY_CRC32,
1988                             .help = "Use crc32 checksums for verification",
1989                           },
1990                           { .ival = "crc32c-intel",
1991                             .oval = VERIFY_CRC32C,
1992                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
1993                           },
1994                           { .ival = "crc32c",
1995                             .oval = VERIFY_CRC32C,
1996                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
1997                           },
1998                           { .ival = "crc16",
1999                             .oval = VERIFY_CRC16,
2000                             .help = "Use crc16 checksums for verification",
2001                           },
2002                           { .ival = "crc7",
2003                             .oval = VERIFY_CRC7,
2004                             .help = "Use crc7 checksums for verification",
2005                           },
2006                           { .ival = "sha1",
2007                             .oval = VERIFY_SHA1,
2008                             .help = "Use sha1 checksums for verification",
2009                           },
2010                           { .ival = "sha256",
2011                             .oval = VERIFY_SHA256,
2012                             .help = "Use sha256 checksums for verification",
2013                           },
2014                           { .ival = "sha512",
2015                             .oval = VERIFY_SHA512,
2016                             .help = "Use sha512 checksums for verification",
2017                           },
2018                           { .ival = "meta",
2019                             .oval = VERIFY_META,
2020                             .help = "Use io information",
2021                           },
2022                           {
2023                             .ival = "null",
2024                             .oval = VERIFY_NULL,
2025                             .help = "Pretend to verify",
2026                           },
2027                 },
2028         },
2029         {
2030                 .name   = "do_verify",
2031                 .lname  = "Perform verify step",
2032                 .type   = FIO_OPT_BOOL,
2033                 .off1   = td_var_offset(do_verify),
2034                 .help   = "Run verification stage after write",
2035                 .def    = "1",
2036                 .parent = "verify",
2037                 .hide   = 1,
2038                 .category = FIO_OPT_C_IO,
2039                 .group  = FIO_OPT_G_VERIFY,
2040         },
2041         {
2042                 .name   = "verifysort",
2043                 .lname  = "Verify sort",
2044                 .type   = FIO_OPT_BOOL,
2045                 .off1   = td_var_offset(verifysort),
2046                 .help   = "Sort written verify blocks for read back",
2047                 .def    = "1",
2048                 .parent = "verify",
2049                 .hide   = 1,
2050                 .category = FIO_OPT_C_IO,
2051                 .group  = FIO_OPT_G_VERIFY,
2052         },
2053         {
2054                 .name   = "verifysort_nr",
2055                 .type   = FIO_OPT_INT,
2056                 .off1   = td_var_offset(verifysort_nr),
2057                 .help   = "Pre-load and sort verify blocks for a read workload",
2058                 .minval = 0,
2059                 .maxval = 131072,
2060                 .def    = "1024",
2061                 .parent = "verify",
2062                 .category = FIO_OPT_C_IO,
2063                 .group  = FIO_OPT_G_VERIFY,
2064         },
2065         {
2066                 .name   = "verify_interval",
2067                 .lname  = "Verify interval",
2068                 .type   = FIO_OPT_INT,
2069                 .off1   = td_var_offset(verify_interval),
2070                 .minval = 2 * sizeof(struct verify_header),
2071                 .help   = "Store verify buffer header every N bytes",
2072                 .parent = "verify",
2073                 .hide   = 1,
2074                 .interval = 2 * sizeof(struct verify_header),
2075                 .category = FIO_OPT_C_IO,
2076                 .group  = FIO_OPT_G_VERIFY,
2077         },
2078         {
2079                 .name   = "verify_offset",
2080                 .lname  = "Verify offset",
2081                 .type   = FIO_OPT_INT,
2082                 .help   = "Offset verify header location by N bytes",
2083                 .off1   = td_var_offset(verify_offset),
2084                 .minval = sizeof(struct verify_header),
2085                 .parent = "verify",
2086                 .hide   = 1,
2087                 .category = FIO_OPT_C_IO,
2088                 .group  = FIO_OPT_G_VERIFY,
2089         },
2090         {
2091                 .name   = "verify_pattern",
2092                 .lname  = "Verify pattern",
2093                 .type   = FIO_OPT_STR,
2094                 .cb     = str_verify_pattern_cb,
2095                 .help   = "Fill pattern for IO buffers",
2096                 .parent = "verify",
2097                 .hide   = 1,
2098                 .category = FIO_OPT_C_IO,
2099                 .group  = FIO_OPT_G_VERIFY,
2100         },
2101         {
2102                 .name   = "verify_fatal",
2103                 .lname  = "Verify fatal",
2104                 .type   = FIO_OPT_BOOL,
2105                 .off1   = td_var_offset(verify_fatal),
2106                 .def    = "0",
2107                 .help   = "Exit on a single verify failure, don't continue",
2108                 .parent = "verify",
2109                 .hide   = 1,
2110                 .category = FIO_OPT_C_IO,
2111                 .group  = FIO_OPT_G_VERIFY,
2112         },
2113         {
2114                 .name   = "verify_dump",
2115                 .lname  = "Verify dump",
2116                 .type   = FIO_OPT_BOOL,
2117                 .off1   = td_var_offset(verify_dump),
2118                 .def    = "0",
2119                 .help   = "Dump contents of good and bad blocks on failure",
2120                 .parent = "verify",
2121                 .hide   = 1,
2122                 .category = FIO_OPT_C_IO,
2123                 .group  = FIO_OPT_G_VERIFY,
2124         },
2125         {
2126                 .name   = "verify_async",
2127                 .lname  = "Verify asynchronously",
2128                 .type   = FIO_OPT_INT,
2129                 .off1   = td_var_offset(verify_async),
2130                 .def    = "0",
2131                 .help   = "Number of async verifier threads to use",
2132                 .parent = "verify",
2133                 .hide   = 1,
2134                 .category = FIO_OPT_C_IO,
2135                 .group  = FIO_OPT_G_VERIFY,
2136         },
2137         {
2138                 .name   = "verify_backlog",
2139                 .lname  = "Verify backlog",
2140                 .type   = FIO_OPT_STR_VAL,
2141                 .off1   = td_var_offset(verify_backlog),
2142                 .help   = "Verify after this number of blocks are written",
2143                 .parent = "verify",
2144                 .hide   = 1,
2145                 .category = FIO_OPT_C_IO,
2146                 .group  = FIO_OPT_G_VERIFY,
2147         },
2148         {
2149                 .name   = "verify_backlog_batch",
2150                 .lname  = "Verify backlog batch",
2151                 .type   = FIO_OPT_INT,
2152                 .off1   = td_var_offset(verify_batch),
2153                 .help   = "Verify this number of IO blocks",
2154                 .parent = "verify",
2155                 .hide   = 1,
2156                 .category = FIO_OPT_C_IO,
2157                 .group  = FIO_OPT_G_VERIFY,
2158         },
2159 #ifdef FIO_HAVE_CPU_AFFINITY
2160         {
2161                 .name   = "verify_async_cpus",
2162                 .lname  = "Async verify CPUs",
2163                 .type   = FIO_OPT_STR,
2164                 .cb     = str_verify_cpus_allowed_cb,
2165                 .help   = "Set CPUs allowed for async verify threads",
2166                 .parent = "verify_async",
2167                 .hide   = 1,
2168                 .category = FIO_OPT_C_IO,
2169                 .group  = FIO_OPT_G_VERIFY,
2170         },
2171 #endif
2172         {
2173                 .name   = "experimental_verify",
2174                 .off1   = td_var_offset(experimental_verify),
2175                 .type   = FIO_OPT_BOOL,
2176                 .help   = "Enable experimental verification",
2177                 .category = FIO_OPT_C_IO,
2178                 .group  = FIO_OPT_G_VERIFY,
2179         },
2180 #ifdef FIO_HAVE_TRIM
2181         {
2182                 .name   = "trim_percentage",
2183                 .lname  = "Trim percentage",
2184                 .type   = FIO_OPT_INT,
2185                 .off1   = td_var_offset(trim_percentage),
2186                 .minval = 0,
2187                 .maxval = 100,
2188                 .help   = "Number of verify blocks to discard/trim",
2189                 .parent = "verify",
2190                 .def    = "0",
2191                 .interval = 1,
2192                 .hide   = 1,
2193                 .category = FIO_OPT_C_IO,
2194                 .group  = FIO_OPT_G_TRIM,
2195         },
2196         {
2197                 .name   = "trim_verify_zero",
2198                 .lname  = "Verify trim zero",
2199                 .type   = FIO_OPT_BOOL,
2200                 .help   = "Verify that trim/discarded blocks are returned as zeroes",
2201                 .off1   = td_var_offset(trim_zero),
2202                 .parent = "trim_percentage",
2203                 .hide   = 1,
2204                 .def    = "1",
2205                 .category = FIO_OPT_C_IO,
2206                 .group  = FIO_OPT_G_TRIM,
2207         },
2208         {
2209                 .name   = "trim_backlog",
2210                 .lname  = "Trim backlog",
2211                 .type   = FIO_OPT_STR_VAL,
2212                 .off1   = td_var_offset(trim_backlog),
2213                 .help   = "Trim after this number of blocks are written",
2214                 .parent = "trim_percentage",
2215                 .hide   = 1,
2216                 .interval = 1,
2217                 .category = FIO_OPT_C_IO,
2218                 .group  = FIO_OPT_G_TRIM,
2219         },
2220         {
2221                 .name   = "trim_backlog_batch",
2222                 .lname  = "Trim backlog batch",
2223                 .type   = FIO_OPT_INT,
2224                 .off1   = td_var_offset(trim_batch),
2225                 .help   = "Trim this number of IO blocks",
2226                 .parent = "trim_percentage",
2227                 .hide   = 1,
2228                 .interval = 1,
2229                 .category = FIO_OPT_C_IO,
2230                 .group  = FIO_OPT_G_TRIM,
2231         },
2232 #endif
2233         {
2234                 .name   = "write_iolog",
2235                 .lname  = "Write I/O log",
2236                 .type   = FIO_OPT_STR_STORE,
2237                 .off1   = td_var_offset(write_iolog_file),
2238                 .help   = "Store IO pattern to file",
2239                 .category = FIO_OPT_C_IO,
2240                 .group  = FIO_OPT_G_IOLOG,
2241         },
2242         {
2243                 .name   = "read_iolog",
2244                 .lname  = "Read I/O log",
2245                 .type   = FIO_OPT_STR_STORE,
2246                 .off1   = td_var_offset(read_iolog_file),
2247                 .help   = "Playback IO pattern from file",
2248                 .category = FIO_OPT_C_IO,
2249                 .group  = FIO_OPT_G_IOLOG,
2250         },
2251         {
2252                 .name   = "replay_no_stall",
2253                 .lname  = "Don't stall on replay",
2254                 .type   = FIO_OPT_BOOL,
2255                 .off1   = td_var_offset(no_stall),
2256                 .def    = "0",
2257                 .parent = "read_iolog",
2258                 .hide   = 1,
2259                 .help   = "Playback IO pattern file as fast as possible without stalls",
2260                 .category = FIO_OPT_C_IO,
2261                 .group  = FIO_OPT_G_IOLOG,
2262         },
2263         {
2264                 .name   = "replay_redirect",
2265                 .lname  = "Redirect device for replay",
2266                 .type   = FIO_OPT_STR_STORE,
2267                 .off1   = td_var_offset(replay_redirect),
2268                 .parent = "read_iolog",
2269                 .hide   = 1,
2270                 .help   = "Replay all I/O onto this device, regardless of trace device",
2271                 .category = FIO_OPT_C_IO,
2272                 .group  = FIO_OPT_G_IOLOG,
2273         },
2274         {
2275                 .name   = "exec_prerun",
2276                 .lname  = "Pre-execute runnable",
2277                 .type   = FIO_OPT_STR_STORE,
2278                 .off1   = td_var_offset(exec_prerun),
2279                 .help   = "Execute this file prior to running job",
2280                 .category = FIO_OPT_C_GENERAL,
2281                 .group  = FIO_OPT_G_INVALID,
2282         },
2283         {
2284                 .name   = "exec_postrun",
2285                 .lname  = "Post-execute runnable",
2286                 .type   = FIO_OPT_STR_STORE,
2287                 .off1   = td_var_offset(exec_postrun),
2288                 .help   = "Execute this file after running job",
2289                 .category = FIO_OPT_C_GENERAL,
2290                 .group  = FIO_OPT_G_INVALID,
2291         },
2292 #ifdef FIO_HAVE_IOSCHED_SWITCH
2293         {
2294                 .name   = "ioscheduler",
2295                 .lname  = "I/O scheduler",
2296                 .type   = FIO_OPT_STR_STORE,
2297                 .off1   = td_var_offset(ioscheduler),
2298                 .help   = "Use this IO scheduler on the backing device",
2299                 .category = FIO_OPT_C_FILE,
2300                 .group  = FIO_OPT_G_INVALID,
2301         },
2302 #endif
2303         {
2304                 .name   = "zonesize",
2305                 .lname  = "Zone size",
2306                 .type   = FIO_OPT_STR_VAL,
2307                 .off1   = td_var_offset(zone_size),
2308                 .help   = "Amount of data to read per zone",
2309                 .def    = "0",
2310                 .interval = 1024 * 1024,
2311                 .category = FIO_OPT_C_IO,
2312                 .group  = FIO_OPT_G_ZONE,
2313         },
2314         {
2315                 .name   = "zonerange",
2316                 .lname  = "Zone range",
2317                 .type   = FIO_OPT_STR_VAL,
2318                 .off1   = td_var_offset(zone_range),
2319                 .help   = "Give size of an IO zone",
2320                 .def    = "0",
2321                 .interval = 1024 * 1024,
2322                 .category = FIO_OPT_C_IO,
2323                 .group  = FIO_OPT_G_ZONE,
2324         },
2325         {
2326                 .name   = "zoneskip",
2327                 .lname  = "Zone skip",
2328                 .type   = FIO_OPT_STR_VAL,
2329                 .off1   = td_var_offset(zone_skip),
2330                 .help   = "Space between IO zones",
2331                 .def    = "0",
2332                 .interval = 1024 * 1024,
2333                 .category = FIO_OPT_C_IO,
2334                 .group  = FIO_OPT_G_ZONE,
2335         },
2336         {
2337                 .name   = "lockmem",
2338                 .lname  = "Lock memory",
2339                 .type   = FIO_OPT_STR_VAL,
2340                 .off1   = td_var_offset(lockmem),
2341                 .help   = "Lock down this amount of memory",
2342                 .def    = "0",
2343                 .interval = 1024 * 1024,
2344                 .category = FIO_OPT_C_GENERAL,
2345                 .group  = FIO_OPT_G_INVALID,
2346         },
2347         {
2348                 .name   = "rwmixread",
2349                 .lname  = "Read/write mix read",
2350                 .type   = FIO_OPT_INT,
2351                 .cb     = str_rwmix_read_cb,
2352                 .maxval = 100,
2353                 .help   = "Percentage of mixed workload that is reads",
2354                 .def    = "50",
2355                 .interval = 5,
2356                 .inverse = "rwmixwrite",
2357                 .category = FIO_OPT_C_IO,
2358                 .group  = FIO_OPT_G_RWMIX,
2359         },
2360         {
2361                 .name   = "rwmixwrite",
2362                 .lname  = "Read/write mix write",
2363                 .type   = FIO_OPT_INT,
2364                 .cb     = str_rwmix_write_cb,
2365                 .maxval = 100,
2366                 .help   = "Percentage of mixed workload that is writes",
2367                 .def    = "50",
2368                 .interval = 5,
2369                 .inverse = "rwmixread",
2370                 .category = FIO_OPT_C_IO,
2371                 .group  = FIO_OPT_G_RWMIX,
2372         },
2373         {
2374                 .name   = "rwmixcycle",
2375                 .lname  = "Read/write mix cycle",
2376                 .type   = FIO_OPT_DEPRECATED,
2377                 .category = FIO_OPT_C_IO,
2378                 .group  = FIO_OPT_G_RWMIX,
2379         },
2380         {
2381                 .name   = "nice",
2382                 .lname  = "Nice",
2383                 .type   = FIO_OPT_INT,
2384                 .off1   = td_var_offset(nice),
2385                 .help   = "Set job CPU nice value",
2386                 .minval = -19,
2387                 .maxval = 20,
2388                 .def    = "0",
2389                 .interval = 1,
2390                 .category = FIO_OPT_C_GENERAL,
2391                 .group  = FIO_OPT_G_CRED,
2392         },
2393 #ifdef FIO_HAVE_IOPRIO
2394         {
2395                 .name   = "prio",
2396                 .lname  = "I/O nice priority",
2397                 .type   = FIO_OPT_INT,
2398                 .off1   = td_var_offset(ioprio),
2399                 .help   = "Set job IO priority value",
2400                 .minval = 0,
2401                 .maxval = 7,
2402                 .interval = 1,
2403                 .category = FIO_OPT_C_GENERAL,
2404                 .group  = FIO_OPT_G_CRED,
2405         },
2406         {
2407                 .name   = "prioclass",
2408                 .lname  = "I/O nice priority class",
2409                 .type   = FIO_OPT_INT,
2410                 .off1   = td_var_offset(ioprio_class),
2411                 .help   = "Set job IO priority class",
2412                 .minval = 0,
2413                 .maxval = 3,
2414                 .interval = 1,
2415                 .category = FIO_OPT_C_GENERAL,
2416                 .group  = FIO_OPT_G_CRED,
2417         },
2418 #endif
2419         {
2420                 .name   = "thinktime",
2421                 .lname  = "Thinktime",
2422                 .type   = FIO_OPT_INT,
2423                 .off1   = td_var_offset(thinktime),
2424                 .help   = "Idle time between IO buffers (usec)",
2425                 .def    = "0",
2426                 .category = FIO_OPT_C_IO,
2427                 .group  = FIO_OPT_G_THINKTIME,
2428         },
2429         {
2430                 .name   = "thinktime_spin",
2431                 .lname  = "Thinktime spin",
2432                 .type   = FIO_OPT_INT,
2433                 .off1   = td_var_offset(thinktime_spin),
2434                 .help   = "Start think time by spinning this amount (usec)",
2435                 .def    = "0",
2436                 .parent = "thinktime",
2437                 .hide   = 1,
2438                 .category = FIO_OPT_C_IO,
2439                 .group  = FIO_OPT_G_THINKTIME,
2440         },
2441         {
2442                 .name   = "thinktime_blocks",
2443                 .lname  = "Thinktime blocks",
2444                 .type   = FIO_OPT_INT,
2445                 .off1   = td_var_offset(thinktime_blocks),
2446                 .help   = "IO buffer period between 'thinktime'",
2447                 .def    = "1",
2448                 .parent = "thinktime",
2449                 .hide   = 1,
2450                 .category = FIO_OPT_C_IO,
2451                 .group  = FIO_OPT_G_THINKTIME,
2452         },
2453         {
2454                 .name   = "rate",
2455                 .lname  = "I/O rate",
2456                 .type   = FIO_OPT_INT,
2457                 .off1   = td_var_offset(rate[DDIR_READ]),
2458                 .off2   = td_var_offset(rate[DDIR_WRITE]),
2459                 .off3   = td_var_offset(rate[DDIR_TRIM]),
2460                 .help   = "Set bandwidth rate",
2461                 .category = FIO_OPT_C_IO,
2462                 .group  = FIO_OPT_G_RATE,
2463         },
2464         {
2465                 .name   = "ratemin",
2466                 .lname  = "I/O min rate",
2467                 .type   = FIO_OPT_INT,
2468                 .off1   = td_var_offset(ratemin[DDIR_READ]),
2469                 .off2   = td_var_offset(ratemin[DDIR_WRITE]),
2470                 .off3   = td_var_offset(ratemin[DDIR_TRIM]),
2471                 .help   = "Job must meet this rate or it will be shutdown",
2472                 .parent = "rate",
2473                 .hide   = 1,
2474                 .category = FIO_OPT_C_IO,
2475                 .group  = FIO_OPT_G_RATE,
2476         },
2477         {
2478                 .name   = "rate_iops",
2479                 .lname  = "I/O rate IOPS",
2480                 .type   = FIO_OPT_INT,
2481                 .off1   = td_var_offset(rate_iops[DDIR_READ]),
2482                 .off2   = td_var_offset(rate_iops[DDIR_WRITE]),
2483                 .off3   = td_var_offset(rate_iops[DDIR_TRIM]),
2484                 .help   = "Limit IO used to this number of IO operations/sec",
2485                 .hide   = 1,
2486                 .category = FIO_OPT_C_IO,
2487                 .group  = FIO_OPT_G_RATE,
2488         },
2489         {
2490                 .name   = "rate_iops_min",
2491                 .lname  = "I/O min rate IOPS",
2492                 .type   = FIO_OPT_INT,
2493                 .off1   = td_var_offset(rate_iops_min[DDIR_READ]),
2494                 .off2   = td_var_offset(rate_iops_min[DDIR_WRITE]),
2495                 .off3   = td_var_offset(rate_iops_min[DDIR_TRIM]),
2496                 .help   = "Job must meet this rate or it will be shut down",
2497                 .parent = "rate_iops",
2498                 .hide   = 1,
2499                 .category = FIO_OPT_C_IO,
2500                 .group  = FIO_OPT_G_RATE,
2501         },
2502         {
2503                 .name   = "ratecycle",
2504                 .lname  = "I/O rate cycle",
2505                 .type   = FIO_OPT_INT,
2506                 .off1   = td_var_offset(ratecycle),
2507                 .help   = "Window average for rate limits (msec)",
2508                 .def    = "1000",
2509                 .parent = "rate",
2510                 .hide   = 1,
2511                 .category = FIO_OPT_C_IO,
2512                 .group  = FIO_OPT_G_RATE,
2513         },
2514         {
2515                 .name   = "max_latency",
2516                 .type   = FIO_OPT_INT,
2517                 .off1   = td_var_offset(max_latency),
2518                 .help   = "Maximum tolerated IO latency (usec)",
2519                 .category = FIO_OPT_C_IO,
2520                 .group = FIO_OPT_G_RATE,
2521         },
2522         {
2523                 .name   = "invalidate",
2524                 .lname  = "Cache invalidate",
2525                 .type   = FIO_OPT_BOOL,
2526                 .off1   = td_var_offset(invalidate_cache),
2527                 .help   = "Invalidate buffer/page cache prior to running job",
2528                 .def    = "1",
2529                 .category = FIO_OPT_C_IO,
2530                 .group  = FIO_OPT_G_IO_TYPE,
2531         },
2532         {
2533                 .name   = "sync",
2534                 .lname  = "Synchronous I/O",
2535                 .type   = FIO_OPT_BOOL,
2536                 .off1   = td_var_offset(sync_io),
2537                 .help   = "Use O_SYNC for buffered writes",
2538                 .def    = "0",
2539                 .parent = "buffered",
2540                 .hide   = 1,
2541                 .category = FIO_OPT_C_IO,
2542                 .group  = FIO_OPT_G_IO_TYPE,
2543         },
2544         {
2545                 .name   = "create_serialize",
2546                 .lname  = "Create serialize",
2547                 .type   = FIO_OPT_BOOL,
2548                 .off1   = td_var_offset(create_serialize),
2549                 .help   = "Serialize creating of job files",
2550                 .def    = "1",
2551                 .category = FIO_OPT_C_FILE,
2552                 .group  = FIO_OPT_G_INVALID,
2553         },
2554         {
2555                 .name   = "create_fsync",
2556                 .lname  = "Create fsync",
2557                 .type   = FIO_OPT_BOOL,
2558                 .off1   = td_var_offset(create_fsync),
2559                 .help   = "fsync file after creation",
2560                 .def    = "1",
2561                 .category = FIO_OPT_C_FILE,
2562                 .group  = FIO_OPT_G_INVALID,
2563         },
2564         {
2565                 .name   = "create_on_open",
2566                 .lname  = "Create on open",
2567                 .type   = FIO_OPT_BOOL,
2568                 .off1   = td_var_offset(create_on_open),
2569                 .help   = "Create files when they are opened for IO",
2570                 .def    = "0",
2571                 .category = FIO_OPT_C_FILE,
2572                 .group  = FIO_OPT_G_INVALID,
2573         },
2574         {
2575                 .name   = "create_only",
2576                 .type   = FIO_OPT_BOOL,
2577                 .off1   = td_var_offset(create_only),
2578                 .help   = "Only perform file creation phase",
2579                 .category = FIO_OPT_C_FILE,
2580                 .def    = "0",
2581         },
2582         {
2583                 .name   = "pre_read",
2584                 .lname  = "Pre-read files",
2585                 .type   = FIO_OPT_BOOL,
2586                 .off1   = td_var_offset(pre_read),
2587                 .help   = "Pre-read files before starting official testing",
2588                 .def    = "0",
2589                 .category = FIO_OPT_C_FILE,
2590                 .group  = FIO_OPT_G_INVALID,
2591         },
2592 #ifdef FIO_HAVE_CPU_AFFINITY
2593         {
2594                 .name   = "cpumask",
2595                 .lname  = "CPU mask",
2596                 .type   = FIO_OPT_INT,
2597                 .cb     = str_cpumask_cb,
2598                 .help   = "CPU affinity mask",
2599                 .category = FIO_OPT_C_GENERAL,
2600                 .group  = FIO_OPT_G_CRED,
2601         },
2602         {
2603                 .name   = "cpus_allowed",
2604                 .lname  = "CPUs allowed",
2605                 .type   = FIO_OPT_STR,
2606                 .cb     = str_cpus_allowed_cb,
2607                 .help   = "Set CPUs allowed",
2608                 .category = FIO_OPT_C_GENERAL,
2609                 .group  = FIO_OPT_G_CRED,
2610         },
2611 #endif
2612 #ifdef CONFIG_LIBNUMA
2613         {
2614                 .name   = "numa_cpu_nodes",
2615                 .type   = FIO_OPT_STR,
2616                 .cb     = str_numa_cpunodes_cb,
2617                 .help   = "NUMA CPU nodes bind",
2618         },
2619         {
2620                 .name   = "numa_mem_policy",
2621                 .type   = FIO_OPT_STR,
2622                 .cb     = str_numa_mpol_cb,
2623                 .help   = "NUMA memory policy setup",
2624         },
2625 #endif
2626         {
2627                 .name   = "end_fsync",
2628                 .lname  = "End fsync",
2629                 .type   = FIO_OPT_BOOL,
2630                 .off1   = td_var_offset(end_fsync),
2631                 .help   = "Include fsync at the end of job",
2632                 .def    = "0",
2633                 .category = FIO_OPT_C_FILE,
2634                 .group  = FIO_OPT_G_INVALID,
2635         },
2636         {
2637                 .name   = "fsync_on_close",
2638                 .lname  = "Fsync on close",
2639                 .type   = FIO_OPT_BOOL,
2640                 .off1   = td_var_offset(fsync_on_close),
2641                 .help   = "fsync files on close",
2642                 .def    = "0",
2643                 .category = FIO_OPT_C_FILE,
2644                 .group  = FIO_OPT_G_INVALID,
2645         },
2646         {
2647                 .name   = "unlink",
2648                 .lname  = "Unlink file",
2649                 .type   = FIO_OPT_BOOL,
2650                 .off1   = td_var_offset(unlink),
2651                 .help   = "Unlink created files after job has completed",
2652                 .def    = "0",
2653                 .category = FIO_OPT_C_FILE,
2654                 .group  = FIO_OPT_G_INVALID,
2655         },
2656         {
2657                 .name   = "exitall",
2658                 .lname  = "Exit-all on terminate",
2659                 .type   = FIO_OPT_STR_SET,
2660                 .cb     = str_exitall_cb,
2661                 .help   = "Terminate all jobs when one exits",
2662                 .category = FIO_OPT_C_GENERAL,
2663                 .group  = FIO_OPT_G_PROCESS,
2664         },
2665         {
2666                 .name   = "stonewall",
2667                 .lname  = "Wait for previous",
2668                 .alias  = "wait_for_previous",
2669                 .type   = FIO_OPT_STR_SET,
2670                 .off1   = td_var_offset(stonewall),
2671                 .help   = "Insert a hard barrier between this job and previous",
2672                 .category = FIO_OPT_C_GENERAL,
2673                 .group  = FIO_OPT_G_PROCESS,
2674         },
2675         {
2676                 .name   = "new_group",
2677                 .lname  = "New group",
2678                 .type   = FIO_OPT_STR_SET,
2679                 .off1   = td_var_offset(new_group),
2680                 .help   = "Mark the start of a new group (for reporting)",
2681                 .category = FIO_OPT_C_GENERAL,
2682                 .group  = FIO_OPT_G_PROCESS,
2683         },
2684         {
2685                 .name   = "thread",
2686                 .lname  = "Thread",
2687                 .type   = FIO_OPT_STR_SET,
2688                 .off1   = td_var_offset(use_thread),
2689                 .help   = "Use threads instead of processes",
2690                 .category = FIO_OPT_C_GENERAL,
2691                 .group  = FIO_OPT_G_PROCESS,
2692         },
2693         {
2694                 .name   = "write_bw_log",
2695                 .lname  = "Write bandwidth log",
2696                 .type   = FIO_OPT_STR_STORE,
2697                 .off1   = td_var_offset(bw_log_file),
2698                 .help   = "Write log of bandwidth during run",
2699                 .category = FIO_OPT_C_LOG,
2700                 .group  = FIO_OPT_G_INVALID,
2701         },
2702         {
2703                 .name   = "write_lat_log",
2704                 .lname  = "Write latency log",
2705                 .type   = FIO_OPT_STR_STORE,
2706                 .off1   = td_var_offset(lat_log_file),
2707                 .help   = "Write log of latency during run",
2708                 .category = FIO_OPT_C_LOG,
2709                 .group  = FIO_OPT_G_INVALID,
2710         },
2711         {
2712                 .name   = "write_iops_log",
2713                 .lname  = "Write IOPS log",
2714                 .type   = FIO_OPT_STR,
2715                 .off1   = td_var_offset(iops_log_file),
2716                 .help   = "Write log of IOPS during run",
2717                 .category = FIO_OPT_C_LOG,
2718                 .group  = FIO_OPT_G_INVALID,
2719         },
2720         {
2721                 .name   = "log_avg_msec",
2722                 .lname  = "Log averaging (msec)",
2723                 .type   = FIO_OPT_INT,
2724                 .off1   = td_var_offset(log_avg_msec),
2725                 .help   = "Average bw/iops/lat logs over this period of time",
2726                 .def    = "0",
2727                 .category = FIO_OPT_C_LOG,
2728                 .group  = FIO_OPT_G_INVALID,
2729         },
2730         {
2731                 .name   = "bwavgtime",
2732                 .lname  = "Bandwidth average time",
2733                 .type   = FIO_OPT_INT,
2734                 .off1   = td_var_offset(bw_avg_time),
2735                 .help   = "Time window over which to calculate bandwidth"
2736                           " (msec)",
2737                 .def    = "500",
2738                 .parent = "write_bw_log",
2739                 .hide   = 1,
2740                 .interval = 100,
2741                 .category = FIO_OPT_C_LOG,
2742                 .group  = FIO_OPT_G_INVALID,
2743         },
2744         {
2745                 .name   = "iopsavgtime",
2746                 .lname  = "IOPS average time",
2747                 .type   = FIO_OPT_INT,
2748                 .off1   = td_var_offset(iops_avg_time),
2749                 .help   = "Time window over which to calculate IOPS (msec)",
2750                 .def    = "500",
2751                 .parent = "write_iops_log",
2752                 .hide   = 1,
2753                 .interval = 100,
2754                 .category = FIO_OPT_C_LOG,
2755                 .group  = FIO_OPT_G_INVALID,
2756         },
2757         {
2758                 .name   = "group_reporting",
2759                 .lname  = "Group reporting",
2760                 .type   = FIO_OPT_BOOL,
2761                 .off1   = td_var_offset(group_reporting),
2762                 .help   = "Do reporting on a per-group basis",
2763                 .def    = "1",
2764                 .category = FIO_OPT_C_STAT,
2765                 .group  = FIO_OPT_G_INVALID,
2766         },
2767         {
2768                 .name   = "zero_buffers",
2769                 .lname  = "Zero I/O buffers",
2770                 .type   = FIO_OPT_STR_SET,
2771                 .off1   = td_var_offset(zero_buffers),
2772                 .help   = "Init IO buffers to all zeroes",
2773                 .category = FIO_OPT_C_IO,
2774                 .group  = FIO_OPT_G_IO_BUF,
2775         },
2776         {
2777                 .name   = "refill_buffers",
2778                 .lname  = "Refill I/O buffers",
2779                 .type   = FIO_OPT_STR_SET,
2780                 .off1   = td_var_offset(refill_buffers),
2781                 .help   = "Refill IO buffers on every IO submit",
2782                 .category = FIO_OPT_C_IO,
2783                 .group  = FIO_OPT_G_IO_BUF,
2784         },
2785         {
2786                 .name   = "scramble_buffers",
2787                 .lname  = "Scramble I/O buffers",
2788                 .type   = FIO_OPT_BOOL,
2789                 .off1   = td_var_offset(scramble_buffers),
2790                 .help   = "Slightly scramble buffers on every IO submit",
2791                 .def    = "1",
2792                 .category = FIO_OPT_C_IO,
2793                 .group  = FIO_OPT_G_IO_BUF,
2794         },
2795         {
2796                 .name   = "buffer_compress_percentage",
2797                 .lname  = "Buffer compression percentage",
2798                 .type   = FIO_OPT_INT,
2799                 .off1   = td_var_offset(compress_percentage),
2800                 .maxval = 100,
2801                 .minval = 1,
2802                 .help   = "How compressible the buffer is (approximately)",
2803                 .interval = 5,
2804                 .category = FIO_OPT_C_IO,
2805                 .group  = FIO_OPT_G_IO_BUF,
2806         },
2807         {
2808                 .name   = "buffer_compress_chunk",
2809                 .lname  = "Buffer compression chunk size",
2810                 .type   = FIO_OPT_INT,
2811                 .off1   = td_var_offset(compress_chunk),
2812                 .parent = "buffer_compress_percentage",
2813                 .hide   = 1,
2814                 .help   = "Size of compressible region in buffer",
2815                 .interval = 256,
2816                 .category = FIO_OPT_C_IO,
2817                 .group  = FIO_OPT_G_IO_BUF,
2818         },
2819         {
2820                 .name   = "clat_percentiles",
2821                 .lname  = "Completion latency percentiles",
2822                 .type   = FIO_OPT_BOOL,
2823                 .off1   = td_var_offset(clat_percentiles),
2824                 .help   = "Enable the reporting of completion latency percentiles",
2825                 .def    = "1",
2826                 .category = FIO_OPT_C_STAT,
2827                 .group  = FIO_OPT_G_INVALID,
2828         },
2829         {
2830                 .name   = "percentile_list",
2831                 .lname  = "Completion latency percentile list",
2832                 .type   = FIO_OPT_FLOAT_LIST,
2833                 .off1   = td_var_offset(percentile_list),
2834                 .off2   = td_var_offset(percentile_precision),
2835                 .help   = "Specify a custom list of percentiles to report",
2836                 .def    = "1:5:10:20:30:40:50:60:70:80:90:95:99:99.5:99.9:99.95:99.99",
2837                 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2838                 .minfp  = 0.0,
2839                 .maxfp  = 100.0,
2840                 .category = FIO_OPT_C_STAT,
2841                 .group  = FIO_OPT_G_INVALID,
2842         },
2843
2844 #ifdef FIO_HAVE_DISK_UTIL
2845         {
2846                 .name   = "disk_util",
2847                 .lname  = "Disk utilization",
2848                 .type   = FIO_OPT_BOOL,
2849                 .off1   = td_var_offset(do_disk_util),
2850                 .help   = "Log disk utilization statistics",
2851                 .def    = "1",
2852                 .category = FIO_OPT_C_STAT,
2853                 .group  = FIO_OPT_G_INVALID,
2854         },
2855 #endif
2856         {
2857                 .name   = "gtod_reduce",
2858                 .lname  = "Reduce gettimeofday() calls",
2859                 .type   = FIO_OPT_BOOL,
2860                 .help   = "Greatly reduce number of gettimeofday() calls",
2861                 .cb     = str_gtod_reduce_cb,
2862                 .def    = "0",
2863                 .hide_on_set = 1,
2864                 .category = FIO_OPT_C_STAT,
2865                 .group  = FIO_OPT_G_INVALID,
2866         },
2867         {
2868                 .name   = "disable_lat",
2869                 .lname  = "Disable all latency stats",
2870                 .type   = FIO_OPT_BOOL,
2871                 .off1   = td_var_offset(disable_lat),
2872                 .help   = "Disable latency numbers",
2873                 .parent = "gtod_reduce",
2874                 .hide   = 1,
2875                 .def    = "0",
2876                 .category = FIO_OPT_C_STAT,
2877                 .group  = FIO_OPT_G_INVALID,
2878         },
2879         {
2880                 .name   = "disable_clat",
2881                 .lname  = "Disable completion latency stats",
2882                 .type   = FIO_OPT_BOOL,
2883                 .off1   = td_var_offset(disable_clat),
2884                 .help   = "Disable completion latency numbers",
2885                 .parent = "gtod_reduce",
2886                 .hide   = 1,
2887                 .def    = "0",
2888                 .category = FIO_OPT_C_STAT,
2889                 .group  = FIO_OPT_G_INVALID,
2890         },
2891         {
2892                 .name   = "disable_slat",
2893                 .lname  = "Disable submission latency stats",
2894                 .type   = FIO_OPT_BOOL,
2895                 .off1   = td_var_offset(disable_slat),
2896                 .help   = "Disable submission latency numbers",
2897                 .parent = "gtod_reduce",
2898                 .hide   = 1,
2899                 .def    = "0",
2900                 .category = FIO_OPT_C_STAT,
2901                 .group  = FIO_OPT_G_INVALID,
2902         },
2903         {
2904                 .name   = "disable_bw_measurement",
2905                 .lname  = "Disable bandwidth stats",
2906                 .type   = FIO_OPT_BOOL,
2907                 .off1   = td_var_offset(disable_bw),
2908                 .help   = "Disable bandwidth logging",
2909                 .parent = "gtod_reduce",
2910                 .hide   = 1,
2911                 .def    = "0",
2912                 .category = FIO_OPT_C_STAT,
2913                 .group  = FIO_OPT_G_INVALID,
2914         },
2915         {
2916                 .name   = "gtod_cpu",
2917                 .lname  = "Dedicated gettimeofday() CPU",
2918                 .type   = FIO_OPT_INT,
2919                 .cb     = str_gtod_cpu_cb,
2920                 .help   = "Set up dedicated gettimeofday() thread on this CPU",
2921                 .verify = gtod_cpu_verify,
2922                 .category = FIO_OPT_C_GENERAL,
2923                 .group  = FIO_OPT_G_CLOCK,
2924         },
2925         {
2926                 .name   = "unified_rw_reporting",
2927                 .type   = FIO_OPT_BOOL,
2928                 .off1   = td_var_offset(unified_rw_rep),
2929                 .help   = "Unify reporting across data direction",
2930                 .def    = "0",
2931                 .category = FIO_OPT_C_GENERAL,
2932                 .group  = FIO_OPT_G_INVALID,
2933         },
2934         {
2935                 .name   = "continue_on_error",
2936                 .lname  = "Continue on error",
2937                 .type   = FIO_OPT_STR,
2938                 .off1   = td_var_offset(continue_on_error),
2939                 .help   = "Continue on non-fatal errors during IO",
2940                 .def    = "none",
2941                 .category = FIO_OPT_C_GENERAL,
2942                 .group  = FIO_OPT_G_ERR,
2943                 .posval = {
2944                           { .ival = "none",
2945                             .oval = ERROR_TYPE_NONE,
2946                             .help = "Exit when an error is encountered",
2947                           },
2948                           { .ival = "read",
2949                             .oval = ERROR_TYPE_READ,
2950                             .help = "Continue on read errors only",
2951                           },
2952                           { .ival = "write",
2953                             .oval = ERROR_TYPE_WRITE,
2954                             .help = "Continue on write errors only",
2955                           },
2956                           { .ival = "io",
2957                             .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2958                             .help = "Continue on any IO errors",
2959                           },
2960                           { .ival = "verify",
2961                             .oval = ERROR_TYPE_VERIFY,
2962                             .help = "Continue on verify errors only",
2963                           },
2964                           { .ival = "all",
2965                             .oval = ERROR_TYPE_ANY,
2966                             .help = "Continue on all io and verify errors",
2967                           },
2968                           { .ival = "0",
2969                             .oval = ERROR_TYPE_NONE,
2970                             .help = "Alias for 'none'",
2971                           },
2972                           { .ival = "1",
2973                             .oval = ERROR_TYPE_ANY,
2974                             .help = "Alias for 'all'",
2975                           },
2976                 },
2977         },
2978         {
2979                 .name   = "ignore_error",
2980                 .type   = FIO_OPT_STR,
2981                 .cb     = str_ignore_error_cb,
2982                 .help   = "Set a specific list of errors to ignore",
2983                 .parent = "rw",
2984                 .category = FIO_OPT_C_GENERAL,
2985                 .group  = FIO_OPT_G_ERR,
2986         },
2987         {
2988                 .name   = "error_dump",
2989                 .type   = FIO_OPT_BOOL,
2990                 .off1   = td_var_offset(error_dump),
2991                 .def    = "0",
2992                 .help   = "Dump info on each error",
2993                 .category = FIO_OPT_C_GENERAL,
2994                 .group  = FIO_OPT_G_ERR,
2995         },
2996         {
2997                 .name   = "profile",
2998                 .lname  = "Profile",
2999                 .type   = FIO_OPT_STR_STORE,
3000                 .off1   = td_var_offset(profile),
3001                 .help   = "Select a specific builtin performance test",
3002                 .category = FIO_OPT_C_PROFILE,
3003                 .group  = FIO_OPT_G_INVALID,
3004         },
3005         {
3006                 .name   = "cgroup",
3007                 .lname  = "Cgroup",
3008                 .type   = FIO_OPT_STR_STORE,
3009                 .off1   = td_var_offset(cgroup),
3010                 .help   = "Add job to cgroup of this name",
3011                 .category = FIO_OPT_C_GENERAL,
3012                 .group  = FIO_OPT_G_CGROUP,
3013         },
3014         {
3015                 .name   = "cgroup_nodelete",
3016                 .lname  = "Cgroup no-delete",
3017                 .type   = FIO_OPT_BOOL,
3018                 .off1   = td_var_offset(cgroup_nodelete),
3019                 .help   = "Do not delete cgroups after job completion",
3020                 .def    = "0",
3021                 .parent = "cgroup",
3022                 .category = FIO_OPT_C_GENERAL,
3023                 .group  = FIO_OPT_G_CGROUP,
3024         },
3025         {
3026                 .name   = "cgroup_weight",
3027                 .lname  = "Cgroup weight",
3028                 .type   = FIO_OPT_INT,
3029                 .off1   = td_var_offset(cgroup_weight),
3030                 .help   = "Use given weight for cgroup",
3031                 .minval = 100,
3032                 .maxval = 1000,
3033                 .parent = "cgroup",
3034                 .category = FIO_OPT_C_GENERAL,
3035                 .group  = FIO_OPT_G_CGROUP,
3036         },
3037         {
3038                 .name   = "uid",
3039                 .lname  = "User ID",
3040                 .type   = FIO_OPT_INT,
3041                 .off1   = td_var_offset(uid),
3042                 .help   = "Run job with this user ID",
3043                 .category = FIO_OPT_C_GENERAL,
3044                 .group  = FIO_OPT_G_CRED,
3045         },
3046         {
3047                 .name   = "gid",
3048                 .lname  = "Group ID",
3049                 .type   = FIO_OPT_INT,
3050                 .off1   = td_var_offset(gid),
3051                 .help   = "Run job with this group ID",
3052                 .category = FIO_OPT_C_GENERAL,
3053                 .group  = FIO_OPT_G_CRED,
3054         },
3055         {
3056                 .name   = "kb_base",
3057                 .lname  = "KB Base",
3058                 .type   = FIO_OPT_INT,
3059                 .off1   = td_var_offset(kb_base),
3060                 .prio   = 1,
3061                 .def    = "1024",
3062                 .posval = {
3063                           { .ival = "1024",
3064                             .oval = 1024,
3065                             .help = "Use 1024 as the K base",
3066                           },
3067                           { .ival = "1000",
3068                             .oval = 1000,
3069                             .help = "Use 1000 as the K base",
3070                           },
3071                 },
3072                 .help   = "How many bytes per KB for reporting (1000 or 1024)",
3073                 .category = FIO_OPT_C_GENERAL,
3074                 .group  = FIO_OPT_G_INVALID,
3075         },
3076         {
3077                 .name   = "unit_base",
3078                 .lname  = "Base unit for reporting (Bits or Bytes)",
3079                 .type   = FIO_OPT_INT,
3080                 .off1   = td_var_offset(unit_base),
3081                 .prio   = 1,
3082                 .posval = {
3083                           { .ival = "0",
3084                             .oval = 0,
3085                             .help = "Auto-detect",
3086                           },
3087                           { .ival = "8",
3088                             .oval = 8,
3089                             .help = "Normal (byte based)",
3090                           },
3091                           { .ival = "1",
3092                             .oval = 1,
3093                             .help = "Bit based",
3094                           },
3095                 },
3096                 .help   = "Bit multiple of result summary data (8 for byte, 1 for bit)",
3097                 .category = FIO_OPT_C_GENERAL,
3098                 .group  = FIO_OPT_G_INVALID,
3099         },
3100         {
3101                 .name   = "hugepage-size",
3102                 .lname  = "Hugepage size",
3103                 .type   = FIO_OPT_INT,
3104                 .off1   = td_var_offset(hugepage_size),
3105                 .help   = "When using hugepages, specify size of each page",
3106                 .def    = __fio_stringify(FIO_HUGE_PAGE),
3107                 .interval = 1024 * 1024,
3108                 .category = FIO_OPT_C_GENERAL,
3109                 .group  = FIO_OPT_G_INVALID,
3110         },
3111         {
3112                 .name   = "flow_id",
3113                 .lname  = "I/O flow ID",
3114                 .type   = FIO_OPT_INT,
3115                 .off1   = td_var_offset(flow_id),
3116                 .help   = "The flow index ID to use",
3117                 .def    = "0",
3118                 .category = FIO_OPT_C_IO,
3119                 .group  = FIO_OPT_G_IO_FLOW,
3120         },
3121         {
3122                 .name   = "flow",
3123                 .lname  = "I/O flow weight",
3124                 .type   = FIO_OPT_INT,
3125                 .off1   = td_var_offset(flow),
3126                 .help   = "Weight for flow control of this job",
3127                 .parent = "flow_id",
3128                 .hide   = 1,
3129                 .def    = "0",
3130                 .category = FIO_OPT_C_IO,
3131                 .group  = FIO_OPT_G_IO_FLOW,
3132         },
3133         {
3134                 .name   = "flow_watermark",
3135                 .lname  = "I/O flow watermark",
3136                 .type   = FIO_OPT_INT,
3137                 .off1   = td_var_offset(flow_watermark),
3138                 .help   = "High watermark for flow control. This option"
3139                         " should be set to the same value for all threads"
3140                         " with non-zero flow.",
3141                 .parent = "flow_id",
3142                 .hide   = 1,
3143                 .def    = "1024",
3144                 .category = FIO_OPT_C_IO,
3145                 .group  = FIO_OPT_G_IO_FLOW,
3146         },
3147         {
3148                 .name   = "flow_sleep",
3149                 .lname  = "I/O flow sleep",
3150                 .type   = FIO_OPT_INT,
3151                 .off1   = td_var_offset(flow_sleep),
3152                 .help   = "How many microseconds to sleep after being held"
3153                         " back by the flow control mechanism",
3154                 .parent = "flow_id",
3155                 .hide   = 1,
3156                 .def    = "0",
3157                 .category = FIO_OPT_C_IO,
3158                 .group  = FIO_OPT_G_IO_FLOW,
3159         },
3160         {
3161                 .name = NULL,
3162         },
3163 };
3164
3165 static void add_to_lopt(struct option *lopt, struct fio_option *o,
3166                         const char *name, int val)
3167 {
3168         lopt->name = (char *) name;
3169         lopt->val = val;
3170         if (o->type == FIO_OPT_STR_SET)
3171                 lopt->has_arg = no_argument;
3172         else
3173                 lopt->has_arg = required_argument;
3174 }
3175
3176 static void options_to_lopts(struct fio_option *opts,
3177                               struct option *long_options,
3178                               int i, int option_type)
3179 {
3180         struct fio_option *o = &opts[0];
3181         while (o->name) {
3182                 add_to_lopt(&long_options[i], o, o->name, option_type);
3183                 if (o->alias) {
3184                         i++;
3185                         add_to_lopt(&long_options[i], o, o->alias, option_type);
3186                 }
3187
3188                 i++;
3189                 o++;
3190                 assert(i < FIO_NR_OPTIONS);
3191         }
3192 }
3193
3194 void fio_options_set_ioengine_opts(struct option *long_options,
3195                                    struct thread_data *td)
3196 {
3197         unsigned int i;
3198
3199         i = 0;
3200         while (long_options[i].name) {
3201                 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
3202                         memset(&long_options[i], 0, sizeof(*long_options));
3203                         break;
3204                 }
3205                 i++;
3206         }
3207
3208         /*
3209          * Just clear out the prior ioengine options.
3210          */
3211         if (!td || !td->eo)
3212                 return;
3213
3214         options_to_lopts(td->io_ops->options, long_options, i,
3215                          FIO_GETOPT_IOENGINE);
3216 }
3217
3218 void fio_options_dup_and_init(struct option *long_options)
3219 {
3220         unsigned int i;
3221
3222         options_init(fio_options);
3223
3224         i = 0;
3225         while (long_options[i].name)
3226                 i++;
3227
3228         options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
3229 }
3230
3231 struct fio_keyword {
3232         const char *word;
3233         const char *desc;
3234         char *replace;
3235 };
3236
3237 static struct fio_keyword fio_keywords[] = {
3238         {
3239                 .word   = "$pagesize",
3240                 .desc   = "Page size in the system",
3241         },
3242         {
3243                 .word   = "$mb_memory",
3244                 .desc   = "Megabytes of memory online",
3245         },
3246         {
3247                 .word   = "$ncpus",
3248                 .desc   = "Number of CPUs online in the system",
3249         },
3250         {
3251                 .word   = NULL,
3252         },
3253 };
3254
3255 void fio_keywords_init(void)
3256 {
3257         unsigned long long mb_memory;
3258         char buf[128];
3259         long l;
3260
3261         sprintf(buf, "%lu", (unsigned long) page_size);
3262         fio_keywords[0].replace = strdup(buf);
3263
3264         mb_memory = os_phys_mem() / (1024 * 1024);
3265         sprintf(buf, "%llu", mb_memory);
3266         fio_keywords[1].replace = strdup(buf);
3267
3268         l = cpus_online();
3269         sprintf(buf, "%lu", l);
3270         fio_keywords[2].replace = strdup(buf);
3271 }
3272
3273 #define BC_APP          "bc"
3274
3275 static char *bc_calc(char *str)
3276 {
3277         char buf[128], *tmp;
3278         FILE *f;
3279         int ret;
3280
3281         /*
3282          * No math, just return string
3283          */
3284         if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
3285              !strchr(str, '/')) || strchr(str, '\''))
3286                 return str;
3287
3288         /*
3289          * Split option from value, we only need to calculate the value
3290          */
3291         tmp = strchr(str, '=');
3292         if (!tmp)
3293                 return str;
3294
3295         tmp++;
3296
3297         /*
3298          * Prevent buffer overflows; such a case isn't reasonable anyway
3299          */
3300         if (strlen(str) >= 128 || strlen(tmp) > 100)
3301                 return str;
3302
3303         sprintf(buf, "which %s > /dev/null", BC_APP);
3304         if (system(buf)) {
3305                 log_err("fio: bc is needed for performing math\n");
3306                 return NULL;
3307         }
3308
3309         sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
3310         f = popen(buf, "r");
3311         if (!f)
3312                 return NULL;
3313
3314         ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
3315         if (ret <= 0)
3316                 return NULL;
3317
3318         pclose(f);
3319         buf[(tmp - str) + ret - 1] = '\0';
3320         memcpy(buf, str, tmp - str);
3321         free(str);
3322         return strdup(buf);
3323 }
3324
3325 /*
3326  * Return a copy of the input string with substrings of the form ${VARNAME}
3327  * substituted with the value of the environment variable VARNAME.  The
3328  * substitution always occurs, even if VARNAME is empty or the corresponding
3329  * environment variable undefined.
3330  */
3331 static char *option_dup_subs(const char *opt)
3332 {
3333         char out[OPT_LEN_MAX+1];
3334         char in[OPT_LEN_MAX+1];
3335         char *outptr = out;
3336         char *inptr = in;
3337         char *ch1, *ch2, *env;
3338         ssize_t nchr = OPT_LEN_MAX;
3339         size_t envlen;
3340
3341         if (strlen(opt) + 1 > OPT_LEN_MAX) {
3342                 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
3343                 return NULL;
3344         }
3345
3346         in[OPT_LEN_MAX] = '\0';
3347         strncpy(in, opt, OPT_LEN_MAX);
3348
3349         while (*inptr && nchr > 0) {
3350                 if (inptr[0] == '$' && inptr[1] == '{') {
3351                         ch2 = strchr(inptr, '}');
3352                         if (ch2 && inptr+1 < ch2) {
3353                                 ch1 = inptr+2;
3354                                 inptr = ch2+1;
3355                                 *ch2 = '\0';
3356
3357                                 env = getenv(ch1);
3358                                 if (env) {
3359                                         envlen = strlen(env);
3360                                         if (envlen <= nchr) {
3361                                                 memcpy(outptr, env, envlen);
3362                                                 outptr += envlen;
3363                                                 nchr -= envlen;
3364                                         }
3365                                 }
3366
3367                                 continue;
3368                         }
3369                 }
3370
3371                 *outptr++ = *inptr++;
3372                 --nchr;
3373         }
3374
3375         *outptr = '\0';
3376         return strdup(out);
3377 }
3378
3379 /*
3380  * Look for reserved variable names and replace them with real values
3381  */
3382 static char *fio_keyword_replace(char *opt)
3383 {
3384         char *s;
3385         int i;
3386         int docalc = 0;
3387
3388         for (i = 0; fio_keywords[i].word != NULL; i++) {
3389                 struct fio_keyword *kw = &fio_keywords[i];
3390
3391                 while ((s = strstr(opt, kw->word)) != NULL) {
3392                         char *new = malloc(strlen(opt) + 1);
3393                         char *o_org = opt;
3394                         int olen = s - opt;
3395                         int len;
3396
3397                         /*
3398                          * Copy part of the string before the keyword and
3399                          * sprintf() the replacement after it.
3400                          */
3401                         memcpy(new, opt, olen);
3402                         len = sprintf(new + olen, "%s", kw->replace);
3403
3404                         /*
3405                          * If there's more in the original string, copy that
3406                          * in too
3407                          */
3408                         opt += strlen(kw->word) + olen;
3409                         if (strlen(opt))
3410                                 memcpy(new + olen + len, opt, opt - o_org - 1);
3411
3412                         /*
3413                          * replace opt and free the old opt
3414                          */
3415                         opt = new;
3416                         free(o_org);
3417
3418                         docalc = 1;
3419                 }
3420         }
3421
3422         /*
3423          * Check for potential math and invoke bc, if possible
3424          */
3425         if (docalc)
3426                 opt = bc_calc(opt);
3427
3428         return opt;
3429 }
3430
3431 static char **dup_and_sub_options(char **opts, int num_opts)
3432 {
3433         int i;
3434         char **opts_copy = malloc(num_opts * sizeof(*opts));
3435         for (i = 0; i < num_opts; i++) {
3436                 opts_copy[i] = option_dup_subs(opts[i]);
3437                 if (!opts_copy[i])
3438                         continue;
3439                 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
3440         }
3441         return opts_copy;
3442 }
3443
3444 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
3445 {
3446         int i, ret, unknown;
3447         char **opts_copy;
3448
3449         sort_options(opts, fio_options, num_opts);
3450         opts_copy = dup_and_sub_options(opts, num_opts);
3451
3452         for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
3453                 struct fio_option *o;
3454                 int newret = parse_option(opts_copy[i], opts[i], fio_options,
3455                                                 &o, td);
3456
3457                 if (opts_copy[i]) {
3458                         if (newret && !o) {
3459                                 unknown++;
3460                                 continue;
3461                         }
3462                         free(opts_copy[i]);
3463                         opts_copy[i] = NULL;
3464                 }
3465
3466                 ret |= newret;
3467         }
3468
3469         if (unknown) {
3470                 ret |= ioengine_load(td);
3471                 if (td->eo) {
3472                         sort_options(opts_copy, td->io_ops->options, num_opts);
3473                         opts = opts_copy;
3474                 }
3475                 for (i = 0; i < num_opts; i++) {
3476                         struct fio_option *o = NULL;
3477                         int newret = 1;
3478                         if (!opts_copy[i])
3479                                 continue;
3480
3481                         if (td->eo)
3482                                 newret = parse_option(opts_copy[i], opts[i],
3483                                                       td->io_ops->options, &o,
3484                                                       td->eo);
3485
3486                         ret |= newret;
3487                         if (!o)
3488                                 log_err("Bad option <%s>\n", opts[i]);
3489
3490                         free(opts_copy[i]);
3491                         opts_copy[i] = NULL;
3492                 }
3493         }
3494
3495         free(opts_copy);
3496         return ret;
3497 }
3498
3499 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
3500 {
3501         return parse_cmd_option(opt, val, fio_options, td);
3502 }
3503
3504 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
3505                                 char *val)
3506 {
3507         return parse_cmd_option(opt, val, td->io_ops->options, td);
3508 }
3509
3510 void fio_fill_default_options(struct thread_data *td)
3511 {
3512         fill_default_options(td, fio_options);
3513 }
3514
3515 int fio_show_option_help(const char *opt)
3516 {
3517         return show_cmd_help(fio_options, opt);
3518 }
3519
3520 void options_mem_dupe(void *data, struct fio_option *options)
3521 {
3522         struct fio_option *o;
3523         char **ptr;
3524
3525         for (o = &options[0]; o->name; o++) {
3526                 if (o->type != FIO_OPT_STR_STORE)
3527                         continue;
3528
3529                 ptr = td_var(data, o->off1);
3530                 if (*ptr)
3531                         *ptr = strdup(*ptr);
3532         }
3533 }
3534
3535 /*
3536  * dupe FIO_OPT_STR_STORE options
3537  */
3538 void fio_options_mem_dupe(struct thread_data *td)
3539 {
3540         options_mem_dupe(&td->o, fio_options);
3541
3542         if (td->eo && td->io_ops) {
3543                 void *oldeo = td->eo;
3544
3545                 td->eo = malloc(td->io_ops->option_struct_size);
3546                 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
3547                 options_mem_dupe(td->eo, td->io_ops->options);
3548         }
3549 }
3550
3551 unsigned int fio_get_kb_base(void *data)
3552 {
3553         struct thread_options *o = data;
3554         unsigned int kb_base = 0;
3555
3556         if (o)
3557                 kb_base = o->kb_base;
3558         if (!kb_base)
3559                 kb_base = 1024;
3560
3561         return kb_base;
3562 }
3563
3564 int add_option(struct fio_option *o)
3565 {
3566         struct fio_option *__o;
3567         int opt_index = 0;
3568
3569         __o = fio_options;
3570         while (__o->name) {
3571                 opt_index++;
3572                 __o++;
3573         }
3574
3575         memcpy(&fio_options[opt_index], o, sizeof(*o));
3576         return 0;
3577 }
3578
3579 void invalidate_profile_options(const char *prof_name)
3580 {
3581         struct fio_option *o;
3582
3583         o = fio_options;
3584         while (o->name) {
3585                 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
3586                         o->type = FIO_OPT_INVALID;
3587                         o->prof_name = NULL;
3588                 }
3589                 o++;
3590         }
3591 }
3592
3593 void add_opt_posval(const char *optname, const char *ival, const char *help)
3594 {
3595         struct fio_option *o;
3596         unsigned int i;
3597
3598         o = find_option(fio_options, optname);
3599         if (!o)
3600                 return;
3601
3602         for (i = 0; i < PARSE_MAX_VP; i++) {
3603                 if (o->posval[i].ival)
3604                         continue;
3605
3606                 o->posval[i].ival = ival;
3607                 o->posval[i].help = help;
3608                 break;
3609         }
3610 }
3611
3612 void del_opt_posval(const char *optname, const char *ival)
3613 {
3614         struct fio_option *o;
3615         unsigned int i;
3616
3617         o = find_option(fio_options, optname);
3618         if (!o)
3619                 return;
3620
3621         for (i = 0; i < PARSE_MAX_VP; i++) {
3622                 if (!o->posval[i].ival)
3623                         continue;
3624                 if (strcmp(o->posval[i].ival, ival))
3625                         continue;
3626
3627                 o->posval[i].ival = NULL;
3628                 o->posval[i].help = NULL;
3629         }
3630 }
3631
3632 void fio_options_free(struct thread_data *td)
3633 {
3634         options_free(fio_options, td);
3635         if (td->eo && td->io_ops && td->io_ops->options) {
3636                 options_free(td->io_ops->options, td->eo);
3637                 free(td->eo);
3638                 td->eo = NULL;
3639         }
3640 }
3641
3642 struct fio_option *fio_option_find(const char *name)
3643 {
3644         return find_option(fio_options, name);
3645 }
3646