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