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