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