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