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