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