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