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