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