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