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