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