Make fio -Wshadow clean
[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_DEPRECATED,
1846                 .off1   = td_var_offset(dep_use_os_rand),
1847                 .category = FIO_OPT_C_IO,
1848                 .group  = FIO_OPT_G_RANDOM,
1849         },
1850         {
1851                 .name   = "norandommap",
1852                 .lname  = "No randommap",
1853                 .type   = FIO_OPT_STR_SET,
1854                 .off1   = td_var_offset(norandommap),
1855                 .help   = "Accept potential duplicate random blocks",
1856                 .parent = "rw",
1857                 .hide   = 1,
1858                 .hide_on_set = 1,
1859                 .category = FIO_OPT_C_IO,
1860                 .group  = FIO_OPT_G_RANDOM,
1861         },
1862         {
1863                 .name   = "softrandommap",
1864                 .lname  = "Soft randommap",
1865                 .type   = FIO_OPT_BOOL,
1866                 .off1   = td_var_offset(softrandommap),
1867                 .help   = "Set norandommap if randommap allocation fails",
1868                 .parent = "norandommap",
1869                 .hide   = 1,
1870                 .def    = "0",
1871                 .category = FIO_OPT_C_IO,
1872                 .group  = FIO_OPT_G_RANDOM,
1873         },
1874         {
1875                 .name   = "random_generator",
1876                 .type   = FIO_OPT_STR,
1877                 .off1   = td_var_offset(random_generator),
1878                 .help   = "Type of random number generator to use",
1879                 .def    = "tausworthe",
1880                 .posval = {
1881                           { .ival = "tausworthe",
1882                             .oval = FIO_RAND_GEN_TAUSWORTHE,
1883                             .help = "Strong Tausworthe generator",
1884                           },
1885                           { .ival = "lfsr",
1886                             .oval = FIO_RAND_GEN_LFSR,
1887                             .help = "Variable length LFSR",
1888                           },
1889                 },
1890                 .category = FIO_OPT_C_IO,
1891                 .group  = FIO_OPT_G_RANDOM,
1892         },
1893         {
1894                 .name   = "random_distribution",
1895                 .type   = FIO_OPT_STR,
1896                 .off1   = td_var_offset(random_distribution),
1897                 .cb     = str_random_distribution_cb,
1898                 .help   = "Random offset distribution generator",
1899                 .def    = "random",
1900                 .posval = {
1901                           { .ival = "random",
1902                             .oval = FIO_RAND_DIST_RANDOM,
1903                             .help = "Completely random",
1904                           },
1905                           { .ival = "zipf",
1906                             .oval = FIO_RAND_DIST_ZIPF,
1907                             .help = "Zipf distribution",
1908                           },
1909                           { .ival = "pareto",
1910                             .oval = FIO_RAND_DIST_PARETO,
1911                             .help = "Pareto distribution",
1912                           },
1913                 },
1914                 .category = FIO_OPT_C_IO,
1915                 .group  = FIO_OPT_G_RANDOM,
1916         },
1917         {
1918                 .name   = "percentage_random",
1919                 .lname  = "Percentage Random",
1920                 .type   = FIO_OPT_INT,
1921                 .off1   = td_var_offset(perc_rand[DDIR_READ]),
1922                 .off2   = td_var_offset(perc_rand[DDIR_WRITE]),
1923                 .off3   = td_var_offset(perc_rand[DDIR_TRIM]),
1924                 .maxval = 100,
1925                 .help   = "Percentage of seq/random mix that should be random",
1926                 .def    = "100,100,100",
1927                 .interval = 5,
1928                 .inverse = "percentage_sequential",
1929                 .category = FIO_OPT_C_IO,
1930                 .group  = FIO_OPT_G_RANDOM,
1931         },
1932         {
1933                 .name   = "percentage_sequential",
1934                 .lname  = "Percentage Sequential",
1935                 .type   = FIO_OPT_DEPRECATED,
1936                 .category = FIO_OPT_C_IO,
1937                 .group  = FIO_OPT_G_RANDOM,
1938         },
1939         {
1940                 .name   = "allrandrepeat",
1941                 .type   = FIO_OPT_BOOL,
1942                 .off1   = td_var_offset(allrand_repeatable),
1943                 .help   = "Use repeatable random numbers for everything",
1944                 .def    = "0",
1945                 .category = FIO_OPT_C_IO,
1946                 .group  = FIO_OPT_G_RANDOM,
1947         },
1948         {
1949                 .name   = "nrfiles",
1950                 .lname  = "Number of files",
1951                 .alias  = "nr_files",
1952                 .type   = FIO_OPT_INT,
1953                 .off1   = td_var_offset(nr_files),
1954                 .help   = "Split job workload between this number of files",
1955                 .def    = "1",
1956                 .interval = 1,
1957                 .category = FIO_OPT_C_FILE,
1958                 .group  = FIO_OPT_G_INVALID,
1959         },
1960         {
1961                 .name   = "openfiles",
1962                 .lname  = "Number of open files",
1963                 .type   = FIO_OPT_INT,
1964                 .off1   = td_var_offset(open_files),
1965                 .help   = "Number of files to keep open at the same time",
1966                 .category = FIO_OPT_C_FILE,
1967                 .group  = FIO_OPT_G_INVALID,
1968         },
1969         {
1970                 .name   = "file_service_type",
1971                 .lname  = "File service type",
1972                 .type   = FIO_OPT_STR,
1973                 .cb     = str_fst_cb,
1974                 .off1   = td_var_offset(file_service_type),
1975                 .help   = "How to select which file to service next",
1976                 .def    = "roundrobin",
1977                 .category = FIO_OPT_C_FILE,
1978                 .group  = FIO_OPT_G_INVALID,
1979                 .posval = {
1980                           { .ival = "random",
1981                             .oval = FIO_FSERVICE_RANDOM,
1982                             .help = "Choose a file at random",
1983                           },
1984                           { .ival = "roundrobin",
1985                             .oval = FIO_FSERVICE_RR,
1986                             .help = "Round robin select files",
1987                           },
1988                           { .ival = "sequential",
1989                             .oval = FIO_FSERVICE_SEQ,
1990                             .help = "Finish one file before moving to the next",
1991                           },
1992                 },
1993                 .parent = "nrfiles",
1994                 .hide   = 1,
1995         },
1996 #ifdef CONFIG_POSIX_FALLOCATE
1997         {
1998                 .name   = "fallocate",
1999                 .lname  = "Fallocate",
2000                 .type   = FIO_OPT_STR,
2001                 .off1   = td_var_offset(fallocate_mode),
2002                 .help   = "Whether pre-allocation is performed when laying out files",
2003                 .def    = "posix",
2004                 .category = FIO_OPT_C_FILE,
2005                 .group  = FIO_OPT_G_INVALID,
2006                 .posval = {
2007                           { .ival = "none",
2008                             .oval = FIO_FALLOCATE_NONE,
2009                             .help = "Do not pre-allocate space",
2010                           },
2011                           { .ival = "posix",
2012                             .oval = FIO_FALLOCATE_POSIX,
2013                             .help = "Use posix_fallocate()",
2014                           },
2015 #ifdef CONFIG_LINUX_FALLOCATE
2016                           { .ival = "keep",
2017                             .oval = FIO_FALLOCATE_KEEP_SIZE,
2018                             .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
2019                           },
2020 #endif
2021                           /* Compatibility with former boolean values */
2022                           { .ival = "0",
2023                             .oval = FIO_FALLOCATE_NONE,
2024                             .help = "Alias for 'none'",
2025                           },
2026                           { .ival = "1",
2027                             .oval = FIO_FALLOCATE_POSIX,
2028                             .help = "Alias for 'posix'",
2029                           },
2030                 },
2031         },
2032 #endif  /* CONFIG_POSIX_FALLOCATE */
2033         {
2034                 .name   = "fadvise_hint",
2035                 .lname  = "Fadvise hint",
2036                 .type   = FIO_OPT_BOOL,
2037                 .off1   = td_var_offset(fadvise_hint),
2038                 .help   = "Use fadvise() to advise the kernel on IO pattern",
2039                 .def    = "1",
2040                 .category = FIO_OPT_C_FILE,
2041                 .group  = FIO_OPT_G_INVALID,
2042         },
2043         {
2044                 .name   = "fsync",
2045                 .lname  = "Fsync",
2046                 .type   = FIO_OPT_INT,
2047                 .off1   = td_var_offset(fsync_blocks),
2048                 .help   = "Issue fsync for writes every given number of blocks",
2049                 .def    = "0",
2050                 .interval = 1,
2051                 .category = FIO_OPT_C_FILE,
2052                 .group  = FIO_OPT_G_INVALID,
2053         },
2054         {
2055                 .name   = "fdatasync",
2056                 .lname  = "Fdatasync",
2057                 .type   = FIO_OPT_INT,
2058                 .off1   = td_var_offset(fdatasync_blocks),
2059                 .help   = "Issue fdatasync for writes every given number of blocks",
2060                 .def    = "0",
2061                 .interval = 1,
2062                 .category = FIO_OPT_C_FILE,
2063                 .group  = FIO_OPT_G_INVALID,
2064         },
2065         {
2066                 .name   = "write_barrier",
2067                 .lname  = "Write barrier",
2068                 .type   = FIO_OPT_INT,
2069                 .off1   = td_var_offset(barrier_blocks),
2070                 .help   = "Make every Nth write a barrier write",
2071                 .def    = "0",
2072                 .interval = 1,
2073                 .category = FIO_OPT_C_IO,
2074                 .group  = FIO_OPT_G_INVALID,
2075         },
2076 #ifdef CONFIG_SYNC_FILE_RANGE
2077         {
2078                 .name   = "sync_file_range",
2079                 .lname  = "Sync file range",
2080                 .posval = {
2081                           { .ival = "wait_before",
2082                             .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
2083                             .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
2084                             .orval  = 1,
2085                           },
2086                           { .ival = "write",
2087                             .oval = SYNC_FILE_RANGE_WRITE,
2088                             .help = "SYNC_FILE_RANGE_WRITE",
2089                             .orval  = 1,
2090                           },
2091                           {
2092                             .ival = "wait_after",
2093                             .oval = SYNC_FILE_RANGE_WAIT_AFTER,
2094                             .help = "SYNC_FILE_RANGE_WAIT_AFTER",
2095                             .orval  = 1,
2096                           },
2097                 },
2098                 .type   = FIO_OPT_STR_MULTI,
2099                 .cb     = str_sfr_cb,
2100                 .off1   = td_var_offset(sync_file_range),
2101                 .help   = "Use sync_file_range()",
2102                 .category = FIO_OPT_C_FILE,
2103                 .group  = FIO_OPT_G_INVALID,
2104         },
2105 #endif
2106         {
2107                 .name   = "direct",
2108                 .lname  = "Direct I/O",
2109                 .type   = FIO_OPT_BOOL,
2110                 .off1   = td_var_offset(odirect),
2111                 .help   = "Use O_DIRECT IO (negates buffered)",
2112                 .def    = "0",
2113                 .inverse = "buffered",
2114                 .category = FIO_OPT_C_IO,
2115                 .group  = FIO_OPT_G_IO_TYPE,
2116         },
2117         {
2118                 .name   = "atomic",
2119                 .lname  = "Atomic I/O",
2120                 .type   = FIO_OPT_BOOL,
2121                 .off1   = td_var_offset(oatomic),
2122                 .help   = "Use Atomic IO with O_DIRECT (implies O_DIRECT)",
2123                 .def    = "0",
2124                 .category = FIO_OPT_C_IO,
2125                 .group  = FIO_OPT_G_IO_TYPE,
2126         },
2127         {
2128                 .name   = "buffered",
2129                 .lname  = "Buffered I/O",
2130                 .type   = FIO_OPT_BOOL,
2131                 .off1   = td_var_offset(odirect),
2132                 .neg    = 1,
2133                 .help   = "Use buffered IO (negates direct)",
2134                 .def    = "1",
2135                 .inverse = "direct",
2136                 .category = FIO_OPT_C_IO,
2137                 .group  = FIO_OPT_G_IO_TYPE,
2138         },
2139         {
2140                 .name   = "overwrite",
2141                 .lname  = "Overwrite",
2142                 .type   = FIO_OPT_BOOL,
2143                 .off1   = td_var_offset(overwrite),
2144                 .help   = "When writing, set whether to overwrite current data",
2145                 .def    = "0",
2146                 .category = FIO_OPT_C_FILE,
2147                 .group  = FIO_OPT_G_INVALID,
2148         },
2149         {
2150                 .name   = "loops",
2151                 .lname  = "Loops",
2152                 .type   = FIO_OPT_INT,
2153                 .off1   = td_var_offset(loops),
2154                 .help   = "Number of times to run the job",
2155                 .def    = "1",
2156                 .interval = 1,
2157                 .category = FIO_OPT_C_GENERAL,
2158                 .group  = FIO_OPT_G_RUNTIME,
2159         },
2160         {
2161                 .name   = "numjobs",
2162                 .lname  = "Number of jobs",
2163                 .type   = FIO_OPT_INT,
2164                 .off1   = td_var_offset(numjobs),
2165                 .help   = "Duplicate this job this many times",
2166                 .def    = "1",
2167                 .interval = 1,
2168                 .category = FIO_OPT_C_GENERAL,
2169                 .group  = FIO_OPT_G_RUNTIME,
2170         },
2171         {
2172                 .name   = "startdelay",
2173                 .lname  = "Start delay",
2174                 .type   = FIO_OPT_STR_VAL_TIME,
2175                 .off1   = td_var_offset(start_delay),
2176                 .off2   = td_var_offset(start_delay_high),
2177                 .help   = "Only start job when this period has passed",
2178                 .def    = "0",
2179                 .is_seconds = 1,
2180                 .category = FIO_OPT_C_GENERAL,
2181                 .group  = FIO_OPT_G_RUNTIME,
2182         },
2183         {
2184                 .name   = "runtime",
2185                 .lname  = "Runtime",
2186                 .alias  = "timeout",
2187                 .type   = FIO_OPT_STR_VAL_TIME,
2188                 .off1   = td_var_offset(timeout),
2189                 .help   = "Stop workload when this amount of time has passed",
2190                 .def    = "0",
2191                 .is_seconds = 1,
2192                 .category = FIO_OPT_C_GENERAL,
2193                 .group  = FIO_OPT_G_RUNTIME,
2194         },
2195         {
2196                 .name   = "time_based",
2197                 .lname  = "Time based",
2198                 .type   = FIO_OPT_STR_SET,
2199                 .off1   = td_var_offset(time_based),
2200                 .help   = "Keep running until runtime/timeout is met",
2201                 .category = FIO_OPT_C_GENERAL,
2202                 .group  = FIO_OPT_G_RUNTIME,
2203         },
2204         {
2205                 .name   = "verify_only",
2206                 .lname  = "Verify only",
2207                 .type   = FIO_OPT_STR_SET,
2208                 .off1   = td_var_offset(verify_only),
2209                 .help   = "Verifies previously written data is still valid",
2210                 .category = FIO_OPT_C_GENERAL,
2211                 .group  = FIO_OPT_G_RUNTIME,
2212         },
2213         {
2214                 .name   = "ramp_time",
2215                 .lname  = "Ramp time",
2216                 .type   = FIO_OPT_STR_VAL_TIME,
2217                 .off1   = td_var_offset(ramp_time),
2218                 .help   = "Ramp up time before measuring performance",
2219                 .is_seconds = 1,
2220                 .category = FIO_OPT_C_GENERAL,
2221                 .group  = FIO_OPT_G_RUNTIME,
2222         },
2223         {
2224                 .name   = "clocksource",
2225                 .lname  = "Clock source",
2226                 .type   = FIO_OPT_STR,
2227                 .cb     = fio_clock_source_cb,
2228                 .off1   = td_var_offset(clocksource),
2229                 .help   = "What type of timing source to use",
2230                 .category = FIO_OPT_C_GENERAL,
2231                 .group  = FIO_OPT_G_CLOCK,
2232                 .posval = {
2233 #ifdef CONFIG_GETTIMEOFDAY
2234                           { .ival = "gettimeofday",
2235                             .oval = CS_GTOD,
2236                             .help = "Use gettimeofday(2) for timing",
2237                           },
2238 #endif
2239 #ifdef CONFIG_CLOCK_GETTIME
2240                           { .ival = "clock_gettime",
2241                             .oval = CS_CGETTIME,
2242                             .help = "Use clock_gettime(2) for timing",
2243                           },
2244 #endif
2245 #ifdef ARCH_HAVE_CPU_CLOCK
2246                           { .ival = "cpu",
2247                             .oval = CS_CPUCLOCK,
2248                             .help = "Use CPU private clock",
2249                           },
2250 #endif
2251                 },
2252         },
2253         {
2254                 .name   = "mem",
2255                 .alias  = "iomem",
2256                 .lname  = "I/O Memory",
2257                 .type   = FIO_OPT_STR,
2258                 .cb     = str_mem_cb,
2259                 .off1   = td_var_offset(mem_type),
2260                 .help   = "Backing type for IO buffers",
2261                 .def    = "malloc",
2262                 .category = FIO_OPT_C_IO,
2263                 .group  = FIO_OPT_G_INVALID,
2264                 .posval = {
2265                           { .ival = "malloc",
2266                             .oval = MEM_MALLOC,
2267                             .help = "Use malloc(3) for IO buffers",
2268                           },
2269 #ifndef CONFIG_NO_SHM
2270                           { .ival = "shm",
2271                             .oval = MEM_SHM,
2272                             .help = "Use shared memory segments for IO buffers",
2273                           },
2274 #ifdef FIO_HAVE_HUGETLB
2275                           { .ival = "shmhuge",
2276                             .oval = MEM_SHMHUGE,
2277                             .help = "Like shm, but use huge pages",
2278                           },
2279 #endif
2280 #endif
2281                           { .ival = "mmap",
2282                             .oval = MEM_MMAP,
2283                             .help = "Use mmap(2) (file or anon) for IO buffers",
2284                           },
2285 #ifdef FIO_HAVE_HUGETLB
2286                           { .ival = "mmaphuge",
2287                             .oval = MEM_MMAPHUGE,
2288                             .help = "Like mmap, but use huge pages",
2289                           },
2290 #endif
2291                   },
2292         },
2293         {
2294                 .name   = "iomem_align",
2295                 .alias  = "mem_align",
2296                 .lname  = "I/O memory alignment",
2297                 .type   = FIO_OPT_INT,
2298                 .off1   = td_var_offset(mem_align),
2299                 .minval = 0,
2300                 .help   = "IO memory buffer offset alignment",
2301                 .def    = "0",
2302                 .parent = "iomem",
2303                 .hide   = 1,
2304                 .category = FIO_OPT_C_IO,
2305                 .group  = FIO_OPT_G_INVALID,
2306         },
2307         {
2308                 .name   = "verify",
2309                 .lname  = "Verify",
2310                 .type   = FIO_OPT_STR,
2311                 .off1   = td_var_offset(verify),
2312                 .help   = "Verify data written",
2313                 .def    = "0",
2314                 .category = FIO_OPT_C_IO,
2315                 .group  = FIO_OPT_G_VERIFY,
2316                 .posval = {
2317                           { .ival = "0",
2318                             .oval = VERIFY_NONE,
2319                             .help = "Don't do IO verification",
2320                           },
2321                           { .ival = "md5",
2322                             .oval = VERIFY_MD5,
2323                             .help = "Use md5 checksums for verification",
2324                           },
2325                           { .ival = "crc64",
2326                             .oval = VERIFY_CRC64,
2327                             .help = "Use crc64 checksums for verification",
2328                           },
2329                           { .ival = "crc32",
2330                             .oval = VERIFY_CRC32,
2331                             .help = "Use crc32 checksums for verification",
2332                           },
2333                           { .ival = "crc32c-intel",
2334                             .oval = VERIFY_CRC32C,
2335                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
2336                           },
2337                           { .ival = "crc32c",
2338                             .oval = VERIFY_CRC32C,
2339                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
2340                           },
2341                           { .ival = "crc16",
2342                             .oval = VERIFY_CRC16,
2343                             .help = "Use crc16 checksums for verification",
2344                           },
2345                           { .ival = "crc7",
2346                             .oval = VERIFY_CRC7,
2347                             .help = "Use crc7 checksums for verification",
2348                           },
2349                           { .ival = "sha1",
2350                             .oval = VERIFY_SHA1,
2351                             .help = "Use sha1 checksums for verification",
2352                           },
2353                           { .ival = "sha256",
2354                             .oval = VERIFY_SHA256,
2355                             .help = "Use sha256 checksums for verification",
2356                           },
2357                           { .ival = "sha512",
2358                             .oval = VERIFY_SHA512,
2359                             .help = "Use sha512 checksums for verification",
2360                           },
2361                           { .ival = "xxhash",
2362                             .oval = VERIFY_XXHASH,
2363                             .help = "Use xxhash checksums for verification",
2364                           },
2365                           { .ival = "meta",
2366                             .oval = VERIFY_META,
2367                             .help = "Use io information",
2368                           },
2369                           {
2370                             .ival = "null",
2371                             .oval = VERIFY_NULL,
2372                             .help = "Pretend to verify",
2373                           },
2374                 },
2375         },
2376         {
2377                 .name   = "do_verify",
2378                 .lname  = "Perform verify step",
2379                 .type   = FIO_OPT_BOOL,
2380                 .off1   = td_var_offset(do_verify),
2381                 .help   = "Run verification stage after write",
2382                 .def    = "1",
2383                 .parent = "verify",
2384                 .hide   = 1,
2385                 .category = FIO_OPT_C_IO,
2386                 .group  = FIO_OPT_G_VERIFY,
2387         },
2388         {
2389                 .name   = "verifysort",
2390                 .lname  = "Verify sort",
2391                 .type   = FIO_OPT_BOOL,
2392                 .off1   = td_var_offset(verifysort),
2393                 .help   = "Sort written verify blocks for read back",
2394                 .def    = "1",
2395                 .parent = "verify",
2396                 .hide   = 1,
2397                 .category = FIO_OPT_C_IO,
2398                 .group  = FIO_OPT_G_VERIFY,
2399         },
2400         {
2401                 .name   = "verifysort_nr",
2402                 .type   = FIO_OPT_INT,
2403                 .off1   = td_var_offset(verifysort_nr),
2404                 .help   = "Pre-load and sort verify blocks for a read workload",
2405                 .minval = 0,
2406                 .maxval = 131072,
2407                 .def    = "1024",
2408                 .parent = "verify",
2409                 .category = FIO_OPT_C_IO,
2410                 .group  = FIO_OPT_G_VERIFY,
2411         },
2412         {
2413                 .name   = "verify_interval",
2414                 .lname  = "Verify interval",
2415                 .type   = FIO_OPT_INT,
2416                 .off1   = td_var_offset(verify_interval),
2417                 .minval = 2 * sizeof(struct verify_header),
2418                 .help   = "Store verify buffer header every N bytes",
2419                 .parent = "verify",
2420                 .hide   = 1,
2421                 .interval = 2 * sizeof(struct verify_header),
2422                 .category = FIO_OPT_C_IO,
2423                 .group  = FIO_OPT_G_VERIFY,
2424         },
2425         {
2426                 .name   = "verify_offset",
2427                 .lname  = "Verify offset",
2428                 .type   = FIO_OPT_INT,
2429                 .help   = "Offset verify header location by N bytes",
2430                 .off1   = td_var_offset(verify_offset),
2431                 .minval = sizeof(struct verify_header),
2432                 .parent = "verify",
2433                 .hide   = 1,
2434                 .category = FIO_OPT_C_IO,
2435                 .group  = FIO_OPT_G_VERIFY,
2436         },
2437         {
2438                 .name   = "verify_pattern",
2439                 .lname  = "Verify pattern",
2440                 .type   = FIO_OPT_STR,
2441                 .cb     = str_verify_pattern_cb,
2442                 .help   = "Fill pattern for IO buffers",
2443                 .parent = "verify",
2444                 .hide   = 1,
2445                 .category = FIO_OPT_C_IO,
2446                 .group  = FIO_OPT_G_VERIFY,
2447         },
2448         {
2449                 .name   = "verify_fatal",
2450                 .lname  = "Verify fatal",
2451                 .type   = FIO_OPT_BOOL,
2452                 .off1   = td_var_offset(verify_fatal),
2453                 .def    = "0",
2454                 .help   = "Exit on a single verify failure, don't continue",
2455                 .parent = "verify",
2456                 .hide   = 1,
2457                 .category = FIO_OPT_C_IO,
2458                 .group  = FIO_OPT_G_VERIFY,
2459         },
2460         {
2461                 .name   = "verify_dump",
2462                 .lname  = "Verify dump",
2463                 .type   = FIO_OPT_BOOL,
2464                 .off1   = td_var_offset(verify_dump),
2465                 .def    = "0",
2466                 .help   = "Dump contents of good and bad blocks on failure",
2467                 .parent = "verify",
2468                 .hide   = 1,
2469                 .category = FIO_OPT_C_IO,
2470                 .group  = FIO_OPT_G_VERIFY,
2471         },
2472         {
2473                 .name   = "verify_async",
2474                 .lname  = "Verify asynchronously",
2475                 .type   = FIO_OPT_INT,
2476                 .off1   = td_var_offset(verify_async),
2477                 .def    = "0",
2478                 .help   = "Number of async verifier threads to use",
2479                 .parent = "verify",
2480                 .hide   = 1,
2481                 .category = FIO_OPT_C_IO,
2482                 .group  = FIO_OPT_G_VERIFY,
2483         },
2484         {
2485                 .name   = "verify_backlog",
2486                 .lname  = "Verify backlog",
2487                 .type   = FIO_OPT_STR_VAL,
2488                 .off1   = td_var_offset(verify_backlog),
2489                 .help   = "Verify after this number of blocks are written",
2490                 .parent = "verify",
2491                 .hide   = 1,
2492                 .category = FIO_OPT_C_IO,
2493                 .group  = FIO_OPT_G_VERIFY,
2494         },
2495         {
2496                 .name   = "verify_backlog_batch",
2497                 .lname  = "Verify backlog batch",
2498                 .type   = FIO_OPT_INT,
2499                 .off1   = td_var_offset(verify_batch),
2500                 .help   = "Verify this number of IO blocks",
2501                 .parent = "verify",
2502                 .hide   = 1,
2503                 .category = FIO_OPT_C_IO,
2504                 .group  = FIO_OPT_G_VERIFY,
2505         },
2506 #ifdef FIO_HAVE_CPU_AFFINITY
2507         {
2508                 .name   = "verify_async_cpus",
2509                 .lname  = "Async verify CPUs",
2510                 .type   = FIO_OPT_STR,
2511                 .cb     = str_verify_cpus_allowed_cb,
2512                 .help   = "Set CPUs allowed for async verify threads",
2513                 .parent = "verify_async",
2514                 .hide   = 1,
2515                 .category = FIO_OPT_C_IO,
2516                 .group  = FIO_OPT_G_VERIFY,
2517         },
2518 #endif
2519         {
2520                 .name   = "experimental_verify",
2521                 .off1   = td_var_offset(experimental_verify),
2522                 .type   = FIO_OPT_BOOL,
2523                 .help   = "Enable experimental verification",
2524                 .category = FIO_OPT_C_IO,
2525                 .group  = FIO_OPT_G_VERIFY,
2526         },
2527 #ifdef FIO_HAVE_TRIM
2528         {
2529                 .name   = "trim_percentage",
2530                 .lname  = "Trim percentage",
2531                 .type   = FIO_OPT_INT,
2532                 .off1   = td_var_offset(trim_percentage),
2533                 .minval = 0,
2534                 .maxval = 100,
2535                 .help   = "Number of verify blocks to discard/trim",
2536                 .parent = "verify",
2537                 .def    = "0",
2538                 .interval = 1,
2539                 .hide   = 1,
2540                 .category = FIO_OPT_C_IO,
2541                 .group  = FIO_OPT_G_TRIM,
2542         },
2543         {
2544                 .name   = "trim_verify_zero",
2545                 .lname  = "Verify trim zero",
2546                 .type   = FIO_OPT_BOOL,
2547                 .help   = "Verify that trim/discarded blocks are returned as zeroes",
2548                 .off1   = td_var_offset(trim_zero),
2549                 .parent = "trim_percentage",
2550                 .hide   = 1,
2551                 .def    = "1",
2552                 .category = FIO_OPT_C_IO,
2553                 .group  = FIO_OPT_G_TRIM,
2554         },
2555         {
2556                 .name   = "trim_backlog",
2557                 .lname  = "Trim backlog",
2558                 .type   = FIO_OPT_STR_VAL,
2559                 .off1   = td_var_offset(trim_backlog),
2560                 .help   = "Trim after this number of blocks are written",
2561                 .parent = "trim_percentage",
2562                 .hide   = 1,
2563                 .interval = 1,
2564                 .category = FIO_OPT_C_IO,
2565                 .group  = FIO_OPT_G_TRIM,
2566         },
2567         {
2568                 .name   = "trim_backlog_batch",
2569                 .lname  = "Trim backlog batch",
2570                 .type   = FIO_OPT_INT,
2571                 .off1   = td_var_offset(trim_batch),
2572                 .help   = "Trim this number of IO blocks",
2573                 .parent = "trim_percentage",
2574                 .hide   = 1,
2575                 .interval = 1,
2576                 .category = FIO_OPT_C_IO,
2577                 .group  = FIO_OPT_G_TRIM,
2578         },
2579 #endif
2580         {
2581                 .name   = "write_iolog",
2582                 .lname  = "Write I/O log",
2583                 .type   = FIO_OPT_STR_STORE,
2584                 .off1   = td_var_offset(write_iolog_file),
2585                 .help   = "Store IO pattern to file",
2586                 .category = FIO_OPT_C_IO,
2587                 .group  = FIO_OPT_G_IOLOG,
2588         },
2589         {
2590                 .name   = "read_iolog",
2591                 .lname  = "Read I/O log",
2592                 .type   = FIO_OPT_STR_STORE,
2593                 .off1   = td_var_offset(read_iolog_file),
2594                 .help   = "Playback IO pattern from file",
2595                 .category = FIO_OPT_C_IO,
2596                 .group  = FIO_OPT_G_IOLOG,
2597         },
2598         {
2599                 .name   = "replay_no_stall",
2600                 .lname  = "Don't stall on replay",
2601                 .type   = FIO_OPT_BOOL,
2602                 .off1   = td_var_offset(no_stall),
2603                 .def    = "0",
2604                 .parent = "read_iolog",
2605                 .hide   = 1,
2606                 .help   = "Playback IO pattern file as fast as possible without stalls",
2607                 .category = FIO_OPT_C_IO,
2608                 .group  = FIO_OPT_G_IOLOG,
2609         },
2610         {
2611                 .name   = "replay_redirect",
2612                 .lname  = "Redirect device for replay",
2613                 .type   = FIO_OPT_STR_STORE,
2614                 .off1   = td_var_offset(replay_redirect),
2615                 .parent = "read_iolog",
2616                 .hide   = 1,
2617                 .help   = "Replay all I/O onto this device, regardless of trace device",
2618                 .category = FIO_OPT_C_IO,
2619                 .group  = FIO_OPT_G_IOLOG,
2620         },
2621         {
2622                 .name   = "exec_prerun",
2623                 .lname  = "Pre-execute runnable",
2624                 .type   = FIO_OPT_STR_STORE,
2625                 .off1   = td_var_offset(exec_prerun),
2626                 .help   = "Execute this file prior to running job",
2627                 .category = FIO_OPT_C_GENERAL,
2628                 .group  = FIO_OPT_G_INVALID,
2629         },
2630         {
2631                 .name   = "exec_postrun",
2632                 .lname  = "Post-execute runnable",
2633                 .type   = FIO_OPT_STR_STORE,
2634                 .off1   = td_var_offset(exec_postrun),
2635                 .help   = "Execute this file after running job",
2636                 .category = FIO_OPT_C_GENERAL,
2637                 .group  = FIO_OPT_G_INVALID,
2638         },
2639 #ifdef FIO_HAVE_IOSCHED_SWITCH
2640         {
2641                 .name   = "ioscheduler",
2642                 .lname  = "I/O scheduler",
2643                 .type   = FIO_OPT_STR_STORE,
2644                 .off1   = td_var_offset(ioscheduler),
2645                 .help   = "Use this IO scheduler on the backing device",
2646                 .category = FIO_OPT_C_FILE,
2647                 .group  = FIO_OPT_G_INVALID,
2648         },
2649 #endif
2650         {
2651                 .name   = "zonesize",
2652                 .lname  = "Zone size",
2653                 .type   = FIO_OPT_STR_VAL,
2654                 .off1   = td_var_offset(zone_size),
2655                 .help   = "Amount of data to read per zone",
2656                 .def    = "0",
2657                 .interval = 1024 * 1024,
2658                 .category = FIO_OPT_C_IO,
2659                 .group  = FIO_OPT_G_ZONE,
2660         },
2661         {
2662                 .name   = "zonerange",
2663                 .lname  = "Zone range",
2664                 .type   = FIO_OPT_STR_VAL,
2665                 .off1   = td_var_offset(zone_range),
2666                 .help   = "Give size of an IO zone",
2667                 .def    = "0",
2668                 .interval = 1024 * 1024,
2669                 .category = FIO_OPT_C_IO,
2670                 .group  = FIO_OPT_G_ZONE,
2671         },
2672         {
2673                 .name   = "zoneskip",
2674                 .lname  = "Zone skip",
2675                 .type   = FIO_OPT_STR_VAL,
2676                 .off1   = td_var_offset(zone_skip),
2677                 .help   = "Space between IO zones",
2678                 .def    = "0",
2679                 .interval = 1024 * 1024,
2680                 .category = FIO_OPT_C_IO,
2681                 .group  = FIO_OPT_G_ZONE,
2682         },
2683         {
2684                 .name   = "lockmem",
2685                 .lname  = "Lock memory",
2686                 .type   = FIO_OPT_STR_VAL,
2687                 .off1   = td_var_offset(lockmem),
2688                 .help   = "Lock down this amount of memory (per worker)",
2689                 .def    = "0",
2690                 .interval = 1024 * 1024,
2691                 .category = FIO_OPT_C_GENERAL,
2692                 .group  = FIO_OPT_G_INVALID,
2693         },
2694         {
2695                 .name   = "rwmixread",
2696                 .lname  = "Read/write mix read",
2697                 .type   = FIO_OPT_INT,
2698                 .cb     = str_rwmix_read_cb,
2699                 .maxval = 100,
2700                 .help   = "Percentage of mixed workload that is reads",
2701                 .def    = "50",
2702                 .interval = 5,
2703                 .inverse = "rwmixwrite",
2704                 .category = FIO_OPT_C_IO,
2705                 .group  = FIO_OPT_G_RWMIX,
2706         },
2707         {
2708                 .name   = "rwmixwrite",
2709                 .lname  = "Read/write mix write",
2710                 .type   = FIO_OPT_INT,
2711                 .cb     = str_rwmix_write_cb,
2712                 .maxval = 100,
2713                 .help   = "Percentage of mixed workload that is writes",
2714                 .def    = "50",
2715                 .interval = 5,
2716                 .inverse = "rwmixread",
2717                 .category = FIO_OPT_C_IO,
2718                 .group  = FIO_OPT_G_RWMIX,
2719         },
2720         {
2721                 .name   = "rwmixcycle",
2722                 .lname  = "Read/write mix cycle",
2723                 .type   = FIO_OPT_DEPRECATED,
2724                 .category = FIO_OPT_C_IO,
2725                 .group  = FIO_OPT_G_RWMIX,
2726         },
2727         {
2728                 .name   = "nice",
2729                 .lname  = "Nice",
2730                 .type   = FIO_OPT_INT,
2731                 .off1   = td_var_offset(nice),
2732                 .help   = "Set job CPU nice value",
2733                 .minval = -19,
2734                 .maxval = 20,
2735                 .def    = "0",
2736                 .interval = 1,
2737                 .category = FIO_OPT_C_GENERAL,
2738                 .group  = FIO_OPT_G_CRED,
2739         },
2740 #ifdef FIO_HAVE_IOPRIO
2741         {
2742                 .name   = "prio",
2743                 .lname  = "I/O nice priority",
2744                 .type   = FIO_OPT_INT,
2745                 .off1   = td_var_offset(ioprio),
2746                 .help   = "Set job IO priority value",
2747                 .minval = 0,
2748                 .maxval = 7,
2749                 .interval = 1,
2750                 .category = FIO_OPT_C_GENERAL,
2751                 .group  = FIO_OPT_G_CRED,
2752         },
2753         {
2754                 .name   = "prioclass",
2755                 .lname  = "I/O nice priority class",
2756                 .type   = FIO_OPT_INT,
2757                 .off1   = td_var_offset(ioprio_class),
2758                 .help   = "Set job IO priority class",
2759                 .minval = 0,
2760                 .maxval = 3,
2761                 .interval = 1,
2762                 .category = FIO_OPT_C_GENERAL,
2763                 .group  = FIO_OPT_G_CRED,
2764         },
2765 #endif
2766         {
2767                 .name   = "thinktime",
2768                 .lname  = "Thinktime",
2769                 .type   = FIO_OPT_INT,
2770                 .off1   = td_var_offset(thinktime),
2771                 .help   = "Idle time between IO buffers (usec)",
2772                 .def    = "0",
2773                 .category = FIO_OPT_C_IO,
2774                 .group  = FIO_OPT_G_THINKTIME,
2775         },
2776         {
2777                 .name   = "thinktime_spin",
2778                 .lname  = "Thinktime spin",
2779                 .type   = FIO_OPT_INT,
2780                 .off1   = td_var_offset(thinktime_spin),
2781                 .help   = "Start think time by spinning this amount (usec)",
2782                 .def    = "0",
2783                 .parent = "thinktime",
2784                 .hide   = 1,
2785                 .category = FIO_OPT_C_IO,
2786                 .group  = FIO_OPT_G_THINKTIME,
2787         },
2788         {
2789                 .name   = "thinktime_blocks",
2790                 .lname  = "Thinktime blocks",
2791                 .type   = FIO_OPT_INT,
2792                 .off1   = td_var_offset(thinktime_blocks),
2793                 .help   = "IO buffer period between 'thinktime'",
2794                 .def    = "1",
2795                 .parent = "thinktime",
2796                 .hide   = 1,
2797                 .category = FIO_OPT_C_IO,
2798                 .group  = FIO_OPT_G_THINKTIME,
2799         },
2800         {
2801                 .name   = "rate",
2802                 .lname  = "I/O rate",
2803                 .type   = FIO_OPT_INT,
2804                 .off1   = td_var_offset(rate[DDIR_READ]),
2805                 .off2   = td_var_offset(rate[DDIR_WRITE]),
2806                 .off3   = td_var_offset(rate[DDIR_TRIM]),
2807                 .help   = "Set bandwidth rate",
2808                 .category = FIO_OPT_C_IO,
2809                 .group  = FIO_OPT_G_RATE,
2810         },
2811         {
2812                 .name   = "ratemin",
2813                 .lname  = "I/O min rate",
2814                 .type   = FIO_OPT_INT,
2815                 .off1   = td_var_offset(ratemin[DDIR_READ]),
2816                 .off2   = td_var_offset(ratemin[DDIR_WRITE]),
2817                 .off3   = td_var_offset(ratemin[DDIR_TRIM]),
2818                 .help   = "Job must meet this rate or it will be shutdown",
2819                 .parent = "rate",
2820                 .hide   = 1,
2821                 .category = FIO_OPT_C_IO,
2822                 .group  = FIO_OPT_G_RATE,
2823         },
2824         {
2825                 .name   = "rate_iops",
2826                 .lname  = "I/O rate IOPS",
2827                 .type   = FIO_OPT_INT,
2828                 .off1   = td_var_offset(rate_iops[DDIR_READ]),
2829                 .off2   = td_var_offset(rate_iops[DDIR_WRITE]),
2830                 .off3   = td_var_offset(rate_iops[DDIR_TRIM]),
2831                 .help   = "Limit IO used to this number of IO operations/sec",
2832                 .hide   = 1,
2833                 .category = FIO_OPT_C_IO,
2834                 .group  = FIO_OPT_G_RATE,
2835         },
2836         {
2837                 .name   = "rate_iops_min",
2838                 .lname  = "I/O min rate IOPS",
2839                 .type   = FIO_OPT_INT,
2840                 .off1   = td_var_offset(rate_iops_min[DDIR_READ]),
2841                 .off2   = td_var_offset(rate_iops_min[DDIR_WRITE]),
2842                 .off3   = td_var_offset(rate_iops_min[DDIR_TRIM]),
2843                 .help   = "Job must meet this rate or it will be shut down",
2844                 .parent = "rate_iops",
2845                 .hide   = 1,
2846                 .category = FIO_OPT_C_IO,
2847                 .group  = FIO_OPT_G_RATE,
2848         },
2849         {
2850                 .name   = "ratecycle",
2851                 .lname  = "I/O rate cycle",
2852                 .type   = FIO_OPT_INT,
2853                 .off1   = td_var_offset(ratecycle),
2854                 .help   = "Window average for rate limits (msec)",
2855                 .def    = "1000",
2856                 .parent = "rate",
2857                 .hide   = 1,
2858                 .category = FIO_OPT_C_IO,
2859                 .group  = FIO_OPT_G_RATE,
2860         },
2861         {
2862                 .name   = "max_latency",
2863                 .type   = FIO_OPT_INT,
2864                 .off1   = td_var_offset(max_latency),
2865                 .help   = "Maximum tolerated IO latency (usec)",
2866                 .category = FIO_OPT_C_IO,
2867                 .group = FIO_OPT_G_LATPROF,
2868         },
2869         {
2870                 .name   = "latency_target",
2871                 .lname  = "Latency Target (usec)",
2872                 .type   = FIO_OPT_STR_VAL_TIME,
2873                 .off1   = td_var_offset(latency_target),
2874                 .help   = "Ramp to max queue depth supporting this latency",
2875                 .category = FIO_OPT_C_IO,
2876                 .group  = FIO_OPT_G_LATPROF,
2877         },
2878         {
2879                 .name   = "latency_window",
2880                 .lname  = "Latency Window (usec)",
2881                 .type   = FIO_OPT_STR_VAL_TIME,
2882                 .off1   = td_var_offset(latency_window),
2883                 .help   = "Time to sustain latency_target",
2884                 .category = FIO_OPT_C_IO,
2885                 .group  = FIO_OPT_G_LATPROF,
2886         },
2887         {
2888                 .name   = "latency_percentile",
2889                 .lname  = "Latency Percentile",
2890                 .type   = FIO_OPT_FLOAT_LIST,
2891                 .off1   = td_var_offset(latency_percentile),
2892                 .help   = "Percentile of IOs must be below latency_target",
2893                 .def    = "100",
2894                 .maxlen = 1,
2895                 .minfp  = 0.0,
2896                 .maxfp  = 100.0,
2897                 .category = FIO_OPT_C_IO,
2898                 .group  = FIO_OPT_G_LATPROF,
2899         },
2900         {
2901                 .name   = "invalidate",
2902                 .lname  = "Cache invalidate",
2903                 .type   = FIO_OPT_BOOL,
2904                 .off1   = td_var_offset(invalidate_cache),
2905                 .help   = "Invalidate buffer/page cache prior to running job",
2906                 .def    = "1",
2907                 .category = FIO_OPT_C_IO,
2908                 .group  = FIO_OPT_G_IO_TYPE,
2909         },
2910         {
2911                 .name   = "sync",
2912                 .lname  = "Synchronous I/O",
2913                 .type   = FIO_OPT_BOOL,
2914                 .off1   = td_var_offset(sync_io),
2915                 .help   = "Use O_SYNC for buffered writes",
2916                 .def    = "0",
2917                 .parent = "buffered",
2918                 .hide   = 1,
2919                 .category = FIO_OPT_C_IO,
2920                 .group  = FIO_OPT_G_IO_TYPE,
2921         },
2922         {
2923                 .name   = "create_serialize",
2924                 .lname  = "Create serialize",
2925                 .type   = FIO_OPT_BOOL,
2926                 .off1   = td_var_offset(create_serialize),
2927                 .help   = "Serialize creating of job files",
2928                 .def    = "1",
2929                 .category = FIO_OPT_C_FILE,
2930                 .group  = FIO_OPT_G_INVALID,
2931         },
2932         {
2933                 .name   = "create_fsync",
2934                 .lname  = "Create fsync",
2935                 .type   = FIO_OPT_BOOL,
2936                 .off1   = td_var_offset(create_fsync),
2937                 .help   = "fsync file after creation",
2938                 .def    = "1",
2939                 .category = FIO_OPT_C_FILE,
2940                 .group  = FIO_OPT_G_INVALID,
2941         },
2942         {
2943                 .name   = "create_on_open",
2944                 .lname  = "Create on open",
2945                 .type   = FIO_OPT_BOOL,
2946                 .off1   = td_var_offset(create_on_open),
2947                 .help   = "Create files when they are opened for IO",
2948                 .def    = "0",
2949                 .category = FIO_OPT_C_FILE,
2950                 .group  = FIO_OPT_G_INVALID,
2951         },
2952         {
2953                 .name   = "create_only",
2954                 .type   = FIO_OPT_BOOL,
2955                 .off1   = td_var_offset(create_only),
2956                 .help   = "Only perform file creation phase",
2957                 .category = FIO_OPT_C_FILE,
2958                 .def    = "0",
2959         },
2960         {
2961                 .name   = "pre_read",
2962                 .lname  = "Pre-read files",
2963                 .type   = FIO_OPT_BOOL,
2964                 .off1   = td_var_offset(pre_read),
2965                 .help   = "Pre-read files before starting official testing",
2966                 .def    = "0",
2967                 .category = FIO_OPT_C_FILE,
2968                 .group  = FIO_OPT_G_INVALID,
2969         },
2970 #ifdef FIO_HAVE_CPU_AFFINITY
2971         {
2972                 .name   = "cpumask",
2973                 .lname  = "CPU mask",
2974                 .type   = FIO_OPT_INT,
2975                 .cb     = str_cpumask_cb,
2976                 .help   = "CPU affinity mask",
2977                 .category = FIO_OPT_C_GENERAL,
2978                 .group  = FIO_OPT_G_CRED,
2979         },
2980         {
2981                 .name   = "cpus_allowed",
2982                 .lname  = "CPUs allowed",
2983                 .type   = FIO_OPT_STR,
2984                 .cb     = str_cpus_allowed_cb,
2985                 .help   = "Set CPUs allowed",
2986                 .category = FIO_OPT_C_GENERAL,
2987                 .group  = FIO_OPT_G_CRED,
2988         },
2989         {
2990                 .name   = "cpus_allowed_policy",
2991                 .lname  = "CPUs allowed distribution policy",
2992                 .type   = FIO_OPT_STR,
2993                 .off1   = td_var_offset(cpus_allowed_policy),
2994                 .help   = "Distribution policy for cpus_allowed",
2995                 .parent = "cpus_allowed",
2996                 .prio   = 1,
2997                 .posval = {
2998                           { .ival = "shared",
2999                             .oval = FIO_CPUS_SHARED,
3000                             .help = "Mask shared between threads",
3001                           },
3002                           { .ival = "split",
3003                             .oval = FIO_CPUS_SPLIT,
3004                             .help = "Mask split between threads",
3005                           },
3006                 },
3007                 .category = FIO_OPT_C_GENERAL,
3008                 .group  = FIO_OPT_G_CRED,
3009         },
3010 #endif
3011 #ifdef CONFIG_LIBNUMA
3012         {
3013                 .name   = "numa_cpu_nodes",
3014                 .type   = FIO_OPT_STR,
3015                 .cb     = str_numa_cpunodes_cb,
3016                 .help   = "NUMA CPU nodes bind",
3017                 .category = FIO_OPT_C_GENERAL,
3018                 .group  = FIO_OPT_G_INVALID,
3019         },
3020         {
3021                 .name   = "numa_mem_policy",
3022                 .type   = FIO_OPT_STR,
3023                 .cb     = str_numa_mpol_cb,
3024                 .help   = "NUMA memory policy setup",
3025                 .category = FIO_OPT_C_GENERAL,
3026                 .group  = FIO_OPT_G_INVALID,
3027         },
3028 #endif
3029         {
3030                 .name   = "end_fsync",
3031                 .lname  = "End fsync",
3032                 .type   = FIO_OPT_BOOL,
3033                 .off1   = td_var_offset(end_fsync),
3034                 .help   = "Include fsync at the end of job",
3035                 .def    = "0",
3036                 .category = FIO_OPT_C_FILE,
3037                 .group  = FIO_OPT_G_INVALID,
3038         },
3039         {
3040                 .name   = "fsync_on_close",
3041                 .lname  = "Fsync on close",
3042                 .type   = FIO_OPT_BOOL,
3043                 .off1   = td_var_offset(fsync_on_close),
3044                 .help   = "fsync files on close",
3045                 .def    = "0",
3046                 .category = FIO_OPT_C_FILE,
3047                 .group  = FIO_OPT_G_INVALID,
3048         },
3049         {
3050                 .name   = "unlink",
3051                 .lname  = "Unlink file",
3052                 .type   = FIO_OPT_BOOL,
3053                 .off1   = td_var_offset(unlink),
3054                 .help   = "Unlink created files after job has completed",
3055                 .def    = "0",
3056                 .category = FIO_OPT_C_FILE,
3057                 .group  = FIO_OPT_G_INVALID,
3058         },
3059         {
3060                 .name   = "exitall",
3061                 .lname  = "Exit-all on terminate",
3062                 .type   = FIO_OPT_STR_SET,
3063                 .cb     = str_exitall_cb,
3064                 .help   = "Terminate all jobs when one exits",
3065                 .category = FIO_OPT_C_GENERAL,
3066                 .group  = FIO_OPT_G_PROCESS,
3067         },
3068         {
3069                 .name   = "stonewall",
3070                 .lname  = "Wait for previous",
3071                 .alias  = "wait_for_previous",
3072                 .type   = FIO_OPT_STR_SET,
3073                 .off1   = td_var_offset(stonewall),
3074                 .help   = "Insert a hard barrier between this job and previous",
3075                 .category = FIO_OPT_C_GENERAL,
3076                 .group  = FIO_OPT_G_PROCESS,
3077         },
3078         {
3079                 .name   = "new_group",
3080                 .lname  = "New group",
3081                 .type   = FIO_OPT_STR_SET,
3082                 .off1   = td_var_offset(new_group),
3083                 .help   = "Mark the start of a new group (for reporting)",
3084                 .category = FIO_OPT_C_GENERAL,
3085                 .group  = FIO_OPT_G_PROCESS,
3086         },
3087         {
3088                 .name   = "thread",
3089                 .lname  = "Thread",
3090                 .type   = FIO_OPT_STR_SET,
3091                 .off1   = td_var_offset(use_thread),
3092                 .help   = "Use threads instead of processes",
3093 #ifdef CONFIG_NO_SHM
3094                 .def    = "1",
3095                 .no_warn_def = 1,
3096 #endif
3097                 .category = FIO_OPT_C_GENERAL,
3098                 .group  = FIO_OPT_G_PROCESS,
3099         },
3100         {
3101                 .name   = "write_bw_log",
3102                 .lname  = "Write bandwidth log",
3103                 .type   = FIO_OPT_STR_STORE,
3104                 .off1   = td_var_offset(bw_log_file),
3105                 .help   = "Write log of bandwidth during run",
3106                 .category = FIO_OPT_C_LOG,
3107                 .group  = FIO_OPT_G_INVALID,
3108         },
3109         {
3110                 .name   = "write_lat_log",
3111                 .lname  = "Write latency log",
3112                 .type   = FIO_OPT_STR_STORE,
3113                 .off1   = td_var_offset(lat_log_file),
3114                 .help   = "Write log of latency during run",
3115                 .category = FIO_OPT_C_LOG,
3116                 .group  = FIO_OPT_G_INVALID,
3117         },
3118         {
3119                 .name   = "write_iops_log",
3120                 .lname  = "Write IOPS log",
3121                 .type   = FIO_OPT_STR_STORE,
3122                 .off1   = td_var_offset(iops_log_file),
3123                 .help   = "Write log of IOPS during run",
3124                 .category = FIO_OPT_C_LOG,
3125                 .group  = FIO_OPT_G_INVALID,
3126         },
3127         {
3128                 .name   = "log_avg_msec",
3129                 .lname  = "Log averaging (msec)",
3130                 .type   = FIO_OPT_INT,
3131                 .off1   = td_var_offset(log_avg_msec),
3132                 .help   = "Average bw/iops/lat logs over this period of time",
3133                 .def    = "0",
3134                 .category = FIO_OPT_C_LOG,
3135                 .group  = FIO_OPT_G_INVALID,
3136         },
3137         {
3138                 .name   = "log_offset",
3139                 .lname  = "Log offset of IO",
3140                 .type   = FIO_OPT_BOOL,
3141                 .off1   = td_var_offset(log_offset),
3142                 .help   = "Include offset of IO for each log entry",
3143                 .def    = "0",
3144                 .category = FIO_OPT_C_LOG,
3145                 .group  = FIO_OPT_G_INVALID,
3146         },
3147 #ifdef CONFIG_ZLIB
3148         {
3149                 .name   = "log_compression",
3150                 .lname  = "Log compression",
3151                 .type   = FIO_OPT_INT,
3152                 .off1   = td_var_offset(log_gz),
3153                 .help   = "Log in compressed chunks of this size",
3154                 .minval = 32 * 1024 * 1024ULL,
3155                 .maxval = 512 * 1024 * 1024ULL,
3156                 .category = FIO_OPT_C_LOG,
3157                 .group  = FIO_OPT_G_INVALID,
3158         },
3159         {
3160                 .name   = "log_store_compressed",
3161                 .lname  = "Log store compressed",
3162                 .type   = FIO_OPT_BOOL,
3163                 .off1   = td_var_offset(log_gz_store),
3164                 .help   = "Store logs in a compressed format",
3165                 .category = FIO_OPT_C_LOG,
3166                 .group  = FIO_OPT_G_INVALID,
3167         },
3168 #endif
3169         {
3170                 .name   = "bwavgtime",
3171                 .lname  = "Bandwidth average time",
3172                 .type   = FIO_OPT_INT,
3173                 .off1   = td_var_offset(bw_avg_time),
3174                 .help   = "Time window over which to calculate bandwidth"
3175                           " (msec)",
3176                 .def    = "500",
3177                 .parent = "write_bw_log",
3178                 .hide   = 1,
3179                 .interval = 100,
3180                 .category = FIO_OPT_C_LOG,
3181                 .group  = FIO_OPT_G_INVALID,
3182         },
3183         {
3184                 .name   = "iopsavgtime",
3185                 .lname  = "IOPS average time",
3186                 .type   = FIO_OPT_INT,
3187                 .off1   = td_var_offset(iops_avg_time),
3188                 .help   = "Time window over which to calculate IOPS (msec)",
3189                 .def    = "500",
3190                 .parent = "write_iops_log",
3191                 .hide   = 1,
3192                 .interval = 100,
3193                 .category = FIO_OPT_C_LOG,
3194                 .group  = FIO_OPT_G_INVALID,
3195         },
3196         {
3197                 .name   = "group_reporting",
3198                 .lname  = "Group reporting",
3199                 .type   = FIO_OPT_STR_SET,
3200                 .off1   = td_var_offset(group_reporting),
3201                 .help   = "Do reporting on a per-group basis",
3202                 .category = FIO_OPT_C_STAT,
3203                 .group  = FIO_OPT_G_INVALID,
3204         },
3205         {
3206                 .name   = "zero_buffers",
3207                 .lname  = "Zero I/O buffers",
3208                 .type   = FIO_OPT_STR_SET,
3209                 .off1   = td_var_offset(zero_buffers),
3210                 .help   = "Init IO buffers to all zeroes",
3211                 .category = FIO_OPT_C_IO,
3212                 .group  = FIO_OPT_G_IO_BUF,
3213         },
3214         {
3215                 .name   = "refill_buffers",
3216                 .lname  = "Refill I/O buffers",
3217                 .type   = FIO_OPT_STR_SET,
3218                 .off1   = td_var_offset(refill_buffers),
3219                 .help   = "Refill IO buffers on every IO submit",
3220                 .category = FIO_OPT_C_IO,
3221                 .group  = FIO_OPT_G_IO_BUF,
3222         },
3223         {
3224                 .name   = "scramble_buffers",
3225                 .lname  = "Scramble I/O buffers",
3226                 .type   = FIO_OPT_BOOL,
3227                 .off1   = td_var_offset(scramble_buffers),
3228                 .help   = "Slightly scramble buffers on every IO submit",
3229                 .def    = "1",
3230                 .category = FIO_OPT_C_IO,
3231                 .group  = FIO_OPT_G_IO_BUF,
3232         },
3233         {
3234                 .name   = "buffer_pattern",
3235                 .lname  = "Buffer pattern",
3236                 .type   = FIO_OPT_STR,
3237                 .cb     = str_buffer_pattern_cb,
3238                 .help   = "Fill pattern for IO buffers",
3239                 .category = FIO_OPT_C_IO,
3240                 .group  = FIO_OPT_G_IO_BUF,
3241         },
3242         {
3243                 .name   = "buffer_compress_percentage",
3244                 .lname  = "Buffer compression percentage",
3245                 .type   = FIO_OPT_INT,
3246                 .cb     = str_buffer_compress_cb,
3247                 .maxval = 100,
3248                 .minval = 0,
3249                 .help   = "How compressible the buffer is (approximately)",
3250                 .interval = 5,
3251                 .category = FIO_OPT_C_IO,
3252                 .group  = FIO_OPT_G_IO_BUF,
3253         },
3254         {
3255                 .name   = "buffer_compress_chunk",
3256                 .lname  = "Buffer compression chunk size",
3257                 .type   = FIO_OPT_INT,
3258                 .off1   = td_var_offset(compress_chunk),
3259                 .parent = "buffer_compress_percentage",
3260                 .hide   = 1,
3261                 .help   = "Size of compressible region in buffer",
3262                 .interval = 256,
3263                 .category = FIO_OPT_C_IO,
3264                 .group  = FIO_OPT_G_IO_BUF,
3265         },
3266         {
3267                 .name   = "dedupe_percentage",
3268                 .lname  = "Dedupe percentage",
3269                 .type   = FIO_OPT_INT,
3270                 .cb     = str_dedupe_cb,
3271                 .maxval = 100,
3272                 .minval = 0,
3273                 .help   = "Percentage of buffers that are dedupable",
3274                 .interval = 1,
3275                 .category = FIO_OPT_C_IO,
3276                 .group  = FIO_OPT_G_IO_BUF,
3277         },
3278         {
3279                 .name   = "clat_percentiles",
3280                 .lname  = "Completion latency percentiles",
3281                 .type   = FIO_OPT_BOOL,
3282                 .off1   = td_var_offset(clat_percentiles),
3283                 .help   = "Enable the reporting of completion latency percentiles",
3284                 .def    = "1",
3285                 .category = FIO_OPT_C_STAT,
3286                 .group  = FIO_OPT_G_INVALID,
3287         },
3288         {
3289                 .name   = "percentile_list",
3290                 .lname  = "Completion latency percentile list",
3291                 .type   = FIO_OPT_FLOAT_LIST,
3292                 .off1   = td_var_offset(percentile_list),
3293                 .off2   = td_var_offset(percentile_precision),
3294                 .help   = "Specify a custom list of percentiles to report",
3295                 .def    = "1:5:10:20:30:40:50:60:70:80:90:95:99:99.5:99.9:99.95:99.99",
3296                 .maxlen = FIO_IO_U_LIST_MAX_LEN,
3297                 .minfp  = 0.0,
3298                 .maxfp  = 100.0,
3299                 .category = FIO_OPT_C_STAT,
3300                 .group  = FIO_OPT_G_INVALID,
3301         },
3302
3303 #ifdef FIO_HAVE_DISK_UTIL
3304         {
3305                 .name   = "disk_util",
3306                 .lname  = "Disk utilization",
3307                 .type   = FIO_OPT_BOOL,
3308                 .off1   = td_var_offset(do_disk_util),
3309                 .help   = "Log disk utilization statistics",
3310                 .def    = "1",
3311                 .category = FIO_OPT_C_STAT,
3312                 .group  = FIO_OPT_G_INVALID,
3313         },
3314 #endif
3315         {
3316                 .name   = "gtod_reduce",
3317                 .lname  = "Reduce gettimeofday() calls",
3318                 .type   = FIO_OPT_BOOL,
3319                 .help   = "Greatly reduce number of gettimeofday() calls",
3320                 .cb     = str_gtod_reduce_cb,
3321                 .def    = "0",
3322                 .hide_on_set = 1,
3323                 .category = FIO_OPT_C_STAT,
3324                 .group  = FIO_OPT_G_INVALID,
3325         },
3326         {
3327                 .name   = "disable_lat",
3328                 .lname  = "Disable all latency stats",
3329                 .type   = FIO_OPT_BOOL,
3330                 .off1   = td_var_offset(disable_lat),
3331                 .help   = "Disable latency numbers",
3332                 .parent = "gtod_reduce",
3333                 .hide   = 1,
3334                 .def    = "0",
3335                 .category = FIO_OPT_C_STAT,
3336                 .group  = FIO_OPT_G_INVALID,
3337         },
3338         {
3339                 .name   = "disable_clat",
3340                 .lname  = "Disable completion latency stats",
3341                 .type   = FIO_OPT_BOOL,
3342                 .off1   = td_var_offset(disable_clat),
3343                 .help   = "Disable completion latency numbers",
3344                 .parent = "gtod_reduce",
3345                 .hide   = 1,
3346                 .def    = "0",
3347                 .category = FIO_OPT_C_STAT,
3348                 .group  = FIO_OPT_G_INVALID,
3349         },
3350         {
3351                 .name   = "disable_slat",
3352                 .lname  = "Disable submission latency stats",
3353                 .type   = FIO_OPT_BOOL,
3354                 .off1   = td_var_offset(disable_slat),
3355                 .help   = "Disable submission latency numbers",
3356                 .parent = "gtod_reduce",
3357                 .hide   = 1,
3358                 .def    = "0",
3359                 .category = FIO_OPT_C_STAT,
3360                 .group  = FIO_OPT_G_INVALID,
3361         },
3362         {
3363                 .name   = "disable_bw_measurement",
3364                 .lname  = "Disable bandwidth stats",
3365                 .type   = FIO_OPT_BOOL,
3366                 .off1   = td_var_offset(disable_bw),
3367                 .help   = "Disable bandwidth logging",
3368                 .parent = "gtod_reduce",
3369                 .hide   = 1,
3370                 .def    = "0",
3371                 .category = FIO_OPT_C_STAT,
3372                 .group  = FIO_OPT_G_INVALID,
3373         },
3374         {
3375                 .name   = "gtod_cpu",
3376                 .lname  = "Dedicated gettimeofday() CPU",
3377                 .type   = FIO_OPT_INT,
3378                 .cb     = str_gtod_cpu_cb,
3379                 .help   = "Set up dedicated gettimeofday() thread on this CPU",
3380                 .verify = gtod_cpu_verify,
3381                 .category = FIO_OPT_C_GENERAL,
3382                 .group  = FIO_OPT_G_CLOCK,
3383         },
3384         {
3385                 .name   = "unified_rw_reporting",
3386                 .type   = FIO_OPT_BOOL,
3387                 .off1   = td_var_offset(unified_rw_rep),
3388                 .help   = "Unify reporting across data direction",
3389                 .def    = "0",
3390                 .category = FIO_OPT_C_GENERAL,
3391                 .group  = FIO_OPT_G_INVALID,
3392         },
3393         {
3394                 .name   = "continue_on_error",
3395                 .lname  = "Continue on error",
3396                 .type   = FIO_OPT_STR,
3397                 .off1   = td_var_offset(continue_on_error),
3398                 .help   = "Continue on non-fatal errors during IO",
3399                 .def    = "none",
3400                 .category = FIO_OPT_C_GENERAL,
3401                 .group  = FIO_OPT_G_ERR,
3402                 .posval = {
3403                           { .ival = "none",
3404                             .oval = ERROR_TYPE_NONE,
3405                             .help = "Exit when an error is encountered",
3406                           },
3407                           { .ival = "read",
3408                             .oval = ERROR_TYPE_READ,
3409                             .help = "Continue on read errors only",
3410                           },
3411                           { .ival = "write",
3412                             .oval = ERROR_TYPE_WRITE,
3413                             .help = "Continue on write errors only",
3414                           },
3415                           { .ival = "io",
3416                             .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
3417                             .help = "Continue on any IO errors",
3418                           },
3419                           { .ival = "verify",
3420                             .oval = ERROR_TYPE_VERIFY,
3421                             .help = "Continue on verify errors only",
3422                           },
3423                           { .ival = "all",
3424                             .oval = ERROR_TYPE_ANY,
3425                             .help = "Continue on all io and verify errors",
3426                           },
3427                           { .ival = "0",
3428                             .oval = ERROR_TYPE_NONE,
3429                             .help = "Alias for 'none'",
3430                           },
3431                           { .ival = "1",
3432                             .oval = ERROR_TYPE_ANY,
3433                             .help = "Alias for 'all'",
3434                           },
3435                 },
3436         },
3437         {
3438                 .name   = "ignore_error",
3439                 .type   = FIO_OPT_STR,
3440                 .cb     = str_ignore_error_cb,
3441                 .help   = "Set a specific list of errors to ignore",
3442                 .parent = "rw",
3443                 .category = FIO_OPT_C_GENERAL,
3444                 .group  = FIO_OPT_G_ERR,
3445         },
3446         {
3447                 .name   = "error_dump",
3448                 .type   = FIO_OPT_BOOL,
3449                 .off1   = td_var_offset(error_dump),
3450                 .def    = "0",
3451                 .help   = "Dump info on each error",
3452                 .category = FIO_OPT_C_GENERAL,
3453                 .group  = FIO_OPT_G_ERR,
3454         },
3455         {
3456                 .name   = "profile",
3457                 .lname  = "Profile",
3458                 .type   = FIO_OPT_STR_STORE,
3459                 .off1   = td_var_offset(profile),
3460                 .help   = "Select a specific builtin performance test",
3461                 .category = FIO_OPT_C_PROFILE,
3462                 .group  = FIO_OPT_G_INVALID,
3463         },
3464         {
3465                 .name   = "cgroup",
3466                 .lname  = "Cgroup",
3467                 .type   = FIO_OPT_STR_STORE,
3468                 .off1   = td_var_offset(cgroup),
3469                 .help   = "Add job to cgroup of this name",
3470                 .category = FIO_OPT_C_GENERAL,
3471                 .group  = FIO_OPT_G_CGROUP,
3472         },
3473         {
3474                 .name   = "cgroup_nodelete",
3475                 .lname  = "Cgroup no-delete",
3476                 .type   = FIO_OPT_BOOL,
3477                 .off1   = td_var_offset(cgroup_nodelete),
3478                 .help   = "Do not delete cgroups after job completion",
3479                 .def    = "0",
3480                 .parent = "cgroup",
3481                 .category = FIO_OPT_C_GENERAL,
3482                 .group  = FIO_OPT_G_CGROUP,
3483         },
3484         {
3485                 .name   = "cgroup_weight",
3486                 .lname  = "Cgroup weight",
3487                 .type   = FIO_OPT_INT,
3488                 .off1   = td_var_offset(cgroup_weight),
3489                 .help   = "Use given weight for cgroup",
3490                 .minval = 100,
3491                 .maxval = 1000,
3492                 .parent = "cgroup",
3493                 .category = FIO_OPT_C_GENERAL,
3494                 .group  = FIO_OPT_G_CGROUP,
3495         },
3496         {
3497                 .name   = "uid",
3498                 .lname  = "User ID",
3499                 .type   = FIO_OPT_INT,
3500                 .off1   = td_var_offset(uid),
3501                 .help   = "Run job with this user ID",
3502                 .category = FIO_OPT_C_GENERAL,
3503                 .group  = FIO_OPT_G_CRED,
3504         },
3505         {
3506                 .name   = "gid",
3507                 .lname  = "Group ID",
3508                 .type   = FIO_OPT_INT,
3509                 .off1   = td_var_offset(gid),
3510                 .help   = "Run job with this group ID",
3511                 .category = FIO_OPT_C_GENERAL,
3512                 .group  = FIO_OPT_G_CRED,
3513         },
3514         {
3515                 .name   = "kb_base",
3516                 .lname  = "KB Base",
3517                 .type   = FIO_OPT_INT,
3518                 .off1   = td_var_offset(kb_base),
3519                 .prio   = 1,
3520                 .def    = "1024",
3521                 .posval = {
3522                           { .ival = "1024",
3523                             .oval = 1024,
3524                             .help = "Use 1024 as the K base",
3525                           },
3526                           { .ival = "1000",
3527                             .oval = 1000,
3528                             .help = "Use 1000 as the K base",
3529                           },
3530                 },
3531                 .help   = "How many bytes per KB for reporting (1000 or 1024)",
3532                 .category = FIO_OPT_C_GENERAL,
3533                 .group  = FIO_OPT_G_INVALID,
3534         },
3535         {
3536                 .name   = "unit_base",
3537                 .lname  = "Base unit for reporting (Bits or Bytes)",
3538                 .type   = FIO_OPT_INT,
3539                 .off1   = td_var_offset(unit_base),
3540                 .prio   = 1,
3541                 .posval = {
3542                           { .ival = "0",
3543                             .oval = 0,
3544                             .help = "Auto-detect",
3545                           },
3546                           { .ival = "8",
3547                             .oval = 8,
3548                             .help = "Normal (byte based)",
3549                           },
3550                           { .ival = "1",
3551                             .oval = 1,
3552                             .help = "Bit based",
3553                           },
3554                 },
3555                 .help   = "Bit multiple of result summary data (8 for byte, 1 for bit)",
3556                 .category = FIO_OPT_C_GENERAL,
3557                 .group  = FIO_OPT_G_INVALID,
3558         },
3559         {
3560                 .name   = "hugepage-size",
3561                 .lname  = "Hugepage size",
3562                 .type   = FIO_OPT_INT,
3563                 .off1   = td_var_offset(hugepage_size),
3564                 .help   = "When using hugepages, specify size of each page",
3565                 .def    = __fio_stringify(FIO_HUGE_PAGE),
3566                 .interval = 1024 * 1024,
3567                 .category = FIO_OPT_C_GENERAL,
3568                 .group  = FIO_OPT_G_INVALID,
3569         },
3570         {
3571                 .name   = "flow_id",
3572                 .lname  = "I/O flow ID",
3573                 .type   = FIO_OPT_INT,
3574                 .off1   = td_var_offset(flow_id),
3575                 .help   = "The flow index ID to use",
3576                 .def    = "0",
3577                 .category = FIO_OPT_C_IO,
3578                 .group  = FIO_OPT_G_IO_FLOW,
3579         },
3580         {
3581                 .name   = "flow",
3582                 .lname  = "I/O flow weight",
3583                 .type   = FIO_OPT_INT,
3584                 .off1   = td_var_offset(flow),
3585                 .help   = "Weight for flow control of this job",
3586                 .parent = "flow_id",
3587                 .hide   = 1,
3588                 .def    = "0",
3589                 .category = FIO_OPT_C_IO,
3590                 .group  = FIO_OPT_G_IO_FLOW,
3591         },
3592         {
3593                 .name   = "flow_watermark",
3594                 .lname  = "I/O flow watermark",
3595                 .type   = FIO_OPT_INT,
3596                 .off1   = td_var_offset(flow_watermark),
3597                 .help   = "High watermark for flow control. This option"
3598                         " should be set to the same value for all threads"
3599                         " with non-zero flow.",
3600                 .parent = "flow_id",
3601                 .hide   = 1,
3602                 .def    = "1024",
3603                 .category = FIO_OPT_C_IO,
3604                 .group  = FIO_OPT_G_IO_FLOW,
3605         },
3606         {
3607                 .name   = "flow_sleep",
3608                 .lname  = "I/O flow sleep",
3609                 .type   = FIO_OPT_INT,
3610                 .off1   = td_var_offset(flow_sleep),
3611                 .help   = "How many microseconds to sleep after being held"
3612                         " back by the flow control mechanism",
3613                 .parent = "flow_id",
3614                 .hide   = 1,
3615                 .def    = "0",
3616                 .category = FIO_OPT_C_IO,
3617                 .group  = FIO_OPT_G_IO_FLOW,
3618         },
3619         {
3620                 .name = NULL,
3621         },
3622 };
3623
3624 static void add_to_lopt(struct option *lopt, struct fio_option *o,
3625                         const char *name, int val)
3626 {
3627         lopt->name = (char *) name;
3628         lopt->val = val;
3629         if (o->type == FIO_OPT_STR_SET)
3630                 lopt->has_arg = optional_argument;
3631         else
3632                 lopt->has_arg = required_argument;
3633 }
3634
3635 static void options_to_lopts(struct fio_option *opts,
3636                               struct option *long_options,
3637                               int i, int option_type)
3638 {
3639         struct fio_option *o = &opts[0];
3640         while (o->name) {
3641                 add_to_lopt(&long_options[i], o, o->name, option_type);
3642                 if (o->alias) {
3643                         i++;
3644                         add_to_lopt(&long_options[i], o, o->alias, option_type);
3645                 }
3646
3647                 i++;
3648                 o++;
3649                 assert(i < FIO_NR_OPTIONS);
3650         }
3651 }
3652
3653 void fio_options_set_ioengine_opts(struct option *long_options,
3654                                    struct thread_data *td)
3655 {
3656         unsigned int i;
3657
3658         i = 0;
3659         while (long_options[i].name) {
3660                 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
3661                         memset(&long_options[i], 0, sizeof(*long_options));
3662                         break;
3663                 }
3664                 i++;
3665         }
3666
3667         /*
3668          * Just clear out the prior ioengine options.
3669          */
3670         if (!td || !td->eo)
3671                 return;
3672
3673         options_to_lopts(td->io_ops->options, long_options, i,
3674                          FIO_GETOPT_IOENGINE);
3675 }
3676
3677 void fio_options_dup_and_init(struct option *long_options)
3678 {
3679         unsigned int i;
3680
3681         options_init(fio_options);
3682
3683         i = 0;
3684         while (long_options[i].name)
3685                 i++;
3686
3687         options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
3688 }
3689
3690 struct fio_keyword {
3691         const char *word;
3692         const char *desc;
3693         char *replace;
3694 };
3695
3696 static struct fio_keyword fio_keywords[] = {
3697         {
3698                 .word   = "$pagesize",
3699                 .desc   = "Page size in the system",
3700         },
3701         {
3702                 .word   = "$mb_memory",
3703                 .desc   = "Megabytes of memory online",
3704         },
3705         {
3706                 .word   = "$ncpus",
3707                 .desc   = "Number of CPUs online in the system",
3708         },
3709         {
3710                 .word   = NULL,
3711         },
3712 };
3713
3714 void fio_keywords_init(void)
3715 {
3716         unsigned long long mb_memory;
3717         char buf[128];
3718         long l;
3719
3720         sprintf(buf, "%lu", (unsigned long) page_size);
3721         fio_keywords[0].replace = strdup(buf);
3722
3723         mb_memory = os_phys_mem() / (1024 * 1024);
3724         sprintf(buf, "%llu", mb_memory);
3725         fio_keywords[1].replace = strdup(buf);
3726
3727         l = cpus_online();
3728         sprintf(buf, "%lu", l);
3729         fio_keywords[2].replace = strdup(buf);
3730 }
3731
3732 #define BC_APP          "bc"
3733
3734 static char *bc_calc(char *str)
3735 {
3736         char buf[128], *tmp;
3737         FILE *f;
3738         int ret;
3739
3740         /*
3741          * No math, just return string
3742          */
3743         if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
3744              !strchr(str, '/')) || strchr(str, '\''))
3745                 return str;
3746
3747         /*
3748          * Split option from value, we only need to calculate the value
3749          */
3750         tmp = strchr(str, '=');
3751         if (!tmp)
3752                 return str;
3753
3754         tmp++;
3755
3756         /*
3757          * Prevent buffer overflows; such a case isn't reasonable anyway
3758          */
3759         if (strlen(str) >= 128 || strlen(tmp) > 100)
3760                 return str;
3761
3762         sprintf(buf, "which %s > /dev/null", BC_APP);
3763         if (system(buf)) {
3764                 log_err("fio: bc is needed for performing math\n");
3765                 return NULL;
3766         }
3767
3768         sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
3769         f = popen(buf, "r");
3770         if (!f)
3771                 return NULL;
3772
3773         ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
3774         if (ret <= 0) {
3775                 pclose(f);
3776                 return NULL;
3777         }
3778
3779         pclose(f);
3780         buf[(tmp - str) + ret - 1] = '\0';
3781         memcpy(buf, str, tmp - str);
3782         free(str);
3783         return strdup(buf);
3784 }
3785
3786 /*
3787  * Return a copy of the input string with substrings of the form ${VARNAME}
3788  * substituted with the value of the environment variable VARNAME.  The
3789  * substitution always occurs, even if VARNAME is empty or the corresponding
3790  * environment variable undefined.
3791  */
3792 static char *option_dup_subs(const char *opt)
3793 {
3794         char out[OPT_LEN_MAX+1];
3795         char in[OPT_LEN_MAX+1];
3796         char *outptr = out;
3797         char *inptr = in;
3798         char *ch1, *ch2, *env;
3799         ssize_t nchr = OPT_LEN_MAX;
3800         size_t envlen;
3801
3802         if (strlen(opt) + 1 > OPT_LEN_MAX) {
3803                 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
3804                 return NULL;
3805         }
3806
3807         in[OPT_LEN_MAX] = '\0';
3808         strncpy(in, opt, OPT_LEN_MAX);
3809
3810         while (*inptr && nchr > 0) {
3811                 if (inptr[0] == '$' && inptr[1] == '{') {
3812                         ch2 = strchr(inptr, '}');
3813                         if (ch2 && inptr+1 < ch2) {
3814                                 ch1 = inptr+2;
3815                                 inptr = ch2+1;
3816                                 *ch2 = '\0';
3817
3818                                 env = getenv(ch1);
3819                                 if (env) {
3820                                         envlen = strlen(env);
3821                                         if (envlen <= nchr) {
3822                                                 memcpy(outptr, env, envlen);
3823                                                 outptr += envlen;
3824                                                 nchr -= envlen;
3825                                         }
3826                                 }
3827
3828                                 continue;
3829                         }
3830                 }
3831
3832                 *outptr++ = *inptr++;
3833                 --nchr;
3834         }
3835
3836         *outptr = '\0';
3837         return strdup(out);
3838 }
3839
3840 /*
3841  * Look for reserved variable names and replace them with real values
3842  */
3843 static char *fio_keyword_replace(char *opt)
3844 {
3845         char *s;
3846         int i;
3847         int docalc = 0;
3848
3849         for (i = 0; fio_keywords[i].word != NULL; i++) {
3850                 struct fio_keyword *kw = &fio_keywords[i];
3851
3852                 while ((s = strstr(opt, kw->word)) != NULL) {
3853                         char *new = malloc(strlen(opt) + 1);
3854                         char *o_org = opt;
3855                         int olen = s - opt;
3856                         int len;
3857
3858                         /*
3859                          * Copy part of the string before the keyword and
3860                          * sprintf() the replacement after it.
3861                          */
3862                         memcpy(new, opt, olen);
3863                         len = sprintf(new + olen, "%s", kw->replace);
3864
3865                         /*
3866                          * If there's more in the original string, copy that
3867                          * in too
3868                          */
3869                         opt += strlen(kw->word) + olen;
3870                         if (strlen(opt))
3871                                 memcpy(new + olen + len, opt, opt - o_org - 1);
3872
3873                         /*
3874                          * replace opt and free the old opt
3875                          */
3876                         opt = new;
3877                         free(o_org);
3878
3879                         docalc = 1;
3880                 }
3881         }
3882
3883         /*
3884          * Check for potential math and invoke bc, if possible
3885          */
3886         if (docalc)
3887                 opt = bc_calc(opt);
3888
3889         return opt;
3890 }
3891
3892 static char **dup_and_sub_options(char **opts, int num_opts)
3893 {
3894         int i;
3895         char **opts_copy = malloc(num_opts * sizeof(*opts));
3896         for (i = 0; i < num_opts; i++) {
3897                 opts_copy[i] = option_dup_subs(opts[i]);
3898                 if (!opts_copy[i])
3899                         continue;
3900                 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
3901         }
3902         return opts_copy;
3903 }
3904
3905 int fio_options_parse(struct thread_data *td, char **opts, int num_opts,
3906                         int dump_cmdline)
3907 {
3908         int i, ret, unknown;
3909         char **opts_copy;
3910
3911         sort_options(opts, fio_options, num_opts);
3912         opts_copy = dup_and_sub_options(opts, num_opts);
3913
3914         for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
3915                 struct fio_option *o;
3916                 int newret = parse_option(opts_copy[i], opts[i], fio_options,
3917                                                 &o, td, dump_cmdline);
3918
3919                 if (opts_copy[i]) {
3920                         if (newret && !o) {
3921                                 unknown++;
3922                                 continue;
3923                         }
3924                         free(opts_copy[i]);
3925                         opts_copy[i] = NULL;
3926                 }
3927
3928                 ret |= newret;
3929         }
3930
3931         if (unknown) {
3932                 ret |= ioengine_load(td);
3933                 if (td->eo) {
3934                         sort_options(opts_copy, td->io_ops->options, num_opts);
3935                         opts = opts_copy;
3936                 }
3937                 for (i = 0; i < num_opts; i++) {
3938                         struct fio_option *o = NULL;
3939                         int newret = 1;
3940                         if (!opts_copy[i])
3941                                 continue;
3942
3943                         if (td->eo)
3944                                 newret = parse_option(opts_copy[i], opts[i],
3945                                                       td->io_ops->options, &o,
3946                                                       td->eo, dump_cmdline);
3947
3948                         ret |= newret;
3949                         if (!o)
3950                                 log_err("Bad option <%s>\n", opts[i]);
3951
3952                         free(opts_copy[i]);
3953                         opts_copy[i] = NULL;
3954                 }
3955         }
3956
3957         free(opts_copy);
3958         return ret;
3959 }
3960
3961 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
3962 {
3963         return parse_cmd_option(opt, val, fio_options, td);
3964 }
3965
3966 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
3967                                 char *val)
3968 {
3969         return parse_cmd_option(opt, val, td->io_ops->options, td->eo);
3970 }
3971
3972 void fio_fill_default_options(struct thread_data *td)
3973 {
3974         td->o.magic = OPT_MAGIC;
3975         fill_default_options(td, fio_options);
3976 }
3977
3978 int fio_show_option_help(const char *opt)
3979 {
3980         return show_cmd_help(fio_options, opt);
3981 }
3982
3983 void options_mem_dupe(void *data, struct fio_option *options)
3984 {
3985         struct fio_option *o;
3986         char **ptr;
3987
3988         for (o = &options[0]; o->name; o++) {
3989                 if (o->type != FIO_OPT_STR_STORE)
3990                         continue;
3991
3992                 ptr = td_var(data, o, o->off1);
3993                 if (*ptr)
3994                         *ptr = strdup(*ptr);
3995         }
3996 }
3997
3998 /*
3999  * dupe FIO_OPT_STR_STORE options
4000  */
4001 void fio_options_mem_dupe(struct thread_data *td)
4002 {
4003         options_mem_dupe(&td->o, fio_options);
4004
4005         if (td->eo && td->io_ops) {
4006                 void *oldeo = td->eo;
4007
4008                 td->eo = malloc(td->io_ops->option_struct_size);
4009                 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
4010                 options_mem_dupe(td->eo, td->io_ops->options);
4011         }
4012 }
4013
4014 unsigned int fio_get_kb_base(void *data)
4015 {
4016         struct thread_options *o = data;
4017         unsigned int kb_base = 0;
4018
4019         /*
4020          * This is a hack... For private options, *data is not holding
4021          * a pointer to the thread_options, but to private data. This means
4022          * we can't safely dereference it, but magic is first so mem wise
4023          * it is valid. But this also means that if the job first sets
4024          * kb_base and expects that to be honored by private options,
4025          * it will be disappointed. We will return the global default
4026          * for this.
4027          */
4028         if (o && o->magic == OPT_MAGIC)
4029                 kb_base = o->kb_base;
4030         if (!kb_base)
4031                 kb_base = 1024;
4032
4033         return kb_base;
4034 }
4035
4036 int add_option(struct fio_option *o)
4037 {
4038         struct fio_option *__o;
4039         int opt_index = 0;
4040
4041         __o = fio_options;
4042         while (__o->name) {
4043                 opt_index++;
4044                 __o++;
4045         }
4046
4047         if (opt_index + 1 == FIO_MAX_OPTS) {
4048                 log_err("fio: FIO_MAX_OPTS is too small\n");
4049                 return 1;
4050         }
4051
4052         memcpy(&fio_options[opt_index], o, sizeof(*o));
4053         fio_options[opt_index + 1].name = NULL;
4054         return 0;
4055 }
4056
4057 void invalidate_profile_options(const char *prof_name)
4058 {
4059         struct fio_option *o;
4060
4061         o = fio_options;
4062         while (o->name) {
4063                 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
4064                         o->type = FIO_OPT_INVALID;
4065                         o->prof_name = NULL;
4066                 }
4067                 o++;
4068         }
4069 }
4070
4071 void add_opt_posval(const char *optname, const char *ival, const char *help)
4072 {
4073         struct fio_option *o;
4074         unsigned int i;
4075
4076         o = find_option(fio_options, optname);
4077         if (!o)
4078                 return;
4079
4080         for (i = 0; i < PARSE_MAX_VP; i++) {
4081                 if (o->posval[i].ival)
4082                         continue;
4083
4084                 o->posval[i].ival = ival;
4085                 o->posval[i].help = help;
4086                 break;
4087         }
4088 }
4089
4090 void del_opt_posval(const char *optname, const char *ival)
4091 {
4092         struct fio_option *o;
4093         unsigned int i;
4094
4095         o = find_option(fio_options, optname);
4096         if (!o)
4097                 return;
4098
4099         for (i = 0; i < PARSE_MAX_VP; i++) {
4100                 if (!o->posval[i].ival)
4101                         continue;
4102                 if (strcmp(o->posval[i].ival, ival))
4103                         continue;
4104
4105                 o->posval[i].ival = NULL;
4106                 o->posval[i].help = NULL;
4107         }
4108 }
4109
4110 void fio_options_free(struct thread_data *td)
4111 {
4112         options_free(fio_options, td);
4113         if (td->eo && td->io_ops && td->io_ops->options) {
4114                 options_free(td->io_ops->options, td->eo);
4115                 free(td->eo);
4116                 td->eo = NULL;
4117         }
4118 }
4119
4120 struct fio_option *fio_option_find(const char *name)
4121 {
4122         return find_option(fio_options, name);
4123 }
4124