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