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