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