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