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