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