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