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