splice: if splicing fails with EINVAL, it's most likely missing fs support
[fio.git] / options.c
... / ...
CommitLineData
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#include <libgen.h>
9#include <fcntl.h>
10#include <sys/types.h>
11#include <sys/stat.h>
12
13#include "fio.h"
14#include "parse.h"
15#include "lib/fls.h"
16
17#define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var)
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
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;
73 td->o.bssplit = realloc(td->o.bssplit,
74 td->o.bssplit_nr
75 * sizeof(struct bssplit));
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
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
156 td->o.ddir_nr = 1;
157 if (nr)
158 td->o.ddir_nr = atoi(nr);
159
160 return 0;
161}
162
163static int str_mem_cb(void *data, const char *mem)
164{
165 struct thread_data *td = data;
166
167 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
168 td->mmapfile = get_opt_postfix(mem);
169 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
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
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
202#ifdef FIO_HAVE_IOPRIO
203static int str_prioclass_cb(void *data, unsigned int *val)
204{
205 struct thread_data *td = data;
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;
213
214 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
215 td->ioprio_set = 1;
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;
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
231 td->ioprio_set = 1;
232 return 0;
233}
234#endif
235
236static int str_exitall_cb(void)
237{
238 exitall_on_terminate = 1;
239 return 0;
240}
241
242#ifdef FIO_HAVE_CPU_AFFINITY
243static int str_cpumask_cb(void *data, unsigned int *val)
244{
245 struct thread_data *td = data;
246 unsigned int i;
247
248 CPU_ZERO(&td->o.cpumask);
249
250 for (i = 0; i < sizeof(int) * 8; i++)
251 if ((1 << i) & *val)
252 CPU_SET(*val, &td->o.cpumask);
253
254 td->o.cpumask_set = 1;
255 return 0;
256}
257
258static int str_cpus_allowed_cb(void *data, const char *input)
259{
260 struct thread_data *td = data;
261 char *cpu, *str, *p;
262
263 CPU_ZERO(&td->o.cpumask);
264
265 p = str = strdup(input);
266
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);
277 td->o.cpumask_set = 1;
278 return 0;
279}
280#endif
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
294static int check_dir(struct thread_data *td, char *fname)
295{
296 char file[PATH_MAX], *dir;
297 int elen = 0;
298
299 if (td->o.directory) {
300 strcpy(file, td->o.directory);
301 strcat(file, "/");
302 elen = strlen(file);
303 }
304
305 sprintf(file + elen, "%s", fname);
306 dir = dirname(file);
307
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 */
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 }
327 }
328#endif
329
330 return 0;
331}
332
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)
344 td->o.nr_files = 0;
345
346 while ((fname = strsep(&str, ":")) != NULL) {
347 if (!strlen(fname))
348 break;
349 if (check_dir(td, fname)) {
350 free(p);
351 return 1;
352 }
353 add_file(td, fname);
354 td->o.nr_files++;
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
366 if (lstat(td->o.directory, &sb) < 0) {
367 int ret = errno;
368
369 log_err("fio: %s is not a directory\n", td->o.directory);
370 td_verror(td, ret, "lstat");
371 return 1;
372 }
373 if (!S_ISDIR(sb.st_mode)) {
374 log_err("fio: %s is not a directory\n", td->o.directory);
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)
386 td->o.nr_files = 0;
387
388 return add_dir_files(td, td->o.opendir);
389}
390
391static int str_verify_offset_cb(void *data, unsigned int *off)
392{
393 struct thread_data *td = data;
394
395 if (*off && *off < sizeof(struct verify_header)) {
396 log_err("fio: verify_offset too small\n");
397 return 1;
398 }
399
400 td->o.verify_offset = *off;
401 return 0;
402}
403
404static int str_verify_pattern_cb(void *data, unsigned int *off)
405{
406 struct thread_data *td = data;
407 unsigned int msb;
408
409 msb = __fls(*off);
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
419 td->o.verify_pattern = *off;
420 return 0;
421}
422
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
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 },
468 {
469 .name = "lockfile",
470 .type = FIO_OPT_STR,
471 .cb = str_lockfile_cb,
472 .off1 = td_var_offset(file_lock_mode),
473 .help = "Lock file when doing IO to it",
474 .parent = "filename",
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 },
491 },
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",
501 .alias = "readwrite",
502 .type = FIO_OPT_STR,
503 .cb = str_rw_cb,
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 },
544 { .ival = "psync",
545 .help = "Use pread/pwrite",
546 },
547 { .ival = "vsync",
548 .help = "Use readv/writev",
549 },
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 },
559#endif
560#ifdef FIO_HAVE_SOLARISAIO
561 { .ival = "solarisaio",
562 .help = "Solaris native asynchronous IO",
563 },
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 },
572 { .ival = "netsplice",
573 .help = "splice/vmsplice to/from the network",
574 },
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 },
595#ifdef FIO_HAVE_GUASI
596 { .ival = "guasi",
597 .help = "GUASI IO engine",
598 },
599#endif
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",
610 .minval = 1,
611 .def = "1",
612 },
613 {
614 .name = "iodepth_batch",
615 .alias = "iodepth_batch_submit",
616 .type = FIO_OPT_INT,
617 .off1 = td_var_offset(iodepth_batch),
618 .help = "Number of IO to submit in one go",
619 .parent = "iodepth",
620 .minval = 1,
621 .def = "1",
622 },
623 {
624 .name = "iodepth_batch_complete",
625 .type = FIO_OPT_INT,
626 .off1 = td_var_offset(iodepth_batch_complete),
627 .help = "Number of IO to retrieve in one go",
628 .parent = "iodepth",
629 .minval = 0,
630 .def = "1",
631 },
632 {
633 .name = "iodepth_low",
634 .type = FIO_OPT_INT,
635 .off1 = td_var_offset(iodepth_low),
636 .help = "Low water mark for queuing depth",
637 .parent = "iodepth",
638 },
639 {
640 .name = "size",
641 .type = FIO_OPT_STR_VAL,
642 .off1 = td_var_offset(size),
643 .minval = 1,
644 .help = "Total size of device or files",
645 },
646 {
647 .name = "fill_device",
648 .type = FIO_OPT_BOOL,
649 .off1 = td_var_offset(fill_device),
650 .help = "Write until an ENOSPC error occurs",
651 .def = "0",
652 },
653 {
654 .name = "filesize",
655 .type = FIO_OPT_STR_VAL,
656 .off1 = td_var_offset(file_size_low),
657 .off2 = td_var_offset(file_size_high),
658 .minval = 1,
659 .help = "Size of individual files",
660 },
661 {
662 .name = "offset",
663 .alias = "fileoffset",
664 .type = FIO_OPT_STR_VAL,
665 .off1 = td_var_offset(start_offset),
666 .help = "Start IO from this offset",
667 .def = "0",
668 },
669 {
670 .name = "bs",
671 .alias = "blocksize",
672 .type = FIO_OPT_STR_VAL_INT,
673 .off1 = td_var_offset(bs[DDIR_READ]),
674 .off2 = td_var_offset(bs[DDIR_WRITE]),
675 .minval = 1,
676 .help = "Block size unit",
677 .def = "4k",
678 .parent = "rw",
679 },
680 {
681 .name = "bsrange",
682 .alias = "blocksize_range",
683 .type = FIO_OPT_RANGE,
684 .off1 = td_var_offset(min_bs[DDIR_READ]),
685 .off2 = td_var_offset(max_bs[DDIR_READ]),
686 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
687 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
688 .minval = 1,
689 .help = "Set block size range (in more detail than bs)",
690 .parent = "rw",
691 },
692 {
693 .name = "bssplit",
694 .type = FIO_OPT_STR,
695 .cb = str_bssplit_cb,
696 .help = "Set a specific mix of block sizes",
697 .parent = "rw",
698 },
699 {
700 .name = "bs_unaligned",
701 .alias = "blocksize_unaligned",
702 .type = FIO_OPT_STR_SET,
703 .off1 = td_var_offset(bs_unaligned),
704 .help = "Don't sector align IO buffer sizes",
705 .parent = "rw",
706 },
707 {
708 .name = "randrepeat",
709 .type = FIO_OPT_BOOL,
710 .off1 = td_var_offset(rand_repeatable),
711 .help = "Use repeatable random IO pattern",
712 .def = "1",
713 .parent = "rw",
714 },
715 {
716 .name = "norandommap",
717 .type = FIO_OPT_STR_SET,
718 .off1 = td_var_offset(norandommap),
719 .help = "Accept potential duplicate random blocks",
720 .parent = "rw",
721 },
722 {
723 .name = "softrandommap",
724 .type = FIO_OPT_BOOL,
725 .off1 = td_var_offset(softrandommap),
726 .help = "Set norandommap if randommap allocation fails",
727 .parent = "norandommap",
728 .def = "0",
729 },
730 {
731 .name = "nrfiles",
732 .type = FIO_OPT_INT,
733 .off1 = td_var_offset(nr_files),
734 .help = "Split job workload between this number of files",
735 .def = "1",
736 },
737 {
738 .name = "openfiles",
739 .type = FIO_OPT_INT,
740 .off1 = td_var_offset(open_files),
741 .help = "Number of files to keep open at the same time",
742 },
743 {
744 .name = "file_service_type",
745 .type = FIO_OPT_STR,
746 .cb = str_fst_cb,
747 .off1 = td_var_offset(file_service_type),
748 .help = "How to select which file to service next",
749 .def = "roundrobin",
750 .posval = {
751 { .ival = "random",
752 .oval = FIO_FSERVICE_RANDOM,
753 .help = "Choose a file at random",
754 },
755 { .ival = "roundrobin",
756 .oval = FIO_FSERVICE_RR,
757 .help = "Round robin select files",
758 },
759 },
760 .parent = "nrfiles",
761 },
762 {
763 .name = "fadvise_hint",
764 .type = FIO_OPT_BOOL,
765 .off1 = td_var_offset(fadvise_hint),
766 .help = "Use fadvise() to advise the kernel on IO pattern",
767 .def = "1",
768 },
769 {
770 .name = "fsync",
771 .type = FIO_OPT_INT,
772 .off1 = td_var_offset(fsync_blocks),
773 .help = "Issue fsync for writes every given number of blocks",
774 .def = "0",
775 },
776 {
777 .name = "direct",
778 .type = FIO_OPT_BOOL,
779 .off1 = td_var_offset(odirect),
780 .help = "Use O_DIRECT IO (negates buffered)",
781 .def = "0",
782 },
783 {
784 .name = "buffered",
785 .type = FIO_OPT_BOOL,
786 .off1 = td_var_offset(odirect),
787 .neg = 1,
788 .help = "Use buffered IO (negates direct)",
789 .def = "1",
790 },
791 {
792 .name = "overwrite",
793 .type = FIO_OPT_BOOL,
794 .off1 = td_var_offset(overwrite),
795 .help = "When writing, set whether to overwrite current data",
796 .def = "0",
797 },
798 {
799 .name = "loops",
800 .type = FIO_OPT_INT,
801 .off1 = td_var_offset(loops),
802 .help = "Number of times to run the job",
803 .def = "1",
804 },
805 {
806 .name = "numjobs",
807 .type = FIO_OPT_INT,
808 .off1 = td_var_offset(numjobs),
809 .help = "Duplicate this job this many times",
810 .def = "1",
811 },
812 {
813 .name = "startdelay",
814 .type = FIO_OPT_INT,
815 .off1 = td_var_offset(start_delay),
816 .help = "Only start job when this period has passed",
817 .def = "0",
818 },
819 {
820 .name = "runtime",
821 .alias = "timeout",
822 .type = FIO_OPT_STR_VAL_TIME,
823 .off1 = td_var_offset(timeout),
824 .help = "Stop workload when this amount of time has passed",
825 .def = "0",
826 },
827 {
828 .name = "time_based",
829 .type = FIO_OPT_STR_SET,
830 .off1 = td_var_offset(time_based),
831 .help = "Keep running until runtime/timeout is met",
832 },
833 {
834 .name = "mem",
835 .alias = "iomem",
836 .type = FIO_OPT_STR,
837 .cb = str_mem_cb,
838 .off1 = td_var_offset(mem_type),
839 .help = "Backing type for IO buffers",
840 .def = "malloc",
841 .posval = {
842 { .ival = "malloc",
843 .oval = MEM_MALLOC,
844 .help = "Use malloc(3) for IO buffers",
845 },
846 { .ival = "shm",
847 .oval = MEM_SHM,
848 .help = "Use shared memory segments for IO buffers",
849 },
850#ifdef FIO_HAVE_HUGETLB
851 { .ival = "shmhuge",
852 .oval = MEM_SHMHUGE,
853 .help = "Like shm, but use huge pages",
854 },
855#endif
856 { .ival = "mmap",
857 .oval = MEM_MMAP,
858 .help = "Use mmap(2) (file or anon) for IO buffers",
859 },
860#ifdef FIO_HAVE_HUGETLB
861 { .ival = "mmaphuge",
862 .oval = MEM_MMAPHUGE,
863 .help = "Like mmap, but use huge pages",
864 },
865#endif
866 },
867 },
868 {
869 .name = "verify",
870 .type = FIO_OPT_STR,
871 .off1 = td_var_offset(verify),
872 .help = "Verify data written",
873 .def = "0",
874 .posval = {
875 { .ival = "0",
876 .oval = VERIFY_NONE,
877 .help = "Don't do IO verification",
878 },
879 { .ival = "md5",
880 .oval = VERIFY_MD5,
881 .help = "Use md5 checksums for verification",
882 },
883 { .ival = "crc64",
884 .oval = VERIFY_CRC64,
885 .help = "Use crc64 checksums for verification",
886 },
887 { .ival = "crc32",
888 .oval = VERIFY_CRC32,
889 .help = "Use crc32 checksums for verification",
890 },
891 { .ival = "crc16",
892 .oval = VERIFY_CRC16,
893 .help = "Use crc16 checksums for verification",
894 },
895 { .ival = "crc7",
896 .oval = VERIFY_CRC7,
897 .help = "Use crc7 checksums for verification",
898 },
899 { .ival = "sha256",
900 .oval = VERIFY_SHA256,
901 .help = "Use sha256 checksums for verification",
902 },
903 { .ival = "sha512",
904 .oval = VERIFY_SHA512,
905 .help = "Use sha512 checksums for verification",
906 },
907 { .ival = "meta",
908 .oval = VERIFY_META,
909 .help = "Use io information",
910 },
911 {
912 .ival = "null",
913 .oval = VERIFY_NULL,
914 .help = "Pretend to verify",
915 },
916 },
917 },
918 {
919 .name = "do_verify",
920 .type = FIO_OPT_BOOL,
921 .off1 = td_var_offset(do_verify),
922 .help = "Run verification stage after write",
923 .def = "1",
924 .parent = "verify",
925 },
926 {
927 .name = "verifysort",
928 .type = FIO_OPT_BOOL,
929 .off1 = td_var_offset(verifysort),
930 .help = "Sort written verify blocks for read back",
931 .def = "1",
932 .parent = "verify",
933 },
934 {
935 .name = "verify_interval",
936 .type = FIO_OPT_STR_VAL_INT,
937 .off1 = td_var_offset(verify_interval),
938 .minval = 2 * sizeof(struct verify_header),
939 .help = "Store verify buffer header every N bytes",
940 .parent = "verify",
941 },
942 {
943 .name = "verify_offset",
944 .type = FIO_OPT_STR_VAL_INT,
945 .help = "Offset verify header location by N bytes",
946 .def = "0",
947 .cb = str_verify_offset_cb,
948 .parent = "verify",
949 },
950 {
951 .name = "verify_pattern",
952 .type = FIO_OPT_INT,
953 .cb = str_verify_pattern_cb,
954 .help = "Fill pattern for IO buffers",
955 .parent = "verify",
956 },
957 {
958 .name = "verify_fatal",
959 .type = FIO_OPT_BOOL,
960 .off1 = td_var_offset(verify_fatal),
961 .def = "0",
962 .help = "Exit on a single verify failure, don't continue",
963 .parent = "verify",
964 },
965 {
966 .name = "write_iolog",
967 .type = FIO_OPT_STR_STORE,
968 .off1 = td_var_offset(write_iolog_file),
969 .help = "Store IO pattern to file",
970 },
971 {
972 .name = "read_iolog",
973 .type = FIO_OPT_STR_STORE,
974 .off1 = td_var_offset(read_iolog_file),
975 .help = "Playback IO pattern from file",
976 },
977 {
978 .name = "exec_prerun",
979 .type = FIO_OPT_STR_STORE,
980 .off1 = td_var_offset(exec_prerun),
981 .help = "Execute this file prior to running job",
982 },
983 {
984 .name = "exec_postrun",
985 .type = FIO_OPT_STR_STORE,
986 .off1 = td_var_offset(exec_postrun),
987 .help = "Execute this file after running job",
988 },
989#ifdef FIO_HAVE_IOSCHED_SWITCH
990 {
991 .name = "ioscheduler",
992 .type = FIO_OPT_STR_STORE,
993 .off1 = td_var_offset(ioscheduler),
994 .help = "Use this IO scheduler on the backing device",
995 },
996#endif
997 {
998 .name = "zonesize",
999 .type = FIO_OPT_STR_VAL,
1000 .off1 = td_var_offset(zone_size),
1001 .help = "Give size of an IO zone",
1002 .def = "0",
1003 },
1004 {
1005 .name = "zoneskip",
1006 .type = FIO_OPT_STR_VAL,
1007 .off1 = td_var_offset(zone_skip),
1008 .help = "Space between IO zones",
1009 .def = "0",
1010 },
1011 {
1012 .name = "lockmem",
1013 .type = FIO_OPT_STR_VAL,
1014 .cb = str_lockmem_cb,
1015 .help = "Lock down this amount of memory",
1016 .def = "0",
1017 },
1018 {
1019 .name = "rwmixread",
1020 .type = FIO_OPT_INT,
1021 .cb = str_rwmix_read_cb,
1022 .maxval = 100,
1023 .help = "Percentage of mixed workload that is reads",
1024 .def = "50",
1025 },
1026 {
1027 .name = "rwmixwrite",
1028 .type = FIO_OPT_INT,
1029 .cb = str_rwmix_write_cb,
1030 .maxval = 100,
1031 .help = "Percentage of mixed workload that is writes",
1032 .def = "50",
1033 },
1034 {
1035 .name = "rwmixcycle",
1036 .type = FIO_OPT_DEPRECATED,
1037 },
1038 {
1039 .name = "nice",
1040 .type = FIO_OPT_INT,
1041 .off1 = td_var_offset(nice),
1042 .help = "Set job CPU nice value",
1043 .minval = -19,
1044 .maxval = 20,
1045 .def = "0",
1046 },
1047#ifdef FIO_HAVE_IOPRIO
1048 {
1049 .name = "prio",
1050 .type = FIO_OPT_INT,
1051 .cb = str_prio_cb,
1052 .help = "Set job IO priority value",
1053 .minval = 0,
1054 .maxval = 7,
1055 },
1056 {
1057 .name = "prioclass",
1058 .type = FIO_OPT_INT,
1059 .cb = str_prioclass_cb,
1060 .help = "Set job IO priority class",
1061 .minval = 0,
1062 .maxval = 3,
1063 },
1064#endif
1065 {
1066 .name = "thinktime",
1067 .type = FIO_OPT_INT,
1068 .off1 = td_var_offset(thinktime),
1069 .help = "Idle time between IO buffers (usec)",
1070 .def = "0",
1071 },
1072 {
1073 .name = "thinktime_spin",
1074 .type = FIO_OPT_INT,
1075 .off1 = td_var_offset(thinktime_spin),
1076 .help = "Start think time by spinning this amount (usec)",
1077 .def = "0",
1078 .parent = "thinktime",
1079 },
1080 {
1081 .name = "thinktime_blocks",
1082 .type = FIO_OPT_INT,
1083 .off1 = td_var_offset(thinktime_blocks),
1084 .help = "IO buffer period between 'thinktime'",
1085 .def = "1",
1086 .parent = "thinktime",
1087 },
1088 {
1089 .name = "rate",
1090 .type = FIO_OPT_INT,
1091 .off1 = td_var_offset(rate),
1092 .help = "Set bandwidth rate",
1093 },
1094 {
1095 .name = "ratemin",
1096 .type = FIO_OPT_INT,
1097 .off1 = td_var_offset(ratemin),
1098 .help = "Job must meet this rate or it will be shutdown",
1099 .parent = "rate",
1100 },
1101 {
1102 .name = "rate_iops",
1103 .type = FIO_OPT_INT,
1104 .off1 = td_var_offset(rate_iops),
1105 .help = "Limit IO used to this number of IO operations/sec",
1106 },
1107 {
1108 .name = "rate_iops_min",
1109 .type = FIO_OPT_INT,
1110 .off1 = td_var_offset(rate_iops_min),
1111 .help = "Job must meet this rate or it will be shutdown",
1112 .parent = "rate_iops",
1113 },
1114 {
1115 .name = "ratecycle",
1116 .type = FIO_OPT_INT,
1117 .off1 = td_var_offset(ratecycle),
1118 .help = "Window average for rate limits (msec)",
1119 .def = "1000",
1120 .parent = "rate",
1121 },
1122 {
1123 .name = "invalidate",
1124 .type = FIO_OPT_BOOL,
1125 .off1 = td_var_offset(invalidate_cache),
1126 .help = "Invalidate buffer/page cache prior to running job",
1127 .def = "1",
1128 },
1129 {
1130 .name = "sync",
1131 .type = FIO_OPT_BOOL,
1132 .off1 = td_var_offset(sync_io),
1133 .help = "Use O_SYNC for buffered writes",
1134 .def = "0",
1135 .parent = "buffered",
1136 },
1137 {
1138 .name = "bwavgtime",
1139 .type = FIO_OPT_INT,
1140 .off1 = td_var_offset(bw_avg_time),
1141 .help = "Time window over which to calculate bandwidth"
1142 " (msec)",
1143 .def = "500",
1144 },
1145 {
1146 .name = "create_serialize",
1147 .type = FIO_OPT_BOOL,
1148 .off1 = td_var_offset(create_serialize),
1149 .help = "Serialize creating of job files",
1150 .def = "1",
1151 },
1152 {
1153 .name = "create_fsync",
1154 .type = FIO_OPT_BOOL,
1155 .off1 = td_var_offset(create_fsync),
1156 .help = "Fsync file after creation",
1157 .def = "1",
1158 },
1159 {
1160 .name = "cpuload",
1161 .type = FIO_OPT_INT,
1162 .off1 = td_var_offset(cpuload),
1163 .help = "Use this percentage of CPU",
1164 },
1165 {
1166 .name = "cpuchunks",
1167 .type = FIO_OPT_INT,
1168 .off1 = td_var_offset(cpucycle),
1169 .help = "Length of the CPU burn cycles (usecs)",
1170 .def = "50000",
1171 .parent = "cpuload",
1172 },
1173#ifdef FIO_HAVE_CPU_AFFINITY
1174 {
1175 .name = "cpumask",
1176 .type = FIO_OPT_INT,
1177 .cb = str_cpumask_cb,
1178 .help = "CPU affinity mask",
1179 },
1180 {
1181 .name = "cpus_allowed",
1182 .type = FIO_OPT_STR,
1183 .cb = str_cpus_allowed_cb,
1184 .help = "Set CPUs allowed",
1185 },
1186#endif
1187 {
1188 .name = "end_fsync",
1189 .type = FIO_OPT_BOOL,
1190 .off1 = td_var_offset(end_fsync),
1191 .help = "Include fsync at the end of job",
1192 .def = "0",
1193 },
1194 {
1195 .name = "fsync_on_close",
1196 .type = FIO_OPT_BOOL,
1197 .off1 = td_var_offset(fsync_on_close),
1198 .help = "fsync files on close",
1199 .def = "0",
1200 },
1201 {
1202 .name = "unlink",
1203 .type = FIO_OPT_BOOL,
1204 .off1 = td_var_offset(unlink),
1205 .help = "Unlink created files after job has completed",
1206 .def = "0",
1207 },
1208 {
1209 .name = "exitall",
1210 .type = FIO_OPT_STR_SET,
1211 .cb = str_exitall_cb,
1212 .help = "Terminate all jobs when one exits",
1213 },
1214 {
1215 .name = "stonewall",
1216 .type = FIO_OPT_STR_SET,
1217 .off1 = td_var_offset(stonewall),
1218 .help = "Insert a hard barrier between this job and previous",
1219 },
1220 {
1221 .name = "new_group",
1222 .type = FIO_OPT_STR_SET,
1223 .off1 = td_var_offset(new_group),
1224 .help = "Mark the start of a new group (for reporting)",
1225 },
1226 {
1227 .name = "thread",
1228 .type = FIO_OPT_STR_SET,
1229 .off1 = td_var_offset(use_thread),
1230 .help = "Use threads instead of forks",
1231 },
1232 {
1233 .name = "write_bw_log",
1234 .type = FIO_OPT_STR_SET,
1235 .off1 = td_var_offset(write_bw_log),
1236 .help = "Write log of bandwidth during run",
1237 },
1238 {
1239 .name = "write_lat_log",
1240 .type = FIO_OPT_STR_SET,
1241 .off1 = td_var_offset(write_lat_log),
1242 .help = "Write log of latency during run",
1243 },
1244 {
1245 .name = "hugepage-size",
1246 .type = FIO_OPT_STR_VAL_INT,
1247 .off1 = td_var_offset(hugepage_size),
1248 .help = "When using hugepages, specify size of each page",
1249 .def = __stringify(FIO_HUGE_PAGE),
1250 },
1251 {
1252 .name = "group_reporting",
1253 .type = FIO_OPT_STR_SET,
1254 .off1 = td_var_offset(group_reporting),
1255 .help = "Do reporting on a per-group basis",
1256 },
1257 {
1258 .name = "zero_buffers",
1259 .type = FIO_OPT_STR_SET,
1260 .off1 = td_var_offset(zero_buffers),
1261 .help = "Init IO buffers to all zeroes",
1262 },
1263 {
1264 .name = "refill_buffers",
1265 .type = FIO_OPT_STR_SET,
1266 .off1 = td_var_offset(refill_buffers),
1267 .help = "Refill IO buffers on every IO submit",
1268 },
1269#ifdef FIO_HAVE_DISK_UTIL
1270 {
1271 .name = "disk_util",
1272 .type = FIO_OPT_BOOL,
1273 .off1 = td_var_offset(do_disk_util),
1274 .help = "Log disk utilization statistics",
1275 .def = "1",
1276 },
1277#endif
1278 {
1279 .name = NULL,
1280 },
1281};
1282
1283void fio_options_dup_and_init(struct option *long_options)
1284{
1285 struct fio_option *o;
1286 unsigned int i;
1287
1288 options_init(options);
1289
1290 i = 0;
1291 while (long_options[i].name)
1292 i++;
1293
1294 o = &options[0];
1295 while (o->name) {
1296 long_options[i].name = (char *) o->name;
1297 long_options[i].val = FIO_GETOPT_JOB;
1298 if (o->type == FIO_OPT_STR_SET)
1299 long_options[i].has_arg = no_argument;
1300 else
1301 long_options[i].has_arg = required_argument;
1302
1303 i++;
1304 o++;
1305 assert(i < FIO_NR_OPTIONS);
1306 }
1307}
1308
1309int fio_option_parse(struct thread_data *td, const char *opt)
1310{
1311 return parse_option(opt, options, td);
1312}
1313
1314int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1315{
1316 return parse_cmd_option(opt, val, options, td);
1317}
1318
1319void fio_fill_default_options(struct thread_data *td)
1320{
1321 fill_default_options(td, options);
1322}
1323
1324int fio_show_option_help(const char *opt)
1325{
1326 return show_cmd_help(options, opt);
1327}
1328
1329static void __options_mem(struct thread_data *td, int alloc)
1330{
1331 struct thread_options *o = &td->o;
1332 struct fio_option *opt;
1333 char **ptr;
1334 int i;
1335
1336 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1337 if (opt->type != FIO_OPT_STR_STORE)
1338 continue;
1339
1340 ptr = (void *) o + opt->off1;
1341 if (*ptr) {
1342 if (alloc)
1343 *ptr = strdup(*ptr);
1344 else {
1345 free(*ptr);
1346 *ptr = NULL;
1347 }
1348 }
1349 }
1350}
1351
1352/*
1353 * dupe FIO_OPT_STR_STORE options
1354 */
1355void options_mem_dupe(struct thread_data *td)
1356{
1357 __options_mem(td, 1);
1358}
1359
1360void options_mem_free(struct thread_data fio_unused *td)
1361{
1362#if 0
1363 __options_mem(td, 0);
1364#endif
1365}