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