18d2f20ded599c9327f105f24258c0280cf9fd05
[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_data *td, 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         td->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 == td->o.bssplit_nr[ddir]) {
88                         td->o.bssplit_nr[ddir] <<= 1;
89                         bssplit = realloc(bssplit, td->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, td)) {
106                         log_err("fio: bssplit conversion failed\n");
107                         free(td->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         td->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 < td->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 < td->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         td->o.min_bs[ddir] = min_bs;
155         td->o.max_bs[ddir] = max_bs;
156
157         /*
158          * now sort based on percentages, for ease of lookup
159          */
160         qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161         td->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;
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                 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
179                 if (!ret) {
180                         *odir = '\0';
181                         ret = bssplit_ddir(td, DDIR_READ, str);
182                 }
183         } else {
184                 char *op;
185
186                 op = strdup(str);
187
188                 ret = bssplit_ddir(td, DDIR_READ, str);
189                 if (!ret)
190                         ret = bssplit_ddir(td, DDIR_WRITE, op);
191
192                 free(op);
193         }
194
195         free(p);
196         return ret;
197 }
198
199 static int str_rw_cb(void *data, const char *str)
200 {
201         struct thread_data *td = data;
202         char *nr = get_opt_postfix(str);
203
204         td->o.ddir_seq_nr = 1;
205         td->o.ddir_seq_add = 0;
206
207         if (!nr)
208                 return 0;
209
210         if (td_random(td))
211                 td->o.ddir_seq_nr = atoi(nr);
212         else {
213                 long long val;
214
215                 if (str_to_decimal(nr, &val, 1, td)) {
216                         log_err("fio: rw postfix parsing failed\n");
217                         free(nr);
218                         return 1;
219                 }
220
221                 td->o.ddir_seq_add = val;
222         }
223
224         free(nr);
225         return 0;
226 }
227
228 static int str_mem_cb(void *data, const char *mem)
229 {
230         struct thread_data *td = data;
231
232         if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
233                 td->mmapfile = get_opt_postfix(mem);
234                 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
235                         log_err("fio: mmaphuge:/path/to/file\n");
236                         return 1;
237                 }
238         }
239
240         return 0;
241 }
242
243 static int str_verify_cb(void *data, const char *mem)
244 {
245         struct thread_data *td = data;
246
247         if (td->o.verify == VERIFY_CRC32C_INTEL ||
248             td->o.verify == VERIFY_CRC32C) {
249                 crc32c_intel_probe();
250         }
251
252         return 0;
253 }
254
255 static int fio_clock_source_cb(void *data, const char *str)
256 {
257         struct thread_data *td = data;
258
259         fio_clock_source = td->o.clocksource;
260         fio_time_init();
261         return 0;
262 }
263
264 static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
265 {
266         mlock_size = *val;
267         return 0;
268 }
269
270 static int str_rwmix_read_cb(void *data, unsigned long long *val)
271 {
272         struct thread_data *td = data;
273
274         td->o.rwmix[DDIR_READ] = *val;
275         td->o.rwmix[DDIR_WRITE] = 100 - *val;
276         return 0;
277 }
278
279 static int str_rwmix_write_cb(void *data, unsigned long long *val)
280 {
281         struct thread_data *td = data;
282
283         td->o.rwmix[DDIR_WRITE] = *val;
284         td->o.rwmix[DDIR_READ] = 100 - *val;
285         return 0;
286 }
287
288 #ifdef FIO_HAVE_IOPRIO
289 static int str_prioclass_cb(void *data, unsigned long long *val)
290 {
291         struct thread_data *td = data;
292         unsigned short mask;
293
294         /*
295          * mask off old class bits, str_prio_cb() may have set a default class
296          */
297         mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
298         td->ioprio &= mask;
299
300         td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
301         td->ioprio_set = 1;
302         return 0;
303 }
304
305 static int str_prio_cb(void *data, unsigned long long *val)
306 {
307         struct thread_data *td = data;
308
309         td->ioprio |= *val;
310
311         /*
312          * If no class is set, assume BE
313          */
314         if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
315                 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
316
317         td->ioprio_set = 1;
318         return 0;
319 }
320 #endif
321
322 static int str_exitall_cb(void)
323 {
324         exitall_on_terminate = 1;
325         return 0;
326 }
327
328 #ifdef FIO_HAVE_CPU_AFFINITY
329 static int str_cpumask_cb(void *data, unsigned long long *val)
330 {
331         struct thread_data *td = data;
332         unsigned int i;
333         long max_cpu;
334         int ret;
335
336         ret = fio_cpuset_init(&td->o.cpumask);
337         if (ret < 0) {
338                 log_err("fio: cpuset_init failed\n");
339                 td_verror(td, ret, "fio_cpuset_init");
340                 return 1;
341         }
342
343         max_cpu = cpus_online();
344
345         for (i = 0; i < sizeof(int) * 8; i++) {
346                 if ((1 << i) & *val) {
347                         if (i > max_cpu) {
348                                 log_err("fio: CPU %d too large (max=%ld)\n", i,
349                                                                 max_cpu);
350                                 return 1;
351                         }
352                         dprint(FD_PARSE, "set cpu allowed %d\n", i);
353                         fio_cpu_set(&td->o.cpumask, i);
354                 }
355         }
356
357         td->o.cpumask_set = 1;
358         return 0;
359 }
360
361 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
362                             const char *input)
363 {
364         char *cpu, *str, *p;
365         long max_cpu;
366         int ret = 0;
367
368         ret = fio_cpuset_init(mask);
369         if (ret < 0) {
370                 log_err("fio: cpuset_init failed\n");
371                 td_verror(td, ret, "fio_cpuset_init");
372                 return 1;
373         }
374
375         p = str = strdup(input);
376
377         strip_blank_front(&str);
378         strip_blank_end(str);
379
380         max_cpu = cpus_online();
381
382         while ((cpu = strsep(&str, ",")) != NULL) {
383                 char *str2, *cpu2;
384                 int icpu, icpu2;
385
386                 if (!strlen(cpu))
387                         break;
388
389                 str2 = cpu;
390                 icpu2 = -1;
391                 while ((cpu2 = strsep(&str2, "-")) != NULL) {
392                         if (!strlen(cpu2))
393                                 break;
394
395                         icpu2 = atoi(cpu2);
396                 }
397
398                 icpu = atoi(cpu);
399                 if (icpu2 == -1)
400                         icpu2 = icpu;
401                 while (icpu <= icpu2) {
402                         if (icpu >= FIO_MAX_CPUS) {
403                                 log_err("fio: your OS only supports up to"
404                                         " %d CPUs\n", (int) FIO_MAX_CPUS);
405                                 ret = 1;
406                                 break;
407                         }
408                         if (icpu > max_cpu) {
409                                 log_err("fio: CPU %d too large (max=%ld)\n",
410                                                         icpu, max_cpu);
411                                 ret = 1;
412                                 break;
413                         }
414
415                         dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
416                         fio_cpu_set(mask, icpu);
417                         icpu++;
418                 }
419                 if (ret)
420                         break;
421         }
422
423         free(p);
424         if (!ret)
425                 td->o.cpumask_set = 1;
426         return ret;
427 }
428
429 static int str_cpus_allowed_cb(void *data, const char *input)
430 {
431         struct thread_data *td = data;
432         int ret;
433
434         ret = set_cpus_allowed(td, &td->o.cpumask, input);
435         if (!ret)
436                 td->o.cpumask_set = 1;
437
438         return ret;
439 }
440
441 static int str_verify_cpus_allowed_cb(void *data, const char *input)
442 {
443         struct thread_data *td = data;
444         int ret;
445
446         ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
447         if (!ret)
448                 td->o.verify_cpumask_set = 1;
449
450         return ret;
451 }
452 #endif
453
454 #ifdef FIO_HAVE_TRIM
455 static int str_verify_trim_cb(void *data, unsigned long long *val)
456 {
457         struct thread_data *td = data;
458
459         td->o.trim_percentage = *val;
460         return 0;
461 }
462 #endif
463
464 static int str_fst_cb(void *data, const char *str)
465 {
466         struct thread_data *td = data;
467         char *nr = get_opt_postfix(str);
468
469         td->file_service_nr = 1;
470         if (nr) {
471                 td->file_service_nr = atoi(nr);
472                 free(nr);
473         }
474
475         return 0;
476 }
477
478 #ifdef FIO_HAVE_SYNC_FILE_RANGE
479 static int str_sfr_cb(void *data, const char *str)
480 {
481         struct thread_data *td = data;
482         char *nr = get_opt_postfix(str);
483
484         td->sync_file_range_nr = 1;
485         if (nr) {
486                 td->sync_file_range_nr = atoi(nr);
487                 free(nr);
488         }
489
490         return 0;
491 }
492 #endif
493
494 static int check_dir(struct thread_data *td, char *fname)
495 {
496 #if 0
497         char file[PATH_MAX], *dir;
498         int elen = 0;
499
500         if (td->o.directory) {
501                 strcpy(file, td->o.directory);
502                 strcat(file, "/");
503                 elen = strlen(file);
504         }
505
506         sprintf(file + elen, "%s", fname);
507         dir = dirname(file);
508
509         {
510         struct stat sb;
511         /*
512          * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
513          * yet, so we can't do this check right here...
514          */
515         if (lstat(dir, &sb) < 0) {
516                 int ret = errno;
517
518                 log_err("fio: %s is not a directory\n", dir);
519                 td_verror(td, ret, "lstat");
520                 return 1;
521         }
522
523         if (!S_ISDIR(sb.st_mode)) {
524                 log_err("fio: %s is not a directory\n", dir);
525                 return 1;
526         }
527         }
528 #endif
529
530         return 0;
531 }
532
533 /*
534  * Return next file in the string. Files are separated with ':'. If the ':'
535  * is escaped with a '\', then that ':' is part of the filename and does not
536  * indicate a new file.
537  */
538 static char *get_next_file_name(char **ptr)
539 {
540         char *str = *ptr;
541         char *p, *start;
542
543         if (!str || !strlen(str))
544                 return NULL;
545
546         start = str;
547         do {
548                 /*
549                  * No colon, we are done
550                  */
551                 p = strchr(str, ':');
552                 if (!p) {
553                         *ptr = NULL;
554                         break;
555                 }
556
557                 /*
558                  * We got a colon, but it's the first character. Skip and
559                  * continue
560                  */
561                 if (p == start) {
562                         str = ++start;
563                         continue;
564                 }
565
566                 if (*(p - 1) != '\\') {
567                         *p = '\0';
568                         *ptr = p + 1;
569                         break;
570                 }
571
572                 memmove(p - 1, p, strlen(p) + 1);
573                 str = p;
574         } while (1);
575
576         return start;
577 }
578
579 static int str_filename_cb(void *data, const char *input)
580 {
581         struct thread_data *td = data;
582         char *fname, *str, *p;
583
584         p = str = strdup(input);
585
586         strip_blank_front(&str);
587         strip_blank_end(str);
588
589         if (!td->files_index)
590                 td->o.nr_files = 0;
591
592         while ((fname = get_next_file_name(&str)) != NULL) {
593                 if (!strlen(fname))
594                         break;
595                 if (check_dir(td, fname)) {
596                         free(p);
597                         return 1;
598                 }
599                 add_file(td, fname);
600                 td->o.nr_files++;
601         }
602
603         free(p);
604         return 0;
605 }
606
607 static int str_directory_cb(void *data, const char fio_unused *str)
608 {
609         struct thread_data *td = data;
610         struct stat sb;
611
612         if (lstat(td->o.directory, &sb) < 0) {
613                 int ret = errno;
614
615                 log_err("fio: %s is not a directory\n", td->o.directory);
616                 td_verror(td, ret, "lstat");
617                 return 1;
618         }
619         if (!S_ISDIR(sb.st_mode)) {
620                 log_err("fio: %s is not a directory\n", td->o.directory);
621                 return 1;
622         }
623
624         return 0;
625 }
626
627 static int str_opendir_cb(void *data, const char fio_unused *str)
628 {
629         struct thread_data *td = data;
630
631         if (!td->files_index)
632                 td->o.nr_files = 0;
633
634         return add_dir_files(td, td->o.opendir);
635 }
636
637 static int str_verify_offset_cb(void *data, unsigned long long *off)
638 {
639         struct thread_data *td = data;
640
641         if (*off && *off < sizeof(struct verify_header)) {
642                 log_err("fio: verify_offset too small\n");
643                 return 1;
644         }
645
646         td->o.verify_offset = *off;
647         return 0;
648 }
649
650 static int str_verify_pattern_cb(void *data, const char *input)
651 {
652         struct thread_data *td = data;
653         long off;
654         int i = 0, j = 0, len, k, base = 10;
655         char* loc1, * loc2;
656
657         loc1 = strstr(input, "0x");
658         loc2 = strstr(input, "0X");
659         if (loc1 || loc2)
660                 base = 16;
661         off = strtol(input, NULL, base);
662         if (off != LONG_MAX || errno != ERANGE) {
663                 while (off) {
664                         td->o.verify_pattern[i] = off & 0xff;
665                         off >>= 8;
666                         i++;
667                 }
668         } else {
669                 len = strlen(input);
670                 k = len - 1;
671                 if (base == 16) {
672                         if (loc1)
673                                 j = loc1 - input + 2;
674                         else
675                                 j = loc2 - input + 2;
676                 } else
677                         return 1;
678                 if (len - j < MAX_PATTERN_SIZE * 2) {
679                         while (k >= j) {
680                                 off = converthexchartoint(input[k--]);
681                                 if (k >= j)
682                                         off += (converthexchartoint(input[k--])
683                                                 * 16);
684                                 td->o.verify_pattern[i++] = (char) off;
685                         }
686                 }
687         }
688
689         /*
690          * Fill the pattern all the way to the end. This greatly reduces
691          * the number of memcpy's we have to do when verifying the IO.
692          */
693         while (i > 1 && i * 2 <= MAX_PATTERN_SIZE) {
694                 memcpy(&td->o.verify_pattern[i], &td->o.verify_pattern[0], i);
695                 i *= 2;
696         }
697         if (i == 1) {
698                 /*
699                  * The code in verify_io_u_pattern assumes a single byte pattern
700                  * fills the whole verify pattern buffer.
701                  */
702                 memset(td->o.verify_pattern, td->o.verify_pattern[0],
703                        MAX_PATTERN_SIZE);
704         }
705
706         td->o.verify_pattern_bytes = i;
707
708         /*
709          * VERIFY_META could already be set
710          */
711         if (td->o.verify == VERIFY_NONE)
712                 td->o.verify = VERIFY_PATTERN;
713
714         return 0;
715 }
716
717 static int str_lockfile_cb(void *data, const char *str)
718 {
719         struct thread_data *td = data;
720         char *nr = get_opt_postfix(str);
721
722         td->o.lockfile_batch = 1;
723         if (nr) {
724                 td->o.lockfile_batch = atoi(nr);
725                 free(nr);
726         }
727
728         return 0;
729 }
730
731 static int str_write_bw_log_cb(void *data, const char *str)
732 {
733         struct thread_data *td = data;
734
735         if (str)
736                 td->o.bw_log_file = strdup(str);
737
738         td->o.write_bw_log = 1;
739         return 0;
740 }
741
742 static int str_write_lat_log_cb(void *data, const char *str)
743 {
744         struct thread_data *td = data;
745
746         if (str)
747                 td->o.lat_log_file = strdup(str);
748
749         td->o.write_lat_log = 1;
750         return 0;
751 }
752
753 static int str_write_iops_log_cb(void *data, const char *str)
754 {
755         struct thread_data *td = data;
756
757         if (str)
758                 td->o.iops_log_file = strdup(str);
759
760         td->o.write_iops_log = 1;
761         return 0;
762 }
763
764 static int str_gtod_reduce_cb(void *data, int *il)
765 {
766         struct thread_data *td = data;
767         int val = *il;
768
769         td->o.disable_lat = !!val;
770         td->o.disable_clat = !!val;
771         td->o.disable_slat = !!val;
772         td->o.disable_bw = !!val;
773         td->o.clat_percentiles = !val;
774         if (val)
775                 td->tv_cache_mask = 63;
776
777         return 0;
778 }
779
780 static int str_gtod_cpu_cb(void *data, long long *il)
781 {
782         struct thread_data *td = data;
783         int val = *il;
784
785         td->o.gtod_cpu = val;
786         td->o.gtod_offload = 1;
787         return 0;
788 }
789
790 static int str_size_cb(void *data, unsigned long long *__val)
791 {
792         struct thread_data *td = data;
793         unsigned long long v = *__val;
794
795         if (parse_is_percent(v)) {
796                 td->o.size = 0;
797                 td->o.size_percent = -1ULL - v;
798         } else
799                 td->o.size = v;
800
801         return 0;
802 }
803
804 static int rw_verify(struct fio_option *o, void *data)
805 {
806         struct thread_data *td = data;
807
808         if (read_only && td_write(td)) {
809                 log_err("fio: job <%s> has write bit set, but fio is in"
810                         " read-only mode\n", td->o.name);
811                 return 1;
812         }
813
814         return 0;
815 }
816
817 static int gtod_cpu_verify(struct fio_option *o, void *data)
818 {
819 #ifndef FIO_HAVE_CPU_AFFINITY
820         struct thread_data *td = data;
821
822         if (td->o.gtod_cpu) {
823                 log_err("fio: platform must support CPU affinity for"
824                         "gettimeofday() offloading\n");
825                 return 1;
826         }
827 #endif
828
829         return 0;
830 }
831
832 static int kb_base_verify(struct fio_option *o, void *data)
833 {
834         struct thread_data *td = data;
835
836         if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
837                 log_err("fio: kb_base set to nonsensical value: %u\n",
838                                 td->o.kb_base);
839                 return 1;
840         }
841
842         return 0;
843 }
844
845 /*
846  * Option grouping
847  */
848 static struct opt_group fio_opt_groups[] = {
849         {
850                 .name   = "Description",
851                 .mask   = FIO_OPT_G_DESC,
852         },
853         {
854                 .name   = "File",
855                 .mask   = FIO_OPT_G_FILE,
856         },
857         {
858                 .name   = "Misc",
859                 .mask   = FIO_OPT_G_MISC,
860         },
861         {
862                 .name   = "IO (main)",
863                 .mask   = FIO_OPT_G_IO,
864         },
865         {
866                 .name   = "IO direction",
867                 .mask   = FIO_OPT_G_IO_DDIR,
868         },
869         {
870                 .name   = "IO buffer",
871                 .mask   = FIO_OPT_G_IO_BUF,
872         },
873         {
874                 .name   = "Random",
875                 .mask   = FIO_OPT_G_RAND,
876         },
877         {
878                 .name   = "OS",
879                 .mask   = FIO_OPT_G_OS,
880         },
881         {
882                 .name   = "Memory",
883                 .mask   = FIO_OPT_G_MEM,
884         },
885         {
886                 .name   = "Verify",
887                 .mask   = FIO_OPT_G_VERIFY,
888         },
889         {
890                 .name   = "CPU",
891                 .mask   = FIO_OPT_G_CPU,
892         },
893         {
894                 .name   = "Log",
895                 .mask   = FIO_OPT_G_LOG,
896         },
897         {
898                 .name   = "Zone",
899                 .mask   = FIO_OPT_G_ZONE,
900         },
901         {
902                 .name   = "Cache",
903                 .mask   = FIO_OPT_G_CACHE,
904         },
905         {
906                 .name   = "Stat",
907                 .mask   = FIO_OPT_G_STAT,
908         },
909         {
910                 .name   = "Error",
911                 .mask   = FIO_OPT_G_ERR,
912         },
913         {
914                 .name   = "Job",
915                 .mask   = FIO_OPT_G_JOB,
916         },
917         {
918                 .name   = NULL,
919         },
920 };
921
922 struct opt_group *opt_group_from_mask(unsigned int *mask)
923 {
924         struct opt_group *og;
925         int i;
926
927         if (*mask == FIO_OPT_G_INVALID)
928                 return NULL;
929
930         for (i = 0; fio_opt_groups[i].name; i++) {
931                 og = &fio_opt_groups[i];
932
933                 if (*mask & og->mask) {
934                         *mask &= ~(og->mask);
935                         return og;
936                 }
937         }
938
939         return NULL;
940 }
941
942 /*
943  * Map of job/command line options
944  */
945 struct fio_option fio_options[FIO_MAX_OPTS] = {
946         {
947                 .name   = "description",
948                 .type   = FIO_OPT_STR_STORE,
949                 .off1   = td_var_offset(description),
950                 .help   = "Text job description",
951                 .category = FIO_OPT_G_DESC,
952         },
953         {
954                 .name   = "name",
955                 .type   = FIO_OPT_STR_STORE,
956                 .off1   = td_var_offset(name),
957                 .help   = "Name of this job",
958                 .category = FIO_OPT_G_DESC,
959         },
960         {
961                 .name   = "directory",
962                 .type   = FIO_OPT_STR_STORE,
963                 .off1   = td_var_offset(directory),
964                 .cb     = str_directory_cb,
965                 .help   = "Directory to store files in",
966                 .category = FIO_OPT_G_FILE,
967         },
968         {
969                 .name   = "filename",
970                 .type   = FIO_OPT_STR_STORE,
971                 .off1   = td_var_offset(filename),
972                 .cb     = str_filename_cb,
973                 .prio   = -1, /* must come after "directory" */
974                 .help   = "File(s) to use for the workload",
975                 .category = FIO_OPT_G_FILE,
976         },
977         {
978                 .name   = "kb_base",
979                 .type   = FIO_OPT_INT,
980                 .off1   = td_var_offset(kb_base),
981                 .verify = kb_base_verify,
982                 .prio   = 1,
983                 .def    = "1024",
984                 .help   = "How many bytes per KB for reporting (1000 or 1024)",
985                 .category = FIO_OPT_G_MISC,
986         },
987         {
988                 .name   = "lockfile",
989                 .type   = FIO_OPT_STR,
990                 .cb     = str_lockfile_cb,
991                 .off1   = td_var_offset(file_lock_mode),
992                 .help   = "Lock file when doing IO to it",
993                 .parent = "filename",
994                 .def    = "none",
995                 .category = FIO_OPT_G_FILE,
996                 .posval = {
997                           { .ival = "none",
998                             .oval = FILE_LOCK_NONE,
999                             .help = "No file locking",
1000                           },
1001                           { .ival = "exclusive",
1002                             .oval = FILE_LOCK_EXCLUSIVE,
1003                             .help = "Exclusive file lock",
1004                           },
1005                           {
1006                             .ival = "readwrite",
1007                             .oval = FILE_LOCK_READWRITE,
1008                             .help = "Read vs write lock",
1009                           },
1010                 },
1011         },
1012         {
1013                 .name   = "opendir",
1014                 .type   = FIO_OPT_STR_STORE,
1015                 .off1   = td_var_offset(opendir),
1016                 .cb     = str_opendir_cb,
1017                 .help   = "Recursively add files from this directory and down",
1018                 .category = FIO_OPT_G_FILE,
1019         },
1020         {
1021                 .name   = "rw",
1022                 .alias  = "readwrite",
1023                 .type   = FIO_OPT_STR,
1024                 .cb     = str_rw_cb,
1025                 .off1   = td_var_offset(td_ddir),
1026                 .help   = "IO direction",
1027                 .def    = "read",
1028                 .verify = rw_verify,
1029                 .category = FIO_OPT_G_IO_DDIR,
1030                 .posval = {
1031                           { .ival = "read",
1032                             .oval = TD_DDIR_READ,
1033                             .help = "Sequential read",
1034                           },
1035                           { .ival = "write",
1036                             .oval = TD_DDIR_WRITE,
1037                             .help = "Sequential write",
1038                           },
1039                           { .ival = "randread",
1040                             .oval = TD_DDIR_RANDREAD,
1041                             .help = "Random read",
1042                           },
1043                           { .ival = "randwrite",
1044                             .oval = TD_DDIR_RANDWRITE,
1045                             .help = "Random write",
1046                           },
1047                           { .ival = "rw",
1048                             .oval = TD_DDIR_RW,
1049                             .help = "Sequential read and write mix",
1050                           },
1051                           { .ival = "randrw",
1052                             .oval = TD_DDIR_RANDRW,
1053                             .help = "Random read and write mix"
1054                           },
1055                 },
1056         },
1057         {
1058                 .name   = "rw_sequencer",
1059                 .type   = FIO_OPT_STR,
1060                 .off1   = td_var_offset(rw_seq),
1061                 .help   = "IO offset generator modifier",
1062                 .def    = "sequential",
1063                 .category = FIO_OPT_G_IO_DDIR,
1064                 .posval = {
1065                           { .ival = "sequential",
1066                             .oval = RW_SEQ_SEQ,
1067                             .help = "Generate sequential offsets",
1068                           },
1069                           { .ival = "identical",
1070                             .oval = RW_SEQ_IDENT,
1071                             .help = "Generate identical offsets",
1072                           },
1073                 },
1074         },
1075
1076         {
1077                 .name   = "ioengine",
1078                 .type   = FIO_OPT_STR_STORE,
1079                 .off1   = td_var_offset(ioengine),
1080                 .help   = "IO engine to use",
1081                 .def    = FIO_PREFERRED_ENGINE,
1082                 .category = FIO_OPT_G_IO,
1083                 .posval = {
1084                           { .ival = "sync",
1085                             .help = "Use read/write",
1086                           },
1087                           { .ival = "psync",
1088                             .help = "Use pread/pwrite",
1089                           },
1090                           { .ival = "vsync",
1091                             .help = "Use readv/writev",
1092                           },
1093 #ifdef FIO_HAVE_LIBAIO
1094                           { .ival = "libaio",
1095                             .help = "Linux native asynchronous IO",
1096                           },
1097 #endif
1098 #ifdef FIO_HAVE_POSIXAIO
1099                           { .ival = "posixaio",
1100                             .help = "POSIX asynchronous IO",
1101                           },
1102 #endif
1103 #ifdef FIO_HAVE_SOLARISAIO
1104                           { .ival = "solarisaio",
1105                             .help = "Solaris native asynchronous IO",
1106                           },
1107 #endif
1108 #ifdef FIO_HAVE_WINDOWSAIO
1109                           { .ival = "windowsaio",
1110                             .help = "Windows native asynchronous IO"
1111                           },
1112 #endif
1113                           { .ival = "mmap",
1114                             .help = "Memory mapped IO"
1115                           },
1116 #ifdef FIO_HAVE_SPLICE
1117                           { .ival = "splice",
1118                             .help = "splice/vmsplice based IO",
1119                           },
1120                           { .ival = "netsplice",
1121                             .help = "splice/vmsplice to/from the network",
1122                           },
1123 #endif
1124 #ifdef FIO_HAVE_SGIO
1125                           { .ival = "sg",
1126                             .help = "SCSI generic v3 IO",
1127                           },
1128 #endif
1129                           { .ival = "null",
1130                             .help = "Testing engine (no data transfer)",
1131                           },
1132                           { .ival = "net",
1133                             .help = "Network IO",
1134                           },
1135 #ifdef FIO_HAVE_SYSLET
1136                           { .ival = "syslet-rw",
1137                             .help = "syslet enabled async pread/pwrite IO",
1138                           },
1139 #endif
1140                           { .ival = "cpuio",
1141                             .help = "CPU cycle burner engine",
1142                           },
1143 #ifdef FIO_HAVE_GUASI
1144                           { .ival = "guasi",
1145                             .help = "GUASI IO engine",
1146                           },
1147 #endif
1148 #ifdef FIO_HAVE_BINJECT
1149                           { .ival = "binject",
1150                             .help = "binject direct inject block engine",
1151                           },
1152 #endif
1153 #ifdef FIO_HAVE_RDMA
1154                           { .ival = "rdma",
1155                             .help = "RDMA IO engine",
1156                           },
1157 #endif
1158                           { .ival = "external",
1159                             .help = "Load external engine (append name)",
1160                           },
1161                 },
1162         },
1163         {
1164                 .name   = "iodepth",
1165                 .type   = FIO_OPT_INT,
1166                 .off1   = td_var_offset(iodepth),
1167                 .help   = "Number of IO buffers to keep in flight",
1168                 .minval = 1,
1169                 .def    = "1",
1170                 .category = FIO_OPT_G_IO,
1171         },
1172         {
1173                 .name   = "iodepth_batch",
1174                 .alias  = "iodepth_batch_submit",
1175                 .type   = FIO_OPT_INT,
1176                 .off1   = td_var_offset(iodepth_batch),
1177                 .help   = "Number of IO buffers to submit in one go",
1178                 .parent = "iodepth",
1179                 .minval = 1,
1180                 .def    = "1",
1181                 .category = FIO_OPT_G_IO,
1182         },
1183         {
1184                 .name   = "iodepth_batch_complete",
1185                 .type   = FIO_OPT_INT,
1186                 .off1   = td_var_offset(iodepth_batch_complete),
1187                 .help   = "Number of IO buffers to retrieve in one go",
1188                 .parent = "iodepth",
1189                 .minval = 0,
1190                 .def    = "1",
1191                 .category = FIO_OPT_G_IO,
1192         },
1193         {
1194                 .name   = "iodepth_low",
1195                 .type   = FIO_OPT_INT,
1196                 .off1   = td_var_offset(iodepth_low),
1197                 .help   = "Low water mark for queuing depth",
1198                 .parent = "iodepth",
1199                 .category = FIO_OPT_G_IO,
1200         },
1201         {
1202                 .name   = "size",
1203                 .type   = FIO_OPT_STR_VAL,
1204                 .cb     = str_size_cb,
1205                 .help   = "Total size of device or files",
1206                 .category = FIO_OPT_G_IO,
1207         },
1208         {
1209                 .name   = "fill_device",
1210                 .alias  = "fill_fs",
1211                 .type   = FIO_OPT_BOOL,
1212                 .off1   = td_var_offset(fill_device),
1213                 .help   = "Write until an ENOSPC error occurs",
1214                 .def    = "0",
1215                 .category = FIO_OPT_G_IO,
1216         },
1217         {
1218                 .name   = "filesize",
1219                 .type   = FIO_OPT_STR_VAL,
1220                 .off1   = td_var_offset(file_size_low),
1221                 .off2   = td_var_offset(file_size_high),
1222                 .minval = 1,
1223                 .help   = "Size of individual files",
1224                 .category = FIO_OPT_G_IO | FIO_OPT_G_FILE,
1225         },
1226         {
1227                 .name   = "offset",
1228                 .alias  = "fileoffset",
1229                 .type   = FIO_OPT_STR_VAL,
1230                 .off1   = td_var_offset(start_offset),
1231                 .help   = "Start IO from this offset",
1232                 .def    = "0",
1233                 .category = FIO_OPT_G_IO,
1234         },
1235         {
1236                 .name   = "offset_increment",
1237                 .type   = FIO_OPT_STR_VAL,
1238                 .off1   = td_var_offset(offset_increment),
1239                 .help   = "What is the increment from one offset to the next",
1240                 .parent = "offset",
1241                 .def    = "0",
1242         },
1243         {
1244                 .name   = "bs",
1245                 .alias  = "blocksize",
1246                 .type   = FIO_OPT_INT,
1247                 .off1   = td_var_offset(bs[DDIR_READ]),
1248                 .off2   = td_var_offset(bs[DDIR_WRITE]),
1249                 .minval = 1,
1250                 .help   = "Block size unit",
1251                 .def    = "4k",
1252                 .parent = "rw",
1253                 .category = FIO_OPT_G_IO,
1254         },
1255         {
1256                 .name   = "ba",
1257                 .alias  = "blockalign",
1258                 .type   = FIO_OPT_INT,
1259                 .off1   = td_var_offset(ba[DDIR_READ]),
1260                 .off2   = td_var_offset(ba[DDIR_WRITE]),
1261                 .minval = 1,
1262                 .help   = "IO block offset alignment",
1263                 .parent = "rw",
1264                 .category = FIO_OPT_G_IO | FIO_OPT_G_IO_BUF,
1265         },
1266         {
1267                 .name   = "bsrange",
1268                 .alias  = "blocksize_range",
1269                 .type   = FIO_OPT_RANGE,
1270                 .off1   = td_var_offset(min_bs[DDIR_READ]),
1271                 .off2   = td_var_offset(max_bs[DDIR_READ]),
1272                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
1273                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
1274                 .minval = 1,
1275                 .help   = "Set block size range (in more detail than bs)",
1276                 .parent = "rw",
1277                 .category = FIO_OPT_G_IO,
1278         },
1279         {
1280                 .name   = "bssplit",
1281                 .type   = FIO_OPT_STR,
1282                 .cb     = str_bssplit_cb,
1283                 .help   = "Set a specific mix of block sizes",
1284                 .parent = "rw",
1285                 .category = FIO_OPT_G_IO,
1286         },
1287         {
1288                 .name   = "bs_unaligned",
1289                 .alias  = "blocksize_unaligned",
1290                 .type   = FIO_OPT_STR_SET,
1291                 .off1   = td_var_offset(bs_unaligned),
1292                 .help   = "Don't sector align IO buffer sizes",
1293                 .parent = "rw",
1294                 .category = FIO_OPT_G_IO,
1295         },
1296         {
1297                 .name   = "randrepeat",
1298                 .type   = FIO_OPT_BOOL,
1299                 .off1   = td_var_offset(rand_repeatable),
1300                 .help   = "Use repeatable random IO pattern",
1301                 .def    = "1",
1302                 .parent = "rw",
1303                 .category = FIO_OPT_G_IO | FIO_OPT_G_RAND,
1304         },
1305         {
1306                 .name   = "use_os_rand",
1307                 .type   = FIO_OPT_BOOL,
1308                 .off1   = td_var_offset(use_os_rand),
1309                 .help   = "Set to use OS random generator",
1310                 .def    = "0",
1311                 .parent = "rw",
1312                 .category = FIO_OPT_G_RAND,
1313         },
1314         {
1315                 .name   = "norandommap",
1316                 .type   = FIO_OPT_STR_SET,
1317                 .off1   = td_var_offset(norandommap),
1318                 .help   = "Accept potential duplicate random blocks",
1319                 .parent = "rw",
1320                 .category = FIO_OPT_G_RAND,
1321         },
1322         {
1323                 .name   = "softrandommap",
1324                 .type   = FIO_OPT_BOOL,
1325                 .off1   = td_var_offset(softrandommap),
1326                 .help   = "Set norandommap if randommap allocation fails",
1327                 .parent = "norandommap",
1328                 .def    = "0",
1329                 .category = FIO_OPT_G_RAND,
1330         },
1331         {
1332                 .name   = "nrfiles",
1333                 .alias  = "nr_files",
1334                 .type   = FIO_OPT_INT,
1335                 .off1   = td_var_offset(nr_files),
1336                 .help   = "Split job workload between this number of files",
1337                 .def    = "1",
1338                 .category = FIO_OPT_G_FILE,
1339         },
1340         {
1341                 .name   = "openfiles",
1342                 .type   = FIO_OPT_INT,
1343                 .off1   = td_var_offset(open_files),
1344                 .help   = "Number of files to keep open at the same time",
1345                 .category = FIO_OPT_G_FILE,
1346         },
1347         {
1348                 .name   = "file_service_type",
1349                 .type   = FIO_OPT_STR,
1350                 .cb     = str_fst_cb,
1351                 .off1   = td_var_offset(file_service_type),
1352                 .help   = "How to select which file to service next",
1353                 .def    = "roundrobin",
1354                 .category = FIO_OPT_G_FILE,
1355                 .posval = {
1356                           { .ival = "random",
1357                             .oval = FIO_FSERVICE_RANDOM,
1358                             .help = "Choose a file at random",
1359                           },
1360                           { .ival = "roundrobin",
1361                             .oval = FIO_FSERVICE_RR,
1362                             .help = "Round robin select files",
1363                           },
1364                           { .ival = "sequential",
1365                             .oval = FIO_FSERVICE_SEQ,
1366                             .help = "Finish one file before moving to the next",
1367                           },
1368                 },
1369                 .parent = "nrfiles",
1370         },
1371 #ifdef FIO_HAVE_FALLOCATE
1372         {
1373                 .name   = "fallocate",
1374                 .type   = FIO_OPT_STR,
1375                 .off1   = td_var_offset(fallocate_mode),
1376                 .help   = "Whether pre-allocation is performed when laying out files",
1377                 .def    = "posix",
1378                 .category = FIO_OPT_G_FILE,
1379                 .posval = {
1380                           { .ival = "none",
1381                             .oval = FIO_FALLOCATE_NONE,
1382                             .help = "Do not pre-allocate space",
1383                           },
1384                           { .ival = "posix",
1385                             .oval = FIO_FALLOCATE_POSIX,
1386                             .help = "Use posix_fallocate()",
1387                           },
1388 #ifdef FIO_HAVE_LINUX_FALLOCATE
1389                           { .ival = "keep",
1390                             .oval = FIO_FALLOCATE_KEEP_SIZE,
1391                             .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1392                           },
1393 #endif
1394                           /* Compatibility with former boolean values */
1395                           { .ival = "0",
1396                             .oval = FIO_FALLOCATE_NONE,
1397                             .help = "Alias for 'none'",
1398                           },
1399                           { .ival = "1",
1400                             .oval = FIO_FALLOCATE_POSIX,
1401                             .help = "Alias for 'posix'",
1402                           },
1403                 },
1404         },
1405 #endif  /* FIO_HAVE_FALLOCATE */
1406         {
1407                 .name   = "fadvise_hint",
1408                 .type   = FIO_OPT_BOOL,
1409                 .off1   = td_var_offset(fadvise_hint),
1410                 .help   = "Use fadvise() to advise the kernel on IO pattern",
1411                 .def    = "1",
1412                 .category = FIO_OPT_G_FILE,
1413         },
1414         {
1415                 .name   = "fsync",
1416                 .type   = FIO_OPT_INT,
1417                 .off1   = td_var_offset(fsync_blocks),
1418                 .help   = "Issue fsync for writes every given number of blocks",
1419                 .def    = "0",
1420                 .category = FIO_OPT_G_FILE,
1421         },
1422         {
1423                 .name   = "fdatasync",
1424                 .type   = FIO_OPT_INT,
1425                 .off1   = td_var_offset(fdatasync_blocks),
1426                 .help   = "Issue fdatasync for writes every given number of blocks",
1427                 .def    = "0",
1428                 .category = FIO_OPT_G_FILE,
1429         },
1430         {
1431                 .name   = "write_barrier",
1432                 .type   = FIO_OPT_INT,
1433                 .off1   = td_var_offset(barrier_blocks),
1434                 .help   = "Make every Nth write a barrier write",
1435                 .def    = "0",
1436                 .category = FIO_OPT_G_IO,
1437         },
1438 #ifdef FIO_HAVE_SYNC_FILE_RANGE
1439         {
1440                 .name   = "sync_file_range",
1441                 .posval = {
1442                           { .ival = "wait_before",
1443                             .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1444                             .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1445                             .or   = 1,
1446                           },
1447                           { .ival = "write",
1448                             .oval = SYNC_FILE_RANGE_WRITE,
1449                             .help = "SYNC_FILE_RANGE_WRITE",
1450                             .or   = 1,
1451                           },
1452                           {
1453                             .ival = "wait_after",
1454                             .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1455                             .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1456                             .or   = 1,
1457                           },
1458                 },
1459                 .type   = FIO_OPT_STR_MULTI,
1460                 .cb     = str_sfr_cb,
1461                 .off1   = td_var_offset(sync_file_range),
1462                 .help   = "Use sync_file_range()",
1463                 .category = FIO_OPT_G_FILE,
1464         },
1465 #endif
1466         {
1467                 .name   = "direct",
1468                 .type   = FIO_OPT_BOOL,
1469                 .off1   = td_var_offset(odirect),
1470                 .help   = "Use O_DIRECT IO (negates buffered)",
1471                 .def    = "0",
1472                 .category = FIO_OPT_G_IO,
1473         },
1474         {
1475                 .name   = "buffered",
1476                 .type   = FIO_OPT_BOOL,
1477                 .off1   = td_var_offset(odirect),
1478                 .neg    = 1,
1479                 .help   = "Use buffered IO (negates direct)",
1480                 .def    = "1",
1481                 .category = FIO_OPT_G_IO,
1482         },
1483         {
1484                 .name   = "overwrite",
1485                 .type   = FIO_OPT_BOOL,
1486                 .off1   = td_var_offset(overwrite),
1487                 .help   = "When writing, set whether to overwrite current data",
1488                 .def    = "0",
1489                 .category = FIO_OPT_G_IO | FIO_OPT_G_FILE,
1490         },
1491         {
1492                 .name   = "loops",
1493                 .type   = FIO_OPT_INT,
1494                 .off1   = td_var_offset(loops),
1495                 .help   = "Number of times to run the job",
1496                 .def    = "1",
1497                 .category = FIO_OPT_G_MISC,
1498         },
1499         {
1500                 .name   = "numjobs",
1501                 .type   = FIO_OPT_INT,
1502                 .off1   = td_var_offset(numjobs),
1503                 .help   = "Duplicate this job this many times",
1504                 .def    = "1",
1505                 .category = FIO_OPT_G_MISC,
1506         },
1507         {
1508                 .name   = "startdelay",
1509                 .type   = FIO_OPT_STR_VAL_TIME,
1510                 .off1   = td_var_offset(start_delay),
1511                 .help   = "Only start job when this period has passed",
1512                 .def    = "0",
1513                 .category = FIO_OPT_G_MISC,
1514         },
1515         {
1516                 .name   = "runtime",
1517                 .alias  = "timeout",
1518                 .type   = FIO_OPT_STR_VAL_TIME,
1519                 .off1   = td_var_offset(timeout),
1520                 .help   = "Stop workload when this amount of time has passed",
1521                 .def    = "0",
1522                 .category = FIO_OPT_G_MISC,
1523         },
1524         {
1525                 .name   = "time_based",
1526                 .type   = FIO_OPT_STR_SET,
1527                 .off1   = td_var_offset(time_based),
1528                 .help   = "Keep running until runtime/timeout is met",
1529                 .category = FIO_OPT_G_MISC,
1530         },
1531         {
1532                 .name   = "ramp_time",
1533                 .type   = FIO_OPT_STR_VAL_TIME,
1534                 .off1   = td_var_offset(ramp_time),
1535                 .help   = "Ramp up time before measuring performance",
1536                 .category = FIO_OPT_G_MISC,
1537         },
1538         {
1539                 .name   = "clocksource",
1540                 .type   = FIO_OPT_STR,
1541                 .cb     = fio_clock_source_cb,
1542                 .off1   = td_var_offset(clocksource),
1543                 .help   = "What type of timing source to use",
1544                 .category = FIO_OPT_G_OS,
1545                 .posval = {
1546                           { .ival = "gettimeofday",
1547                             .oval = CS_GTOD,
1548                             .help = "Use gettimeofday(2) for timing",
1549                           },
1550                           { .ival = "clock_gettime",
1551                             .oval = CS_CGETTIME,
1552                             .help = "Use clock_gettime(2) for timing",
1553                           },
1554 #ifdef ARCH_HAVE_CPU_CLOCK
1555                           { .ival = "cpu",
1556                             .oval = CS_CPUCLOCK,
1557                             .help = "Use CPU private clock",
1558                           },
1559 #endif
1560                 },
1561         },
1562         {
1563                 .name   = "mem",
1564                 .alias  = "iomem",
1565                 .type   = FIO_OPT_STR,
1566                 .cb     = str_mem_cb,
1567                 .off1   = td_var_offset(mem_type),
1568                 .help   = "Backing type for IO buffers",
1569                 .def    = "malloc",
1570                 .category = FIO_OPT_G_IO_BUF | FIO_OPT_G_MEM,
1571                 .posval = {
1572                           { .ival = "malloc",
1573                             .oval = MEM_MALLOC,
1574                             .help = "Use malloc(3) for IO buffers",
1575                           },
1576                           { .ival = "shm",
1577                             .oval = MEM_SHM,
1578                             .help = "Use shared memory segments for IO buffers",
1579                           },
1580 #ifdef FIO_HAVE_HUGETLB
1581                           { .ival = "shmhuge",
1582                             .oval = MEM_SHMHUGE,
1583                             .help = "Like shm, but use huge pages",
1584                           },
1585 #endif
1586                           { .ival = "mmap",
1587                             .oval = MEM_MMAP,
1588                             .help = "Use mmap(2) (file or anon) for IO buffers",
1589                           },
1590 #ifdef FIO_HAVE_HUGETLB
1591                           { .ival = "mmaphuge",
1592                             .oval = MEM_MMAPHUGE,
1593                             .help = "Like mmap, but use huge pages",
1594                           },
1595 #endif
1596                   },
1597         },
1598         {
1599                 .name   = "iomem_align",
1600                 .alias  = "mem_align",
1601                 .type   = FIO_OPT_INT,
1602                 .off1   = td_var_offset(mem_align),
1603                 .minval = 0,
1604                 .help   = "IO memory buffer offset alignment",
1605                 .def    = "0",
1606                 .parent = "iomem",
1607                 .category = FIO_OPT_G_IO_BUF | FIO_OPT_G_MEM,
1608         },
1609         {
1610                 .name   = "verify",
1611                 .type   = FIO_OPT_STR,
1612                 .off1   = td_var_offset(verify),
1613                 .help   = "Verify data written",
1614                 .cb     = str_verify_cb,
1615                 .def    = "0",
1616                 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1617                 .posval = {
1618                           { .ival = "0",
1619                             .oval = VERIFY_NONE,
1620                             .help = "Don't do IO verification",
1621                           },
1622                           { .ival = "md5",
1623                             .oval = VERIFY_MD5,
1624                             .help = "Use md5 checksums for verification",
1625                           },
1626                           { .ival = "crc64",
1627                             .oval = VERIFY_CRC64,
1628                             .help = "Use crc64 checksums for verification",
1629                           },
1630                           { .ival = "crc32",
1631                             .oval = VERIFY_CRC32,
1632                             .help = "Use crc32 checksums for verification",
1633                           },
1634                           { .ival = "crc32c-intel",
1635                             .oval = VERIFY_CRC32C,
1636                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
1637                           },
1638                           { .ival = "crc32c",
1639                             .oval = VERIFY_CRC32C,
1640                             .help = "Use crc32c checksums for verification (hw assisted, if available)",
1641                           },
1642                           { .ival = "crc16",
1643                             .oval = VERIFY_CRC16,
1644                             .help = "Use crc16 checksums for verification",
1645                           },
1646                           { .ival = "crc7",
1647                             .oval = VERIFY_CRC7,
1648                             .help = "Use crc7 checksums for verification",
1649                           },
1650                           { .ival = "sha1",
1651                             .oval = VERIFY_SHA1,
1652                             .help = "Use sha1 checksums for verification",
1653                           },
1654                           { .ival = "sha256",
1655                             .oval = VERIFY_SHA256,
1656                             .help = "Use sha256 checksums for verification",
1657                           },
1658                           { .ival = "sha512",
1659                             .oval = VERIFY_SHA512,
1660                             .help = "Use sha512 checksums for verification",
1661                           },
1662                           { .ival = "meta",
1663                             .oval = VERIFY_META,
1664                             .help = "Use io information",
1665                           },
1666                           {
1667                             .ival = "null",
1668                             .oval = VERIFY_NULL,
1669                             .help = "Pretend to verify",
1670                           },
1671                 },
1672         },
1673         {
1674                 .name   = "do_verify",
1675                 .type   = FIO_OPT_BOOL,
1676                 .off1   = td_var_offset(do_verify),
1677                 .help   = "Run verification stage after write",
1678                 .def    = "1",
1679                 .parent = "verify",
1680                 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1681         },
1682         {
1683                 .name   = "verifysort",
1684                 .type   = FIO_OPT_BOOL,
1685                 .off1   = td_var_offset(verifysort),
1686                 .help   = "Sort written verify blocks for read back",
1687                 .def    = "1",
1688                 .parent = "verify",
1689                 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1690         },
1691         {
1692                 .name   = "verify_interval",
1693                 .type   = FIO_OPT_INT,
1694                 .off1   = td_var_offset(verify_interval),
1695                 .minval = 2 * sizeof(struct verify_header),
1696                 .help   = "Store verify buffer header every N bytes",
1697                 .parent = "verify",
1698                 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1699         },
1700         {
1701                 .name   = "verify_offset",
1702                 .type   = FIO_OPT_INT,
1703                 .help   = "Offset verify header location by N bytes",
1704                 .def    = "0",
1705                 .cb     = str_verify_offset_cb,
1706                 .parent = "verify",
1707                 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1708         },
1709         {
1710                 .name   = "verify_pattern",
1711                 .type   = FIO_OPT_STR,
1712                 .cb     = str_verify_pattern_cb,
1713                 .help   = "Fill pattern for IO buffers",
1714                 .parent = "verify",
1715                 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1716         },
1717         {
1718                 .name   = "verify_fatal",
1719                 .type   = FIO_OPT_BOOL,
1720                 .off1   = td_var_offset(verify_fatal),
1721                 .def    = "0",
1722                 .help   = "Exit on a single verify failure, don't continue",
1723                 .parent = "verify",
1724                 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY | FIO_OPT_G_ERR,
1725         },
1726         {
1727                 .name   = "verify_dump",
1728                 .type   = FIO_OPT_BOOL,
1729                 .off1   = td_var_offset(verify_dump),
1730                 .def    = "0",
1731                 .help   = "Dump contents of good and bad blocks on failure",
1732                 .parent = "verify",
1733                 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY | FIO_OPT_G_ERR,
1734         },
1735         {
1736                 .name   = "verify_async",
1737                 .type   = FIO_OPT_INT,
1738                 .off1   = td_var_offset(verify_async),
1739                 .def    = "0",
1740                 .help   = "Number of async verifier threads to use",
1741                 .parent = "verify",
1742                 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1743         },
1744         {
1745                 .name   = "verify_backlog",
1746                 .type   = FIO_OPT_STR_VAL,
1747                 .off1   = td_var_offset(verify_backlog),
1748                 .help   = "Verify after this number of blocks are written",
1749                 .parent = "verify",
1750                 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1751         },
1752         {
1753                 .name   = "verify_backlog_batch",
1754                 .type   = FIO_OPT_INT,
1755                 .off1   = td_var_offset(verify_batch),
1756                 .help   = "Verify this number of IO blocks",
1757                 .parent = "verify",
1758                 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1759         },
1760 #ifdef FIO_HAVE_CPU_AFFINITY
1761         {
1762                 .name   = "verify_async_cpus",
1763                 .type   = FIO_OPT_STR,
1764                 .cb     = str_verify_cpus_allowed_cb,
1765                 .help   = "Set CPUs allowed for async verify threads",
1766                 .parent = "verify_async",
1767                 .category = FIO_OPT_G_OS | FIO_OPT_G_CPU | FIO_OPT_G_VERIFY,
1768         },
1769 #endif
1770 #ifdef FIO_HAVE_TRIM
1771         {
1772                 .name   = "trim_percentage",
1773                 .type   = FIO_OPT_INT,
1774                 .cb     = str_verify_trim_cb,
1775                 .maxval = 100,
1776                 .help   = "Number of verify blocks to discard/trim",
1777                 .parent = "verify",
1778                 .def    = "0",
1779                 .category = FIO_OPT_G_IO,
1780         },
1781         {
1782                 .name   = "trim_verify_zero",
1783                 .type   = FIO_OPT_INT,
1784                 .help   = "Verify that trim/discarded blocks are returned as zeroes",
1785                 .off1   = td_var_offset(trim_zero),
1786                 .parent = "trim_percentage",
1787                 .def    = "1",
1788                 .category = FIO_OPT_G_IO,
1789         },
1790         {
1791                 .name   = "trim_backlog",
1792                 .type   = FIO_OPT_STR_VAL,
1793                 .off1   = td_var_offset(trim_backlog),
1794                 .help   = "Trim after this number of blocks are written",
1795                 .parent = "trim_percentage",
1796                 .category = FIO_OPT_G_IO,
1797         },
1798         {
1799                 .name   = "trim_backlog_batch",
1800                 .type   = FIO_OPT_INT,
1801                 .off1   = td_var_offset(trim_batch),
1802                 .help   = "Trim this number of IO blocks",
1803                 .parent = "trim_percentage",
1804                 .category = FIO_OPT_G_IO,
1805         },
1806 #endif
1807         {
1808                 .name   = "write_iolog",
1809                 .type   = FIO_OPT_STR_STORE,
1810                 .off1   = td_var_offset(write_iolog_file),
1811                 .help   = "Store IO pattern to file",
1812                 .category = FIO_OPT_G_IO | FIO_OPT_G_LOG,
1813         },
1814         {
1815                 .name   = "read_iolog",
1816                 .type   = FIO_OPT_STR_STORE,
1817                 .off1   = td_var_offset(read_iolog_file),
1818                 .help   = "Playback IO pattern from file",
1819                 .category = FIO_OPT_G_IO | FIO_OPT_G_LOG,
1820         },
1821         {
1822                 .name   = "replay_no_stall",
1823                 .type   = FIO_OPT_INT,
1824                 .off1   = td_var_offset(no_stall),
1825                 .def    = "0",
1826                 .parent = "read_iolog",
1827                 .help   = "Playback IO pattern file as fast as possible without stalls",
1828                 .category = FIO_OPT_G_IO | FIO_OPT_G_LOG,
1829         },
1830         {
1831                 .name   = "replay_redirect",
1832                 .type   = FIO_OPT_STR_STORE,
1833                 .off1   = td_var_offset(replay_redirect),
1834                 .parent = "read_iolog",
1835                 .help   = "Replay all I/O onto this device, regardless of trace device",
1836                 .category = FIO_OPT_G_IO | FIO_OPT_G_LOG,
1837         },
1838         {
1839                 .name   = "exec_prerun",
1840                 .type   = FIO_OPT_STR_STORE,
1841                 .off1   = td_var_offset(exec_prerun),
1842                 .help   = "Execute this file prior to running job",
1843                 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
1844         },
1845         {
1846                 .name   = "exec_postrun",
1847                 .type   = FIO_OPT_STR_STORE,
1848                 .off1   = td_var_offset(exec_postrun),
1849                 .help   = "Execute this file after running job",
1850                 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
1851         },
1852 #ifdef FIO_HAVE_IOSCHED_SWITCH
1853         {
1854                 .name   = "ioscheduler",
1855                 .type   = FIO_OPT_STR_STORE,
1856                 .off1   = td_var_offset(ioscheduler),
1857                 .help   = "Use this IO scheduler on the backing device",
1858                 .category = FIO_OPT_G_OS | FIO_OPT_G_IO,
1859         },
1860 #endif
1861         {
1862                 .name   = "zonesize",
1863                 .type   = FIO_OPT_STR_VAL,
1864                 .off1   = td_var_offset(zone_size),
1865                 .help   = "Amount of data to read per zone",
1866                 .def    = "0",
1867                 .category = FIO_OPT_G_IO | FIO_OPT_G_ZONE,
1868         },
1869         {
1870                 .name   = "zonerange",
1871                 .type   = FIO_OPT_STR_VAL,
1872                 .off1   = td_var_offset(zone_range),
1873                 .help   = "Give size of an IO zone",
1874                 .def    = "0",
1875                 .category = FIO_OPT_G_IO | FIO_OPT_G_ZONE,
1876         },
1877         {
1878                 .name   = "zoneskip",
1879                 .type   = FIO_OPT_STR_VAL,
1880                 .off1   = td_var_offset(zone_skip),
1881                 .help   = "Space between IO zones",
1882                 .def    = "0",
1883                 .category = FIO_OPT_G_IO | FIO_OPT_G_ZONE,
1884         },
1885         {
1886                 .name   = "lockmem",
1887                 .type   = FIO_OPT_STR_VAL,
1888                 .cb     = str_lockmem_cb,
1889                 .help   = "Lock down this amount of memory",
1890                 .def    = "0",
1891                 .category = FIO_OPT_G_OS | FIO_OPT_G_MEM,
1892         },
1893         {
1894                 .name   = "rwmixread",
1895                 .type   = FIO_OPT_INT,
1896                 .cb     = str_rwmix_read_cb,
1897                 .maxval = 100,
1898                 .help   = "Percentage of mixed workload that is reads",
1899                 .def    = "50",
1900                 .category = FIO_OPT_G_IO,
1901         },
1902         {
1903                 .name   = "rwmixwrite",
1904                 .type   = FIO_OPT_INT,
1905                 .cb     = str_rwmix_write_cb,
1906                 .maxval = 100,
1907                 .help   = "Percentage of mixed workload that is writes",
1908                 .def    = "50",
1909                 .category = FIO_OPT_G_IO,
1910         },
1911         {
1912                 .name   = "rwmixcycle",
1913                 .type   = FIO_OPT_DEPRECATED,
1914                 .category = FIO_OPT_G_IO,
1915         },
1916         {
1917                 .name   = "nice",
1918                 .type   = FIO_OPT_INT,
1919                 .off1   = td_var_offset(nice),
1920                 .help   = "Set job CPU nice value",
1921                 .minval = -19,
1922                 .maxval = 20,
1923                 .def    = "0",
1924                 .category = FIO_OPT_G_OS | FIO_OPT_G_CPU,
1925         },
1926 #ifdef FIO_HAVE_IOPRIO
1927         {
1928                 .name   = "prio",
1929                 .type   = FIO_OPT_INT,
1930                 .cb     = str_prio_cb,
1931                 .help   = "Set job IO priority value",
1932                 .minval = 0,
1933                 .maxval = 7,
1934                 .category = FIO_OPT_G_OS | FIO_OPT_G_CPU,
1935         },
1936         {
1937                 .name   = "prioclass",
1938                 .type   = FIO_OPT_INT,
1939                 .cb     = str_prioclass_cb,
1940                 .help   = "Set job IO priority class",
1941                 .minval = 0,
1942                 .maxval = 3,
1943                 .category = FIO_OPT_G_OS | FIO_OPT_G_CPU,
1944         },
1945 #endif
1946         {
1947                 .name   = "thinktime",
1948                 .type   = FIO_OPT_INT,
1949                 .off1   = td_var_offset(thinktime),
1950                 .help   = "Idle time between IO buffers (usec)",
1951                 .def    = "0",
1952                 .category = FIO_OPT_G_MISC,
1953         },
1954         {
1955                 .name   = "thinktime_spin",
1956                 .type   = FIO_OPT_INT,
1957                 .off1   = td_var_offset(thinktime_spin),
1958                 .help   = "Start think time by spinning this amount (usec)",
1959                 .def    = "0",
1960                 .parent = "thinktime",
1961                 .category = FIO_OPT_G_MISC,
1962         },
1963         {
1964                 .name   = "thinktime_blocks",
1965                 .type   = FIO_OPT_INT,
1966                 .off1   = td_var_offset(thinktime_blocks),
1967                 .help   = "IO buffer period between 'thinktime'",
1968                 .def    = "1",
1969                 .parent = "thinktime",
1970                 .category = FIO_OPT_G_MISC,
1971         },
1972         {
1973                 .name   = "rate",
1974                 .type   = FIO_OPT_INT,
1975                 .off1   = td_var_offset(rate[0]),
1976                 .off2   = td_var_offset(rate[1]),
1977                 .help   = "Set bandwidth rate",
1978                 .category = FIO_OPT_G_IO,
1979         },
1980         {
1981                 .name   = "ratemin",
1982                 .type   = FIO_OPT_INT,
1983                 .off1   = td_var_offset(ratemin[0]),
1984                 .off2   = td_var_offset(ratemin[1]),
1985                 .help   = "Job must meet this rate or it will be shutdown",
1986                 .parent = "rate",
1987                 .category = FIO_OPT_G_IO,
1988         },
1989         {
1990                 .name   = "rate_iops",
1991                 .type   = FIO_OPT_INT,
1992                 .off1   = td_var_offset(rate_iops[0]),
1993                 .off2   = td_var_offset(rate_iops[1]),
1994                 .help   = "Limit IO used to this number of IO operations/sec",
1995                 .category = FIO_OPT_G_IO,
1996         },
1997         {
1998                 .name   = "rate_iops_min",
1999                 .type   = FIO_OPT_INT,
2000                 .off1   = td_var_offset(rate_iops_min[0]),
2001                 .off2   = td_var_offset(rate_iops_min[1]),
2002                 .help   = "Job must meet this rate or it will be shut down",
2003                 .parent = "rate_iops",
2004                 .category = FIO_OPT_G_IO,
2005         },
2006         {
2007                 .name   = "ratecycle",
2008                 .type   = FIO_OPT_INT,
2009                 .off1   = td_var_offset(ratecycle),
2010                 .help   = "Window average for rate limits (msec)",
2011                 .def    = "1000",
2012                 .parent = "rate",
2013                 .category = FIO_OPT_G_IO,
2014         },
2015         {
2016                 .name   = "invalidate",
2017                 .type   = FIO_OPT_BOOL,
2018                 .off1   = td_var_offset(invalidate_cache),
2019                 .help   = "Invalidate buffer/page cache prior to running job",
2020                 .def    = "1",
2021                 .category = FIO_OPT_G_IO | FIO_OPT_G_CACHE,
2022         },
2023         {
2024                 .name   = "sync",
2025                 .type   = FIO_OPT_BOOL,
2026                 .off1   = td_var_offset(sync_io),
2027                 .help   = "Use O_SYNC for buffered writes",
2028                 .def    = "0",
2029                 .parent = "buffered",
2030                 .category = FIO_OPT_G_IO | FIO_OPT_G_FILE,
2031         },
2032         {
2033                 .name   = "bwavgtime",
2034                 .type   = FIO_OPT_INT,
2035                 .off1   = td_var_offset(bw_avg_time),
2036                 .help   = "Time window over which to calculate bandwidth"
2037                           " (msec)",
2038                 .def    = "500",
2039                 .parent = "write_bw_log",
2040                 .category = FIO_OPT_G_LOG | FIO_OPT_G_STAT,
2041         },
2042         {
2043                 .name   = "iopsavgtime",
2044                 .type   = FIO_OPT_INT,
2045                 .off1   = td_var_offset(iops_avg_time),
2046                 .help   = "Time window over which to calculate IOPS (msec)",
2047                 .def    = "500",
2048                 .parent = "write_iops_log",
2049                 .category = FIO_OPT_G_LOG | FIO_OPT_G_STAT,
2050         },
2051         {
2052                 .name   = "create_serialize",
2053                 .type   = FIO_OPT_BOOL,
2054                 .off1   = td_var_offset(create_serialize),
2055                 .help   = "Serialize creating of job files",
2056                 .def    = "1",
2057                 .category = FIO_OPT_G_FILE,
2058         },
2059         {
2060                 .name   = "create_fsync",
2061                 .type   = FIO_OPT_BOOL,
2062                 .off1   = td_var_offset(create_fsync),
2063                 .help   = "fsync file after creation",
2064                 .def    = "1",
2065                 .category = FIO_OPT_G_FILE,
2066         },
2067         {
2068                 .name   = "create_on_open",
2069                 .type   = FIO_OPT_BOOL,
2070                 .off1   = td_var_offset(create_on_open),
2071                 .help   = "Create files when they are opened for IO",
2072                 .def    = "0",
2073                 .category = FIO_OPT_G_FILE,
2074         },
2075         {
2076                 .name   = "pre_read",
2077                 .type   = FIO_OPT_BOOL,
2078                 .off1   = td_var_offset(pre_read),
2079                 .help   = "Pre-read files before starting official testing",
2080                 .def    = "0",
2081                 .category = FIO_OPT_G_FILE | FIO_OPT_G_CACHE,
2082         },
2083         {
2084                 .name   = "cpuload",
2085                 .type   = FIO_OPT_INT,
2086                 .off1   = td_var_offset(cpuload),
2087                 .help   = "Use this percentage of CPU",
2088                 .category = FIO_OPT_G_CPU,
2089         },
2090         {
2091                 .name   = "cpuchunks",
2092                 .type   = FIO_OPT_INT,
2093                 .off1   = td_var_offset(cpucycle),
2094                 .help   = "Length of the CPU burn cycles (usecs)",
2095                 .def    = "50000",
2096                 .parent = "cpuload",
2097                 .category = FIO_OPT_G_CPU,
2098         },
2099 #ifdef FIO_HAVE_CPU_AFFINITY
2100         {
2101                 .name   = "cpumask",
2102                 .type   = FIO_OPT_INT,
2103                 .cb     = str_cpumask_cb,
2104                 .help   = "CPU affinity mask",
2105                 .category = FIO_OPT_G_CPU | FIO_OPT_G_OS,
2106         },
2107         {
2108                 .name   = "cpus_allowed",
2109                 .type   = FIO_OPT_STR,
2110                 .cb     = str_cpus_allowed_cb,
2111                 .help   = "Set CPUs allowed",
2112                 .category = FIO_OPT_G_CPU | FIO_OPT_G_OS,
2113         },
2114 #endif
2115         {
2116                 .name   = "end_fsync",
2117                 .type   = FIO_OPT_BOOL,
2118                 .off1   = td_var_offset(end_fsync),
2119                 .help   = "Include fsync at the end of job",
2120                 .def    = "0",
2121                 .category = FIO_OPT_G_FILE,
2122         },
2123         {
2124                 .name   = "fsync_on_close",
2125                 .type   = FIO_OPT_BOOL,
2126                 .off1   = td_var_offset(fsync_on_close),
2127                 .help   = "fsync files on close",
2128                 .def    = "0",
2129                 .category = FIO_OPT_G_FILE,
2130         },
2131         {
2132                 .name   = "unlink",
2133                 .type   = FIO_OPT_BOOL,
2134                 .off1   = td_var_offset(unlink),
2135                 .help   = "Unlink created files after job has completed",
2136                 .def    = "0",
2137                 .category = FIO_OPT_G_FILE,
2138         },
2139         {
2140                 .name   = "exitall",
2141                 .type   = FIO_OPT_STR_SET,
2142                 .cb     = str_exitall_cb,
2143                 .help   = "Terminate all jobs when one exits",
2144                 .category = FIO_OPT_G_MISC | FIO_OPT_G_JOB,
2145         },
2146         {
2147                 .name   = "stonewall",
2148                 .alias  = "wait_for_previous",
2149                 .type   = FIO_OPT_STR_SET,
2150                 .off1   = td_var_offset(stonewall),
2151                 .help   = "Insert a hard barrier between this job and previous",
2152                 .category = FIO_OPT_G_MISC | FIO_OPT_G_JOB,
2153         },
2154         {
2155                 .name   = "new_group",
2156                 .type   = FIO_OPT_STR_SET,
2157                 .off1   = td_var_offset(new_group),
2158                 .help   = "Mark the start of a new group (for reporting)",
2159                 .category = FIO_OPT_G_MISC | FIO_OPT_G_JOB,
2160         },
2161         {
2162                 .name   = "thread",
2163                 .type   = FIO_OPT_STR_SET,
2164                 .off1   = td_var_offset(use_thread),
2165                 .help   = "Use threads instead of forks",
2166                 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS | FIO_OPT_G_JOB,
2167         },
2168         {
2169                 .name   = "write_bw_log",
2170                 .type   = FIO_OPT_STR,
2171                 .off1   = td_var_offset(write_bw_log),
2172                 .cb     = str_write_bw_log_cb,
2173                 .help   = "Write log of bandwidth during run",
2174                 .category = FIO_OPT_G_LOG,
2175         },
2176         {
2177                 .name   = "write_lat_log",
2178                 .type   = FIO_OPT_STR,
2179                 .off1   = td_var_offset(write_lat_log),
2180                 .cb     = str_write_lat_log_cb,
2181                 .help   = "Write log of latency during run",
2182                 .category = FIO_OPT_G_LOG,
2183         },
2184         {
2185                 .name   = "write_iops_log",
2186                 .type   = FIO_OPT_STR,
2187                 .off1   = td_var_offset(write_iops_log),
2188                 .cb     = str_write_iops_log_cb,
2189                 .help   = "Write log of IOPS during run",
2190                 .category = FIO_OPT_G_LOG,
2191         },
2192         {
2193                 .name   = "log_avg_msec",
2194                 .type   = FIO_OPT_INT,
2195                 .off1   = td_var_offset(log_avg_msec),
2196                 .help   = "Average bw/iops/lat logs over this period of time",
2197                 .def    = "0",
2198                 .category = FIO_OPT_G_LOG,
2199         },
2200         {
2201                 .name   = "hugepage-size",
2202                 .type   = FIO_OPT_INT,
2203                 .off1   = td_var_offset(hugepage_size),
2204                 .help   = "When using hugepages, specify size of each page",
2205                 .def    = __fio_stringify(FIO_HUGE_PAGE),
2206                 .category = FIO_OPT_G_OS | FIO_OPT_G_MEM,
2207         },
2208         {
2209                 .name   = "group_reporting",
2210                 .type   = FIO_OPT_STR_SET,
2211                 .off1   = td_var_offset(group_reporting),
2212                 .help   = "Do reporting on a per-group basis",
2213                 .category = FIO_OPT_G_MISC,
2214         },
2215         {
2216                 .name   = "zero_buffers",
2217                 .type   = FIO_OPT_STR_SET,
2218                 .off1   = td_var_offset(zero_buffers),
2219                 .help   = "Init IO buffers to all zeroes",
2220                 .category = FIO_OPT_G_IO_BUF,
2221         },
2222         {
2223                 .name   = "refill_buffers",
2224                 .type   = FIO_OPT_STR_SET,
2225                 .off1   = td_var_offset(refill_buffers),
2226                 .help   = "Refill IO buffers on every IO submit",
2227                 .category = FIO_OPT_G_IO_BUF,
2228         },
2229         {
2230                 .name   = "scramble_buffers",
2231                 .type   = FIO_OPT_BOOL,
2232                 .off1   = td_var_offset(scramble_buffers),
2233                 .help   = "Slightly scramble buffers on every IO submit",
2234                 .def    = "1",
2235                 .category = FIO_OPT_G_IO_BUF,
2236         },
2237         {
2238                 .name   = "buffer_compress_percentage",
2239                 .type   = FIO_OPT_INT,
2240                 .off1   = td_var_offset(compress_percentage),
2241                 .maxval = 100,
2242                 .minval = 1,
2243                 .help   = "How compressible the buffer is (approximately)",
2244         },
2245         {
2246                 .name   = "buffer_compress_chunk",
2247                 .type   = FIO_OPT_INT,
2248                 .off1   = td_var_offset(compress_chunk),
2249                 .parent = "buffer_compress_percentage",
2250                 .help   = "Size of compressible region in buffer",
2251         },
2252         {
2253                 .name   = "clat_percentiles",
2254                 .type   = FIO_OPT_BOOL,
2255                 .off1   = td_var_offset(clat_percentiles),
2256                 .help   = "Enable the reporting of completion latency percentiles",
2257                 .def    = "1",
2258                 .category = FIO_OPT_G_STAT,
2259         },
2260         {
2261                 .name   = "percentile_list",
2262                 .type   = FIO_OPT_FLOAT_LIST,
2263                 .off1   = td_var_offset(percentile_list),
2264                 .off2   = td_var_offset(overwrite_plist),
2265                 .help   = "Specify a custom list of percentiles to report",
2266                 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2267                 .minfp  = 0.0,
2268                 .maxfp  = 100.0,
2269                 .category = FIO_OPT_G_STAT,
2270         },
2271
2272 #ifdef FIO_HAVE_DISK_UTIL
2273         {
2274                 .name   = "disk_util",
2275                 .type   = FIO_OPT_BOOL,
2276                 .off1   = td_var_offset(do_disk_util),
2277                 .help   = "Log disk utilization statistics",
2278                 .def    = "1",
2279                 .category = FIO_OPT_G_OS | FIO_OPT_G_STAT,
2280         },
2281 #endif
2282         {
2283                 .name   = "gtod_reduce",
2284                 .type   = FIO_OPT_BOOL,
2285                 .help   = "Greatly reduce number of gettimeofday() calls",
2286                 .cb     = str_gtod_reduce_cb,
2287                 .def    = "0",
2288                 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2289         },
2290         {
2291                 .name   = "disable_lat",
2292                 .type   = FIO_OPT_BOOL,
2293                 .off1   = td_var_offset(disable_lat),
2294                 .help   = "Disable latency numbers",
2295                 .parent = "gtod_reduce",
2296                 .def    = "0",
2297                 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2298         },
2299         {
2300                 .name   = "disable_clat",
2301                 .type   = FIO_OPT_BOOL,
2302                 .off1   = td_var_offset(disable_clat),
2303                 .help   = "Disable completion latency numbers",
2304                 .parent = "gtod_reduce",
2305                 .def    = "0",
2306                 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2307         },
2308         {
2309                 .name   = "disable_slat",
2310                 .type   = FIO_OPT_BOOL,
2311                 .off1   = td_var_offset(disable_slat),
2312                 .help   = "Disable submission latency numbers",
2313                 .parent = "gtod_reduce",
2314                 .def    = "0",
2315                 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2316         },
2317         {
2318                 .name   = "disable_bw_measurement",
2319                 .type   = FIO_OPT_BOOL,
2320                 .off1   = td_var_offset(disable_bw),
2321                 .help   = "Disable bandwidth logging",
2322                 .parent = "gtod_reduce",
2323                 .def    = "0",
2324                 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2325         },
2326         {
2327                 .name   = "gtod_cpu",
2328                 .type   = FIO_OPT_INT,
2329                 .cb     = str_gtod_cpu_cb,
2330                 .help   = "Set up dedicated gettimeofday() thread on this CPU",
2331                 .verify = gtod_cpu_verify,
2332                 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2333         },
2334         {
2335                 .name   = "continue_on_error",
2336                 .type   = FIO_OPT_STR,
2337                 .off1   = td_var_offset(continue_on_error),
2338                 .help   = "Continue on non-fatal errors during IO",
2339                 .def    = "none",
2340                 .category = FIO_OPT_G_MISC | FIO_OPT_G_ERR,
2341                 .posval = {
2342                           { .ival = "none",
2343                             .oval = ERROR_TYPE_NONE,
2344                             .help = "Exit when an error is encountered",
2345                           },
2346                           { .ival = "read",
2347                             .oval = ERROR_TYPE_READ,
2348                             .help = "Continue on read errors only",
2349                           },
2350                           { .ival = "write",
2351                             .oval = ERROR_TYPE_WRITE,
2352                             .help = "Continue on write errors only",
2353                           },
2354                           { .ival = "io",
2355                             .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2356                             .help = "Continue on any IO errors",
2357                           },
2358                           { .ival = "verify",
2359                             .oval = ERROR_TYPE_VERIFY,
2360                             .help = "Continue on verify errors only",
2361                           },
2362                           { .ival = "all",
2363                             .oval = ERROR_TYPE_ANY,
2364                             .help = "Continue on all io and verify errors",
2365                           },
2366                           { .ival = "0",
2367                             .oval = ERROR_TYPE_NONE,
2368                             .help = "Alias for 'none'",
2369                           },
2370                           { .ival = "1",
2371                             .oval = ERROR_TYPE_ANY,
2372                             .help = "Alias for 'all'",
2373                           },
2374                 },
2375         },
2376         {
2377                 .name   = "profile",
2378                 .type   = FIO_OPT_STR_STORE,
2379                 .off1   = td_var_offset(profile),
2380                 .help   = "Select a specific builtin performance test",
2381                 .category = FIO_OPT_G_MISC | FIO_OPT_G_JOB,
2382         },
2383         {
2384                 .name   = "cgroup",
2385                 .type   = FIO_OPT_STR_STORE,
2386                 .off1   = td_var_offset(cgroup),
2387                 .help   = "Add job to cgroup of this name",
2388                 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
2389         },
2390         {
2391                 .name   = "cgroup_weight",
2392                 .type   = FIO_OPT_INT,
2393                 .off1   = td_var_offset(cgroup_weight),
2394                 .help   = "Use given weight for cgroup",
2395                 .minval = 100,
2396                 .maxval = 1000,
2397                 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
2398         },
2399         {
2400                 .name   = "cgroup_nodelete",
2401                 .type   = FIO_OPT_BOOL,
2402                 .off1   = td_var_offset(cgroup_nodelete),
2403                 .help   = "Do not delete cgroups after job completion",
2404                 .def    = "0",
2405                 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
2406         },
2407         {
2408                 .name   = "uid",
2409                 .type   = FIO_OPT_INT,
2410                 .off1   = td_var_offset(uid),
2411                 .help   = "Run job with this user ID",
2412                 .category = FIO_OPT_G_OS | FIO_OPT_G_JOB,
2413         },
2414         {
2415                 .name   = "gid",
2416                 .type   = FIO_OPT_INT,
2417                 .off1   = td_var_offset(gid),
2418                 .help   = "Run job with this group ID",
2419                 .category = FIO_OPT_G_OS | FIO_OPT_G_JOB,
2420         },
2421         {
2422                 .name   = "flow_id",
2423                 .type   = FIO_OPT_INT,
2424                 .off1   = td_var_offset(flow_id),
2425                 .help   = "The flow index ID to use",
2426                 .def    = "0",
2427                 .category = FIO_OPT_G_IO,
2428         },
2429         {
2430                 .name   = "flow",
2431                 .type   = FIO_OPT_INT,
2432                 .off1   = td_var_offset(flow),
2433                 .help   = "Weight for flow control of this job",
2434                 .parent = "flow_id",
2435                 .def    = "0",
2436                 .category = FIO_OPT_G_IO,
2437         },
2438         {
2439                 .name   = "flow_watermark",
2440                 .type   = FIO_OPT_INT,
2441                 .off1   = td_var_offset(flow_watermark),
2442                 .help   = "High watermark for flow control. This option"
2443                         " should be set to the same value for all threads"
2444                         " with non-zero flow.",
2445                 .parent = "flow_id",
2446                 .def    = "1024",
2447                 .category = FIO_OPT_G_IO,
2448         },
2449         {
2450                 .name   = "flow_sleep",
2451                 .type   = FIO_OPT_INT,
2452                 .off1   = td_var_offset(flow_sleep),
2453                 .help   = "How many microseconds to sleep after being held"
2454                         " back by the flow control mechanism",
2455                 .parent = "flow_id",
2456                 .def    = "0",
2457                 .category = FIO_OPT_G_IO,
2458         },
2459         {
2460                 .name = NULL,
2461         },
2462 };
2463
2464 static void add_to_lopt(struct option *lopt, struct fio_option *o,
2465                         const char *name, int val)
2466 {
2467         lopt->name = (char *) name;
2468         lopt->val = val;
2469         if (o->type == FIO_OPT_STR_SET)
2470                 lopt->has_arg = no_argument;
2471         else
2472                 lopt->has_arg = required_argument;
2473 }
2474
2475 static void options_to_lopts(struct fio_option *opts,
2476                               struct option *long_options,
2477                               int i, int option_type)
2478 {
2479         struct fio_option *o = &opts[0];
2480         while (o->name) {
2481                 add_to_lopt(&long_options[i], o, o->name, option_type);
2482                 if (o->alias) {
2483                         i++;
2484                         add_to_lopt(&long_options[i], o, o->alias, option_type);
2485                 }
2486
2487                 i++;
2488                 o++;
2489                 assert(i < FIO_NR_OPTIONS);
2490         }
2491 }
2492
2493 void fio_options_set_ioengine_opts(struct option *long_options,
2494                                    struct thread_data *td)
2495 {
2496         unsigned int i;
2497
2498         i = 0;
2499         while (long_options[i].name) {
2500                 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2501                         memset(&long_options[i], 0, sizeof(*long_options));
2502                         break;
2503                 }
2504                 i++;
2505         }
2506
2507         /*
2508          * Just clear out the prior ioengine options.
2509          */
2510         if (!td || !td->eo)
2511                 return;
2512
2513         options_to_lopts(td->io_ops->options, long_options, i,
2514                          FIO_GETOPT_IOENGINE);
2515 }
2516
2517 void fio_options_dup_and_init(struct option *long_options)
2518 {
2519         unsigned int i;
2520
2521         options_init(fio_options);
2522
2523         i = 0;
2524         while (long_options[i].name)
2525                 i++;
2526
2527         options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
2528 }
2529
2530 struct fio_keyword {
2531         const char *word;
2532         const char *desc;
2533         char *replace;
2534 };
2535
2536 static struct fio_keyword fio_keywords[] = {
2537         {
2538                 .word   = "$pagesize",
2539                 .desc   = "Page size in the system",
2540         },
2541         {
2542                 .word   = "$mb_memory",
2543                 .desc   = "Megabytes of memory online",
2544         },
2545         {
2546                 .word   = "$ncpus",
2547                 .desc   = "Number of CPUs online in the system",
2548         },
2549         {
2550                 .word   = NULL,
2551         },
2552 };
2553
2554 void fio_keywords_init(void)
2555 {
2556         unsigned long long mb_memory;
2557         char buf[128];
2558         long l;
2559
2560         sprintf(buf, "%lu", page_size);
2561         fio_keywords[0].replace = strdup(buf);
2562
2563         mb_memory = os_phys_mem() / (1024 * 1024);
2564         sprintf(buf, "%llu", mb_memory);
2565         fio_keywords[1].replace = strdup(buf);
2566
2567         l = cpus_online();
2568         sprintf(buf, "%lu", l);
2569         fio_keywords[2].replace = strdup(buf);
2570 }
2571
2572 #define BC_APP          "bc"
2573
2574 static char *bc_calc(char *str)
2575 {
2576         char buf[128], *tmp;
2577         FILE *f;
2578         int ret;
2579
2580         /*
2581          * No math, just return string
2582          */
2583         if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2584              !strchr(str, '/')) || strchr(str, '\''))
2585                 return str;
2586
2587         /*
2588          * Split option from value, we only need to calculate the value
2589          */
2590         tmp = strchr(str, '=');
2591         if (!tmp)
2592                 return str;
2593
2594         tmp++;
2595
2596         /*
2597          * Prevent buffer overflows; such a case isn't reasonable anyway
2598          */
2599         if (strlen(str) >= 128 || strlen(tmp) > 100)
2600                 return str;
2601
2602         sprintf(buf, "which %s > /dev/null", BC_APP);
2603         if (system(buf)) {
2604                 log_err("fio: bc is needed for performing math\n");
2605                 return NULL;
2606         }
2607
2608         sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
2609         f = popen(buf, "r");
2610         if (!f) {
2611                 return NULL;
2612         }
2613
2614         ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
2615         if (ret <= 0) {
2616                 return NULL;
2617         }
2618
2619         pclose(f);
2620         buf[(tmp - str) + ret - 1] = '\0';
2621         memcpy(buf, str, tmp - str);
2622         free(str);
2623         return strdup(buf);
2624 }
2625
2626 /*
2627  * Return a copy of the input string with substrings of the form ${VARNAME}
2628  * substituted with the value of the environment variable VARNAME.  The
2629  * substitution always occurs, even if VARNAME is empty or the corresponding
2630  * environment variable undefined.
2631  */
2632 static char *option_dup_subs(const char *opt)
2633 {
2634         char out[OPT_LEN_MAX+1];
2635         char in[OPT_LEN_MAX+1];
2636         char *outptr = out;
2637         char *inptr = in;
2638         char *ch1, *ch2, *env;
2639         ssize_t nchr = OPT_LEN_MAX;
2640         size_t envlen;
2641
2642         if (strlen(opt) + 1 > OPT_LEN_MAX) {
2643                 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2644                 return NULL;
2645         }
2646
2647         in[OPT_LEN_MAX] = '\0';
2648         strncpy(in, opt, OPT_LEN_MAX);
2649
2650         while (*inptr && nchr > 0) {
2651                 if (inptr[0] == '$' && inptr[1] == '{') {
2652                         ch2 = strchr(inptr, '}');
2653                         if (ch2 && inptr+1 < ch2) {
2654                                 ch1 = inptr+2;
2655                                 inptr = ch2+1;
2656                                 *ch2 = '\0';
2657
2658                                 env = getenv(ch1);
2659                                 if (env) {
2660                                         envlen = strlen(env);
2661                                         if (envlen <= nchr) {
2662                                                 memcpy(outptr, env, envlen);
2663                                                 outptr += envlen;
2664                                                 nchr -= envlen;
2665                                         }
2666                                 }
2667
2668                                 continue;
2669                         }
2670                 }
2671
2672                 *outptr++ = *inptr++;
2673                 --nchr;
2674         }
2675
2676         *outptr = '\0';
2677         return strdup(out);
2678 }
2679
2680 /*
2681  * Look for reserved variable names and replace them with real values
2682  */
2683 static char *fio_keyword_replace(char *opt)
2684 {
2685         char *s;
2686         int i;
2687         int docalc = 0;
2688
2689         for (i = 0; fio_keywords[i].word != NULL; i++) {
2690                 struct fio_keyword *kw = &fio_keywords[i];
2691
2692                 while ((s = strstr(opt, kw->word)) != NULL) {
2693                         char *new = malloc(strlen(opt) + 1);
2694                         char *o_org = opt;
2695                         int olen = s - opt;
2696                         int len;
2697
2698                         /*
2699                          * Copy part of the string before the keyword and
2700                          * sprintf() the replacement after it.
2701                          */
2702                         memcpy(new, opt, olen);
2703                         len = sprintf(new + olen, "%s", kw->replace);
2704
2705                         /*
2706                          * If there's more in the original string, copy that
2707                          * in too
2708                          */
2709                         opt += strlen(kw->word) + olen;
2710                         if (strlen(opt))
2711                                 memcpy(new + olen + len, opt, opt - o_org - 1);
2712
2713                         /*
2714                          * replace opt and free the old opt
2715                          */
2716                         opt = new;
2717                         free(o_org);
2718
2719                         docalc = 1;
2720                 }
2721         }
2722
2723         /*
2724          * Check for potential math and invoke bc, if possible
2725          */
2726         if (docalc)
2727                 opt = bc_calc(opt);
2728
2729         return opt;
2730 }
2731
2732 static char **dup_and_sub_options(char **opts, int num_opts)
2733 {
2734         int i;
2735         char **opts_copy = malloc(num_opts * sizeof(*opts));
2736         for (i = 0; i < num_opts; i++) {
2737                 opts_copy[i] = option_dup_subs(opts[i]);
2738                 if (!opts_copy[i])
2739                         continue;
2740                 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2741         }
2742         return opts_copy;
2743 }
2744
2745 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2746 {
2747         int i, ret, unknown;
2748         char **opts_copy;
2749
2750         sort_options(opts, fio_options, num_opts);
2751         opts_copy = dup_and_sub_options(opts, num_opts);
2752
2753         for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
2754                 struct fio_option *o;
2755                 int newret = parse_option(opts_copy[i], opts[i], fio_options,
2756                                                 &o, td);
2757
2758                 if (opts_copy[i]) {
2759                         if (newret && !o) {
2760                                 unknown++;
2761                                 continue;
2762                         }
2763                         free(opts_copy[i]);
2764                         opts_copy[i] = NULL;
2765                 }
2766
2767                 ret |= newret;
2768         }
2769
2770         if (unknown) {
2771                 ret |= ioengine_load(td);
2772                 if (td->eo) {
2773                         sort_options(opts_copy, td->io_ops->options, num_opts);
2774                         opts = opts_copy;
2775                 }
2776                 for (i = 0; i < num_opts; i++) {
2777                         struct fio_option *o = NULL;
2778                         int newret = 1;
2779                         if (!opts_copy[i])
2780                                 continue;
2781
2782                         if (td->eo)
2783                                 newret = parse_option(opts_copy[i], opts[i],
2784                                                       td->io_ops->options, &o,
2785                                                       td->eo);
2786
2787                         ret |= newret;
2788                         if (!o)
2789                                 log_err("Bad option <%s>\n", opts[i]);
2790
2791                         free(opts_copy[i]);
2792                         opts_copy[i] = NULL;
2793                 }
2794         }
2795
2796         free(opts_copy);
2797         return ret;
2798 }
2799
2800 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2801 {
2802         return parse_cmd_option(opt, val, fio_options, td);
2803 }
2804
2805 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
2806                                 char *val)
2807 {
2808         return parse_cmd_option(opt, val, td->io_ops->options, td);
2809 }
2810
2811 void fio_fill_default_options(struct thread_data *td)
2812 {
2813         fill_default_options(td, fio_options);
2814 }
2815
2816 int fio_show_option_help(const char *opt)
2817 {
2818         return show_cmd_help(fio_options, opt);
2819 }
2820
2821 void options_mem_dupe(void *data, struct fio_option *options)
2822 {
2823         struct fio_option *o;
2824         char **ptr;
2825
2826         for (o = &options[0]; o->name; o++) {
2827                 if (o->type != FIO_OPT_STR_STORE)
2828                         continue;
2829
2830                 ptr = td_var(data, o->off1);
2831                 if (*ptr)
2832                         *ptr = strdup(*ptr);
2833         }
2834 }
2835
2836 /*
2837  * dupe FIO_OPT_STR_STORE options
2838  */
2839 void fio_options_mem_dupe(struct thread_data *td)
2840 {
2841         options_mem_dupe(&td->o, fio_options);
2842
2843         if (td->eo && td->io_ops) {
2844                 void *oldeo = td->eo;
2845
2846                 td->eo = malloc(td->io_ops->option_struct_size);
2847                 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
2848                 options_mem_dupe(td->eo, td->io_ops->options);
2849         }
2850 }
2851
2852 unsigned int fio_get_kb_base(void *data)
2853 {
2854         struct thread_data *td = data;
2855         unsigned int kb_base = 0;
2856
2857         if (td)
2858                 kb_base = td->o.kb_base;
2859         if (!kb_base)
2860                 kb_base = 1024;
2861
2862         return kb_base;
2863 }
2864
2865 int add_option(struct fio_option *o)
2866 {
2867         struct fio_option *__o;
2868         int opt_index = 0;
2869
2870         __o = fio_options;
2871         while (__o->name) {
2872                 opt_index++;
2873                 __o++;
2874         }
2875
2876         memcpy(&fio_options[opt_index], o, sizeof(*o));
2877         return 0;
2878 }
2879
2880 void invalidate_profile_options(const char *prof_name)
2881 {
2882         struct fio_option *o;
2883
2884         o = fio_options;
2885         while (o->name) {
2886                 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2887                         o->type = FIO_OPT_INVALID;
2888                         o->prof_name = NULL;
2889                 }
2890                 o++;
2891         }
2892 }
2893
2894 void add_opt_posval(const char *optname, const char *ival, const char *help)
2895 {
2896         struct fio_option *o;
2897         unsigned int i;
2898
2899         o = find_option(fio_options, optname);
2900         if (!o)
2901                 return;
2902
2903         for (i = 0; i < PARSE_MAX_VP; i++) {
2904                 if (o->posval[i].ival)
2905                         continue;
2906
2907                 o->posval[i].ival = ival;
2908                 o->posval[i].help = help;
2909                 break;
2910         }
2911 }
2912
2913 void del_opt_posval(const char *optname, const char *ival)
2914 {
2915         struct fio_option *o;
2916         unsigned int i;
2917
2918         o = find_option(fio_options, optname);
2919         if (!o)
2920                 return;
2921
2922         for (i = 0; i < PARSE_MAX_VP; i++) {
2923                 if (!o->posval[i].ival)
2924                         continue;
2925                 if (strcmp(o->posval[i].ival, ival))
2926                         continue;
2927
2928                 o->posval[i].ival = NULL;
2929                 o->posval[i].help = NULL;
2930         }
2931 }
2932
2933 void fio_options_free(struct thread_data *td)
2934 {
2935         options_free(fio_options, td);
2936         if (td->eo && td->io_ops && td->io_ops->options) {
2937                 options_free(td->io_ops->options, td->eo);
2938                 free(td->eo);
2939                 td->eo = NULL;
2940         }
2941 }