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