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