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