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