Add sample file for surface scan
[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         },
508         {
509                 .name   = "iodepth_low",
510                 .type   = FIO_OPT_INT,
511                 .off1   = td_var_offset(iodepth_low),
512                 .help   = "Low water mark for queuing depth",
513                 .parent = "iodepth",
514         },
515         {
516                 .name   = "size",
517                 .type   = FIO_OPT_STR_VAL,
518                 .off1   = td_var_offset(size),
519                 .minval = 1,
520                 .help   = "Total size of device or files",
521         },
522         {
523                 .name   = "fill_device",
524                 .type   = FIO_OPT_BOOL,
525                 .off1   = td_var_offset(fill_device),
526                 .help   = "Write until an ENOSPC error occurs",
527                 .def    = "0",
528         },
529         {
530                 .name   = "filesize",
531                 .type   = FIO_OPT_STR_VAL,
532                 .off1   = td_var_offset(file_size_low),
533                 .off2   = td_var_offset(file_size_high),
534                 .minval = 1,
535                 .help   = "Size of individual files",
536         },
537         {
538                 .name   = "offset",
539                 .alias  = "fileoffset",
540                 .type   = FIO_OPT_STR_VAL,
541                 .off1   = td_var_offset(start_offset),
542                 .help   = "Start IO from this offset",
543                 .def    = "0",
544         },
545         {
546                 .name   = "bs",
547                 .alias  = "blocksize",
548                 .type   = FIO_OPT_STR_VAL_INT,
549                 .off1   = td_var_offset(bs[DDIR_READ]),
550                 .off2   = td_var_offset(bs[DDIR_WRITE]),
551                 .minval = 1,
552                 .help   = "Block size unit",
553                 .def    = "4k",
554                 .parent = "rw",
555         },
556         {
557                 .name   = "bsrange",
558                 .alias  = "blocksize_range",
559                 .type   = FIO_OPT_RANGE,
560                 .off1   = td_var_offset(min_bs[DDIR_READ]),
561                 .off2   = td_var_offset(max_bs[DDIR_READ]),
562                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
563                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
564                 .minval = 1,
565                 .help   = "Set block size range (in more detail than bs)",
566                 .parent = "rw",
567         },
568         {
569                 .name   = "bssplit",
570                 .type   = FIO_OPT_STR,
571                 .cb     = str_bssplit_cb,
572                 .help   = "Set a specific mix of block sizes",
573                 .parent = "rw",
574         },
575         {
576                 .name   = "bs_unaligned",
577                 .alias  = "blocksize_unaligned",
578                 .type   = FIO_OPT_STR_SET,
579                 .off1   = td_var_offset(bs_unaligned),
580                 .help   = "Don't sector align IO buffer sizes",
581                 .parent = "rw",
582         },
583         {
584                 .name   = "randrepeat",
585                 .type   = FIO_OPT_BOOL,
586                 .off1   = td_var_offset(rand_repeatable),
587                 .help   = "Use repeatable random IO pattern",
588                 .def    = "1",
589                 .parent = "rw",
590         },
591         {
592                 .name   = "norandommap",
593                 .type   = FIO_OPT_STR_SET,
594                 .off1   = td_var_offset(norandommap),
595                 .help   = "Accept potential duplicate random blocks",
596                 .parent = "rw",
597         },
598         {
599                 .name   = "nrfiles",
600                 .type   = FIO_OPT_INT,
601                 .off1   = td_var_offset(nr_files),
602                 .help   = "Split job workload between this number of files",
603                 .def    = "1",
604         },
605         {
606                 .name   = "openfiles",
607                 .type   = FIO_OPT_INT,
608                 .off1   = td_var_offset(open_files),
609                 .help   = "Number of files to keep open at the same time",
610         },
611         {
612                 .name   = "file_service_type",
613                 .type   = FIO_OPT_STR,
614                 .cb     = str_fst_cb,
615                 .off1   = td_var_offset(file_service_type),
616                 .help   = "How to select which file to service next",
617                 .def    = "roundrobin",
618                 .posval = {
619                           { .ival = "random",
620                             .oval = FIO_FSERVICE_RANDOM,
621                             .help = "Choose a file at random",
622                           },
623                           { .ival = "roundrobin",
624                             .oval = FIO_FSERVICE_RR,
625                             .help = "Round robin select files",
626                           },
627                 },
628                 .parent = "nrfiles",
629         },
630         {
631                 .name   = "fadvise_hint",
632                 .type   = FIO_OPT_BOOL,
633                 .off1   = td_var_offset(fadvise_hint),
634                 .help   = "Use fadvise() to advise the kernel on IO pattern",
635                 .def    = "1",
636         },
637         {
638                 .name   = "fsync",
639                 .type   = FIO_OPT_INT,
640                 .off1   = td_var_offset(fsync_blocks),
641                 .help   = "Issue fsync for writes every given number of blocks",
642                 .def    = "0",
643         },
644         {
645                 .name   = "direct",
646                 .type   = FIO_OPT_BOOL,
647                 .off1   = td_var_offset(odirect),
648                 .help   = "Use O_DIRECT IO (negates buffered)",
649                 .def    = "0",
650         },
651         {
652                 .name   = "buffered",
653                 .type   = FIO_OPT_BOOL,
654                 .off1   = td_var_offset(odirect),
655                 .neg    = 1,
656                 .help   = "Use buffered IO (negates direct)",
657                 .def    = "1",
658         },
659         {
660                 .name   = "overwrite",
661                 .type   = FIO_OPT_BOOL,
662                 .off1   = td_var_offset(overwrite),
663                 .help   = "When writing, set whether to overwrite current data",
664                 .def    = "0",
665         },
666         {
667                 .name   = "loops",
668                 .type   = FIO_OPT_INT,
669                 .off1   = td_var_offset(loops),
670                 .help   = "Number of times to run the job",
671                 .def    = "1",
672         },
673         {
674                 .name   = "numjobs",
675                 .type   = FIO_OPT_INT,
676                 .off1   = td_var_offset(numjobs),
677                 .help   = "Duplicate this job this many times",
678                 .def    = "1",
679         },
680         {
681                 .name   = "startdelay",
682                 .type   = FIO_OPT_INT,
683                 .off1   = td_var_offset(start_delay),
684                 .help   = "Only start job when this period has passed",
685                 .def    = "0",
686         },
687         {
688                 .name   = "runtime",
689                 .alias  = "timeout",
690                 .type   = FIO_OPT_STR_VAL_TIME,
691                 .off1   = td_var_offset(timeout),
692                 .help   = "Stop workload when this amount of time has passed",
693                 .def    = "0",
694         },
695         {
696                 .name   = "time_based",
697                 .type   = FIO_OPT_STR_SET,
698                 .off1   = td_var_offset(time_based),
699                 .help   = "Keep running until runtime/timeout is met",
700         },
701         {
702                 .name   = "mem",
703                 .alias  = "iomem",
704                 .type   = FIO_OPT_STR,
705                 .cb     = str_mem_cb,
706                 .off1   = td_var_offset(mem_type),
707                 .help   = "Backing type for IO buffers",
708                 .def    = "malloc",
709                 .posval = {
710                           { .ival = "malloc",
711                             .oval = MEM_MALLOC,
712                             .help = "Use malloc(3) for IO buffers",
713                           },
714                           { .ival = "shm",
715                             .oval = MEM_SHM,
716                             .help = "Use shared memory segments for IO buffers",
717                           },
718 #ifdef FIO_HAVE_HUGETLB
719                           { .ival = "shmhuge",
720                             .oval = MEM_SHMHUGE,
721                             .help = "Like shm, but use huge pages",
722                           },
723 #endif
724                           { .ival = "mmap",
725                             .oval = MEM_MMAP,
726                             .help = "Use mmap(2) (file or anon) for IO buffers",
727                           },
728 #ifdef FIO_HAVE_HUGETLB
729                           { .ival = "mmaphuge",
730                             .oval = MEM_MMAPHUGE,
731                             .help = "Like mmap, but use huge pages",
732                           },
733 #endif
734                   },
735         },
736         {
737                 .name   = "verify",
738                 .type   = FIO_OPT_STR,
739                 .off1   = td_var_offset(verify),
740                 .help   = "Verify data written",
741                 .def    = "0",
742                 .posval = {
743                           { .ival = "0",
744                             .oval = VERIFY_NONE,
745                             .help = "Don't do IO verification",
746                           },
747                           { .ival = "md5",
748                             .oval = VERIFY_MD5,
749                             .help = "Use md5 checksums for verification",
750                           },
751                           { .ival = "crc64",
752                             .oval = VERIFY_CRC64,
753                             .help = "Use crc64 checksums for verification",
754                           },
755                           { .ival = "crc32",
756                             .oval = VERIFY_CRC32,
757                             .help = "Use crc32 checksums for verification",
758                           },
759                           { .ival = "crc16",
760                             .oval = VERIFY_CRC16,
761                             .help = "Use crc16 checksums for verification",
762                           },
763                           { .ival = "crc7",
764                             .oval = VERIFY_CRC7,
765                             .help = "Use crc7 checksums for verification",
766                           },
767                           { .ival = "sha256",
768                             .oval = VERIFY_SHA256,
769                             .help = "Use sha256 checksums for verification",
770                           },
771                           { .ival = "sha512",
772                             .oval = VERIFY_SHA512,
773                             .help = "Use sha512 checksums for verification",
774                           },
775                           { .ival = "meta",
776                             .oval = VERIFY_META,
777                             .help = "Use io information",
778                           },
779                           {
780                             .ival = "null",
781                             .oval = VERIFY_NULL,
782                             .help = "Pretend to verify",
783                           },
784                 },
785         },
786         {
787                 .name   = "do_verify",
788                 .type   = FIO_OPT_BOOL,
789                 .off1   = td_var_offset(do_verify),
790                 .help   = "Run verification stage after write",
791                 .def    = "1",
792                 .parent = "verify",
793         },
794         {
795                 .name   = "verifysort",
796                 .type   = FIO_OPT_BOOL,
797                 .off1   = td_var_offset(verifysort),
798                 .help   = "Sort written verify blocks for read back",
799                 .def    = "1",
800                 .parent = "verify",
801         },
802         {
803                 .name   = "verify_interval",
804                 .type   = FIO_OPT_STR_VAL_INT,
805                 .off1   = td_var_offset(verify_interval),
806                 .minval = 2 * sizeof(struct verify_header),
807                 .help   = "Store verify buffer header every N bytes",
808                 .parent = "verify",
809         },
810         {
811                 .name   = "verify_offset",
812                 .type   = FIO_OPT_STR_VAL_INT,
813                 .help   = "Offset verify header location by N bytes",
814                 .def    = "0",
815                 .cb     = str_verify_offset_cb, 
816                 .parent = "verify",
817         },
818         {
819                 .name   = "verify_pattern",
820                 .type   = FIO_OPT_INT,
821                 .cb     = str_verify_pattern_cb,
822                 .help   = "Fill pattern for IO buffers",
823                 .parent = "verify",
824         },
825         {
826                 .name   = "verify_fatal",
827                 .type   = FIO_OPT_BOOL,
828                 .off1   = td_var_offset(verify_fatal),
829                 .def    = "0",
830                 .help   = "Exit on a single verify failure, don't continue",
831                 .parent = "verify",
832         },
833         {
834                 .name   = "write_iolog",
835                 .type   = FIO_OPT_STR_STORE,
836                 .off1   = td_var_offset(write_iolog_file),
837                 .help   = "Store IO pattern to file",
838         },
839         {
840                 .name   = "read_iolog",
841                 .type   = FIO_OPT_STR_STORE,
842                 .off1   = td_var_offset(read_iolog_file),
843                 .help   = "Playback IO pattern from file",
844         },
845         {
846                 .name   = "exec_prerun",
847                 .type   = FIO_OPT_STR_STORE,
848                 .off1   = td_var_offset(exec_prerun),
849                 .help   = "Execute this file prior to running job",
850         },
851         {
852                 .name   = "exec_postrun",
853                 .type   = FIO_OPT_STR_STORE,
854                 .off1   = td_var_offset(exec_postrun),
855                 .help   = "Execute this file after running job",
856         },
857 #ifdef FIO_HAVE_IOSCHED_SWITCH
858         {
859                 .name   = "ioscheduler",
860                 .type   = FIO_OPT_STR_STORE,
861                 .off1   = td_var_offset(ioscheduler),
862                 .help   = "Use this IO scheduler on the backing device",
863         },
864 #endif
865         {
866                 .name   = "zonesize",
867                 .type   = FIO_OPT_STR_VAL,
868                 .off1   = td_var_offset(zone_size),
869                 .help   = "Give size of an IO zone",
870                 .def    = "0",
871         },
872         {
873                 .name   = "zoneskip",
874                 .type   = FIO_OPT_STR_VAL,
875                 .off1   = td_var_offset(zone_skip),
876                 .help   = "Space between IO zones",
877                 .def    = "0",
878         },
879         {
880                 .name   = "lockmem",
881                 .type   = FIO_OPT_STR_VAL,
882                 .cb     = str_lockmem_cb,
883                 .help   = "Lock down this amount of memory",
884                 .def    = "0",
885         },
886         {
887                 .name   = "rwmixread",
888                 .type   = FIO_OPT_INT,
889                 .off1   = td_var_offset(rwmix[DDIR_READ]),
890                 .maxval = 100,
891                 .help   = "Percentage of mixed workload that is reads",
892                 .def    = "50",
893         },
894         {
895                 .name   = "rwmixwrite",
896                 .type   = FIO_OPT_INT,
897                 .off1   = td_var_offset(rwmix[DDIR_WRITE]),
898                 .maxval = 100,
899                 .help   = "Percentage of mixed workload that is writes",
900                 .def    = "50",
901         },
902         {
903                 .name   = "rwmixcycle",
904                 .type   = FIO_OPT_INT,
905                 .off1   = td_var_offset(rwmixcycle),
906                 .help   = "Cycle period for mixed read/write workloads (msec)",
907                 .def    = "500",
908                 .parent = "rwmixread",
909         },
910         {
911                 .name   = "nice",
912                 .type   = FIO_OPT_INT,
913                 .off1   = td_var_offset(nice),
914                 .help   = "Set job CPU nice value",
915                 .minval = -19,
916                 .maxval = 20,
917                 .def    = "0",
918         },
919 #ifdef FIO_HAVE_IOPRIO
920         {
921                 .name   = "prio",
922                 .type   = FIO_OPT_INT,
923                 .cb     = str_prio_cb,
924                 .help   = "Set job IO priority value",
925                 .minval = 0,
926                 .maxval = 7,
927         },
928         {
929                 .name   = "prioclass",
930                 .type   = FIO_OPT_INT,
931                 .cb     = str_prioclass_cb,
932                 .help   = "Set job IO priority class",
933                 .minval = 0,
934                 .maxval = 3,
935         },
936 #endif
937         {
938                 .name   = "thinktime",
939                 .type   = FIO_OPT_INT,
940                 .off1   = td_var_offset(thinktime),
941                 .help   = "Idle time between IO buffers (usec)",
942                 .def    = "0",
943         },
944         {
945                 .name   = "thinktime_spin",
946                 .type   = FIO_OPT_INT,
947                 .off1   = td_var_offset(thinktime_spin),
948                 .help   = "Start think time by spinning this amount (usec)",
949                 .def    = "0",
950                 .parent = "thinktime",
951         },
952         {
953                 .name   = "thinktime_blocks",
954                 .type   = FIO_OPT_INT,
955                 .off1   = td_var_offset(thinktime_blocks),
956                 .help   = "IO buffer period between 'thinktime'",
957                 .def    = "1",
958                 .parent = "thinktime",
959         },
960         {
961                 .name   = "rate",
962                 .type   = FIO_OPT_INT,
963                 .off1   = td_var_offset(rate),
964                 .help   = "Set bandwidth rate",
965         },
966         {
967                 .name   = "ratemin",
968                 .type   = FIO_OPT_INT,
969                 .off1   = td_var_offset(ratemin),
970                 .help   = "Job must meet this rate or it will be shutdown",
971                 .parent = "rate",
972         },
973         {
974                 .name   = "rate_iops",
975                 .type   = FIO_OPT_INT,
976                 .off1   = td_var_offset(rate_iops),
977                 .help   = "Limit IO used to this number of IO operations/sec",
978         },
979         {
980                 .name   = "rate_iops_min",
981                 .type   = FIO_OPT_INT,
982                 .off1   = td_var_offset(rate_iops_min),
983                 .help   = "Job must meet this rate or it will be shutdown",
984                 .parent = "rate_iops",
985         },
986         {
987                 .name   = "ratecycle",
988                 .type   = FIO_OPT_INT,
989                 .off1   = td_var_offset(ratecycle),
990                 .help   = "Window average for rate limits (msec)",
991                 .def    = "1000",
992                 .parent = "rate",
993         },
994         {
995                 .name   = "invalidate",
996                 .type   = FIO_OPT_BOOL,
997                 .off1   = td_var_offset(invalidate_cache),
998                 .help   = "Invalidate buffer/page cache prior to running job",
999                 .def    = "1",
1000         },
1001         {
1002                 .name   = "sync",
1003                 .type   = FIO_OPT_BOOL,
1004                 .off1   = td_var_offset(sync_io),
1005                 .help   = "Use O_SYNC for buffered writes",
1006                 .def    = "0",
1007                 .parent = "buffered",
1008         },
1009         {
1010                 .name   = "bwavgtime",
1011                 .type   = FIO_OPT_INT,
1012                 .off1   = td_var_offset(bw_avg_time),
1013                 .help   = "Time window over which to calculate bandwidth (msec)",
1014                 .def    = "500",
1015         },
1016         {
1017                 .name   = "create_serialize",
1018                 .type   = FIO_OPT_BOOL,
1019                 .off1   = td_var_offset(create_serialize),
1020                 .help   = "Serialize creating of job files",
1021                 .def    = "1",
1022         },
1023         {
1024                 .name   = "create_fsync",
1025                 .type   = FIO_OPT_BOOL,
1026                 .off1   = td_var_offset(create_fsync),
1027                 .help   = "Fsync file after creation",
1028                 .def    = "1",
1029         },
1030         {
1031                 .name   = "cpuload",
1032                 .type   = FIO_OPT_INT,
1033                 .off1   = td_var_offset(cpuload),
1034                 .help   = "Use this percentage of CPU",
1035         },
1036         {
1037                 .name   = "cpuchunks",
1038                 .type   = FIO_OPT_INT,
1039                 .off1   = td_var_offset(cpucycle),
1040                 .help   = "Length of the CPU burn cycles (usecs)",
1041                 .def    = "50000",
1042                 .parent = "cpuload",
1043         },
1044 #ifdef FIO_HAVE_CPU_AFFINITY
1045         {
1046                 .name   = "cpumask",
1047                 .type   = FIO_OPT_INT,
1048                 .cb     = str_cpumask_cb,
1049                 .help   = "CPU affinity mask",
1050         },
1051         {
1052                 .name   = "cpus_allowed",
1053                 .type   = FIO_OPT_STR,
1054                 .cb     = str_cpus_allowed_cb,
1055                 .help   = "Set CPUs allowed",
1056         },
1057 #endif
1058         {
1059                 .name   = "end_fsync",
1060                 .type   = FIO_OPT_BOOL,
1061                 .off1   = td_var_offset(end_fsync),
1062                 .help   = "Include fsync at the end of job",
1063                 .def    = "0",
1064         },
1065         {
1066                 .name   = "fsync_on_close",
1067                 .type   = FIO_OPT_BOOL,
1068                 .off1   = td_var_offset(fsync_on_close),
1069                 .help   = "fsync files on close",
1070                 .def    = "0",
1071         },
1072         {
1073                 .name   = "unlink",
1074                 .type   = FIO_OPT_BOOL,
1075                 .off1   = td_var_offset(unlink),
1076                 .help   = "Unlink created files after job has completed",
1077                 .def    = "0",
1078         },
1079         {
1080                 .name   = "exitall",
1081                 .type   = FIO_OPT_STR_SET,
1082                 .cb     = str_exitall_cb,
1083                 .help   = "Terminate all jobs when one exits",
1084         },
1085         {
1086                 .name   = "stonewall",
1087                 .type   = FIO_OPT_STR_SET,
1088                 .off1   = td_var_offset(stonewall),
1089                 .help   = "Insert a hard barrier between this job and previous",
1090         },
1091         {
1092                 .name   = "new_group",
1093                 .type   = FIO_OPT_STR_SET,
1094                 .off1   = td_var_offset(new_group),
1095                 .help   = "Mark the start of a new group (for reporting)",
1096         },
1097         {
1098                 .name   = "thread",
1099                 .type   = FIO_OPT_STR_SET,
1100                 .off1   = td_var_offset(use_thread),
1101                 .help   = "Use threads instead of forks",
1102         },
1103         {
1104                 .name   = "write_bw_log",
1105                 .type   = FIO_OPT_STR_SET,
1106                 .off1   = td_var_offset(write_bw_log),
1107                 .help   = "Write log of bandwidth during run",
1108         },
1109         {
1110                 .name   = "write_lat_log",
1111                 .type   = FIO_OPT_STR_SET,
1112                 .off1   = td_var_offset(write_lat_log),
1113                 .help   = "Write log of latency during run",
1114         },
1115         {
1116                 .name   = "hugepage-size",
1117                 .type   = FIO_OPT_STR_VAL,
1118                 .off1   = td_var_offset(hugepage_size),
1119                 .help   = "When using hugepages, specify size of each page",
1120                 .def    = __stringify(FIO_HUGE_PAGE),
1121         },
1122         {
1123                 .name   = "group_reporting",
1124                 .type   = FIO_OPT_STR_SET,
1125                 .off1   = td_var_offset(group_reporting),
1126                 .help   = "Do reporting on a per-group basis",
1127         },
1128         {
1129                 .name   = "zero_buffers",
1130                 .type   = FIO_OPT_STR_SET,
1131                 .off1   = td_var_offset(zero_buffers),
1132                 .help   = "Init IO buffers to all zeroes",
1133         },
1134 #ifdef FIO_HAVE_DISK_UTIL
1135         {
1136                 .name   = "disk_util",
1137                 .type   = FIO_OPT_BOOL,
1138                 .off1   = td_var_offset(do_disk_util),
1139                 .help   = "Log disk utilization stats",
1140                 .def    = "1",
1141         },
1142 #endif
1143         {
1144                 .name = NULL,
1145         },
1146 };
1147
1148 void fio_options_dup_and_init(struct option *long_options)
1149 {
1150         struct fio_option *o;
1151         unsigned int i;
1152
1153         options_init(options);
1154
1155         i = 0;
1156         while (long_options[i].name)
1157                 i++;
1158
1159         o = &options[0];
1160         while (o->name) {
1161                 long_options[i].name = o->name;
1162                 long_options[i].val = FIO_GETOPT_JOB;
1163                 if (o->type == FIO_OPT_STR_SET)
1164                         long_options[i].has_arg = no_argument;
1165                 else
1166                         long_options[i].has_arg = required_argument;
1167
1168                 i++;
1169                 o++;
1170                 assert(i < FIO_NR_OPTIONS);
1171         }
1172 }
1173
1174 int fio_option_parse(struct thread_data *td, const char *opt)
1175 {
1176         return parse_option(opt, options, td);
1177 }
1178
1179 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1180 {
1181         return parse_cmd_option(opt, val, options, td);
1182 }
1183
1184 void fio_fill_default_options(struct thread_data *td)
1185 {
1186         fill_default_options(td, options);
1187 }
1188
1189 int fio_show_option_help(const char *opt)
1190 {
1191         return show_cmd_help(options, opt);
1192 }
1193
1194 static void __options_mem(struct thread_data *td, int alloc)
1195 {
1196         struct thread_options *o = &td->o;
1197         struct fio_option *opt;
1198         char **ptr;
1199         int i;
1200
1201         for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1202                 if (opt->type != FIO_OPT_STR_STORE)
1203                         continue;
1204
1205                 ptr = (void *) o + opt->off1;
1206                 if (*ptr) {
1207                         if (alloc)
1208                                 *ptr = strdup(*ptr);
1209                         else {
1210                                 free(*ptr);
1211                                 *ptr = NULL;
1212                         }
1213                 }
1214         }
1215 }
1216
1217 /*
1218  * dupe FIO_OPT_STR_STORE options
1219  */
1220 void options_mem_dupe(struct thread_data *td)
1221 {
1222         __options_mem(td, 1);
1223 }
1224
1225 void options_mem_free(struct thread_data fio_unused *td)
1226 {
1227 #if 0
1228         __options_mem(td, 0);
1229 #endif
1230 }