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