Allow options to specify intervals
[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 <assert.h>
7#include <libgen.h>
8#include <fcntl.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11
12#include "fio.h"
13#include "verify.h"
14#include "parse.h"
15#include "lib/fls.h"
16#include "options.h"
17
18#include "crc/crc32c.h"
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 converthexchartoint(char a)
37{
38 int base;
39
40 switch(a) {
41 case '0'...'9':
42 base = '0';
43 break;
44 case 'A'...'F':
45 base = 'A' - 10;
46 break;
47 case 'a'...'f':
48 base = 'a' - 10;
49 break;
50 default:
51 base = 0;
52 }
53 return (a - base);
54}
55
56static int bs_cmp(const void *p1, const void *p2)
57{
58 const struct bssplit *bsp1 = p1;
59 const struct bssplit *bsp2 = p2;
60
61 return bsp1->perc < bsp2->perc;
62}
63
64static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
65{
66 struct bssplit *bssplit;
67 unsigned int i, perc, perc_missing;
68 unsigned int max_bs, min_bs;
69 long long val;
70 char *fname;
71
72 td->o.bssplit_nr[ddir] = 4;
73 bssplit = malloc(4 * sizeof(struct bssplit));
74
75 i = 0;
76 max_bs = 0;
77 min_bs = -1;
78 while ((fname = strsep(&str, ":")) != NULL) {
79 char *perc_str;
80
81 if (!strlen(fname))
82 break;
83
84 /*
85 * grow struct buffer, if needed
86 */
87 if (i == td->o.bssplit_nr[ddir]) {
88 td->o.bssplit_nr[ddir] <<= 1;
89 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
90 * sizeof(struct bssplit));
91 }
92
93 perc_str = strstr(fname, "/");
94 if (perc_str) {
95 *perc_str = '\0';
96 perc_str++;
97 perc = atoi(perc_str);
98 if (perc > 100)
99 perc = 100;
100 else if (!perc)
101 perc = -1;
102 } else
103 perc = -1;
104
105 if (str_to_decimal(fname, &val, 1, td)) {
106 log_err("fio: bssplit conversion failed\n");
107 free(td->o.bssplit);
108 return 1;
109 }
110
111 if (val > max_bs)
112 max_bs = val;
113 if (val < min_bs)
114 min_bs = val;
115
116 bssplit[i].bs = val;
117 bssplit[i].perc = perc;
118 i++;
119 }
120
121 td->o.bssplit_nr[ddir] = i;
122
123 /*
124 * Now check if the percentages add up, and how much is missing
125 */
126 perc = perc_missing = 0;
127 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
128 struct bssplit *bsp = &bssplit[i];
129
130 if (bsp->perc == (unsigned char) -1)
131 perc_missing++;
132 else
133 perc += bsp->perc;
134 }
135
136 if (perc > 100) {
137 log_err("fio: bssplit percentages add to more than 100%%\n");
138 free(bssplit);
139 return 1;
140 }
141 /*
142 * If values didn't have a percentage set, divide the remains between
143 * them.
144 */
145 if (perc_missing) {
146 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
147 struct bssplit *bsp = &bssplit[i];
148
149 if (bsp->perc == (unsigned char) -1)
150 bsp->perc = (100 - perc) / perc_missing;
151 }
152 }
153
154 td->o.min_bs[ddir] = min_bs;
155 td->o.max_bs[ddir] = max_bs;
156
157 /*
158 * now sort based on percentages, for ease of lookup
159 */
160 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161 td->o.bssplit[ddir] = bssplit;
162 return 0;
163}
164
165static int str_bssplit_cb(void *data, const char *input)
166{
167 struct thread_data *td = data;
168 char *str, *p, *odir;
169 int ret = 0;
170
171 p = str = strdup(input);
172
173 strip_blank_front(&str);
174 strip_blank_end(str);
175
176 odir = strchr(str, ',');
177 if (odir) {
178 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
179 if (!ret) {
180 *odir = '\0';
181 ret = bssplit_ddir(td, DDIR_READ, str);
182 }
183 } else {
184 char *op;
185
186 op = strdup(str);
187
188 ret = bssplit_ddir(td, DDIR_READ, str);
189 if (!ret)
190 ret = bssplit_ddir(td, DDIR_WRITE, op);
191
192 free(op);
193 }
194
195 free(p);
196 return ret;
197}
198
199static int str_rw_cb(void *data, const char *str)
200{
201 struct thread_data *td = data;
202 char *nr = get_opt_postfix(str);
203
204 td->o.ddir_seq_nr = 1;
205 td->o.ddir_seq_add = 0;
206
207 if (!nr)
208 return 0;
209
210 if (td_random(td))
211 td->o.ddir_seq_nr = atoi(nr);
212 else {
213 long long val;
214
215 if (str_to_decimal(nr, &val, 1, td)) {
216 log_err("fio: rw postfix parsing failed\n");
217 free(nr);
218 return 1;
219 }
220
221 td->o.ddir_seq_add = val;
222 }
223
224 free(nr);
225 return 0;
226}
227
228static int str_mem_cb(void *data, const char *mem)
229{
230 struct thread_data *td = data;
231
232 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
233 td->mmapfile = get_opt_postfix(mem);
234 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
235 log_err("fio: mmaphuge:/path/to/file\n");
236 return 1;
237 }
238 }
239
240 return 0;
241}
242
243static int str_verify_cb(void *data, const char *mem)
244{
245 struct thread_data *td = data;
246
247 if (td->o.verify == VERIFY_CRC32C_INTEL ||
248 td->o.verify == VERIFY_CRC32C) {
249 crc32c_intel_probe();
250 }
251
252 return 0;
253}
254
255static int fio_clock_source_cb(void *data, const char *str)
256{
257 struct thread_data *td = data;
258
259 fio_clock_source = td->o.clocksource;
260 fio_time_init();
261 return 0;
262}
263
264static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
265{
266 mlock_size = *val;
267 return 0;
268}
269
270static int str_rwmix_read_cb(void *data, unsigned long long *val)
271{
272 struct thread_data *td = data;
273
274 td->o.rwmix[DDIR_READ] = *val;
275 td->o.rwmix[DDIR_WRITE] = 100 - *val;
276 return 0;
277}
278
279static int str_rwmix_write_cb(void *data, unsigned long long *val)
280{
281 struct thread_data *td = data;
282
283 td->o.rwmix[DDIR_WRITE] = *val;
284 td->o.rwmix[DDIR_READ] = 100 - *val;
285 return 0;
286}
287
288#ifdef FIO_HAVE_IOPRIO
289static int str_prioclass_cb(void *data, unsigned long long *val)
290{
291 struct thread_data *td = data;
292 unsigned short mask;
293
294 /*
295 * mask off old class bits, str_prio_cb() may have set a default class
296 */
297 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
298 td->ioprio &= mask;
299
300 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
301 td->ioprio_set = 1;
302 return 0;
303}
304
305static int str_prio_cb(void *data, unsigned long long *val)
306{
307 struct thread_data *td = data;
308
309 td->ioprio |= *val;
310
311 /*
312 * If no class is set, assume BE
313 */
314 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
315 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
316
317 td->ioprio_set = 1;
318 return 0;
319}
320#endif
321
322static int str_exitall_cb(void)
323{
324 exitall_on_terminate = 1;
325 return 0;
326}
327
328#ifdef FIO_HAVE_CPU_AFFINITY
329static int str_cpumask_cb(void *data, unsigned long long *val)
330{
331 struct thread_data *td = data;
332 unsigned int i;
333 long max_cpu;
334 int ret;
335
336 ret = fio_cpuset_init(&td->o.cpumask);
337 if (ret < 0) {
338 log_err("fio: cpuset_init failed\n");
339 td_verror(td, ret, "fio_cpuset_init");
340 return 1;
341 }
342
343 max_cpu = cpus_online();
344
345 for (i = 0; i < sizeof(int) * 8; i++) {
346 if ((1 << i) & *val) {
347 if (i > max_cpu) {
348 log_err("fio: CPU %d too large (max=%ld)\n", i,
349 max_cpu);
350 return 1;
351 }
352 dprint(FD_PARSE, "set cpu allowed %d\n", i);
353 fio_cpu_set(&td->o.cpumask, i);
354 }
355 }
356
357 td->o.cpumask_set = 1;
358 return 0;
359}
360
361static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
362 const char *input)
363{
364 char *cpu, *str, *p;
365 long max_cpu;
366 int ret = 0;
367
368 ret = fio_cpuset_init(mask);
369 if (ret < 0) {
370 log_err("fio: cpuset_init failed\n");
371 td_verror(td, ret, "fio_cpuset_init");
372 return 1;
373 }
374
375 p = str = strdup(input);
376
377 strip_blank_front(&str);
378 strip_blank_end(str);
379
380 max_cpu = cpus_online();
381
382 while ((cpu = strsep(&str, ",")) != NULL) {
383 char *str2, *cpu2;
384 int icpu, icpu2;
385
386 if (!strlen(cpu))
387 break;
388
389 str2 = cpu;
390 icpu2 = -1;
391 while ((cpu2 = strsep(&str2, "-")) != NULL) {
392 if (!strlen(cpu2))
393 break;
394
395 icpu2 = atoi(cpu2);
396 }
397
398 icpu = atoi(cpu);
399 if (icpu2 == -1)
400 icpu2 = icpu;
401 while (icpu <= icpu2) {
402 if (icpu >= FIO_MAX_CPUS) {
403 log_err("fio: your OS only supports up to"
404 " %d CPUs\n", (int) FIO_MAX_CPUS);
405 ret = 1;
406 break;
407 }
408 if (icpu > max_cpu) {
409 log_err("fio: CPU %d too large (max=%ld)\n",
410 icpu, max_cpu);
411 ret = 1;
412 break;
413 }
414
415 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
416 fio_cpu_set(mask, icpu);
417 icpu++;
418 }
419 if (ret)
420 break;
421 }
422
423 free(p);
424 if (!ret)
425 td->o.cpumask_set = 1;
426 return ret;
427}
428
429static int str_cpus_allowed_cb(void *data, const char *input)
430{
431 struct thread_data *td = data;
432 int ret;
433
434 ret = set_cpus_allowed(td, &td->o.cpumask, input);
435 if (!ret)
436 td->o.cpumask_set = 1;
437
438 return ret;
439}
440
441static int str_verify_cpus_allowed_cb(void *data, const char *input)
442{
443 struct thread_data *td = data;
444 int ret;
445
446 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
447 if (!ret)
448 td->o.verify_cpumask_set = 1;
449
450 return ret;
451}
452#endif
453
454#ifdef FIO_HAVE_TRIM
455static int str_verify_trim_cb(void *data, unsigned long long *val)
456{
457 struct thread_data *td = data;
458
459 td->o.trim_percentage = *val;
460 return 0;
461}
462#endif
463
464static int str_fst_cb(void *data, const char *str)
465{
466 struct thread_data *td = data;
467 char *nr = get_opt_postfix(str);
468
469 td->file_service_nr = 1;
470 if (nr) {
471 td->file_service_nr = atoi(nr);
472 free(nr);
473 }
474
475 return 0;
476}
477
478#ifdef FIO_HAVE_SYNC_FILE_RANGE
479static int str_sfr_cb(void *data, const char *str)
480{
481 struct thread_data *td = data;
482 char *nr = get_opt_postfix(str);
483
484 td->sync_file_range_nr = 1;
485 if (nr) {
486 td->sync_file_range_nr = atoi(nr);
487 free(nr);
488 }
489
490 return 0;
491}
492#endif
493
494static int check_dir(struct thread_data *td, char *fname)
495{
496#if 0
497 char file[PATH_MAX], *dir;
498 int elen = 0;
499
500 if (td->o.directory) {
501 strcpy(file, td->o.directory);
502 strcat(file, "/");
503 elen = strlen(file);
504 }
505
506 sprintf(file + elen, "%s", fname);
507 dir = dirname(file);
508
509 {
510 struct stat sb;
511 /*
512 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
513 * yet, so we can't do this check right here...
514 */
515 if (lstat(dir, &sb) < 0) {
516 int ret = errno;
517
518 log_err("fio: %s is not a directory\n", dir);
519 td_verror(td, ret, "lstat");
520 return 1;
521 }
522
523 if (!S_ISDIR(sb.st_mode)) {
524 log_err("fio: %s is not a directory\n", dir);
525 return 1;
526 }
527 }
528#endif
529
530 return 0;
531}
532
533/*
534 * Return next file in the string. Files are separated with ':'. If the ':'
535 * is escaped with a '\', then that ':' is part of the filename and does not
536 * indicate a new file.
537 */
538static char *get_next_file_name(char **ptr)
539{
540 char *str = *ptr;
541 char *p, *start;
542
543 if (!str || !strlen(str))
544 return NULL;
545
546 start = str;
547 do {
548 /*
549 * No colon, we are done
550 */
551 p = strchr(str, ':');
552 if (!p) {
553 *ptr = NULL;
554 break;
555 }
556
557 /*
558 * We got a colon, but it's the first character. Skip and
559 * continue
560 */
561 if (p == start) {
562 str = ++start;
563 continue;
564 }
565
566 if (*(p - 1) != '\\') {
567 *p = '\0';
568 *ptr = p + 1;
569 break;
570 }
571
572 memmove(p - 1, p, strlen(p) + 1);
573 str = p;
574 } while (1);
575
576 return start;
577}
578
579static int str_filename_cb(void *data, const char *input)
580{
581 struct thread_data *td = data;
582 char *fname, *str, *p;
583
584 p = str = strdup(input);
585
586 strip_blank_front(&str);
587 strip_blank_end(str);
588
589 if (!td->files_index)
590 td->o.nr_files = 0;
591
592 while ((fname = get_next_file_name(&str)) != NULL) {
593 if (!strlen(fname))
594 break;
595 if (check_dir(td, fname)) {
596 free(p);
597 return 1;
598 }
599 add_file(td, fname);
600 td->o.nr_files++;
601 }
602
603 free(p);
604 return 0;
605}
606
607static int str_directory_cb(void *data, const char fio_unused *str)
608{
609 struct thread_data *td = data;
610 struct stat sb;
611
612 if (lstat(td->o.directory, &sb) < 0) {
613 int ret = errno;
614
615 log_err("fio: %s is not a directory\n", td->o.directory);
616 td_verror(td, ret, "lstat");
617 return 1;
618 }
619 if (!S_ISDIR(sb.st_mode)) {
620 log_err("fio: %s is not a directory\n", td->o.directory);
621 return 1;
622 }
623
624 return 0;
625}
626
627static int str_opendir_cb(void *data, const char fio_unused *str)
628{
629 struct thread_data *td = data;
630
631 if (!td->files_index)
632 td->o.nr_files = 0;
633
634 return add_dir_files(td, td->o.opendir);
635}
636
637static int str_verify_offset_cb(void *data, unsigned long long *off)
638{
639 struct thread_data *td = data;
640
641 if (*off && *off < sizeof(struct verify_header)) {
642 log_err("fio: verify_offset too small\n");
643 return 1;
644 }
645
646 td->o.verify_offset = *off;
647 return 0;
648}
649
650static int str_verify_pattern_cb(void *data, const char *input)
651{
652 struct thread_data *td = data;
653 long off;
654 int i = 0, j = 0, len, k, base = 10;
655 char* loc1, * loc2;
656
657 loc1 = strstr(input, "0x");
658 loc2 = strstr(input, "0X");
659 if (loc1 || loc2)
660 base = 16;
661 off = strtol(input, NULL, base);
662 if (off != LONG_MAX || errno != ERANGE) {
663 while (off) {
664 td->o.verify_pattern[i] = off & 0xff;
665 off >>= 8;
666 i++;
667 }
668 } else {
669 len = strlen(input);
670 k = len - 1;
671 if (base == 16) {
672 if (loc1)
673 j = loc1 - input + 2;
674 else
675 j = loc2 - input + 2;
676 } else
677 return 1;
678 if (len - j < MAX_PATTERN_SIZE * 2) {
679 while (k >= j) {
680 off = converthexchartoint(input[k--]);
681 if (k >= j)
682 off += (converthexchartoint(input[k--])
683 * 16);
684 td->o.verify_pattern[i++] = (char) off;
685 }
686 }
687 }
688
689 /*
690 * Fill the pattern all the way to the end. This greatly reduces
691 * the number of memcpy's we have to do when verifying the IO.
692 */
693 while (i > 1 && i * 2 <= MAX_PATTERN_SIZE) {
694 memcpy(&td->o.verify_pattern[i], &td->o.verify_pattern[0], i);
695 i *= 2;
696 }
697 if (i == 1) {
698 /*
699 * The code in verify_io_u_pattern assumes a single byte pattern
700 * fills the whole verify pattern buffer.
701 */
702 memset(td->o.verify_pattern, td->o.verify_pattern[0],
703 MAX_PATTERN_SIZE);
704 }
705
706 td->o.verify_pattern_bytes = i;
707
708 /*
709 * VERIFY_META could already be set
710 */
711 if (td->o.verify == VERIFY_NONE)
712 td->o.verify = VERIFY_PATTERN;
713
714 return 0;
715}
716
717static int str_lockfile_cb(void *data, const char *str)
718{
719 struct thread_data *td = data;
720 char *nr = get_opt_postfix(str);
721
722 td->o.lockfile_batch = 1;
723 if (nr) {
724 td->o.lockfile_batch = atoi(nr);
725 free(nr);
726 }
727
728 return 0;
729}
730
731static int str_write_bw_log_cb(void *data, const char *str)
732{
733 struct thread_data *td = data;
734
735 if (str)
736 td->o.bw_log_file = strdup(str);
737
738 td->o.write_bw_log = 1;
739 return 0;
740}
741
742static int str_write_lat_log_cb(void *data, const char *str)
743{
744 struct thread_data *td = data;
745
746 if (str)
747 td->o.lat_log_file = strdup(str);
748
749 td->o.write_lat_log = 1;
750 return 0;
751}
752
753static int str_write_iops_log_cb(void *data, const char *str)
754{
755 struct thread_data *td = data;
756
757 if (str)
758 td->o.iops_log_file = strdup(str);
759
760 td->o.write_iops_log = 1;
761 return 0;
762}
763
764static int str_gtod_reduce_cb(void *data, int *il)
765{
766 struct thread_data *td = data;
767 int val = *il;
768
769 td->o.disable_lat = !!val;
770 td->o.disable_clat = !!val;
771 td->o.disable_slat = !!val;
772 td->o.disable_bw = !!val;
773 td->o.clat_percentiles = !val;
774 if (val)
775 td->tv_cache_mask = 63;
776
777 return 0;
778}
779
780static int str_gtod_cpu_cb(void *data, long long *il)
781{
782 struct thread_data *td = data;
783 int val = *il;
784
785 td->o.gtod_cpu = val;
786 td->o.gtod_offload = 1;
787 return 0;
788}
789
790static int str_size_cb(void *data, unsigned long long *__val)
791{
792 struct thread_data *td = data;
793 unsigned long long v = *__val;
794
795 if (parse_is_percent(v)) {
796 td->o.size = 0;
797 td->o.size_percent = -1ULL - v;
798 } else
799 td->o.size = v;
800
801 return 0;
802}
803
804static int rw_verify(struct fio_option *o, void *data)
805{
806 struct thread_data *td = data;
807
808 if (read_only && td_write(td)) {
809 log_err("fio: job <%s> has write bit set, but fio is in"
810 " read-only mode\n", td->o.name);
811 return 1;
812 }
813
814 return 0;
815}
816
817static int gtod_cpu_verify(struct fio_option *o, void *data)
818{
819#ifndef FIO_HAVE_CPU_AFFINITY
820 struct thread_data *td = data;
821
822 if (td->o.gtod_cpu) {
823 log_err("fio: platform must support CPU affinity for"
824 "gettimeofday() offloading\n");
825 return 1;
826 }
827#endif
828
829 return 0;
830}
831
832static int kb_base_verify(struct fio_option *o, void *data)
833{
834 struct thread_data *td = data;
835
836 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
837 log_err("fio: kb_base set to nonsensical value: %u\n",
838 td->o.kb_base);
839 return 1;
840 }
841
842 return 0;
843}
844
845/*
846 * Option grouping
847 */
848static struct opt_group fio_opt_groups[] = {
849 {
850 .name = "Description",
851 .mask = FIO_OPT_G_DESC,
852 },
853 {
854 .name = "File",
855 .mask = FIO_OPT_G_FILE,
856 },
857 {
858 .name = "Misc",
859 .mask = FIO_OPT_G_MISC,
860 },
861 {
862 .name = "IO (main)",
863 .mask = FIO_OPT_G_IO,
864 },
865 {
866 .name = "IO direction",
867 .mask = FIO_OPT_G_IO_DDIR,
868 },
869 {
870 .name = "IO buffer",
871 .mask = FIO_OPT_G_IO_BUF,
872 },
873 {
874 .name = "IO engine",
875 .mask = FIO_OPT_G_IO_ENG,
876 },
877 {
878 .name = "Random",
879 .mask = FIO_OPT_G_RAND,
880 },
881 {
882 .name = "OS",
883 .mask = FIO_OPT_G_OS,
884 },
885 {
886 .name = "Memory",
887 .mask = FIO_OPT_G_MEM,
888 },
889 {
890 .name = "Verify",
891 .mask = FIO_OPT_G_VERIFY,
892 },
893 {
894 .name = "CPU",
895 .mask = FIO_OPT_G_CPU,
896 },
897 {
898 .name = "Log",
899 .mask = FIO_OPT_G_LOG,
900 },
901 {
902 .name = "Zone",
903 .mask = FIO_OPT_G_ZONE,
904 },
905 {
906 .name = "Cache",
907 .mask = FIO_OPT_G_CACHE,
908 },
909 {
910 .name = "Stat",
911 .mask = FIO_OPT_G_STAT,
912 },
913 {
914 .name = "Error",
915 .mask = FIO_OPT_G_ERR,
916 },
917 {
918 .name = "Job",
919 .mask = FIO_OPT_G_JOB,
920 },
921 {
922 .name = NULL,
923 },
924};
925
926struct opt_group *opt_group_from_mask(unsigned int *mask)
927{
928 struct opt_group *og;
929 int i;
930
931 if (*mask == FIO_OPT_G_INVALID)
932 return NULL;
933
934 for (i = 0; fio_opt_groups[i].name; i++) {
935 og = &fio_opt_groups[i];
936
937 if (*mask & og->mask) {
938 *mask &= ~(og->mask);
939 return og;
940 }
941 }
942
943 return NULL;
944}
945
946/*
947 * Map of job/command line options
948 */
949struct fio_option fio_options[FIO_MAX_OPTS] = {
950 {
951 .name = "description",
952 .type = FIO_OPT_STR_STORE,
953 .off1 = td_var_offset(description),
954 .help = "Text job description",
955 .category = FIO_OPT_G_DESC,
956 },
957 {
958 .name = "name",
959 .type = FIO_OPT_STR_STORE,
960 .off1 = td_var_offset(name),
961 .help = "Name of this job",
962 .category = FIO_OPT_G_DESC,
963 },
964 {
965 .name = "directory",
966 .type = FIO_OPT_STR_STORE,
967 .off1 = td_var_offset(directory),
968 .cb = str_directory_cb,
969 .help = "Directory to store files in",
970 .category = FIO_OPT_G_FILE,
971 },
972 {
973 .name = "filename",
974 .type = FIO_OPT_STR_STORE,
975 .off1 = td_var_offset(filename),
976 .cb = str_filename_cb,
977 .prio = -1, /* must come after "directory" */
978 .help = "File(s) to use for the workload",
979 .category = FIO_OPT_G_FILE,
980 },
981 {
982 .name = "kb_base",
983 .type = FIO_OPT_INT,
984 .off1 = td_var_offset(kb_base),
985 .verify = kb_base_verify,
986 .prio = 1,
987 .def = "1024",
988 .help = "How many bytes per KB for reporting (1000 or 1024)",
989 .category = FIO_OPT_G_MISC,
990 },
991 {
992 .name = "lockfile",
993 .type = FIO_OPT_STR,
994 .cb = str_lockfile_cb,
995 .off1 = td_var_offset(file_lock_mode),
996 .help = "Lock file when doing IO to it",
997 .parent = "filename",
998 .def = "none",
999 .category = FIO_OPT_G_FILE,
1000 .posval = {
1001 { .ival = "none",
1002 .oval = FILE_LOCK_NONE,
1003 .help = "No file locking",
1004 },
1005 { .ival = "exclusive",
1006 .oval = FILE_LOCK_EXCLUSIVE,
1007 .help = "Exclusive file lock",
1008 },
1009 {
1010 .ival = "readwrite",
1011 .oval = FILE_LOCK_READWRITE,
1012 .help = "Read vs write lock",
1013 },
1014 },
1015 },
1016 {
1017 .name = "opendir",
1018 .type = FIO_OPT_STR_STORE,
1019 .off1 = td_var_offset(opendir),
1020 .cb = str_opendir_cb,
1021 .help = "Recursively add files from this directory and down",
1022 .category = FIO_OPT_G_FILE,
1023 },
1024 {
1025 .name = "rw",
1026 .alias = "readwrite",
1027 .type = FIO_OPT_STR,
1028 .cb = str_rw_cb,
1029 .off1 = td_var_offset(td_ddir),
1030 .help = "IO direction",
1031 .def = "read",
1032 .verify = rw_verify,
1033 .category = FIO_OPT_G_IO_DDIR,
1034 .posval = {
1035 { .ival = "read",
1036 .oval = TD_DDIR_READ,
1037 .help = "Sequential read",
1038 },
1039 { .ival = "write",
1040 .oval = TD_DDIR_WRITE,
1041 .help = "Sequential write",
1042 },
1043 { .ival = "randread",
1044 .oval = TD_DDIR_RANDREAD,
1045 .help = "Random read",
1046 },
1047 { .ival = "randwrite",
1048 .oval = TD_DDIR_RANDWRITE,
1049 .help = "Random write",
1050 },
1051 { .ival = "rw",
1052 .oval = TD_DDIR_RW,
1053 .help = "Sequential read and write mix",
1054 },
1055 { .ival = "randrw",
1056 .oval = TD_DDIR_RANDRW,
1057 .help = "Random read and write mix"
1058 },
1059 },
1060 },
1061 {
1062 .name = "rw_sequencer",
1063 .type = FIO_OPT_STR,
1064 .off1 = td_var_offset(rw_seq),
1065 .help = "IO offset generator modifier",
1066 .def = "sequential",
1067 .category = FIO_OPT_G_IO_DDIR,
1068 .posval = {
1069 { .ival = "sequential",
1070 .oval = RW_SEQ_SEQ,
1071 .help = "Generate sequential offsets",
1072 },
1073 { .ival = "identical",
1074 .oval = RW_SEQ_IDENT,
1075 .help = "Generate identical offsets",
1076 },
1077 },
1078 },
1079
1080 {
1081 .name = "ioengine",
1082 .type = FIO_OPT_STR_STORE,
1083 .off1 = td_var_offset(ioengine),
1084 .help = "IO engine to use",
1085 .def = FIO_PREFERRED_ENGINE,
1086 .category = FIO_OPT_G_IO,
1087 .posval = {
1088 { .ival = "sync",
1089 .help = "Use read/write",
1090 },
1091 { .ival = "psync",
1092 .help = "Use pread/pwrite",
1093 },
1094 { .ival = "vsync",
1095 .help = "Use readv/writev",
1096 },
1097#ifdef FIO_HAVE_LIBAIO
1098 { .ival = "libaio",
1099 .help = "Linux native asynchronous IO",
1100 },
1101#endif
1102#ifdef FIO_HAVE_POSIXAIO
1103 { .ival = "posixaio",
1104 .help = "POSIX asynchronous IO",
1105 },
1106#endif
1107#ifdef FIO_HAVE_SOLARISAIO
1108 { .ival = "solarisaio",
1109 .help = "Solaris native asynchronous IO",
1110 },
1111#endif
1112#ifdef FIO_HAVE_WINDOWSAIO
1113 { .ival = "windowsaio",
1114 .help = "Windows native asynchronous IO"
1115 },
1116#endif
1117 { .ival = "mmap",
1118 .help = "Memory mapped IO"
1119 },
1120#ifdef FIO_HAVE_SPLICE
1121 { .ival = "splice",
1122 .help = "splice/vmsplice based IO",
1123 },
1124 { .ival = "netsplice",
1125 .help = "splice/vmsplice to/from the network",
1126 },
1127#endif
1128#ifdef FIO_HAVE_SGIO
1129 { .ival = "sg",
1130 .help = "SCSI generic v3 IO",
1131 },
1132#endif
1133 { .ival = "null",
1134 .help = "Testing engine (no data transfer)",
1135 },
1136 { .ival = "net",
1137 .help = "Network IO",
1138 },
1139#ifdef FIO_HAVE_SYSLET
1140 { .ival = "syslet-rw",
1141 .help = "syslet enabled async pread/pwrite IO",
1142 },
1143#endif
1144 { .ival = "cpuio",
1145 .help = "CPU cycle burner engine",
1146 },
1147#ifdef FIO_HAVE_GUASI
1148 { .ival = "guasi",
1149 .help = "GUASI IO engine",
1150 },
1151#endif
1152#ifdef FIO_HAVE_BINJECT
1153 { .ival = "binject",
1154 .help = "binject direct inject block engine",
1155 },
1156#endif
1157#ifdef FIO_HAVE_RDMA
1158 { .ival = "rdma",
1159 .help = "RDMA IO engine",
1160 },
1161#endif
1162 { .ival = "external",
1163 .help = "Load external engine (append name)",
1164 },
1165 },
1166 },
1167 {
1168 .name = "iodepth",
1169 .type = FIO_OPT_INT,
1170 .off1 = td_var_offset(iodepth),
1171 .help = "Number of IO buffers to keep in flight",
1172 .minval = 1,
1173 .interval = 1,
1174 .def = "1",
1175 .category = FIO_OPT_G_IO,
1176 },
1177 {
1178 .name = "iodepth_batch",
1179 .alias = "iodepth_batch_submit",
1180 .type = FIO_OPT_INT,
1181 .off1 = td_var_offset(iodepth_batch),
1182 .help = "Number of IO buffers to submit in one go",
1183 .parent = "iodepth",
1184 .minval = 1,
1185 .interval = 1,
1186 .def = "1",
1187 .category = FIO_OPT_G_IO,
1188 },
1189 {
1190 .name = "iodepth_batch_complete",
1191 .type = FIO_OPT_INT,
1192 .off1 = td_var_offset(iodepth_batch_complete),
1193 .help = "Number of IO buffers to retrieve in one go",
1194 .parent = "iodepth",
1195 .minval = 0,
1196 .interval = 1,
1197 .def = "1",
1198 .category = FIO_OPT_G_IO,
1199 },
1200 {
1201 .name = "iodepth_low",
1202 .type = FIO_OPT_INT,
1203 .off1 = td_var_offset(iodepth_low),
1204 .help = "Low water mark for queuing depth",
1205 .parent = "iodepth",
1206 .interval = 1,
1207 .category = FIO_OPT_G_IO,
1208 },
1209 {
1210 .name = "size",
1211 .type = FIO_OPT_STR_VAL,
1212 .cb = str_size_cb,
1213 .help = "Total size of device or files",
1214 .interval = 1024 * 1024,
1215 .category = FIO_OPT_G_IO,
1216 },
1217 {
1218 .name = "fill_device",
1219 .alias = "fill_fs",
1220 .type = FIO_OPT_BOOL,
1221 .off1 = td_var_offset(fill_device),
1222 .help = "Write until an ENOSPC error occurs",
1223 .def = "0",
1224 .category = FIO_OPT_G_IO,
1225 },
1226 {
1227 .name = "filesize",
1228 .type = FIO_OPT_STR_VAL,
1229 .off1 = td_var_offset(file_size_low),
1230 .off2 = td_var_offset(file_size_high),
1231 .minval = 1,
1232 .help = "Size of individual files",
1233 .interval = 1024 * 1024,
1234 .category = FIO_OPT_G_IO | FIO_OPT_G_FILE,
1235 },
1236 {
1237 .name = "offset",
1238 .alias = "fileoffset",
1239 .type = FIO_OPT_STR_VAL,
1240 .off1 = td_var_offset(start_offset),
1241 .help = "Start IO from this offset",
1242 .def = "0",
1243 .interval = 1024 * 1024,
1244 .category = FIO_OPT_G_IO,
1245 },
1246 {
1247 .name = "offset_increment",
1248 .type = FIO_OPT_STR_VAL,
1249 .off1 = td_var_offset(offset_increment),
1250 .help = "What is the increment from one offset to the next",
1251 .parent = "offset",
1252 .def = "0",
1253 .interval = 1024 * 1024,
1254 .category = FIO_OPT_G_IO,
1255 },
1256 {
1257 .name = "bs",
1258 .alias = "blocksize",
1259 .type = FIO_OPT_INT,
1260 .off1 = td_var_offset(bs[DDIR_READ]),
1261 .off2 = td_var_offset(bs[DDIR_WRITE]),
1262 .minval = 1,
1263 .help = "Block size unit",
1264 .def = "4k",
1265 .parent = "rw",
1266 .interval = 512,
1267 .category = FIO_OPT_G_IO,
1268 },
1269 {
1270 .name = "ba",
1271 .alias = "blockalign",
1272 .type = FIO_OPT_INT,
1273 .off1 = td_var_offset(ba[DDIR_READ]),
1274 .off2 = td_var_offset(ba[DDIR_WRITE]),
1275 .minval = 1,
1276 .help = "IO block offset alignment",
1277 .parent = "rw",
1278 .interval = 512,
1279 .category = FIO_OPT_G_IO | FIO_OPT_G_IO_BUF,
1280 },
1281 {
1282 .name = "bsrange",
1283 .alias = "blocksize_range",
1284 .type = FIO_OPT_RANGE,
1285 .off1 = td_var_offset(min_bs[DDIR_READ]),
1286 .off2 = td_var_offset(max_bs[DDIR_READ]),
1287 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1288 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1289 .minval = 1,
1290 .help = "Set block size range (in more detail than bs)",
1291 .parent = "rw",
1292 .interval = 4096,
1293 .category = FIO_OPT_G_IO,
1294 },
1295 {
1296 .name = "bssplit",
1297 .type = FIO_OPT_STR,
1298 .cb = str_bssplit_cb,
1299 .help = "Set a specific mix of block sizes",
1300 .parent = "rw",
1301 .category = FIO_OPT_G_IO,
1302 },
1303 {
1304 .name = "bs_unaligned",
1305 .alias = "blocksize_unaligned",
1306 .type = FIO_OPT_STR_SET,
1307 .off1 = td_var_offset(bs_unaligned),
1308 .help = "Don't sector align IO buffer sizes",
1309 .parent = "rw",
1310 .category = FIO_OPT_G_IO,
1311 },
1312 {
1313 .name = "randrepeat",
1314 .type = FIO_OPT_BOOL,
1315 .off1 = td_var_offset(rand_repeatable),
1316 .help = "Use repeatable random IO pattern",
1317 .def = "1",
1318 .parent = "rw",
1319 .category = FIO_OPT_G_IO | FIO_OPT_G_RAND,
1320 },
1321 {
1322 .name = "use_os_rand",
1323 .type = FIO_OPT_BOOL,
1324 .off1 = td_var_offset(use_os_rand),
1325 .help = "Set to use OS random generator",
1326 .def = "0",
1327 .parent = "rw",
1328 .category = FIO_OPT_G_RAND,
1329 },
1330 {
1331 .name = "norandommap",
1332 .type = FIO_OPT_STR_SET,
1333 .off1 = td_var_offset(norandommap),
1334 .help = "Accept potential duplicate random blocks",
1335 .parent = "rw",
1336 .category = FIO_OPT_G_RAND,
1337 },
1338 {
1339 .name = "softrandommap",
1340 .type = FIO_OPT_BOOL,
1341 .off1 = td_var_offset(softrandommap),
1342 .help = "Set norandommap if randommap allocation fails",
1343 .parent = "norandommap",
1344 .def = "0",
1345 .category = FIO_OPT_G_RAND,
1346 },
1347 {
1348 .name = "nrfiles",
1349 .alias = "nr_files",
1350 .type = FIO_OPT_INT,
1351 .off1 = td_var_offset(nr_files),
1352 .help = "Split job workload between this number of files",
1353 .def = "1",
1354 .interval = 1,
1355 .category = FIO_OPT_G_FILE,
1356 },
1357 {
1358 .name = "openfiles",
1359 .type = FIO_OPT_INT,
1360 .off1 = td_var_offset(open_files),
1361 .help = "Number of files to keep open at the same time",
1362 .category = FIO_OPT_G_FILE,
1363 },
1364 {
1365 .name = "file_service_type",
1366 .type = FIO_OPT_STR,
1367 .cb = str_fst_cb,
1368 .off1 = td_var_offset(file_service_type),
1369 .help = "How to select which file to service next",
1370 .def = "roundrobin",
1371 .category = FIO_OPT_G_FILE,
1372 .posval = {
1373 { .ival = "random",
1374 .oval = FIO_FSERVICE_RANDOM,
1375 .help = "Choose a file at random",
1376 },
1377 { .ival = "roundrobin",
1378 .oval = FIO_FSERVICE_RR,
1379 .help = "Round robin select files",
1380 },
1381 { .ival = "sequential",
1382 .oval = FIO_FSERVICE_SEQ,
1383 .help = "Finish one file before moving to the next",
1384 },
1385 },
1386 .parent = "nrfiles",
1387 },
1388#ifdef FIO_HAVE_FALLOCATE
1389 {
1390 .name = "fallocate",
1391 .type = FIO_OPT_STR,
1392 .off1 = td_var_offset(fallocate_mode),
1393 .help = "Whether pre-allocation is performed when laying out files",
1394 .def = "posix",
1395 .category = FIO_OPT_G_FILE,
1396 .posval = {
1397 { .ival = "none",
1398 .oval = FIO_FALLOCATE_NONE,
1399 .help = "Do not pre-allocate space",
1400 },
1401 { .ival = "posix",
1402 .oval = FIO_FALLOCATE_POSIX,
1403 .help = "Use posix_fallocate()",
1404 },
1405#ifdef FIO_HAVE_LINUX_FALLOCATE
1406 { .ival = "keep",
1407 .oval = FIO_FALLOCATE_KEEP_SIZE,
1408 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1409 },
1410#endif
1411 /* Compatibility with former boolean values */
1412 { .ival = "0",
1413 .oval = FIO_FALLOCATE_NONE,
1414 .help = "Alias for 'none'",
1415 },
1416 { .ival = "1",
1417 .oval = FIO_FALLOCATE_POSIX,
1418 .help = "Alias for 'posix'",
1419 },
1420 },
1421 },
1422#endif /* FIO_HAVE_FALLOCATE */
1423 {
1424 .name = "fadvise_hint",
1425 .type = FIO_OPT_BOOL,
1426 .off1 = td_var_offset(fadvise_hint),
1427 .help = "Use fadvise() to advise the kernel on IO pattern",
1428 .def = "1",
1429 .category = FIO_OPT_G_FILE,
1430 },
1431 {
1432 .name = "fsync",
1433 .type = FIO_OPT_INT,
1434 .off1 = td_var_offset(fsync_blocks),
1435 .help = "Issue fsync for writes every given number of blocks",
1436 .def = "0",
1437 .interval = 1,
1438 .category = FIO_OPT_G_FILE,
1439 },
1440 {
1441 .name = "fdatasync",
1442 .type = FIO_OPT_INT,
1443 .off1 = td_var_offset(fdatasync_blocks),
1444 .help = "Issue fdatasync for writes every given number of blocks",
1445 .def = "0",
1446 .interval = 1,
1447 .category = FIO_OPT_G_FILE,
1448 },
1449 {
1450 .name = "write_barrier",
1451 .type = FIO_OPT_INT,
1452 .off1 = td_var_offset(barrier_blocks),
1453 .help = "Make every Nth write a barrier write",
1454 .def = "0",
1455 .interval = 1,
1456 .category = FIO_OPT_G_IO,
1457 },
1458#ifdef FIO_HAVE_SYNC_FILE_RANGE
1459 {
1460 .name = "sync_file_range",
1461 .posval = {
1462 { .ival = "wait_before",
1463 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1464 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1465 .or = 1,
1466 },
1467 { .ival = "write",
1468 .oval = SYNC_FILE_RANGE_WRITE,
1469 .help = "SYNC_FILE_RANGE_WRITE",
1470 .or = 1,
1471 },
1472 {
1473 .ival = "wait_after",
1474 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1475 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1476 .or = 1,
1477 },
1478 },
1479 .type = FIO_OPT_STR_MULTI,
1480 .cb = str_sfr_cb,
1481 .off1 = td_var_offset(sync_file_range),
1482 .help = "Use sync_file_range()",
1483 .category = FIO_OPT_G_FILE,
1484 },
1485#endif
1486 {
1487 .name = "direct",
1488 .type = FIO_OPT_BOOL,
1489 .off1 = td_var_offset(odirect),
1490 .help = "Use O_DIRECT IO (negates buffered)",
1491 .def = "0",
1492 .category = FIO_OPT_G_IO,
1493 },
1494 {
1495 .name = "buffered",
1496 .type = FIO_OPT_BOOL,
1497 .off1 = td_var_offset(odirect),
1498 .neg = 1,
1499 .help = "Use buffered IO (negates direct)",
1500 .def = "1",
1501 .category = FIO_OPT_G_IO,
1502 },
1503 {
1504 .name = "overwrite",
1505 .type = FIO_OPT_BOOL,
1506 .off1 = td_var_offset(overwrite),
1507 .help = "When writing, set whether to overwrite current data",
1508 .def = "0",
1509 .category = FIO_OPT_G_IO | FIO_OPT_G_FILE,
1510 },
1511 {
1512 .name = "loops",
1513 .type = FIO_OPT_INT,
1514 .off1 = td_var_offset(loops),
1515 .help = "Number of times to run the job",
1516 .def = "1",
1517 .interval = 1,
1518 .category = FIO_OPT_G_MISC,
1519 },
1520 {
1521 .name = "numjobs",
1522 .type = FIO_OPT_INT,
1523 .off1 = td_var_offset(numjobs),
1524 .help = "Duplicate this job this many times",
1525 .def = "1",
1526 .interval = 1,
1527 .category = FIO_OPT_G_MISC,
1528 },
1529 {
1530 .name = "startdelay",
1531 .type = FIO_OPT_STR_VAL_TIME,
1532 .off1 = td_var_offset(start_delay),
1533 .help = "Only start job when this period has passed",
1534 .def = "0",
1535 .category = FIO_OPT_G_MISC,
1536 },
1537 {
1538 .name = "runtime",
1539 .alias = "timeout",
1540 .type = FIO_OPT_STR_VAL_TIME,
1541 .off1 = td_var_offset(timeout),
1542 .help = "Stop workload when this amount of time has passed",
1543 .def = "0",
1544 .category = FIO_OPT_G_MISC,
1545 },
1546 {
1547 .name = "time_based",
1548 .type = FIO_OPT_STR_SET,
1549 .off1 = td_var_offset(time_based),
1550 .help = "Keep running until runtime/timeout is met",
1551 .category = FIO_OPT_G_MISC,
1552 },
1553 {
1554 .name = "ramp_time",
1555 .type = FIO_OPT_STR_VAL_TIME,
1556 .off1 = td_var_offset(ramp_time),
1557 .help = "Ramp up time before measuring performance",
1558 .category = FIO_OPT_G_MISC,
1559 },
1560 {
1561 .name = "clocksource",
1562 .type = FIO_OPT_STR,
1563 .cb = fio_clock_source_cb,
1564 .off1 = td_var_offset(clocksource),
1565 .help = "What type of timing source to use",
1566 .category = FIO_OPT_G_OS,
1567 .posval = {
1568 { .ival = "gettimeofday",
1569 .oval = CS_GTOD,
1570 .help = "Use gettimeofday(2) for timing",
1571 },
1572 { .ival = "clock_gettime",
1573 .oval = CS_CGETTIME,
1574 .help = "Use clock_gettime(2) for timing",
1575 },
1576#ifdef ARCH_HAVE_CPU_CLOCK
1577 { .ival = "cpu",
1578 .oval = CS_CPUCLOCK,
1579 .help = "Use CPU private clock",
1580 },
1581#endif
1582 },
1583 },
1584 {
1585 .name = "mem",
1586 .alias = "iomem",
1587 .type = FIO_OPT_STR,
1588 .cb = str_mem_cb,
1589 .off1 = td_var_offset(mem_type),
1590 .help = "Backing type for IO buffers",
1591 .def = "malloc",
1592 .category = FIO_OPT_G_IO_BUF | FIO_OPT_G_MEM,
1593 .posval = {
1594 { .ival = "malloc",
1595 .oval = MEM_MALLOC,
1596 .help = "Use malloc(3) for IO buffers",
1597 },
1598 { .ival = "shm",
1599 .oval = MEM_SHM,
1600 .help = "Use shared memory segments for IO buffers",
1601 },
1602#ifdef FIO_HAVE_HUGETLB
1603 { .ival = "shmhuge",
1604 .oval = MEM_SHMHUGE,
1605 .help = "Like shm, but use huge pages",
1606 },
1607#endif
1608 { .ival = "mmap",
1609 .oval = MEM_MMAP,
1610 .help = "Use mmap(2) (file or anon) for IO buffers",
1611 },
1612#ifdef FIO_HAVE_HUGETLB
1613 { .ival = "mmaphuge",
1614 .oval = MEM_MMAPHUGE,
1615 .help = "Like mmap, but use huge pages",
1616 },
1617#endif
1618 },
1619 },
1620 {
1621 .name = "iomem_align",
1622 .alias = "mem_align",
1623 .type = FIO_OPT_INT,
1624 .off1 = td_var_offset(mem_align),
1625 .minval = 0,
1626 .help = "IO memory buffer offset alignment",
1627 .def = "0",
1628 .parent = "iomem",
1629 .category = FIO_OPT_G_IO_BUF | FIO_OPT_G_MEM,
1630 },
1631 {
1632 .name = "verify",
1633 .type = FIO_OPT_STR,
1634 .off1 = td_var_offset(verify),
1635 .help = "Verify data written",
1636 .cb = str_verify_cb,
1637 .def = "0",
1638 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1639 .posval = {
1640 { .ival = "0",
1641 .oval = VERIFY_NONE,
1642 .help = "Don't do IO verification",
1643 },
1644 { .ival = "md5",
1645 .oval = VERIFY_MD5,
1646 .help = "Use md5 checksums for verification",
1647 },
1648 { .ival = "crc64",
1649 .oval = VERIFY_CRC64,
1650 .help = "Use crc64 checksums for verification",
1651 },
1652 { .ival = "crc32",
1653 .oval = VERIFY_CRC32,
1654 .help = "Use crc32 checksums for verification",
1655 },
1656 { .ival = "crc32c-intel",
1657 .oval = VERIFY_CRC32C,
1658 .help = "Use crc32c checksums for verification (hw assisted, if available)",
1659 },
1660 { .ival = "crc32c",
1661 .oval = VERIFY_CRC32C,
1662 .help = "Use crc32c checksums for verification (hw assisted, if available)",
1663 },
1664 { .ival = "crc16",
1665 .oval = VERIFY_CRC16,
1666 .help = "Use crc16 checksums for verification",
1667 },
1668 { .ival = "crc7",
1669 .oval = VERIFY_CRC7,
1670 .help = "Use crc7 checksums for verification",
1671 },
1672 { .ival = "sha1",
1673 .oval = VERIFY_SHA1,
1674 .help = "Use sha1 checksums for verification",
1675 },
1676 { .ival = "sha256",
1677 .oval = VERIFY_SHA256,
1678 .help = "Use sha256 checksums for verification",
1679 },
1680 { .ival = "sha512",
1681 .oval = VERIFY_SHA512,
1682 .help = "Use sha512 checksums for verification",
1683 },
1684 { .ival = "meta",
1685 .oval = VERIFY_META,
1686 .help = "Use io information",
1687 },
1688 {
1689 .ival = "null",
1690 .oval = VERIFY_NULL,
1691 .help = "Pretend to verify",
1692 },
1693 },
1694 },
1695 {
1696 .name = "do_verify",
1697 .type = FIO_OPT_BOOL,
1698 .off1 = td_var_offset(do_verify),
1699 .help = "Run verification stage after write",
1700 .def = "1",
1701 .parent = "verify",
1702 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1703 },
1704 {
1705 .name = "verifysort",
1706 .type = FIO_OPT_BOOL,
1707 .off1 = td_var_offset(verifysort),
1708 .help = "Sort written verify blocks for read back",
1709 .def = "1",
1710 .parent = "verify",
1711 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1712 },
1713 {
1714 .name = "verify_interval",
1715 .type = FIO_OPT_INT,
1716 .off1 = td_var_offset(verify_interval),
1717 .minval = 2 * sizeof(struct verify_header),
1718 .help = "Store verify buffer header every N bytes",
1719 .parent = "verify",
1720 .interval = 2 * sizeof(struct verify_header),
1721 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1722 },
1723 {
1724 .name = "verify_offset",
1725 .type = FIO_OPT_INT,
1726 .help = "Offset verify header location by N bytes",
1727 .def = "0",
1728 .cb = str_verify_offset_cb,
1729 .parent = "verify",
1730 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1731 },
1732 {
1733 .name = "verify_pattern",
1734 .type = FIO_OPT_STR,
1735 .cb = str_verify_pattern_cb,
1736 .help = "Fill pattern for IO buffers",
1737 .parent = "verify",
1738 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1739 },
1740 {
1741 .name = "verify_fatal",
1742 .type = FIO_OPT_BOOL,
1743 .off1 = td_var_offset(verify_fatal),
1744 .def = "0",
1745 .help = "Exit on a single verify failure, don't continue",
1746 .parent = "verify",
1747 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY | FIO_OPT_G_ERR,
1748 },
1749 {
1750 .name = "verify_dump",
1751 .type = FIO_OPT_BOOL,
1752 .off1 = td_var_offset(verify_dump),
1753 .def = "0",
1754 .help = "Dump contents of good and bad blocks on failure",
1755 .parent = "verify",
1756 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY | FIO_OPT_G_ERR,
1757 },
1758 {
1759 .name = "verify_async",
1760 .type = FIO_OPT_INT,
1761 .off1 = td_var_offset(verify_async),
1762 .def = "0",
1763 .help = "Number of async verifier threads to use",
1764 .parent = "verify",
1765 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1766 },
1767 {
1768 .name = "verify_backlog",
1769 .type = FIO_OPT_STR_VAL,
1770 .off1 = td_var_offset(verify_backlog),
1771 .help = "Verify after this number of blocks are written",
1772 .parent = "verify",
1773 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1774 },
1775 {
1776 .name = "verify_backlog_batch",
1777 .type = FIO_OPT_INT,
1778 .off1 = td_var_offset(verify_batch),
1779 .help = "Verify this number of IO blocks",
1780 .parent = "verify",
1781 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1782 },
1783#ifdef FIO_HAVE_CPU_AFFINITY
1784 {
1785 .name = "verify_async_cpus",
1786 .type = FIO_OPT_STR,
1787 .cb = str_verify_cpus_allowed_cb,
1788 .help = "Set CPUs allowed for async verify threads",
1789 .parent = "verify_async",
1790 .category = FIO_OPT_G_OS | FIO_OPT_G_CPU | FIO_OPT_G_VERIFY,
1791 },
1792#endif
1793#ifdef FIO_HAVE_TRIM
1794 {
1795 .name = "trim_percentage",
1796 .type = FIO_OPT_INT,
1797 .cb = str_verify_trim_cb,
1798 .minval = 0,
1799 .maxval = 100,
1800 .help = "Number of verify blocks to discard/trim",
1801 .parent = "verify",
1802 .def = "0",
1803 .interval = 1,
1804 .category = FIO_OPT_G_IO,
1805 },
1806 {
1807 .name = "trim_verify_zero",
1808 .type = FIO_OPT_BOOL,
1809 .help = "Verify that trim/discarded blocks are returned as zeroes",
1810 .off1 = td_var_offset(trim_zero),
1811 .parent = "trim_percentage",
1812 .def = "1",
1813 .category = FIO_OPT_G_IO,
1814 },
1815 {
1816 .name = "trim_backlog",
1817 .type = FIO_OPT_STR_VAL,
1818 .off1 = td_var_offset(trim_backlog),
1819 .help = "Trim after this number of blocks are written",
1820 .parent = "trim_percentage",
1821 .interval = 1,
1822 .category = FIO_OPT_G_IO,
1823 },
1824 {
1825 .name = "trim_backlog_batch",
1826 .type = FIO_OPT_INT,
1827 .off1 = td_var_offset(trim_batch),
1828 .help = "Trim this number of IO blocks",
1829 .parent = "trim_percentage",
1830 .interval = 1,
1831 .category = FIO_OPT_G_IO,
1832 },
1833#endif
1834 {
1835 .name = "write_iolog",
1836 .type = FIO_OPT_STR_STORE,
1837 .off1 = td_var_offset(write_iolog_file),
1838 .help = "Store IO pattern to file",
1839 .category = FIO_OPT_G_IO | FIO_OPT_G_LOG,
1840 },
1841 {
1842 .name = "read_iolog",
1843 .type = FIO_OPT_STR_STORE,
1844 .off1 = td_var_offset(read_iolog_file),
1845 .help = "Playback IO pattern from file",
1846 .category = FIO_OPT_G_IO | FIO_OPT_G_LOG,
1847 },
1848 {
1849 .name = "replay_no_stall",
1850 .type = FIO_OPT_BOOL,
1851 .off1 = td_var_offset(no_stall),
1852 .def = "0",
1853 .parent = "read_iolog",
1854 .help = "Playback IO pattern file as fast as possible without stalls",
1855 .category = FIO_OPT_G_IO | FIO_OPT_G_LOG,
1856 },
1857 {
1858 .name = "replay_redirect",
1859 .type = FIO_OPT_STR_STORE,
1860 .off1 = td_var_offset(replay_redirect),
1861 .parent = "read_iolog",
1862 .help = "Replay all I/O onto this device, regardless of trace device",
1863 .category = FIO_OPT_G_IO | FIO_OPT_G_LOG,
1864 },
1865 {
1866 .name = "exec_prerun",
1867 .type = FIO_OPT_STR_STORE,
1868 .off1 = td_var_offset(exec_prerun),
1869 .help = "Execute this file prior to running job",
1870 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
1871 },
1872 {
1873 .name = "exec_postrun",
1874 .type = FIO_OPT_STR_STORE,
1875 .off1 = td_var_offset(exec_postrun),
1876 .help = "Execute this file after running job",
1877 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
1878 },
1879#ifdef FIO_HAVE_IOSCHED_SWITCH
1880 {
1881 .name = "ioscheduler",
1882 .type = FIO_OPT_STR_STORE,
1883 .off1 = td_var_offset(ioscheduler),
1884 .help = "Use this IO scheduler on the backing device",
1885 .category = FIO_OPT_G_OS | FIO_OPT_G_IO,
1886 },
1887#endif
1888 {
1889 .name = "zonesize",
1890 .type = FIO_OPT_STR_VAL,
1891 .off1 = td_var_offset(zone_size),
1892 .help = "Amount of data to read per zone",
1893 .def = "0",
1894 .interval = 1024 * 1024,
1895 .category = FIO_OPT_G_IO | FIO_OPT_G_ZONE,
1896 },
1897 {
1898 .name = "zonerange",
1899 .type = FIO_OPT_STR_VAL,
1900 .off1 = td_var_offset(zone_range),
1901 .help = "Give size of an IO zone",
1902 .def = "0",
1903 .interval = 1024 * 1024,
1904 .category = FIO_OPT_G_IO | FIO_OPT_G_ZONE,
1905 },
1906 {
1907 .name = "zoneskip",
1908 .type = FIO_OPT_STR_VAL,
1909 .off1 = td_var_offset(zone_skip),
1910 .help = "Space between IO zones",
1911 .def = "0",
1912 .interval = 1024 * 1024,
1913 .category = FIO_OPT_G_IO | FIO_OPT_G_ZONE,
1914 },
1915 {
1916 .name = "lockmem",
1917 .type = FIO_OPT_STR_VAL,
1918 .cb = str_lockmem_cb,
1919 .help = "Lock down this amount of memory",
1920 .def = "0",
1921 .interval = 1024 * 1024,
1922 .category = FIO_OPT_G_OS | FIO_OPT_G_MEM,
1923 },
1924 {
1925 .name = "rwmixread",
1926 .type = FIO_OPT_INT,
1927 .cb = str_rwmix_read_cb,
1928 .maxval = 100,
1929 .help = "Percentage of mixed workload that is reads",
1930 .def = "50",
1931 .interval = 5,
1932 .category = FIO_OPT_G_IO,
1933 },
1934 {
1935 .name = "rwmixwrite",
1936 .type = FIO_OPT_INT,
1937 .cb = str_rwmix_write_cb,
1938 .maxval = 100,
1939 .help = "Percentage of mixed workload that is writes",
1940 .def = "50",
1941 .interval = 5,
1942 .category = FIO_OPT_G_IO,
1943 },
1944 {
1945 .name = "rwmixcycle",
1946 .type = FIO_OPT_DEPRECATED,
1947 .category = FIO_OPT_G_IO,
1948 },
1949 {
1950 .name = "nice",
1951 .type = FIO_OPT_INT,
1952 .off1 = td_var_offset(nice),
1953 .help = "Set job CPU nice value",
1954 .minval = -19,
1955 .maxval = 20,
1956 .def = "0",
1957 .interval = 1,
1958 .category = FIO_OPT_G_OS | FIO_OPT_G_CPU,
1959 },
1960#ifdef FIO_HAVE_IOPRIO
1961 {
1962 .name = "prio",
1963 .type = FIO_OPT_INT,
1964 .cb = str_prio_cb,
1965 .help = "Set job IO priority value",
1966 .minval = 0,
1967 .maxval = 7,
1968 .interval = 1,
1969 .category = FIO_OPT_G_OS | FIO_OPT_G_CPU,
1970 },
1971 {
1972 .name = "prioclass",
1973 .type = FIO_OPT_INT,
1974 .cb = str_prioclass_cb,
1975 .help = "Set job IO priority class",
1976 .minval = 0,
1977 .maxval = 3,
1978 .interval = 1,
1979 .category = FIO_OPT_G_OS | FIO_OPT_G_CPU,
1980 },
1981#endif
1982 {
1983 .name = "thinktime",
1984 .type = FIO_OPT_INT,
1985 .off1 = td_var_offset(thinktime),
1986 .help = "Idle time between IO buffers (usec)",
1987 .def = "0",
1988 .category = FIO_OPT_G_MISC,
1989 },
1990 {
1991 .name = "thinktime_spin",
1992 .type = FIO_OPT_INT,
1993 .off1 = td_var_offset(thinktime_spin),
1994 .help = "Start think time by spinning this amount (usec)",
1995 .def = "0",
1996 .parent = "thinktime",
1997 .category = FIO_OPT_G_MISC,
1998 },
1999 {
2000 .name = "thinktime_blocks",
2001 .type = FIO_OPT_INT,
2002 .off1 = td_var_offset(thinktime_blocks),
2003 .help = "IO buffer period between 'thinktime'",
2004 .def = "1",
2005 .parent = "thinktime",
2006 .category = FIO_OPT_G_MISC,
2007 },
2008 {
2009 .name = "rate",
2010 .type = FIO_OPT_INT,
2011 .off1 = td_var_offset(rate[0]),
2012 .off2 = td_var_offset(rate[1]),
2013 .help = "Set bandwidth rate",
2014 .category = FIO_OPT_G_IO,
2015 },
2016 {
2017 .name = "ratemin",
2018 .type = FIO_OPT_INT,
2019 .off1 = td_var_offset(ratemin[0]),
2020 .off2 = td_var_offset(ratemin[1]),
2021 .help = "Job must meet this rate or it will be shutdown",
2022 .parent = "rate",
2023 .category = FIO_OPT_G_IO,
2024 },
2025 {
2026 .name = "rate_iops",
2027 .type = FIO_OPT_INT,
2028 .off1 = td_var_offset(rate_iops[0]),
2029 .off2 = td_var_offset(rate_iops[1]),
2030 .help = "Limit IO used to this number of IO operations/sec",
2031 .category = FIO_OPT_G_IO,
2032 },
2033 {
2034 .name = "rate_iops_min",
2035 .type = FIO_OPT_INT,
2036 .off1 = td_var_offset(rate_iops_min[0]),
2037 .off2 = td_var_offset(rate_iops_min[1]),
2038 .help = "Job must meet this rate or it will be shut down",
2039 .parent = "rate_iops",
2040 .category = FIO_OPT_G_IO,
2041 },
2042 {
2043 .name = "ratecycle",
2044 .type = FIO_OPT_INT,
2045 .off1 = td_var_offset(ratecycle),
2046 .help = "Window average for rate limits (msec)",
2047 .def = "1000",
2048 .parent = "rate",
2049 .category = FIO_OPT_G_IO,
2050 },
2051 {
2052 .name = "invalidate",
2053 .type = FIO_OPT_BOOL,
2054 .off1 = td_var_offset(invalidate_cache),
2055 .help = "Invalidate buffer/page cache prior to running job",
2056 .def = "1",
2057 .category = FIO_OPT_G_IO | FIO_OPT_G_CACHE,
2058 },
2059 {
2060 .name = "sync",
2061 .type = FIO_OPT_BOOL,
2062 .off1 = td_var_offset(sync_io),
2063 .help = "Use O_SYNC for buffered writes",
2064 .def = "0",
2065 .parent = "buffered",
2066 .category = FIO_OPT_G_IO | FIO_OPT_G_FILE,
2067 },
2068 {
2069 .name = "bwavgtime",
2070 .type = FIO_OPT_INT,
2071 .off1 = td_var_offset(bw_avg_time),
2072 .help = "Time window over which to calculate bandwidth"
2073 " (msec)",
2074 .def = "500",
2075 .parent = "write_bw_log",
2076 .interval = 100,
2077 .category = FIO_OPT_G_LOG | FIO_OPT_G_STAT,
2078 },
2079 {
2080 .name = "iopsavgtime",
2081 .type = FIO_OPT_INT,
2082 .off1 = td_var_offset(iops_avg_time),
2083 .help = "Time window over which to calculate IOPS (msec)",
2084 .def = "500",
2085 .parent = "write_iops_log",
2086 .interval = 100,
2087 .category = FIO_OPT_G_LOG | FIO_OPT_G_STAT,
2088 },
2089 {
2090 .name = "create_serialize",
2091 .type = FIO_OPT_BOOL,
2092 .off1 = td_var_offset(create_serialize),
2093 .help = "Serialize creating of job files",
2094 .def = "1",
2095 .category = FIO_OPT_G_FILE,
2096 },
2097 {
2098 .name = "create_fsync",
2099 .type = FIO_OPT_BOOL,
2100 .off1 = td_var_offset(create_fsync),
2101 .help = "fsync file after creation",
2102 .def = "1",
2103 .category = FIO_OPT_G_FILE,
2104 },
2105 {
2106 .name = "create_on_open",
2107 .type = FIO_OPT_BOOL,
2108 .off1 = td_var_offset(create_on_open),
2109 .help = "Create files when they are opened for IO",
2110 .def = "0",
2111 .category = FIO_OPT_G_FILE,
2112 },
2113 {
2114 .name = "pre_read",
2115 .type = FIO_OPT_BOOL,
2116 .off1 = td_var_offset(pre_read),
2117 .help = "Pre-read files before starting official testing",
2118 .def = "0",
2119 .category = FIO_OPT_G_FILE | FIO_OPT_G_CACHE,
2120 },
2121 {
2122 .name = "cpuload",
2123 .type = FIO_OPT_INT,
2124 .off1 = td_var_offset(cpuload),
2125 .help = "Use this percentage of CPU",
2126 .category = FIO_OPT_G_CPU,
2127 },
2128 {
2129 .name = "cpuchunks",
2130 .type = FIO_OPT_INT,
2131 .off1 = td_var_offset(cpucycle),
2132 .help = "Length of the CPU burn cycles (usecs)",
2133 .def = "50000",
2134 .parent = "cpuload",
2135 .category = FIO_OPT_G_CPU,
2136 },
2137#ifdef FIO_HAVE_CPU_AFFINITY
2138 {
2139 .name = "cpumask",
2140 .type = FIO_OPT_INT,
2141 .cb = str_cpumask_cb,
2142 .help = "CPU affinity mask",
2143 .category = FIO_OPT_G_CPU | FIO_OPT_G_OS,
2144 },
2145 {
2146 .name = "cpus_allowed",
2147 .type = FIO_OPT_STR,
2148 .cb = str_cpus_allowed_cb,
2149 .help = "Set CPUs allowed",
2150 .category = FIO_OPT_G_CPU | FIO_OPT_G_OS,
2151 },
2152#endif
2153 {
2154 .name = "end_fsync",
2155 .type = FIO_OPT_BOOL,
2156 .off1 = td_var_offset(end_fsync),
2157 .help = "Include fsync at the end of job",
2158 .def = "0",
2159 .category = FIO_OPT_G_FILE,
2160 },
2161 {
2162 .name = "fsync_on_close",
2163 .type = FIO_OPT_BOOL,
2164 .off1 = td_var_offset(fsync_on_close),
2165 .help = "fsync files on close",
2166 .def = "0",
2167 .category = FIO_OPT_G_FILE,
2168 },
2169 {
2170 .name = "unlink",
2171 .type = FIO_OPT_BOOL,
2172 .off1 = td_var_offset(unlink),
2173 .help = "Unlink created files after job has completed",
2174 .def = "0",
2175 .category = FIO_OPT_G_FILE,
2176 },
2177 {
2178 .name = "exitall",
2179 .type = FIO_OPT_STR_SET,
2180 .cb = str_exitall_cb,
2181 .help = "Terminate all jobs when one exits",
2182 .category = FIO_OPT_G_MISC | FIO_OPT_G_JOB,
2183 },
2184 {
2185 .name = "stonewall",
2186 .alias = "wait_for_previous",
2187 .type = FIO_OPT_STR_SET,
2188 .off1 = td_var_offset(stonewall),
2189 .help = "Insert a hard barrier between this job and previous",
2190 .category = FIO_OPT_G_MISC | FIO_OPT_G_JOB,
2191 },
2192 {
2193 .name = "new_group",
2194 .type = FIO_OPT_STR_SET,
2195 .off1 = td_var_offset(new_group),
2196 .help = "Mark the start of a new group (for reporting)",
2197 .category = FIO_OPT_G_MISC | FIO_OPT_G_JOB,
2198 },
2199 {
2200 .name = "thread",
2201 .type = FIO_OPT_STR_SET,
2202 .off1 = td_var_offset(use_thread),
2203 .help = "Use threads instead of processes",
2204 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS | FIO_OPT_G_JOB,
2205 },
2206 {
2207 .name = "write_bw_log",
2208 .type = FIO_OPT_STR,
2209 .off1 = td_var_offset(write_bw_log),
2210 .cb = str_write_bw_log_cb,
2211 .help = "Write log of bandwidth during run",
2212 .category = FIO_OPT_G_LOG,
2213 },
2214 {
2215 .name = "write_lat_log",
2216 .type = FIO_OPT_STR,
2217 .off1 = td_var_offset(write_lat_log),
2218 .cb = str_write_lat_log_cb,
2219 .help = "Write log of latency during run",
2220 .category = FIO_OPT_G_LOG,
2221 },
2222 {
2223 .name = "write_iops_log",
2224 .type = FIO_OPT_STR,
2225 .off1 = td_var_offset(write_iops_log),
2226 .cb = str_write_iops_log_cb,
2227 .help = "Write log of IOPS during run",
2228 .category = FIO_OPT_G_LOG,
2229 },
2230 {
2231 .name = "log_avg_msec",
2232 .type = FIO_OPT_INT,
2233 .off1 = td_var_offset(log_avg_msec),
2234 .help = "Average bw/iops/lat logs over this period of time",
2235 .def = "0",
2236 .category = FIO_OPT_G_LOG,
2237 },
2238 {
2239 .name = "hugepage-size",
2240 .type = FIO_OPT_INT,
2241 .off1 = td_var_offset(hugepage_size),
2242 .help = "When using hugepages, specify size of each page",
2243 .def = __fio_stringify(FIO_HUGE_PAGE),
2244 .interval = 1024 * 1024,
2245 .category = FIO_OPT_G_OS | FIO_OPT_G_MEM,
2246 },
2247 {
2248 .name = "group_reporting",
2249 .type = FIO_OPT_STR_SET,
2250 .off1 = td_var_offset(group_reporting),
2251 .help = "Do reporting on a per-group basis",
2252 .category = FIO_OPT_G_MISC,
2253 },
2254 {
2255 .name = "zero_buffers",
2256 .type = FIO_OPT_STR_SET,
2257 .off1 = td_var_offset(zero_buffers),
2258 .help = "Init IO buffers to all zeroes",
2259 .category = FIO_OPT_G_IO_BUF,
2260 },
2261 {
2262 .name = "refill_buffers",
2263 .type = FIO_OPT_STR_SET,
2264 .off1 = td_var_offset(refill_buffers),
2265 .help = "Refill IO buffers on every IO submit",
2266 .category = FIO_OPT_G_IO_BUF,
2267 },
2268 {
2269 .name = "scramble_buffers",
2270 .type = FIO_OPT_BOOL,
2271 .off1 = td_var_offset(scramble_buffers),
2272 .help = "Slightly scramble buffers on every IO submit",
2273 .def = "1",
2274 .category = FIO_OPT_G_IO_BUF,
2275 },
2276 {
2277 .name = "buffer_compress_percentage",
2278 .type = FIO_OPT_INT,
2279 .off1 = td_var_offset(compress_percentage),
2280 .maxval = 100,
2281 .minval = 1,
2282 .help = "How compressible the buffer is (approximately)",
2283 .interval = 5,
2284 .category = FIO_OPT_G_IO_BUF,
2285 },
2286 {
2287 .name = "buffer_compress_chunk",
2288 .type = FIO_OPT_INT,
2289 .off1 = td_var_offset(compress_chunk),
2290 .parent = "buffer_compress_percentage",
2291 .help = "Size of compressible region in buffer",
2292 .interval = 256,
2293 .category = FIO_OPT_G_IO_BUF,
2294 },
2295 {
2296 .name = "clat_percentiles",
2297 .type = FIO_OPT_BOOL,
2298 .off1 = td_var_offset(clat_percentiles),
2299 .help = "Enable the reporting of completion latency percentiles",
2300 .def = "1",
2301 .category = FIO_OPT_G_STAT,
2302 },
2303 {
2304 .name = "percentile_list",
2305 .type = FIO_OPT_FLOAT_LIST,
2306 .off1 = td_var_offset(percentile_list),
2307 .off2 = td_var_offset(overwrite_plist),
2308 .help = "Specify a custom list of percentiles to report",
2309 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2310 .minfp = 0.0,
2311 .maxfp = 100.0,
2312 .category = FIO_OPT_G_STAT,
2313 },
2314
2315#ifdef FIO_HAVE_DISK_UTIL
2316 {
2317 .name = "disk_util",
2318 .type = FIO_OPT_BOOL,
2319 .off1 = td_var_offset(do_disk_util),
2320 .help = "Log disk utilization statistics",
2321 .def = "1",
2322 .category = FIO_OPT_G_OS | FIO_OPT_G_STAT,
2323 },
2324#endif
2325 {
2326 .name = "gtod_reduce",
2327 .type = FIO_OPT_BOOL,
2328 .help = "Greatly reduce number of gettimeofday() calls",
2329 .cb = str_gtod_reduce_cb,
2330 .def = "0",
2331 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2332 },
2333 {
2334 .name = "disable_lat",
2335 .type = FIO_OPT_BOOL,
2336 .off1 = td_var_offset(disable_lat),
2337 .help = "Disable latency numbers",
2338 .parent = "gtod_reduce",
2339 .def = "0",
2340 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2341 },
2342 {
2343 .name = "disable_clat",
2344 .type = FIO_OPT_BOOL,
2345 .off1 = td_var_offset(disable_clat),
2346 .help = "Disable completion latency numbers",
2347 .parent = "gtod_reduce",
2348 .def = "0",
2349 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2350 },
2351 {
2352 .name = "disable_slat",
2353 .type = FIO_OPT_BOOL,
2354 .off1 = td_var_offset(disable_slat),
2355 .help = "Disable submission latency numbers",
2356 .parent = "gtod_reduce",
2357 .def = "0",
2358 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2359 },
2360 {
2361 .name = "disable_bw_measurement",
2362 .type = FIO_OPT_BOOL,
2363 .off1 = td_var_offset(disable_bw),
2364 .help = "Disable bandwidth logging",
2365 .parent = "gtod_reduce",
2366 .def = "0",
2367 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2368 },
2369 {
2370 .name = "gtod_cpu",
2371 .type = FIO_OPT_INT,
2372 .cb = str_gtod_cpu_cb,
2373 .help = "Set up dedicated gettimeofday() thread on this CPU",
2374 .verify = gtod_cpu_verify,
2375 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2376 },
2377 {
2378 .name = "continue_on_error",
2379 .type = FIO_OPT_STR,
2380 .off1 = td_var_offset(continue_on_error),
2381 .help = "Continue on non-fatal errors during IO",
2382 .def = "none",
2383 .category = FIO_OPT_G_MISC | FIO_OPT_G_ERR,
2384 .posval = {
2385 { .ival = "none",
2386 .oval = ERROR_TYPE_NONE,
2387 .help = "Exit when an error is encountered",
2388 },
2389 { .ival = "read",
2390 .oval = ERROR_TYPE_READ,
2391 .help = "Continue on read errors only",
2392 },
2393 { .ival = "write",
2394 .oval = ERROR_TYPE_WRITE,
2395 .help = "Continue on write errors only",
2396 },
2397 { .ival = "io",
2398 .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2399 .help = "Continue on any IO errors",
2400 },
2401 { .ival = "verify",
2402 .oval = ERROR_TYPE_VERIFY,
2403 .help = "Continue on verify errors only",
2404 },
2405 { .ival = "all",
2406 .oval = ERROR_TYPE_ANY,
2407 .help = "Continue on all io and verify errors",
2408 },
2409 { .ival = "0",
2410 .oval = ERROR_TYPE_NONE,
2411 .help = "Alias for 'none'",
2412 },
2413 { .ival = "1",
2414 .oval = ERROR_TYPE_ANY,
2415 .help = "Alias for 'all'",
2416 },
2417 },
2418 },
2419 {
2420 .name = "profile",
2421 .type = FIO_OPT_STR_STORE,
2422 .off1 = td_var_offset(profile),
2423 .help = "Select a specific builtin performance test",
2424 .category = FIO_OPT_G_MISC | FIO_OPT_G_JOB,
2425 },
2426 {
2427 .name = "cgroup",
2428 .type = FIO_OPT_STR_STORE,
2429 .off1 = td_var_offset(cgroup),
2430 .help = "Add job to cgroup of this name",
2431 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
2432 },
2433 {
2434 .name = "cgroup_weight",
2435 .type = FIO_OPT_INT,
2436 .off1 = td_var_offset(cgroup_weight),
2437 .help = "Use given weight for cgroup",
2438 .minval = 100,
2439 .maxval = 1000,
2440 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
2441 },
2442 {
2443 .name = "cgroup_nodelete",
2444 .type = FIO_OPT_BOOL,
2445 .off1 = td_var_offset(cgroup_nodelete),
2446 .help = "Do not delete cgroups after job completion",
2447 .def = "0",
2448 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
2449 },
2450 {
2451 .name = "uid",
2452 .type = FIO_OPT_INT,
2453 .off1 = td_var_offset(uid),
2454 .help = "Run job with this user ID",
2455 .category = FIO_OPT_G_OS | FIO_OPT_G_JOB,
2456 },
2457 {
2458 .name = "gid",
2459 .type = FIO_OPT_INT,
2460 .off1 = td_var_offset(gid),
2461 .help = "Run job with this group ID",
2462 .category = FIO_OPT_G_OS | FIO_OPT_G_JOB,
2463 },
2464 {
2465 .name = "flow_id",
2466 .type = FIO_OPT_INT,
2467 .off1 = td_var_offset(flow_id),
2468 .help = "The flow index ID to use",
2469 .def = "0",
2470 .category = FIO_OPT_G_IO,
2471 },
2472 {
2473 .name = "flow",
2474 .type = FIO_OPT_INT,
2475 .off1 = td_var_offset(flow),
2476 .help = "Weight for flow control of this job",
2477 .parent = "flow_id",
2478 .def = "0",
2479 .category = FIO_OPT_G_IO,
2480 },
2481 {
2482 .name = "flow_watermark",
2483 .type = FIO_OPT_INT,
2484 .off1 = td_var_offset(flow_watermark),
2485 .help = "High watermark for flow control. This option"
2486 " should be set to the same value for all threads"
2487 " with non-zero flow.",
2488 .parent = "flow_id",
2489 .def = "1024",
2490 .category = FIO_OPT_G_IO,
2491 },
2492 {
2493 .name = "flow_sleep",
2494 .type = FIO_OPT_INT,
2495 .off1 = td_var_offset(flow_sleep),
2496 .help = "How many microseconds to sleep after being held"
2497 " back by the flow control mechanism",
2498 .parent = "flow_id",
2499 .def = "0",
2500 .category = FIO_OPT_G_IO,
2501 },
2502 {
2503 .name = NULL,
2504 },
2505};
2506
2507static void add_to_lopt(struct option *lopt, struct fio_option *o,
2508 const char *name, int val)
2509{
2510 lopt->name = (char *) name;
2511 lopt->val = val;
2512 if (o->type == FIO_OPT_STR_SET)
2513 lopt->has_arg = no_argument;
2514 else
2515 lopt->has_arg = required_argument;
2516}
2517
2518static void options_to_lopts(struct fio_option *opts,
2519 struct option *long_options,
2520 int i, int option_type)
2521{
2522 struct fio_option *o = &opts[0];
2523 while (o->name) {
2524 add_to_lopt(&long_options[i], o, o->name, option_type);
2525 if (o->alias) {
2526 i++;
2527 add_to_lopt(&long_options[i], o, o->alias, option_type);
2528 }
2529
2530 i++;
2531 o++;
2532 assert(i < FIO_NR_OPTIONS);
2533 }
2534}
2535
2536void fio_options_set_ioengine_opts(struct option *long_options,
2537 struct thread_data *td)
2538{
2539 unsigned int i;
2540
2541 i = 0;
2542 while (long_options[i].name) {
2543 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2544 memset(&long_options[i], 0, sizeof(*long_options));
2545 break;
2546 }
2547 i++;
2548 }
2549
2550 /*
2551 * Just clear out the prior ioengine options.
2552 */
2553 if (!td || !td->eo)
2554 return;
2555
2556 options_to_lopts(td->io_ops->options, long_options, i,
2557 FIO_GETOPT_IOENGINE);
2558}
2559
2560void fio_options_dup_and_init(struct option *long_options)
2561{
2562 unsigned int i;
2563
2564 options_init(fio_options);
2565
2566 i = 0;
2567 while (long_options[i].name)
2568 i++;
2569
2570 options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
2571}
2572
2573struct fio_keyword {
2574 const char *word;
2575 const char *desc;
2576 char *replace;
2577};
2578
2579static struct fio_keyword fio_keywords[] = {
2580 {
2581 .word = "$pagesize",
2582 .desc = "Page size in the system",
2583 },
2584 {
2585 .word = "$mb_memory",
2586 .desc = "Megabytes of memory online",
2587 },
2588 {
2589 .word = "$ncpus",
2590 .desc = "Number of CPUs online in the system",
2591 },
2592 {
2593 .word = NULL,
2594 },
2595};
2596
2597void fio_keywords_init(void)
2598{
2599 unsigned long long mb_memory;
2600 char buf[128];
2601 long l;
2602
2603 sprintf(buf, "%lu", page_size);
2604 fio_keywords[0].replace = strdup(buf);
2605
2606 mb_memory = os_phys_mem() / (1024 * 1024);
2607 sprintf(buf, "%llu", mb_memory);
2608 fio_keywords[1].replace = strdup(buf);
2609
2610 l = cpus_online();
2611 sprintf(buf, "%lu", l);
2612 fio_keywords[2].replace = strdup(buf);
2613}
2614
2615#define BC_APP "bc"
2616
2617static char *bc_calc(char *str)
2618{
2619 char buf[128], *tmp;
2620 FILE *f;
2621 int ret;
2622
2623 /*
2624 * No math, just return string
2625 */
2626 if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2627 !strchr(str, '/')) || strchr(str, '\''))
2628 return str;
2629
2630 /*
2631 * Split option from value, we only need to calculate the value
2632 */
2633 tmp = strchr(str, '=');
2634 if (!tmp)
2635 return str;
2636
2637 tmp++;
2638
2639 /*
2640 * Prevent buffer overflows; such a case isn't reasonable anyway
2641 */
2642 if (strlen(str) >= 128 || strlen(tmp) > 100)
2643 return str;
2644
2645 sprintf(buf, "which %s > /dev/null", BC_APP);
2646 if (system(buf)) {
2647 log_err("fio: bc is needed for performing math\n");
2648 return NULL;
2649 }
2650
2651 sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
2652 f = popen(buf, "r");
2653 if (!f) {
2654 return NULL;
2655 }
2656
2657 ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
2658 if (ret <= 0) {
2659 return NULL;
2660 }
2661
2662 pclose(f);
2663 buf[(tmp - str) + ret - 1] = '\0';
2664 memcpy(buf, str, tmp - str);
2665 free(str);
2666 return strdup(buf);
2667}
2668
2669/*
2670 * Return a copy of the input string with substrings of the form ${VARNAME}
2671 * substituted with the value of the environment variable VARNAME. The
2672 * substitution always occurs, even if VARNAME is empty or the corresponding
2673 * environment variable undefined.
2674 */
2675static char *option_dup_subs(const char *opt)
2676{
2677 char out[OPT_LEN_MAX+1];
2678 char in[OPT_LEN_MAX+1];
2679 char *outptr = out;
2680 char *inptr = in;
2681 char *ch1, *ch2, *env;
2682 ssize_t nchr = OPT_LEN_MAX;
2683 size_t envlen;
2684
2685 if (strlen(opt) + 1 > OPT_LEN_MAX) {
2686 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2687 return NULL;
2688 }
2689
2690 in[OPT_LEN_MAX] = '\0';
2691 strncpy(in, opt, OPT_LEN_MAX);
2692
2693 while (*inptr && nchr > 0) {
2694 if (inptr[0] == '$' && inptr[1] == '{') {
2695 ch2 = strchr(inptr, '}');
2696 if (ch2 && inptr+1 < ch2) {
2697 ch1 = inptr+2;
2698 inptr = ch2+1;
2699 *ch2 = '\0';
2700
2701 env = getenv(ch1);
2702 if (env) {
2703 envlen = strlen(env);
2704 if (envlen <= nchr) {
2705 memcpy(outptr, env, envlen);
2706 outptr += envlen;
2707 nchr -= envlen;
2708 }
2709 }
2710
2711 continue;
2712 }
2713 }
2714
2715 *outptr++ = *inptr++;
2716 --nchr;
2717 }
2718
2719 *outptr = '\0';
2720 return strdup(out);
2721}
2722
2723/*
2724 * Look for reserved variable names and replace them with real values
2725 */
2726static char *fio_keyword_replace(char *opt)
2727{
2728 char *s;
2729 int i;
2730 int docalc = 0;
2731
2732 for (i = 0; fio_keywords[i].word != NULL; i++) {
2733 struct fio_keyword *kw = &fio_keywords[i];
2734
2735 while ((s = strstr(opt, kw->word)) != NULL) {
2736 char *new = malloc(strlen(opt) + 1);
2737 char *o_org = opt;
2738 int olen = s - opt;
2739 int len;
2740
2741 /*
2742 * Copy part of the string before the keyword and
2743 * sprintf() the replacement after it.
2744 */
2745 memcpy(new, opt, olen);
2746 len = sprintf(new + olen, "%s", kw->replace);
2747
2748 /*
2749 * If there's more in the original string, copy that
2750 * in too
2751 */
2752 opt += strlen(kw->word) + olen;
2753 if (strlen(opt))
2754 memcpy(new + olen + len, opt, opt - o_org - 1);
2755
2756 /*
2757 * replace opt and free the old opt
2758 */
2759 opt = new;
2760 free(o_org);
2761
2762 docalc = 1;
2763 }
2764 }
2765
2766 /*
2767 * Check for potential math and invoke bc, if possible
2768 */
2769 if (docalc)
2770 opt = bc_calc(opt);
2771
2772 return opt;
2773}
2774
2775static char **dup_and_sub_options(char **opts, int num_opts)
2776{
2777 int i;
2778 char **opts_copy = malloc(num_opts * sizeof(*opts));
2779 for (i = 0; i < num_opts; i++) {
2780 opts_copy[i] = option_dup_subs(opts[i]);
2781 if (!opts_copy[i])
2782 continue;
2783 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2784 }
2785 return opts_copy;
2786}
2787
2788int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2789{
2790 int i, ret, unknown;
2791 char **opts_copy;
2792
2793 sort_options(opts, fio_options, num_opts);
2794 opts_copy = dup_and_sub_options(opts, num_opts);
2795
2796 for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
2797 struct fio_option *o;
2798 int newret = parse_option(opts_copy[i], opts[i], fio_options,
2799 &o, td);
2800
2801 if (opts_copy[i]) {
2802 if (newret && !o) {
2803 unknown++;
2804 continue;
2805 }
2806 free(opts_copy[i]);
2807 opts_copy[i] = NULL;
2808 }
2809
2810 ret |= newret;
2811 }
2812
2813 if (unknown) {
2814 ret |= ioengine_load(td);
2815 if (td->eo) {
2816 sort_options(opts_copy, td->io_ops->options, num_opts);
2817 opts = opts_copy;
2818 }
2819 for (i = 0; i < num_opts; i++) {
2820 struct fio_option *o = NULL;
2821 int newret = 1;
2822 if (!opts_copy[i])
2823 continue;
2824
2825 if (td->eo)
2826 newret = parse_option(opts_copy[i], opts[i],
2827 td->io_ops->options, &o,
2828 td->eo);
2829
2830 ret |= newret;
2831 if (!o)
2832 log_err("Bad option <%s>\n", opts[i]);
2833
2834 free(opts_copy[i]);
2835 opts_copy[i] = NULL;
2836 }
2837 }
2838
2839 free(opts_copy);
2840 return ret;
2841}
2842
2843int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2844{
2845 return parse_cmd_option(opt, val, fio_options, td);
2846}
2847
2848int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
2849 char *val)
2850{
2851 return parse_cmd_option(opt, val, td->io_ops->options, td);
2852}
2853
2854void fio_fill_default_options(struct thread_data *td)
2855{
2856 fill_default_options(td, fio_options);
2857}
2858
2859int fio_show_option_help(const char *opt)
2860{
2861 return show_cmd_help(fio_options, opt);
2862}
2863
2864void options_mem_dupe(void *data, struct fio_option *options)
2865{
2866 struct fio_option *o;
2867 char **ptr;
2868
2869 for (o = &options[0]; o->name; o++) {
2870 if (o->type != FIO_OPT_STR_STORE)
2871 continue;
2872
2873 ptr = td_var(data, o->off1);
2874 if (*ptr)
2875 *ptr = strdup(*ptr);
2876 }
2877}
2878
2879/*
2880 * dupe FIO_OPT_STR_STORE options
2881 */
2882void fio_options_mem_dupe(struct thread_data *td)
2883{
2884 options_mem_dupe(&td->o, fio_options);
2885
2886 if (td->eo && td->io_ops) {
2887 void *oldeo = td->eo;
2888
2889 td->eo = malloc(td->io_ops->option_struct_size);
2890 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
2891 options_mem_dupe(td->eo, td->io_ops->options);
2892 }
2893}
2894
2895unsigned int fio_get_kb_base(void *data)
2896{
2897 struct thread_data *td = data;
2898 unsigned int kb_base = 0;
2899
2900 if (td)
2901 kb_base = td->o.kb_base;
2902 if (!kb_base)
2903 kb_base = 1024;
2904
2905 return kb_base;
2906}
2907
2908int add_option(struct fio_option *o)
2909{
2910 struct fio_option *__o;
2911 int opt_index = 0;
2912
2913 __o = fio_options;
2914 while (__o->name) {
2915 opt_index++;
2916 __o++;
2917 }
2918
2919 memcpy(&fio_options[opt_index], o, sizeof(*o));
2920 return 0;
2921}
2922
2923void invalidate_profile_options(const char *prof_name)
2924{
2925 struct fio_option *o;
2926
2927 o = fio_options;
2928 while (o->name) {
2929 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2930 o->type = FIO_OPT_INVALID;
2931 o->prof_name = NULL;
2932 }
2933 o++;
2934 }
2935}
2936
2937void add_opt_posval(const char *optname, const char *ival, const char *help)
2938{
2939 struct fio_option *o;
2940 unsigned int i;
2941
2942 o = find_option(fio_options, optname);
2943 if (!o)
2944 return;
2945
2946 for (i = 0; i < PARSE_MAX_VP; i++) {
2947 if (o->posval[i].ival)
2948 continue;
2949
2950 o->posval[i].ival = ival;
2951 o->posval[i].help = help;
2952 break;
2953 }
2954}
2955
2956void del_opt_posval(const char *optname, const char *ival)
2957{
2958 struct fio_option *o;
2959 unsigned int i;
2960
2961 o = find_option(fio_options, optname);
2962 if (!o)
2963 return;
2964
2965 for (i = 0; i < PARSE_MAX_VP; i++) {
2966 if (!o->posval[i].ival)
2967 continue;
2968 if (strcmp(o->posval[i].ival, ival))
2969 continue;
2970
2971 o->posval[i].ival = NULL;
2972 o->posval[i].help = NULL;
2973 }
2974}
2975
2976void fio_options_free(struct thread_data *td)
2977{
2978 options_free(fio_options, td);
2979 if (td->eo && td->io_ops && td->io_ops->options) {
2980 options_free(td->io_ops->options, td->eo);
2981 free(td->eo);
2982 td->eo = NULL;
2983 }
2984}