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