pre_read fixes
[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 <getopt.h>
7 #include <assert.h>
8 #include <libgen.h>
9 #include <fcntl.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12
13 #include "fio.h"
14 #include "parse.h"
15 #include "lib/fls.h"
16
17 #define td_var_offset(var)      ((size_t) &((struct thread_options *)0)->var)
18
19 /*
20  * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
21  */
22 static char *get_opt_postfix(const char *str)
23 {
24         char *p = strstr(str, ":");
25
26         if (!p)
27                 return NULL;
28
29         p++;
30         strip_blank_front(&p);
31         strip_blank_end(p);
32         return strdup(p);
33 }
34
35 static int bs_cmp(const void *p1, const void *p2)
36 {
37         const struct bssplit *bsp1 = p1;
38         const struct bssplit *bsp2 = p2;
39
40         return bsp1->perc < bsp2->perc;
41 }
42
43 static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
44 {
45         struct bssplit *bssplit;
46         unsigned int i, perc, perc_missing;
47         unsigned int max_bs, min_bs;
48         long long val;
49         char *fname;
50
51         td->o.bssplit_nr[ddir] = 4;
52         bssplit = malloc(4 * sizeof(struct bssplit));
53
54         i = 0;
55         max_bs = 0;
56         min_bs = -1;
57         while ((fname = strsep(&str, ":")) != NULL) {
58                 char *perc_str;
59
60                 if (!strlen(fname))
61                         break;
62
63                 /*
64                  * grow struct buffer, if needed
65                  */
66                 if (i == td->o.bssplit_nr[ddir]) {
67                         td->o.bssplit_nr[ddir] <<= 1;
68                         bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
69                                                   * sizeof(struct bssplit));
70                 }
71
72                 perc_str = strstr(fname, "/");
73                 if (perc_str) {
74                         *perc_str = '\0';
75                         perc_str++;
76                         perc = atoi(perc_str);
77                         if (perc > 100)
78                                 perc = 100;
79                         else if (!perc)
80                                 perc = -1;
81                 } else
82                         perc = -1;
83
84                 if (str_to_decimal(fname, &val, 1)) {
85                         log_err("fio: bssplit conversion failed\n");
86                         free(td->o.bssplit);
87                         return 1;
88                 }
89
90                 if (val > max_bs)
91                         max_bs = val;
92                 if (val < min_bs)
93                         min_bs = val;
94
95                 bssplit[i].bs = val;
96                 bssplit[i].perc = perc;
97                 i++;
98         }
99
100         td->o.bssplit_nr[ddir] = i;
101
102         /*
103          * Now check if the percentages add up, and how much is missing
104          */
105         perc = perc_missing = 0;
106         for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
107                 struct bssplit *bsp = &bssplit[i];
108
109                 if (bsp->perc == (unsigned char) -1)
110                         perc_missing++;
111                 else
112                         perc += bsp->perc;
113         }
114
115         if (perc > 100) {
116                 log_err("fio: bssplit percentages add to more than 100%%\n");
117                 free(bssplit);
118                 return 1;
119         }
120         /*
121          * If values didn't have a percentage set, divide the remains between
122          * them.
123          */
124         if (perc_missing) {
125                 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
126                         struct bssplit *bsp = &bssplit[i];
127
128                         if (bsp->perc == (unsigned char) -1)
129                                 bsp->perc = (100 - perc) / perc_missing;
130                 }
131         }
132
133         td->o.min_bs[ddir] = min_bs;
134         td->o.max_bs[ddir] = max_bs;
135
136         /*
137          * now sort based on percentages, for ease of lookup
138          */
139         qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
140         td->o.bssplit[ddir] = bssplit;
141         return 0;
142
143 }
144
145 static int str_bssplit_cb(void *data, const char *input)
146 {
147         struct thread_data *td = data;
148         char *str, *p, *odir;
149         int ret = 0;
150
151         p = str = strdup(input);
152
153         strip_blank_front(&str);
154         strip_blank_end(str);
155
156         odir = strchr(str, ',');
157         if (odir) {
158                 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
159                 if (!ret) {
160                         *odir = '\0';
161                         ret = bssplit_ddir(td, DDIR_READ, str);
162                 }
163         } else {
164                 char *op;
165
166                 op = strdup(str);
167
168                 ret = bssplit_ddir(td, DDIR_READ, str);
169                 if (!ret)
170                         ret = bssplit_ddir(td, DDIR_WRITE, op);
171
172                 free(op);
173         }
174
175         free(p);
176         return ret;
177 }
178
179 static int str_rw_cb(void *data, const char *str)
180 {
181         struct thread_data *td = data;
182         char *nr = get_opt_postfix(str);
183
184         td->o.ddir_nr = 1;
185         if (nr) {
186                 td->o.ddir_nr = atoi(nr);
187                 free(nr);
188         }
189
190         return 0;
191 }
192
193 static int str_mem_cb(void *data, const char *mem)
194 {
195         struct thread_data *td = data;
196
197         if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
198                 td->mmapfile = get_opt_postfix(mem);
199                 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
200                         log_err("fio: mmaphuge:/path/to/file\n");
201                         return 1;
202                 }
203         }
204
205         return 0;
206 }
207
208 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
209 {
210         mlock_size = *val;
211         return 0;
212 }
213
214 static int str_rwmix_read_cb(void *data, unsigned int *val)
215 {
216         struct thread_data *td = data;
217
218         td->o.rwmix[DDIR_READ] = *val;
219         td->o.rwmix[DDIR_WRITE] = 100 - *val;
220         return 0;
221 }
222
223 static int str_rwmix_write_cb(void *data, unsigned int *val)
224 {
225         struct thread_data *td = data;
226
227         td->o.rwmix[DDIR_WRITE] = *val;
228         td->o.rwmix[DDIR_READ] = 100 - *val;
229         return 0;
230 }
231
232 #ifdef FIO_HAVE_IOPRIO
233 static int str_prioclass_cb(void *data, unsigned int *val)
234 {
235         struct thread_data *td = data;
236         unsigned short mask;
237
238         /*
239          * mask off old class bits, str_prio_cb() may have set a default class
240          */
241         mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
242         td->ioprio &= mask;
243
244         td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
245         td->ioprio_set = 1;
246         return 0;
247 }
248
249 static int str_prio_cb(void *data, unsigned int *val)
250 {
251         struct thread_data *td = data;
252
253         td->ioprio |= *val;
254
255         /*
256          * If no class is set, assume BE
257          */
258         if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
259                 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
260
261         td->ioprio_set = 1;
262         return 0;
263 }
264 #endif
265
266 static int str_exitall_cb(void)
267 {
268         exitall_on_terminate = 1;
269         return 0;
270 }
271
272 #ifdef FIO_HAVE_CPU_AFFINITY
273 static int str_cpumask_cb(void *data, unsigned int *val)
274 {
275         struct thread_data *td = data;
276         unsigned int i;
277         long max_cpu;
278         int ret;
279
280         ret = fio_cpuset_init(&td->o.cpumask);
281         if (ret < 0) {
282                 log_err("fio: cpuset_init failed\n");
283                 td_verror(td, ret, "fio_cpuset_init");
284                 return 1;
285         }
286
287         max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
288
289         for (i = 0; i < sizeof(int) * 8; i++) {
290                 if ((1 << i) & *val) {
291                         if (i > max_cpu) {
292                                 log_err("fio: CPU %d too large (max=%ld)\n", i,
293                                                                 max_cpu);
294                                 return 1;
295                         }
296                         dprint(FD_PARSE, "set cpu allowed %d\n", i);
297                         fio_cpu_set(&td->o.cpumask, i);
298                 }
299         }
300
301         td->o.cpumask_set = 1;
302         return 0;
303 }
304
305 static int str_cpus_allowed_cb(void *data, const char *input)
306 {
307         struct thread_data *td = data;
308         char *cpu, *str, *p;
309         long max_cpu;
310         int ret = 0;
311
312         ret = fio_cpuset_init(&td->o.cpumask);
313         if (ret < 0) {
314                 log_err("fio: cpuset_init failed\n");
315                 td_verror(td, ret, "fio_cpuset_init");
316                 return 1;
317         }
318
319         p = str = strdup(input);
320
321         strip_blank_front(&str);
322         strip_blank_end(str);
323
324         max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
325
326         while ((cpu = strsep(&str, ",")) != NULL) {
327                 char *str2, *cpu2;
328                 int icpu, icpu2;
329
330                 if (!strlen(cpu))
331                         break;
332
333                 str2 = cpu;
334                 icpu2 = -1;
335                 while ((cpu2 = strsep(&str2, "-")) != NULL) {
336                         if (!strlen(cpu2))
337                                 break;
338
339                         icpu2 = atoi(cpu2);
340                 }
341
342                 icpu = atoi(cpu);
343                 if (icpu2 == -1)
344                         icpu2 = icpu;
345                 while (icpu <= icpu2) {
346                         if (icpu >= FIO_MAX_CPUS) {
347                                 log_err("fio: your OS only supports up to"
348                                         " %d CPUs\n", (int) FIO_MAX_CPUS);
349                                 ret = 1;
350                                 break;
351                         }
352                         if (icpu > max_cpu) {
353                                 log_err("fio: CPU %d too large (max=%ld)\n",
354                                                         icpu, max_cpu);
355                                 ret = 1;
356                                 break;
357                         }
358         
359                         dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
360                         fio_cpu_set(&td->o.cpumask, icpu);
361                         icpu++;
362                 }
363                 if (ret)
364                         break;
365         }
366
367         free(p);
368         if (!ret)
369                 td->o.cpumask_set = 1;
370         return ret;
371 }
372 #endif
373
374 static int str_fst_cb(void *data, const char *str)
375 {
376         struct thread_data *td = data;
377         char *nr = get_opt_postfix(str);
378
379         td->file_service_nr = 1;
380         if (nr) {
381                 td->file_service_nr = atoi(nr);
382                 free(nr);
383         }
384
385         return 0;
386 }
387
388 static int check_dir(struct thread_data *td, char *fname)
389 {
390         char file[PATH_MAX], *dir;
391         int elen = 0;
392
393         if (td->o.directory) {
394                 strcpy(file, td->o.directory);
395                 strcat(file, "/");
396                 elen = strlen(file);
397         }
398
399         sprintf(file + elen, "%s", fname);
400         dir = dirname(file);
401
402 #if 0
403         {
404         struct stat sb;
405         /*
406          * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
407          * yet, so we can't do this check right here...
408          */
409         if (lstat(dir, &sb) < 0) {
410                 int ret = errno;
411
412                 log_err("fio: %s is not a directory\n", dir);
413                 td_verror(td, ret, "lstat");
414                 return 1;
415         }
416
417         if (!S_ISDIR(sb.st_mode)) {
418                 log_err("fio: %s is not a directory\n", dir);
419                 return 1;
420         }
421         }
422 #endif
423
424         return 0;
425 }
426
427 static int str_filename_cb(void *data, const char *input)
428 {
429         struct thread_data *td = data;
430         char *fname, *str, *p;
431
432         p = str = strdup(input);
433
434         strip_blank_front(&str);
435         strip_blank_end(str);
436
437         if (!td->files_index)
438                 td->o.nr_files = 0;
439
440         while ((fname = strsep(&str, ":")) != NULL) {
441                 if (!strlen(fname))
442                         break;
443                 if (check_dir(td, fname)) {
444                         free(p);
445                         return 1;
446                 }
447                 add_file(td, fname);
448                 td->o.nr_files++;
449         }
450
451         free(p);
452         return 0;
453 }
454
455 static int str_directory_cb(void *data, const char fio_unused *str)
456 {
457         struct thread_data *td = data;
458         struct stat sb;
459
460         if (lstat(td->o.directory, &sb) < 0) {
461                 int ret = errno;
462
463                 log_err("fio: %s is not a directory\n", td->o.directory);
464                 td_verror(td, ret, "lstat");
465                 return 1;
466         }
467         if (!S_ISDIR(sb.st_mode)) {
468                 log_err("fio: %s is not a directory\n", td->o.directory);
469                 return 1;
470         }
471
472         return 0;
473 }
474
475 static int str_opendir_cb(void *data, const char fio_unused *str)
476 {
477         struct thread_data *td = data;
478
479         if (!td->files_index)
480                 td->o.nr_files = 0;
481
482         return add_dir_files(td, td->o.opendir);
483 }
484
485 static int str_verify_offset_cb(void *data, unsigned int *off)
486 {
487         struct thread_data *td = data;
488
489         if (*off && *off < sizeof(struct verify_header)) {
490                 log_err("fio: verify_offset too small\n");
491                 return 1;
492         }
493
494         td->o.verify_offset = *off;
495         return 0;
496 }
497
498 static int str_verify_pattern_cb(void *data, unsigned int *off)
499 {
500         struct thread_data *td = data;
501         unsigned int msb;
502
503         msb = __fls(*off);
504         if (msb <= 8)
505                 td->o.verify_pattern_bytes = 1;
506         else if (msb <= 16)
507                 td->o.verify_pattern_bytes = 2;
508         else if (msb <= 24)
509                 td->o.verify_pattern_bytes = 3;
510         else
511                 td->o.verify_pattern_bytes = 4;
512
513         td->o.verify_pattern = *off;
514         return 0;
515 }
516
517 static int str_lockfile_cb(void *data, const char *str)
518 {
519         struct thread_data *td = data;
520         char *nr = get_opt_postfix(str);
521
522         td->o.lockfile_batch = 1;
523         if (nr) {
524                 td->o.lockfile_batch = atoi(nr);
525                 free(nr);
526         }
527
528         return 0;
529 }
530
531 static int str_write_bw_log_cb(void *data, const char *str)
532 {
533         struct thread_data *td = data;
534
535         if (str)
536                 td->o.bw_log_file = strdup(str);
537
538         td->o.write_bw_log = 1;
539         return 0;
540 }
541
542 static int str_write_lat_log_cb(void *data, const char *str)
543 {
544         struct thread_data *td = data;
545
546         if (str)
547                 td->o.lat_log_file = strdup(str);
548
549         td->o.write_lat_log = 1;
550         return 0;
551 }
552
553 static int str_gtod_reduce_cb(void *data, int *il)
554 {
555         struct thread_data *td = data;
556         int val = *il;
557
558         td->o.disable_clat = !!val;
559         td->o.disable_slat = !!val;
560         td->o.disable_bw = !!val;
561         if (val)
562                 td->tv_cache_mask = 63;
563
564         return 0;
565 }
566
567 static int str_gtod_cpu_cb(void *data, int *il)
568 {
569         struct thread_data *td = data;
570         int val = *il;
571
572         td->o.gtod_cpu = val;
573         td->o.gtod_offload = 1;
574         return 0;
575 }
576
577 #define __stringify_1(x)        #x
578 #define __stringify(x)          __stringify_1(x)
579
580 /*
581  * Map of job/command line options
582  */
583 static struct fio_option options[] = {
584         {
585                 .name   = "description",
586                 .type   = FIO_OPT_STR_STORE,
587                 .off1   = td_var_offset(description),
588                 .help   = "Text job description",
589         },
590         {
591                 .name   = "name",
592                 .type   = FIO_OPT_STR_STORE,
593                 .off1   = td_var_offset(name),
594                 .help   = "Name of this job",
595         },
596         {
597                 .name   = "directory",
598                 .type   = FIO_OPT_STR_STORE,
599                 .off1   = td_var_offset(directory),
600                 .cb     = str_directory_cb,
601                 .help   = "Directory to store files in",
602         },
603         {
604                 .name   = "filename",
605                 .type   = FIO_OPT_STR_STORE,
606                 .off1   = td_var_offset(filename),
607                 .cb     = str_filename_cb,
608                 .prio   = -1, /* must come after "directory" */
609                 .help   = "File(s) to use for the workload",
610         },
611         {
612                 .name   = "lockfile",
613                 .type   = FIO_OPT_STR,
614                 .cb     = str_lockfile_cb,
615                 .off1   = td_var_offset(file_lock_mode),
616                 .help   = "Lock file when doing IO to it",
617                 .parent = "filename",
618                 .def    = "none",
619                 .posval = {
620                           { .ival = "none",
621                             .oval = FILE_LOCK_NONE,
622                             .help = "No file locking",
623                           },
624                           { .ival = "exclusive",
625                             .oval = FILE_LOCK_EXCLUSIVE,
626                             .help = "Exclusive file lock",
627                           },
628                           {
629                             .ival = "readwrite",
630                             .oval = FILE_LOCK_READWRITE,
631                             .help = "Read vs write lock",
632                           },
633                 },
634         },
635         {
636                 .name   = "opendir",
637                 .type   = FIO_OPT_STR_STORE,
638                 .off1   = td_var_offset(opendir),
639                 .cb     = str_opendir_cb,
640                 .help   = "Recursively add files from this directory and down",
641         },
642         {
643                 .name   = "rw",
644                 .alias  = "readwrite",
645                 .type   = FIO_OPT_STR,
646                 .cb     = str_rw_cb,
647                 .off1   = td_var_offset(td_ddir),
648                 .help   = "IO direction",
649                 .def    = "read",
650                 .posval = {
651                           { .ival = "read",
652                             .oval = TD_DDIR_READ,
653                             .help = "Sequential read",
654                           },
655                           { .ival = "write",
656                             .oval = TD_DDIR_WRITE,
657                             .help = "Sequential write",
658                           },
659                           { .ival = "randread",
660                             .oval = TD_DDIR_RANDREAD,
661                             .help = "Random read",
662                           },
663                           { .ival = "randwrite",
664                             .oval = TD_DDIR_RANDWRITE,
665                             .help = "Random write",
666                           },
667                           { .ival = "rw",
668                             .oval = TD_DDIR_RW,
669                             .help = "Sequential read and write mix",
670                           },
671                           { .ival = "randrw",
672                             .oval = TD_DDIR_RANDRW,
673                             .help = "Random read and write mix"
674                           },
675                 },
676         },
677         {
678                 .name   = "ioengine",
679                 .type   = FIO_OPT_STR_STORE,
680                 .off1   = td_var_offset(ioengine),
681                 .help   = "IO engine to use",
682                 .def    = "sync",
683                 .posval = {
684                           { .ival = "sync",
685                             .help = "Use read/write",
686                           },
687                           { .ival = "psync",
688                             .help = "Use pread/pwrite",
689                           },
690                           { .ival = "vsync",
691                              .help = "Use readv/writev",
692                           },
693 #ifdef FIO_HAVE_LIBAIO
694                           { .ival = "libaio",
695                             .help = "Linux native asynchronous IO",
696                           },
697 #endif
698 #ifdef FIO_HAVE_POSIXAIO
699                           { .ival = "posixaio",
700                             .help = "POSIX asynchronous IO",
701                           },
702 #endif
703 #ifdef FIO_HAVE_SOLARISAIO
704                           { .ival = "solarisaio",
705                             .help = "Solaris native asynchronous IO",
706                           },
707 #endif
708                           { .ival = "mmap",
709                             .help = "Memory mapped IO",
710                           },
711 #ifdef FIO_HAVE_SPLICE
712                           { .ival = "splice",
713                             .help = "splice/vmsplice based IO",
714                           },
715                           { .ival = "netsplice",
716                             .help = "splice/vmsplice to/from the network",
717                           },
718 #endif
719 #ifdef FIO_HAVE_SGIO
720                           { .ival = "sg",
721                             .help = "SCSI generic v3 IO",
722                           },
723 #endif
724                           { .ival = "null",
725                             .help = "Testing engine (no data transfer)",
726                           },
727                           { .ival = "net",
728                             .help = "Network IO",
729                           },
730 #ifdef FIO_HAVE_SYSLET
731                           { .ival = "syslet-rw",
732                             .help = "syslet enabled async pread/pwrite IO",
733                           },
734 #endif
735                           { .ival = "cpuio",
736                             .help = "CPU cycler burner engine",
737                           },
738 #ifdef FIO_HAVE_GUASI
739                           { .ival = "guasi",
740                             .help = "GUASI IO engine",
741                           },
742 #endif
743                           { .ival = "external",
744                             .help = "Load external engine (append name)",
745                           },
746                 },
747         },
748         {
749                 .name   = "iodepth",
750                 .type   = FIO_OPT_INT,
751                 .off1   = td_var_offset(iodepth),
752                 .help   = "Amount of IO buffers to keep in flight",
753                 .minval = 1,
754                 .def    = "1",
755         },
756         {
757                 .name   = "iodepth_batch",
758                 .alias  = "iodepth_batch_submit",
759                 .type   = FIO_OPT_INT,
760                 .off1   = td_var_offset(iodepth_batch),
761                 .help   = "Number of IO buffers to submit in one go",
762                 .parent = "iodepth",
763                 .minval = 1,
764                 .def    = "1",
765         },
766         {
767                 .name   = "iodepth_batch_complete",
768                 .type   = FIO_OPT_INT,
769                 .off1   = td_var_offset(iodepth_batch_complete),
770                 .help   = "Number of IO buffers to retrieve in one go",
771                 .parent = "iodepth",
772                 .minval = 0,
773                 .def    = "1",
774         },
775         {
776                 .name   = "iodepth_low",
777                 .type   = FIO_OPT_INT,
778                 .off1   = td_var_offset(iodepth_low),
779                 .help   = "Low water mark for queuing depth",
780                 .parent = "iodepth",
781         },
782         {
783                 .name   = "size",
784                 .type   = FIO_OPT_STR_VAL,
785                 .off1   = td_var_offset(size),
786                 .minval = 1,
787                 .help   = "Total size of device or files",
788         },
789         {
790                 .name   = "fill_device",
791                 .type   = FIO_OPT_BOOL,
792                 .off1   = td_var_offset(fill_device),
793                 .help   = "Write until an ENOSPC error occurs",
794                 .def    = "0",
795         },
796         {
797                 .name   = "filesize",
798                 .type   = FIO_OPT_STR_VAL,
799                 .off1   = td_var_offset(file_size_low),
800                 .off2   = td_var_offset(file_size_high),
801                 .minval = 1,
802                 .help   = "Size of individual files",
803         },
804         {
805                 .name   = "offset",
806                 .alias  = "fileoffset",
807                 .type   = FIO_OPT_STR_VAL,
808                 .off1   = td_var_offset(start_offset),
809                 .help   = "Start IO from this offset",
810                 .def    = "0",
811         },
812         {
813                 .name   = "bs",
814                 .alias  = "blocksize",
815                 .type   = FIO_OPT_STR_VAL_INT,
816                 .off1   = td_var_offset(bs[DDIR_READ]),
817                 .off2   = td_var_offset(bs[DDIR_WRITE]),
818                 .minval = 1,
819                 .help   = "Block size unit",
820                 .def    = "4k",
821                 .parent = "rw",
822         },
823         {
824                 .name   = "ba",
825                 .alias  = "blockalign",
826                 .type   = FIO_OPT_STR_VAL_INT,
827                 .off1   = td_var_offset(ba[DDIR_READ]),
828                 .off2   = td_var_offset(ba[DDIR_WRITE]),
829                 .minval = 1,
830                 .help   = "IO block offset alignment",
831                 .parent = "rw",
832         },
833         {
834                 .name   = "bsrange",
835                 .alias  = "blocksize_range",
836                 .type   = FIO_OPT_RANGE,
837                 .off1   = td_var_offset(min_bs[DDIR_READ]),
838                 .off2   = td_var_offset(max_bs[DDIR_READ]),
839                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
840                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
841                 .minval = 1,
842                 .help   = "Set block size range (in more detail than bs)",
843                 .parent = "rw",
844         },
845         {
846                 .name   = "bssplit",
847                 .type   = FIO_OPT_STR,
848                 .cb     = str_bssplit_cb,
849                 .help   = "Set a specific mix of block sizes",
850                 .parent = "rw",
851         },
852         {
853                 .name   = "bs_unaligned",
854                 .alias  = "blocksize_unaligned",
855                 .type   = FIO_OPT_STR_SET,
856                 .off1   = td_var_offset(bs_unaligned),
857                 .help   = "Don't sector align IO buffer sizes",
858                 .parent = "rw",
859         },
860         {
861                 .name   = "randrepeat",
862                 .type   = FIO_OPT_BOOL,
863                 .off1   = td_var_offset(rand_repeatable),
864                 .help   = "Use repeatable random IO pattern",
865                 .def    = "1",
866                 .parent = "rw",
867         },
868         {
869                 .name   = "norandommap",
870                 .type   = FIO_OPT_STR_SET,
871                 .off1   = td_var_offset(norandommap),
872                 .help   = "Accept potential duplicate random blocks",
873                 .parent = "rw",
874         },
875         {
876                 .name   = "softrandommap",
877                 .type   = FIO_OPT_BOOL,
878                 .off1   = td_var_offset(softrandommap),
879                 .help   = "Set norandommap if randommap allocation fails",
880                 .parent = "norandommap",
881                 .def    = "0",
882         },
883         {
884                 .name   = "nrfiles",
885                 .type   = FIO_OPT_INT,
886                 .off1   = td_var_offset(nr_files),
887                 .help   = "Split job workload between this number of files",
888                 .def    = "1",
889         },
890         {
891                 .name   = "openfiles",
892                 .type   = FIO_OPT_INT,
893                 .off1   = td_var_offset(open_files),
894                 .help   = "Number of files to keep open at the same time",
895         },
896         {
897                 .name   = "file_service_type",
898                 .type   = FIO_OPT_STR,
899                 .cb     = str_fst_cb,
900                 .off1   = td_var_offset(file_service_type),
901                 .help   = "How to select which file to service next",
902                 .def    = "roundrobin",
903                 .posval = {
904                           { .ival = "random",
905                             .oval = FIO_FSERVICE_RANDOM,
906                             .help = "Choose a file at random",
907                           },
908                           { .ival = "roundrobin",
909                             .oval = FIO_FSERVICE_RR,
910                             .help = "Round robin select files",
911                           },
912                           { .ival = "sequential",
913                             .oval = FIO_FSERVICE_SEQ,
914                             .help = "Finish one file before moving to the next",
915                           },
916                 },
917                 .parent = "nrfiles",
918         },
919         {
920                 .name   = "fadvise_hint",
921                 .type   = FIO_OPT_BOOL,
922                 .off1   = td_var_offset(fadvise_hint),
923                 .help   = "Use fadvise() to advise the kernel on IO pattern",
924                 .def    = "1",
925         },
926         {
927                 .name   = "fsync",
928                 .type   = FIO_OPT_INT,
929                 .off1   = td_var_offset(fsync_blocks),
930                 .help   = "Issue fsync for writes every given number of blocks",
931                 .def    = "0",
932         },
933         {
934                 .name   = "direct",
935                 .type   = FIO_OPT_BOOL,
936                 .off1   = td_var_offset(odirect),
937                 .help   = "Use O_DIRECT IO (negates buffered)",
938                 .def    = "0",
939         },
940         {
941                 .name   = "buffered",
942                 .type   = FIO_OPT_BOOL,
943                 .off1   = td_var_offset(odirect),
944                 .neg    = 1,
945                 .help   = "Use buffered IO (negates direct)",
946                 .def    = "1",
947         },
948         {
949                 .name   = "overwrite",
950                 .type   = FIO_OPT_BOOL,
951                 .off1   = td_var_offset(overwrite),
952                 .help   = "When writing, set whether to overwrite current data",
953                 .def    = "0",
954         },
955         {
956                 .name   = "loops",
957                 .type   = FIO_OPT_INT,
958                 .off1   = td_var_offset(loops),
959                 .help   = "Number of times to run the job",
960                 .def    = "1",
961         },
962         {
963                 .name   = "numjobs",
964                 .type   = FIO_OPT_INT,
965                 .off1   = td_var_offset(numjobs),
966                 .help   = "Duplicate this job this many times",
967                 .def    = "1",
968         },
969         {
970                 .name   = "startdelay",
971                 .type   = FIO_OPT_INT,
972                 .off1   = td_var_offset(start_delay),
973                 .help   = "Only start job when this period has passed",
974                 .def    = "0",
975         },
976         {
977                 .name   = "runtime",
978                 .alias  = "timeout",
979                 .type   = FIO_OPT_STR_VAL_TIME,
980                 .off1   = td_var_offset(timeout),
981                 .help   = "Stop workload when this amount of time has passed",
982                 .def    = "0",
983         },
984         {
985                 .name   = "time_based",
986                 .type   = FIO_OPT_STR_SET,
987                 .off1   = td_var_offset(time_based),
988                 .help   = "Keep running until runtime/timeout is met",
989         },
990         {
991                 .name   = "ramp_time",
992                 .type   = FIO_OPT_STR_VAL_TIME,
993                 .off1   = td_var_offset(ramp_time),
994                 .help   = "Ramp up time before measuring performance",
995         },
996         {
997                 .name   = "mem",
998                 .alias  = "iomem",
999                 .type   = FIO_OPT_STR,
1000                 .cb     = str_mem_cb,
1001                 .off1   = td_var_offset(mem_type),
1002                 .help   = "Backing type for IO buffers",
1003                 .def    = "malloc",
1004                 .posval = {
1005                           { .ival = "malloc",
1006                             .oval = MEM_MALLOC,
1007                             .help = "Use malloc(3) for IO buffers",
1008                           },
1009                           { .ival = "shm",
1010                             .oval = MEM_SHM,
1011                             .help = "Use shared memory segments for IO buffers",
1012                           },
1013 #ifdef FIO_HAVE_HUGETLB
1014                           { .ival = "shmhuge",
1015                             .oval = MEM_SHMHUGE,
1016                             .help = "Like shm, but use huge pages",
1017                           },
1018 #endif
1019                           { .ival = "mmap",
1020                             .oval = MEM_MMAP,
1021                             .help = "Use mmap(2) (file or anon) for IO buffers",
1022                           },
1023 #ifdef FIO_HAVE_HUGETLB
1024                           { .ival = "mmaphuge",
1025                             .oval = MEM_MMAPHUGE,
1026                             .help = "Like mmap, but use huge pages",
1027                           },
1028 #endif
1029                   },
1030         },
1031         {
1032                 .name   = "verify",
1033                 .type   = FIO_OPT_STR,
1034                 .off1   = td_var_offset(verify),
1035                 .help   = "Verify data written",
1036                 .def    = "0",
1037                 .posval = {
1038                           { .ival = "0",
1039                             .oval = VERIFY_NONE,
1040                             .help = "Don't do IO verification",
1041                           },
1042                           { .ival = "md5",
1043                             .oval = VERIFY_MD5,
1044                             .help = "Use md5 checksums for verification",
1045                           },
1046                           { .ival = "crc64",
1047                             .oval = VERIFY_CRC64,
1048                             .help = "Use crc64 checksums for verification",
1049                           },
1050                           { .ival = "crc32",
1051                             .oval = VERIFY_CRC32,
1052                             .help = "Use crc32 checksums for verification",
1053                           },
1054                           { .ival = "crc32c-intel",
1055                             .oval = VERIFY_CRC32C_INTEL,
1056                             .help = "Use hw crc32c checksums for verification",
1057                           },
1058                           { .ival = "crc32c",
1059                             .oval = VERIFY_CRC32C,
1060                             .help = "Use crc32c checksums for verification",
1061                           },
1062                           { .ival = "crc16",
1063                             .oval = VERIFY_CRC16,
1064                             .help = "Use crc16 checksums for verification",
1065                           },
1066                           { .ival = "crc7",
1067                             .oval = VERIFY_CRC7,
1068                             .help = "Use crc7 checksums for verification",
1069                           },
1070                           { .ival = "sha256",
1071                             .oval = VERIFY_SHA256,
1072                             .help = "Use sha256 checksums for verification",
1073                           },
1074                           { .ival = "sha512",
1075                             .oval = VERIFY_SHA512,
1076                             .help = "Use sha512 checksums for verification",
1077                           },
1078                           { .ival = "meta",
1079                             .oval = VERIFY_META,
1080                             .help = "Use io information",
1081                           },
1082                           {
1083                             .ival = "null",
1084                             .oval = VERIFY_NULL,
1085                             .help = "Pretend to verify",
1086                           },
1087                 },
1088         },
1089         {
1090                 .name   = "do_verify",
1091                 .type   = FIO_OPT_BOOL,
1092                 .off1   = td_var_offset(do_verify),
1093                 .help   = "Run verification stage after write",
1094                 .def    = "1",
1095                 .parent = "verify",
1096         },
1097         {
1098                 .name   = "verifysort",
1099                 .type   = FIO_OPT_BOOL,
1100                 .off1   = td_var_offset(verifysort),
1101                 .help   = "Sort written verify blocks for read back",
1102                 .def    = "1",
1103                 .parent = "verify",
1104         },
1105         {
1106                 .name   = "verify_interval",
1107                 .type   = FIO_OPT_STR_VAL_INT,
1108                 .off1   = td_var_offset(verify_interval),
1109                 .minval = 2 * sizeof(struct verify_header),
1110                 .help   = "Store verify buffer header every N bytes",
1111                 .parent = "verify",
1112         },
1113         {
1114                 .name   = "verify_offset",
1115                 .type   = FIO_OPT_STR_VAL_INT,
1116                 .help   = "Offset verify header location by N bytes",
1117                 .def    = "0",
1118                 .cb     = str_verify_offset_cb,
1119                 .parent = "verify",
1120         },
1121         {
1122                 .name   = "verify_pattern",
1123                 .type   = FIO_OPT_INT,
1124                 .cb     = str_verify_pattern_cb,
1125                 .help   = "Fill pattern for IO buffers",
1126                 .parent = "verify",
1127         },
1128         {
1129                 .name   = "verify_fatal",
1130                 .type   = FIO_OPT_BOOL,
1131                 .off1   = td_var_offset(verify_fatal),
1132                 .def    = "0",
1133                 .help   = "Exit on a single verify failure, don't continue",
1134                 .parent = "verify",
1135         },
1136         {
1137                 .name   = "write_iolog",
1138                 .type   = FIO_OPT_STR_STORE,
1139                 .off1   = td_var_offset(write_iolog_file),
1140                 .help   = "Store IO pattern to file",
1141         },
1142         {
1143                 .name   = "read_iolog",
1144                 .type   = FIO_OPT_STR_STORE,
1145                 .off1   = td_var_offset(read_iolog_file),
1146                 .help   = "Playback IO pattern from file",
1147         },
1148         {
1149                 .name   = "exec_prerun",
1150                 .type   = FIO_OPT_STR_STORE,
1151                 .off1   = td_var_offset(exec_prerun),
1152                 .help   = "Execute this file prior to running job",
1153         },
1154         {
1155                 .name   = "exec_postrun",
1156                 .type   = FIO_OPT_STR_STORE,
1157                 .off1   = td_var_offset(exec_postrun),
1158                 .help   = "Execute this file after running job",
1159         },
1160 #ifdef FIO_HAVE_IOSCHED_SWITCH
1161         {
1162                 .name   = "ioscheduler",
1163                 .type   = FIO_OPT_STR_STORE,
1164                 .off1   = td_var_offset(ioscheduler),
1165                 .help   = "Use this IO scheduler on the backing device",
1166         },
1167 #endif
1168         {
1169                 .name   = "zonesize",
1170                 .type   = FIO_OPT_STR_VAL,
1171                 .off1   = td_var_offset(zone_size),
1172                 .help   = "Give size of an IO zone",
1173                 .def    = "0",
1174         },
1175         {
1176                 .name   = "zoneskip",
1177                 .type   = FIO_OPT_STR_VAL,
1178                 .off1   = td_var_offset(zone_skip),
1179                 .help   = "Space between IO zones",
1180                 .def    = "0",
1181         },
1182         {
1183                 .name   = "lockmem",
1184                 .type   = FIO_OPT_STR_VAL,
1185                 .cb     = str_lockmem_cb,
1186                 .help   = "Lock down this amount of memory",
1187                 .def    = "0",
1188         },
1189         {
1190                 .name   = "rwmixread",
1191                 .type   = FIO_OPT_INT,
1192                 .cb     = str_rwmix_read_cb,
1193                 .maxval = 100,
1194                 .help   = "Percentage of mixed workload that is reads",
1195                 .def    = "50",
1196         },
1197         {
1198                 .name   = "rwmixwrite",
1199                 .type   = FIO_OPT_INT,
1200                 .cb     = str_rwmix_write_cb,
1201                 .maxval = 100,
1202                 .help   = "Percentage of mixed workload that is writes",
1203                 .def    = "50",
1204         },
1205         {
1206                 .name   = "rwmixcycle",
1207                 .type   = FIO_OPT_DEPRECATED,
1208         },
1209         {
1210                 .name   = "nice",
1211                 .type   = FIO_OPT_INT,
1212                 .off1   = td_var_offset(nice),
1213                 .help   = "Set job CPU nice value",
1214                 .minval = -19,
1215                 .maxval = 20,
1216                 .def    = "0",
1217         },
1218 #ifdef FIO_HAVE_IOPRIO
1219         {
1220                 .name   = "prio",
1221                 .type   = FIO_OPT_INT,
1222                 .cb     = str_prio_cb,
1223                 .help   = "Set job IO priority value",
1224                 .minval = 0,
1225                 .maxval = 7,
1226         },
1227         {
1228                 .name   = "prioclass",
1229                 .type   = FIO_OPT_INT,
1230                 .cb     = str_prioclass_cb,
1231                 .help   = "Set job IO priority class",
1232                 .minval = 0,
1233                 .maxval = 3,
1234         },
1235 #endif
1236         {
1237                 .name   = "thinktime",
1238                 .type   = FIO_OPT_INT,
1239                 .off1   = td_var_offset(thinktime),
1240                 .help   = "Idle time between IO buffers (usec)",
1241                 .def    = "0",
1242         },
1243         {
1244                 .name   = "thinktime_spin",
1245                 .type   = FIO_OPT_INT,
1246                 .off1   = td_var_offset(thinktime_spin),
1247                 .help   = "Start think time by spinning this amount (usec)",
1248                 .def    = "0",
1249                 .parent = "thinktime",
1250         },
1251         {
1252                 .name   = "thinktime_blocks",
1253                 .type   = FIO_OPT_INT,
1254                 .off1   = td_var_offset(thinktime_blocks),
1255                 .help   = "IO buffer period between 'thinktime'",
1256                 .def    = "1",
1257                 .parent = "thinktime",
1258         },
1259         {
1260                 .name   = "rate",
1261                 .type   = FIO_OPT_INT,
1262                 .off1   = td_var_offset(rate),
1263                 .help   = "Set bandwidth rate",
1264         },
1265         {
1266                 .name   = "ratemin",
1267                 .type   = FIO_OPT_INT,
1268                 .off1   = td_var_offset(ratemin),
1269                 .help   = "Job must meet this rate or it will be shutdown",
1270                 .parent = "rate",
1271         },
1272         {
1273                 .name   = "rate_iops",
1274                 .type   = FIO_OPT_INT,
1275                 .off1   = td_var_offset(rate_iops),
1276                 .help   = "Limit IO used to this number of IO operations/sec",
1277         },
1278         {
1279                 .name   = "rate_iops_min",
1280                 .type   = FIO_OPT_INT,
1281                 .off1   = td_var_offset(rate_iops_min),
1282                 .help   = "Job must meet this rate or it will be shutdown",
1283                 .parent = "rate_iops",
1284         },
1285         {
1286                 .name   = "ratecycle",
1287                 .type   = FIO_OPT_INT,
1288                 .off1   = td_var_offset(ratecycle),
1289                 .help   = "Window average for rate limits (msec)",
1290                 .def    = "1000",
1291                 .parent = "rate",
1292         },
1293         {
1294                 .name   = "invalidate",
1295                 .type   = FIO_OPT_BOOL,
1296                 .off1   = td_var_offset(invalidate_cache),
1297                 .help   = "Invalidate buffer/page cache prior to running job",
1298                 .def    = "1",
1299         },
1300         {
1301                 .name   = "sync",
1302                 .type   = FIO_OPT_BOOL,
1303                 .off1   = td_var_offset(sync_io),
1304                 .help   = "Use O_SYNC for buffered writes",
1305                 .def    = "0",
1306                 .parent = "buffered",
1307         },
1308         {
1309                 .name   = "bwavgtime",
1310                 .type   = FIO_OPT_INT,
1311                 .off1   = td_var_offset(bw_avg_time),
1312                 .help   = "Time window over which to calculate bandwidth"
1313                           " (msec)",
1314                 .def    = "500",
1315         },
1316         {
1317                 .name   = "create_serialize",
1318                 .type   = FIO_OPT_BOOL,
1319                 .off1   = td_var_offset(create_serialize),
1320                 .help   = "Serialize creating of job files",
1321                 .def    = "1",
1322         },
1323         {
1324                 .name   = "create_fsync",
1325                 .type   = FIO_OPT_BOOL,
1326                 .off1   = td_var_offset(create_fsync),
1327                 .help   = "Fsync file after creation",
1328                 .def    = "1",
1329         },
1330         {
1331                 .name   = "create_on_open",
1332                 .type   = FIO_OPT_BOOL,
1333                 .off1   = td_var_offset(create_on_open),
1334                 .help   = "Create files when they are opened for IO",
1335                 .def    = "0",
1336         },
1337         {
1338                 .name   = "pre_read",
1339                 .type   = FIO_OPT_BOOL,
1340                 .off1   = td_var_offset(pre_read),
1341                 .help   = "Preread files before starting official testing",
1342                 .def    = "0",
1343         },
1344         {
1345                 .name   = "cpuload",
1346                 .type   = FIO_OPT_INT,
1347                 .off1   = td_var_offset(cpuload),
1348                 .help   = "Use this percentage of CPU",
1349         },
1350         {
1351                 .name   = "cpuchunks",
1352                 .type   = FIO_OPT_INT,
1353                 .off1   = td_var_offset(cpucycle),
1354                 .help   = "Length of the CPU burn cycles (usecs)",
1355                 .def    = "50000",
1356                 .parent = "cpuload",
1357         },
1358 #ifdef FIO_HAVE_CPU_AFFINITY
1359         {
1360                 .name   = "cpumask",
1361                 .type   = FIO_OPT_INT,
1362                 .cb     = str_cpumask_cb,
1363                 .help   = "CPU affinity mask",
1364         },
1365         {
1366                 .name   = "cpus_allowed",
1367                 .type   = FIO_OPT_STR,
1368                 .cb     = str_cpus_allowed_cb,
1369                 .help   = "Set CPUs allowed",
1370         },
1371 #endif
1372         {
1373                 .name   = "end_fsync",
1374                 .type   = FIO_OPT_BOOL,
1375                 .off1   = td_var_offset(end_fsync),
1376                 .help   = "Include fsync at the end of job",
1377                 .def    = "0",
1378         },
1379         {
1380                 .name   = "fsync_on_close",
1381                 .type   = FIO_OPT_BOOL,
1382                 .off1   = td_var_offset(fsync_on_close),
1383                 .help   = "fsync files on close",
1384                 .def    = "0",
1385         },
1386         {
1387                 .name   = "unlink",
1388                 .type   = FIO_OPT_BOOL,
1389                 .off1   = td_var_offset(unlink),
1390                 .help   = "Unlink created files after job has completed",
1391                 .def    = "0",
1392         },
1393         {
1394                 .name   = "exitall",
1395                 .type   = FIO_OPT_STR_SET,
1396                 .cb     = str_exitall_cb,
1397                 .help   = "Terminate all jobs when one exits",
1398         },
1399         {
1400                 .name   = "stonewall",
1401                 .type   = FIO_OPT_STR_SET,
1402                 .off1   = td_var_offset(stonewall),
1403                 .help   = "Insert a hard barrier between this job and previous",
1404         },
1405         {
1406                 .name   = "new_group",
1407                 .type   = FIO_OPT_STR_SET,
1408                 .off1   = td_var_offset(new_group),
1409                 .help   = "Mark the start of a new group (for reporting)",
1410         },
1411         {
1412                 .name   = "thread",
1413                 .type   = FIO_OPT_STR_SET,
1414                 .off1   = td_var_offset(use_thread),
1415                 .help   = "Use threads instead of forks",
1416         },
1417         {
1418                 .name   = "write_bw_log",
1419                 .type   = FIO_OPT_STR,
1420                 .off1   = td_var_offset(write_bw_log),
1421                 .cb     = str_write_bw_log_cb,
1422                 .help   = "Write log of bandwidth during run",
1423         },
1424         {
1425                 .name   = "write_lat_log",
1426                 .type   = FIO_OPT_STR,
1427                 .off1   = td_var_offset(write_lat_log),
1428                 .cb     = str_write_lat_log_cb,
1429                 .help   = "Write log of latency during run",
1430         },
1431         {
1432                 .name   = "hugepage-size",
1433                 .type   = FIO_OPT_STR_VAL_INT,
1434                 .off1   = td_var_offset(hugepage_size),
1435                 .help   = "When using hugepages, specify size of each page",
1436                 .def    = __stringify(FIO_HUGE_PAGE),
1437         },
1438         {
1439                 .name   = "group_reporting",
1440                 .type   = FIO_OPT_STR_SET,
1441                 .off1   = td_var_offset(group_reporting),
1442                 .help   = "Do reporting on a per-group basis",
1443         },
1444         {
1445                 .name   = "zero_buffers",
1446                 .type   = FIO_OPT_STR_SET,
1447                 .off1   = td_var_offset(zero_buffers),
1448                 .help   = "Init IO buffers to all zeroes",
1449         },
1450         {
1451                 .name   = "refill_buffers",
1452                 .type   = FIO_OPT_STR_SET,
1453                 .off1   = td_var_offset(refill_buffers),
1454                 .help   = "Refill IO buffers on every IO submit",
1455         },
1456 #ifdef FIO_HAVE_DISK_UTIL
1457         {
1458                 .name   = "disk_util",
1459                 .type   = FIO_OPT_BOOL,
1460                 .off1   = td_var_offset(do_disk_util),
1461                 .help   = "Log disk utilization statistics",
1462                 .def    = "1",
1463         },
1464 #endif
1465         {
1466                 .name   = "gtod_reduce",
1467                 .type   = FIO_OPT_BOOL,
1468                 .help   = "Greatly reduce number of gettimeofday() calls",
1469                 .cb     = str_gtod_reduce_cb,
1470                 .def    = "0",
1471         },
1472         {
1473                 .name   = "disable_clat",
1474                 .type   = FIO_OPT_BOOL,
1475                 .off1   = td_var_offset(disable_clat),
1476                 .help   = "Disable completion latency numbers",
1477                 .parent = "gtod_reduce",
1478                 .def    = "0",
1479         },
1480         {
1481                 .name   = "disable_slat",
1482                 .type   = FIO_OPT_BOOL,
1483                 .off1   = td_var_offset(disable_slat),
1484                 .help   = "Disable submissionn latency numbers",
1485                 .parent = "gtod_reduce",
1486                 .def    = "0",
1487         },
1488         {
1489                 .name   = "disable_bw_measurement",
1490                 .type   = FIO_OPT_BOOL,
1491                 .off1   = td_var_offset(disable_bw),
1492                 .help   = "Disable bandwidth logging",
1493                 .parent = "gtod_reduce",
1494                 .def    = "0",
1495         },
1496         {
1497                 .name   = "gtod_cpu",
1498                 .type   = FIO_OPT_INT,
1499                 .cb     = str_gtod_cpu_cb,
1500                 .help   = "Setup dedicated gettimeofday() thread on this CPU",
1501         },
1502         {
1503                 .name = NULL,
1504         },
1505 };
1506
1507 void fio_options_dup_and_init(struct option *long_options)
1508 {
1509         struct fio_option *o;
1510         unsigned int i;
1511
1512         options_init(options);
1513
1514         i = 0;
1515         while (long_options[i].name)
1516                 i++;
1517
1518         o = &options[0];
1519         while (o->name) {
1520                 long_options[i].name = (char *) o->name;
1521                 long_options[i].val = FIO_GETOPT_JOB;
1522                 if (o->type == FIO_OPT_STR_SET)
1523                         long_options[i].has_arg = no_argument;
1524                 else
1525                         long_options[i].has_arg = required_argument;
1526
1527                 i++;
1528                 o++;
1529                 assert(i < FIO_NR_OPTIONS);
1530         }
1531 }
1532
1533 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
1534 {
1535         int i, ret;
1536
1537         sort_options(opts, options, num_opts);
1538
1539         for (ret = 0, i = 0; i < num_opts; i++)
1540                 ret |= parse_option(opts[i], options, td);
1541
1542         return ret;
1543 }
1544
1545 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1546 {
1547         return parse_cmd_option(opt, val, options, td);
1548 }
1549
1550 void fio_fill_default_options(struct thread_data *td)
1551 {
1552         fill_default_options(td, options);
1553 }
1554
1555 int fio_show_option_help(const char *opt)
1556 {
1557         return show_cmd_help(options, opt);
1558 }
1559
1560 static void __options_mem(struct thread_data *td, int alloc)
1561 {
1562         struct thread_options *o = &td->o;
1563         struct fio_option *opt;
1564         char **ptr;
1565         int i;
1566
1567         for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1568                 if (opt->type != FIO_OPT_STR_STORE)
1569                         continue;
1570
1571                 ptr = (void *) o + opt->off1;
1572                 if (*ptr) {
1573                         if (alloc)
1574                                 *ptr = strdup(*ptr);
1575                         else {
1576                                 free(*ptr);
1577                                 *ptr = NULL;
1578                         }
1579                 }
1580         }
1581 }
1582
1583 /*
1584  * dupe FIO_OPT_STR_STORE options
1585  */
1586 void options_mem_dupe(struct thread_data *td)
1587 {
1588         __options_mem(td, 1);
1589 }
1590
1591 void options_mem_free(struct thread_data fio_unused *td)
1592 {
1593 #if 0
1594         __options_mem(td, 0);
1595 #endif
1596 }