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