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