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