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