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