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