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