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