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