Add FIO_OPT_G_IO_ENG category
[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 .def = "1",
1174 .category = FIO_OPT_G_IO,
1175 },
1176 {
1177 .name = "iodepth_batch",
1178 .alias = "iodepth_batch_submit",
1179 .type = FIO_OPT_INT,
1180 .off1 = td_var_offset(iodepth_batch),
1181 .help = "Number of IO buffers to submit in one go",
1182 .parent = "iodepth",
1183 .minval = 1,
1184 .def = "1",
1185 .category = FIO_OPT_G_IO,
1186 },
1187 {
1188 .name = "iodepth_batch_complete",
1189 .type = FIO_OPT_INT,
1190 .off1 = td_var_offset(iodepth_batch_complete),
1191 .help = "Number of IO buffers to retrieve in one go",
1192 .parent = "iodepth",
1193 .minval = 0,
1194 .def = "1",
1195 .category = FIO_OPT_G_IO,
1196 },
1197 {
1198 .name = "iodepth_low",
1199 .type = FIO_OPT_INT,
1200 .off1 = td_var_offset(iodepth_low),
1201 .help = "Low water mark for queuing depth",
1202 .parent = "iodepth",
1203 .category = FIO_OPT_G_IO,
1204 },
1205 {
1206 .name = "size",
1207 .type = FIO_OPT_STR_VAL,
1208 .cb = str_size_cb,
1209 .help = "Total size of device or files",
1210 .category = FIO_OPT_G_IO,
1211 },
1212 {
1213 .name = "fill_device",
1214 .alias = "fill_fs",
1215 .type = FIO_OPT_BOOL,
1216 .off1 = td_var_offset(fill_device),
1217 .help = "Write until an ENOSPC error occurs",
1218 .def = "0",
1219 .category = FIO_OPT_G_IO,
1220 },
1221 {
1222 .name = "filesize",
1223 .type = FIO_OPT_STR_VAL,
1224 .off1 = td_var_offset(file_size_low),
1225 .off2 = td_var_offset(file_size_high),
1226 .minval = 1,
1227 .help = "Size of individual files",
1228 .category = FIO_OPT_G_IO | FIO_OPT_G_FILE,
1229 },
1230 {
1231 .name = "offset",
1232 .alias = "fileoffset",
1233 .type = FIO_OPT_STR_VAL,
1234 .off1 = td_var_offset(start_offset),
1235 .help = "Start IO from this offset",
1236 .def = "0",
1237 .category = FIO_OPT_G_IO,
1238 },
1239 {
1240 .name = "offset_increment",
1241 .type = FIO_OPT_STR_VAL,
1242 .off1 = td_var_offset(offset_increment),
1243 .help = "What is the increment from one offset to the next",
1244 .parent = "offset",
1245 .def = "0",
1246 .category = FIO_OPT_G_IO,
1247 },
1248 {
1249 .name = "bs",
1250 .alias = "blocksize",
1251 .type = FIO_OPT_INT,
1252 .off1 = td_var_offset(bs[DDIR_READ]),
1253 .off2 = td_var_offset(bs[DDIR_WRITE]),
1254 .minval = 1,
1255 .help = "Block size unit",
1256 .def = "4k",
1257 .parent = "rw",
1258 .category = FIO_OPT_G_IO,
1259 },
1260 {
1261 .name = "ba",
1262 .alias = "blockalign",
1263 .type = FIO_OPT_INT,
1264 .off1 = td_var_offset(ba[DDIR_READ]),
1265 .off2 = td_var_offset(ba[DDIR_WRITE]),
1266 .minval = 1,
1267 .help = "IO block offset alignment",
1268 .parent = "rw",
1269 .category = FIO_OPT_G_IO | FIO_OPT_G_IO_BUF,
1270 },
1271 {
1272 .name = "bsrange",
1273 .alias = "blocksize_range",
1274 .type = FIO_OPT_RANGE,
1275 .off1 = td_var_offset(min_bs[DDIR_READ]),
1276 .off2 = td_var_offset(max_bs[DDIR_READ]),
1277 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1278 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1279 .minval = 1,
1280 .help = "Set block size range (in more detail than bs)",
1281 .parent = "rw",
1282 .category = FIO_OPT_G_IO,
1283 },
1284 {
1285 .name = "bssplit",
1286 .type = FIO_OPT_STR,
1287 .cb = str_bssplit_cb,
1288 .help = "Set a specific mix of block sizes",
1289 .parent = "rw",
1290 .category = FIO_OPT_G_IO,
1291 },
1292 {
1293 .name = "bs_unaligned",
1294 .alias = "blocksize_unaligned",
1295 .type = FIO_OPT_STR_SET,
1296 .off1 = td_var_offset(bs_unaligned),
1297 .help = "Don't sector align IO buffer sizes",
1298 .parent = "rw",
1299 .category = FIO_OPT_G_IO,
1300 },
1301 {
1302 .name = "randrepeat",
1303 .type = FIO_OPT_BOOL,
1304 .off1 = td_var_offset(rand_repeatable),
1305 .help = "Use repeatable random IO pattern",
1306 .def = "1",
1307 .parent = "rw",
1308 .category = FIO_OPT_G_IO | FIO_OPT_G_RAND,
1309 },
1310 {
1311 .name = "use_os_rand",
1312 .type = FIO_OPT_BOOL,
1313 .off1 = td_var_offset(use_os_rand),
1314 .help = "Set to use OS random generator",
1315 .def = "0",
1316 .parent = "rw",
1317 .category = FIO_OPT_G_RAND,
1318 },
1319 {
1320 .name = "norandommap",
1321 .type = FIO_OPT_STR_SET,
1322 .off1 = td_var_offset(norandommap),
1323 .help = "Accept potential duplicate random blocks",
1324 .parent = "rw",
1325 .category = FIO_OPT_G_RAND,
1326 },
1327 {
1328 .name = "softrandommap",
1329 .type = FIO_OPT_BOOL,
1330 .off1 = td_var_offset(softrandommap),
1331 .help = "Set norandommap if randommap allocation fails",
1332 .parent = "norandommap",
1333 .def = "0",
1334 .category = FIO_OPT_G_RAND,
1335 },
1336 {
1337 .name = "nrfiles",
1338 .alias = "nr_files",
1339 .type = FIO_OPT_INT,
1340 .off1 = td_var_offset(nr_files),
1341 .help = "Split job workload between this number of files",
1342 .def = "1",
1343 .category = FIO_OPT_G_FILE,
1344 },
1345 {
1346 .name = "openfiles",
1347 .type = FIO_OPT_INT,
1348 .off1 = td_var_offset(open_files),
1349 .help = "Number of files to keep open at the same time",
1350 .category = FIO_OPT_G_FILE,
1351 },
1352 {
1353 .name = "file_service_type",
1354 .type = FIO_OPT_STR,
1355 .cb = str_fst_cb,
1356 .off1 = td_var_offset(file_service_type),
1357 .help = "How to select which file to service next",
1358 .def = "roundrobin",
1359 .category = FIO_OPT_G_FILE,
1360 .posval = {
1361 { .ival = "random",
1362 .oval = FIO_FSERVICE_RANDOM,
1363 .help = "Choose a file at random",
1364 },
1365 { .ival = "roundrobin",
1366 .oval = FIO_FSERVICE_RR,
1367 .help = "Round robin select files",
1368 },
1369 { .ival = "sequential",
1370 .oval = FIO_FSERVICE_SEQ,
1371 .help = "Finish one file before moving to the next",
1372 },
1373 },
1374 .parent = "nrfiles",
1375 },
1376#ifdef FIO_HAVE_FALLOCATE
1377 {
1378 .name = "fallocate",
1379 .type = FIO_OPT_STR,
1380 .off1 = td_var_offset(fallocate_mode),
1381 .help = "Whether pre-allocation is performed when laying out files",
1382 .def = "posix",
1383 .category = FIO_OPT_G_FILE,
1384 .posval = {
1385 { .ival = "none",
1386 .oval = FIO_FALLOCATE_NONE,
1387 .help = "Do not pre-allocate space",
1388 },
1389 { .ival = "posix",
1390 .oval = FIO_FALLOCATE_POSIX,
1391 .help = "Use posix_fallocate()",
1392 },
1393#ifdef FIO_HAVE_LINUX_FALLOCATE
1394 { .ival = "keep",
1395 .oval = FIO_FALLOCATE_KEEP_SIZE,
1396 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1397 },
1398#endif
1399 /* Compatibility with former boolean values */
1400 { .ival = "0",
1401 .oval = FIO_FALLOCATE_NONE,
1402 .help = "Alias for 'none'",
1403 },
1404 { .ival = "1",
1405 .oval = FIO_FALLOCATE_POSIX,
1406 .help = "Alias for 'posix'",
1407 },
1408 },
1409 },
1410#endif /* FIO_HAVE_FALLOCATE */
1411 {
1412 .name = "fadvise_hint",
1413 .type = FIO_OPT_BOOL,
1414 .off1 = td_var_offset(fadvise_hint),
1415 .help = "Use fadvise() to advise the kernel on IO pattern",
1416 .def = "1",
1417 .category = FIO_OPT_G_FILE,
1418 },
1419 {
1420 .name = "fsync",
1421 .type = FIO_OPT_INT,
1422 .off1 = td_var_offset(fsync_blocks),
1423 .help = "Issue fsync for writes every given number of blocks",
1424 .def = "0",
1425 .category = FIO_OPT_G_FILE,
1426 },
1427 {
1428 .name = "fdatasync",
1429 .type = FIO_OPT_INT,
1430 .off1 = td_var_offset(fdatasync_blocks),
1431 .help = "Issue fdatasync for writes every given number of blocks",
1432 .def = "0",
1433 .category = FIO_OPT_G_FILE,
1434 },
1435 {
1436 .name = "write_barrier",
1437 .type = FIO_OPT_INT,
1438 .off1 = td_var_offset(barrier_blocks),
1439 .help = "Make every Nth write a barrier write",
1440 .def = "0",
1441 .category = FIO_OPT_G_IO,
1442 },
1443#ifdef FIO_HAVE_SYNC_FILE_RANGE
1444 {
1445 .name = "sync_file_range",
1446 .posval = {
1447 { .ival = "wait_before",
1448 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1449 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1450 .or = 1,
1451 },
1452 { .ival = "write",
1453 .oval = SYNC_FILE_RANGE_WRITE,
1454 .help = "SYNC_FILE_RANGE_WRITE",
1455 .or = 1,
1456 },
1457 {
1458 .ival = "wait_after",
1459 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1460 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1461 .or = 1,
1462 },
1463 },
1464 .type = FIO_OPT_STR_MULTI,
1465 .cb = str_sfr_cb,
1466 .off1 = td_var_offset(sync_file_range),
1467 .help = "Use sync_file_range()",
1468 .category = FIO_OPT_G_FILE,
1469 },
1470#endif
1471 {
1472 .name = "direct",
1473 .type = FIO_OPT_BOOL,
1474 .off1 = td_var_offset(odirect),
1475 .help = "Use O_DIRECT IO (negates buffered)",
1476 .def = "0",
1477 .category = FIO_OPT_G_IO,
1478 },
1479 {
1480 .name = "buffered",
1481 .type = FIO_OPT_BOOL,
1482 .off1 = td_var_offset(odirect),
1483 .neg = 1,
1484 .help = "Use buffered IO (negates direct)",
1485 .def = "1",
1486 .category = FIO_OPT_G_IO,
1487 },
1488 {
1489 .name = "overwrite",
1490 .type = FIO_OPT_BOOL,
1491 .off1 = td_var_offset(overwrite),
1492 .help = "When writing, set whether to overwrite current data",
1493 .def = "0",
1494 .category = FIO_OPT_G_IO | FIO_OPT_G_FILE,
1495 },
1496 {
1497 .name = "loops",
1498 .type = FIO_OPT_INT,
1499 .off1 = td_var_offset(loops),
1500 .help = "Number of times to run the job",
1501 .def = "1",
1502 .category = FIO_OPT_G_MISC,
1503 },
1504 {
1505 .name = "numjobs",
1506 .type = FIO_OPT_INT,
1507 .off1 = td_var_offset(numjobs),
1508 .help = "Duplicate this job this many times",
1509 .def = "1",
1510 .category = FIO_OPT_G_MISC,
1511 },
1512 {
1513 .name = "startdelay",
1514 .type = FIO_OPT_STR_VAL_TIME,
1515 .off1 = td_var_offset(start_delay),
1516 .help = "Only start job when this period has passed",
1517 .def = "0",
1518 .category = FIO_OPT_G_MISC,
1519 },
1520 {
1521 .name = "runtime",
1522 .alias = "timeout",
1523 .type = FIO_OPT_STR_VAL_TIME,
1524 .off1 = td_var_offset(timeout),
1525 .help = "Stop workload when this amount of time has passed",
1526 .def = "0",
1527 .category = FIO_OPT_G_MISC,
1528 },
1529 {
1530 .name = "time_based",
1531 .type = FIO_OPT_STR_SET,
1532 .off1 = td_var_offset(time_based),
1533 .help = "Keep running until runtime/timeout is met",
1534 .category = FIO_OPT_G_MISC,
1535 },
1536 {
1537 .name = "ramp_time",
1538 .type = FIO_OPT_STR_VAL_TIME,
1539 .off1 = td_var_offset(ramp_time),
1540 .help = "Ramp up time before measuring performance",
1541 .category = FIO_OPT_G_MISC,
1542 },
1543 {
1544 .name = "clocksource",
1545 .type = FIO_OPT_STR,
1546 .cb = fio_clock_source_cb,
1547 .off1 = td_var_offset(clocksource),
1548 .help = "What type of timing source to use",
1549 .category = FIO_OPT_G_OS,
1550 .posval = {
1551 { .ival = "gettimeofday",
1552 .oval = CS_GTOD,
1553 .help = "Use gettimeofday(2) for timing",
1554 },
1555 { .ival = "clock_gettime",
1556 .oval = CS_CGETTIME,
1557 .help = "Use clock_gettime(2) for timing",
1558 },
1559#ifdef ARCH_HAVE_CPU_CLOCK
1560 { .ival = "cpu",
1561 .oval = CS_CPUCLOCK,
1562 .help = "Use CPU private clock",
1563 },
1564#endif
1565 },
1566 },
1567 {
1568 .name = "mem",
1569 .alias = "iomem",
1570 .type = FIO_OPT_STR,
1571 .cb = str_mem_cb,
1572 .off1 = td_var_offset(mem_type),
1573 .help = "Backing type for IO buffers",
1574 .def = "malloc",
1575 .category = FIO_OPT_G_IO_BUF | FIO_OPT_G_MEM,
1576 .posval = {
1577 { .ival = "malloc",
1578 .oval = MEM_MALLOC,
1579 .help = "Use malloc(3) for IO buffers",
1580 },
1581 { .ival = "shm",
1582 .oval = MEM_SHM,
1583 .help = "Use shared memory segments for IO buffers",
1584 },
1585#ifdef FIO_HAVE_HUGETLB
1586 { .ival = "shmhuge",
1587 .oval = MEM_SHMHUGE,
1588 .help = "Like shm, but use huge pages",
1589 },
1590#endif
1591 { .ival = "mmap",
1592 .oval = MEM_MMAP,
1593 .help = "Use mmap(2) (file or anon) for IO buffers",
1594 },
1595#ifdef FIO_HAVE_HUGETLB
1596 { .ival = "mmaphuge",
1597 .oval = MEM_MMAPHUGE,
1598 .help = "Like mmap, but use huge pages",
1599 },
1600#endif
1601 },
1602 },
1603 {
1604 .name = "iomem_align",
1605 .alias = "mem_align",
1606 .type = FIO_OPT_INT,
1607 .off1 = td_var_offset(mem_align),
1608 .minval = 0,
1609 .help = "IO memory buffer offset alignment",
1610 .def = "0",
1611 .parent = "iomem",
1612 .category = FIO_OPT_G_IO_BUF | FIO_OPT_G_MEM,
1613 },
1614 {
1615 .name = "verify",
1616 .type = FIO_OPT_STR,
1617 .off1 = td_var_offset(verify),
1618 .help = "Verify data written",
1619 .cb = str_verify_cb,
1620 .def = "0",
1621 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1622 .posval = {
1623 { .ival = "0",
1624 .oval = VERIFY_NONE,
1625 .help = "Don't do IO verification",
1626 },
1627 { .ival = "md5",
1628 .oval = VERIFY_MD5,
1629 .help = "Use md5 checksums for verification",
1630 },
1631 { .ival = "crc64",
1632 .oval = VERIFY_CRC64,
1633 .help = "Use crc64 checksums for verification",
1634 },
1635 { .ival = "crc32",
1636 .oval = VERIFY_CRC32,
1637 .help = "Use crc32 checksums for verification",
1638 },
1639 { .ival = "crc32c-intel",
1640 .oval = VERIFY_CRC32C,
1641 .help = "Use crc32c checksums for verification (hw assisted, if available)",
1642 },
1643 { .ival = "crc32c",
1644 .oval = VERIFY_CRC32C,
1645 .help = "Use crc32c checksums for verification (hw assisted, if available)",
1646 },
1647 { .ival = "crc16",
1648 .oval = VERIFY_CRC16,
1649 .help = "Use crc16 checksums for verification",
1650 },
1651 { .ival = "crc7",
1652 .oval = VERIFY_CRC7,
1653 .help = "Use crc7 checksums for verification",
1654 },
1655 { .ival = "sha1",
1656 .oval = VERIFY_SHA1,
1657 .help = "Use sha1 checksums for verification",
1658 },
1659 { .ival = "sha256",
1660 .oval = VERIFY_SHA256,
1661 .help = "Use sha256 checksums for verification",
1662 },
1663 { .ival = "sha512",
1664 .oval = VERIFY_SHA512,
1665 .help = "Use sha512 checksums for verification",
1666 },
1667 { .ival = "meta",
1668 .oval = VERIFY_META,
1669 .help = "Use io information",
1670 },
1671 {
1672 .ival = "null",
1673 .oval = VERIFY_NULL,
1674 .help = "Pretend to verify",
1675 },
1676 },
1677 },
1678 {
1679 .name = "do_verify",
1680 .type = FIO_OPT_BOOL,
1681 .off1 = td_var_offset(do_verify),
1682 .help = "Run verification stage after write",
1683 .def = "1",
1684 .parent = "verify",
1685 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1686 },
1687 {
1688 .name = "verifysort",
1689 .type = FIO_OPT_BOOL,
1690 .off1 = td_var_offset(verifysort),
1691 .help = "Sort written verify blocks for read back",
1692 .def = "1",
1693 .parent = "verify",
1694 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1695 },
1696 {
1697 .name = "verify_interval",
1698 .type = FIO_OPT_INT,
1699 .off1 = td_var_offset(verify_interval),
1700 .minval = 2 * sizeof(struct verify_header),
1701 .help = "Store verify buffer header every N bytes",
1702 .parent = "verify",
1703 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1704 },
1705 {
1706 .name = "verify_offset",
1707 .type = FIO_OPT_INT,
1708 .help = "Offset verify header location by N bytes",
1709 .def = "0",
1710 .cb = str_verify_offset_cb,
1711 .parent = "verify",
1712 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1713 },
1714 {
1715 .name = "verify_pattern",
1716 .type = FIO_OPT_STR,
1717 .cb = str_verify_pattern_cb,
1718 .help = "Fill pattern for IO buffers",
1719 .parent = "verify",
1720 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1721 },
1722 {
1723 .name = "verify_fatal",
1724 .type = FIO_OPT_BOOL,
1725 .off1 = td_var_offset(verify_fatal),
1726 .def = "0",
1727 .help = "Exit on a single verify failure, don't continue",
1728 .parent = "verify",
1729 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY | FIO_OPT_G_ERR,
1730 },
1731 {
1732 .name = "verify_dump",
1733 .type = FIO_OPT_BOOL,
1734 .off1 = td_var_offset(verify_dump),
1735 .def = "0",
1736 .help = "Dump contents of good and bad blocks on failure",
1737 .parent = "verify",
1738 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY | FIO_OPT_G_ERR,
1739 },
1740 {
1741 .name = "verify_async",
1742 .type = FIO_OPT_INT,
1743 .off1 = td_var_offset(verify_async),
1744 .def = "0",
1745 .help = "Number of async verifier threads to use",
1746 .parent = "verify",
1747 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1748 },
1749 {
1750 .name = "verify_backlog",
1751 .type = FIO_OPT_STR_VAL,
1752 .off1 = td_var_offset(verify_backlog),
1753 .help = "Verify after this number of blocks are written",
1754 .parent = "verify",
1755 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1756 },
1757 {
1758 .name = "verify_backlog_batch",
1759 .type = FIO_OPT_INT,
1760 .off1 = td_var_offset(verify_batch),
1761 .help = "Verify this number of IO blocks",
1762 .parent = "verify",
1763 .category = FIO_OPT_G_IO | FIO_OPT_G_VERIFY,
1764 },
1765#ifdef FIO_HAVE_CPU_AFFINITY
1766 {
1767 .name = "verify_async_cpus",
1768 .type = FIO_OPT_STR,
1769 .cb = str_verify_cpus_allowed_cb,
1770 .help = "Set CPUs allowed for async verify threads",
1771 .parent = "verify_async",
1772 .category = FIO_OPT_G_OS | FIO_OPT_G_CPU | FIO_OPT_G_VERIFY,
1773 },
1774#endif
1775#ifdef FIO_HAVE_TRIM
1776 {
1777 .name = "trim_percentage",
1778 .type = FIO_OPT_INT,
1779 .cb = str_verify_trim_cb,
1780 .maxval = 100,
1781 .help = "Number of verify blocks to discard/trim",
1782 .parent = "verify",
1783 .def = "0",
1784 .category = FIO_OPT_G_IO,
1785 },
1786 {
1787 .name = "trim_verify_zero",
1788 .type = FIO_OPT_INT,
1789 .help = "Verify that trim/discarded blocks are returned as zeroes",
1790 .off1 = td_var_offset(trim_zero),
1791 .parent = "trim_percentage",
1792 .def = "1",
1793 .category = FIO_OPT_G_IO,
1794 },
1795 {
1796 .name = "trim_backlog",
1797 .type = FIO_OPT_STR_VAL,
1798 .off1 = td_var_offset(trim_backlog),
1799 .help = "Trim after this number of blocks are written",
1800 .parent = "trim_percentage",
1801 .category = FIO_OPT_G_IO,
1802 },
1803 {
1804 .name = "trim_backlog_batch",
1805 .type = FIO_OPT_INT,
1806 .off1 = td_var_offset(trim_batch),
1807 .help = "Trim this number of IO blocks",
1808 .parent = "trim_percentage",
1809 .category = FIO_OPT_G_IO,
1810 },
1811#endif
1812 {
1813 .name = "write_iolog",
1814 .type = FIO_OPT_STR_STORE,
1815 .off1 = td_var_offset(write_iolog_file),
1816 .help = "Store IO pattern to file",
1817 .category = FIO_OPT_G_IO | FIO_OPT_G_LOG,
1818 },
1819 {
1820 .name = "read_iolog",
1821 .type = FIO_OPT_STR_STORE,
1822 .off1 = td_var_offset(read_iolog_file),
1823 .help = "Playback IO pattern from file",
1824 .category = FIO_OPT_G_IO | FIO_OPT_G_LOG,
1825 },
1826 {
1827 .name = "replay_no_stall",
1828 .type = FIO_OPT_INT,
1829 .off1 = td_var_offset(no_stall),
1830 .def = "0",
1831 .parent = "read_iolog",
1832 .help = "Playback IO pattern file as fast as possible without stalls",
1833 .category = FIO_OPT_G_IO | FIO_OPT_G_LOG,
1834 },
1835 {
1836 .name = "replay_redirect",
1837 .type = FIO_OPT_STR_STORE,
1838 .off1 = td_var_offset(replay_redirect),
1839 .parent = "read_iolog",
1840 .help = "Replay all I/O onto this device, regardless of trace device",
1841 .category = FIO_OPT_G_IO | FIO_OPT_G_LOG,
1842 },
1843 {
1844 .name = "exec_prerun",
1845 .type = FIO_OPT_STR_STORE,
1846 .off1 = td_var_offset(exec_prerun),
1847 .help = "Execute this file prior to running job",
1848 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
1849 },
1850 {
1851 .name = "exec_postrun",
1852 .type = FIO_OPT_STR_STORE,
1853 .off1 = td_var_offset(exec_postrun),
1854 .help = "Execute this file after running job",
1855 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
1856 },
1857#ifdef FIO_HAVE_IOSCHED_SWITCH
1858 {
1859 .name = "ioscheduler",
1860 .type = FIO_OPT_STR_STORE,
1861 .off1 = td_var_offset(ioscheduler),
1862 .help = "Use this IO scheduler on the backing device",
1863 .category = FIO_OPT_G_OS | FIO_OPT_G_IO,
1864 },
1865#endif
1866 {
1867 .name = "zonesize",
1868 .type = FIO_OPT_STR_VAL,
1869 .off1 = td_var_offset(zone_size),
1870 .help = "Amount of data to read per zone",
1871 .def = "0",
1872 .category = FIO_OPT_G_IO | FIO_OPT_G_ZONE,
1873 },
1874 {
1875 .name = "zonerange",
1876 .type = FIO_OPT_STR_VAL,
1877 .off1 = td_var_offset(zone_range),
1878 .help = "Give size of an IO zone",
1879 .def = "0",
1880 .category = FIO_OPT_G_IO | FIO_OPT_G_ZONE,
1881 },
1882 {
1883 .name = "zoneskip",
1884 .type = FIO_OPT_STR_VAL,
1885 .off1 = td_var_offset(zone_skip),
1886 .help = "Space between IO zones",
1887 .def = "0",
1888 .category = FIO_OPT_G_IO | FIO_OPT_G_ZONE,
1889 },
1890 {
1891 .name = "lockmem",
1892 .type = FIO_OPT_STR_VAL,
1893 .cb = str_lockmem_cb,
1894 .help = "Lock down this amount of memory",
1895 .def = "0",
1896 .category = FIO_OPT_G_OS | FIO_OPT_G_MEM,
1897 },
1898 {
1899 .name = "rwmixread",
1900 .type = FIO_OPT_INT,
1901 .cb = str_rwmix_read_cb,
1902 .maxval = 100,
1903 .help = "Percentage of mixed workload that is reads",
1904 .def = "50",
1905 .category = FIO_OPT_G_IO,
1906 },
1907 {
1908 .name = "rwmixwrite",
1909 .type = FIO_OPT_INT,
1910 .cb = str_rwmix_write_cb,
1911 .maxval = 100,
1912 .help = "Percentage of mixed workload that is writes",
1913 .def = "50",
1914 .category = FIO_OPT_G_IO,
1915 },
1916 {
1917 .name = "rwmixcycle",
1918 .type = FIO_OPT_DEPRECATED,
1919 .category = FIO_OPT_G_IO,
1920 },
1921 {
1922 .name = "nice",
1923 .type = FIO_OPT_INT,
1924 .off1 = td_var_offset(nice),
1925 .help = "Set job CPU nice value",
1926 .minval = -19,
1927 .maxval = 20,
1928 .def = "0",
1929 .category = FIO_OPT_G_OS | FIO_OPT_G_CPU,
1930 },
1931#ifdef FIO_HAVE_IOPRIO
1932 {
1933 .name = "prio",
1934 .type = FIO_OPT_INT,
1935 .cb = str_prio_cb,
1936 .help = "Set job IO priority value",
1937 .minval = 0,
1938 .maxval = 7,
1939 .category = FIO_OPT_G_OS | FIO_OPT_G_CPU,
1940 },
1941 {
1942 .name = "prioclass",
1943 .type = FIO_OPT_INT,
1944 .cb = str_prioclass_cb,
1945 .help = "Set job IO priority class",
1946 .minval = 0,
1947 .maxval = 3,
1948 .category = FIO_OPT_G_OS | FIO_OPT_G_CPU,
1949 },
1950#endif
1951 {
1952 .name = "thinktime",
1953 .type = FIO_OPT_INT,
1954 .off1 = td_var_offset(thinktime),
1955 .help = "Idle time between IO buffers (usec)",
1956 .def = "0",
1957 .category = FIO_OPT_G_MISC,
1958 },
1959 {
1960 .name = "thinktime_spin",
1961 .type = FIO_OPT_INT,
1962 .off1 = td_var_offset(thinktime_spin),
1963 .help = "Start think time by spinning this amount (usec)",
1964 .def = "0",
1965 .parent = "thinktime",
1966 .category = FIO_OPT_G_MISC,
1967 },
1968 {
1969 .name = "thinktime_blocks",
1970 .type = FIO_OPT_INT,
1971 .off1 = td_var_offset(thinktime_blocks),
1972 .help = "IO buffer period between 'thinktime'",
1973 .def = "1",
1974 .parent = "thinktime",
1975 .category = FIO_OPT_G_MISC,
1976 },
1977 {
1978 .name = "rate",
1979 .type = FIO_OPT_INT,
1980 .off1 = td_var_offset(rate[0]),
1981 .off2 = td_var_offset(rate[1]),
1982 .help = "Set bandwidth rate",
1983 .category = FIO_OPT_G_IO,
1984 },
1985 {
1986 .name = "ratemin",
1987 .type = FIO_OPT_INT,
1988 .off1 = td_var_offset(ratemin[0]),
1989 .off2 = td_var_offset(ratemin[1]),
1990 .help = "Job must meet this rate or it will be shutdown",
1991 .parent = "rate",
1992 .category = FIO_OPT_G_IO,
1993 },
1994 {
1995 .name = "rate_iops",
1996 .type = FIO_OPT_INT,
1997 .off1 = td_var_offset(rate_iops[0]),
1998 .off2 = td_var_offset(rate_iops[1]),
1999 .help = "Limit IO used to this number of IO operations/sec",
2000 .category = FIO_OPT_G_IO,
2001 },
2002 {
2003 .name = "rate_iops_min",
2004 .type = FIO_OPT_INT,
2005 .off1 = td_var_offset(rate_iops_min[0]),
2006 .off2 = td_var_offset(rate_iops_min[1]),
2007 .help = "Job must meet this rate or it will be shut down",
2008 .parent = "rate_iops",
2009 .category = FIO_OPT_G_IO,
2010 },
2011 {
2012 .name = "ratecycle",
2013 .type = FIO_OPT_INT,
2014 .off1 = td_var_offset(ratecycle),
2015 .help = "Window average for rate limits (msec)",
2016 .def = "1000",
2017 .parent = "rate",
2018 .category = FIO_OPT_G_IO,
2019 },
2020 {
2021 .name = "invalidate",
2022 .type = FIO_OPT_BOOL,
2023 .off1 = td_var_offset(invalidate_cache),
2024 .help = "Invalidate buffer/page cache prior to running job",
2025 .def = "1",
2026 .category = FIO_OPT_G_IO | FIO_OPT_G_CACHE,
2027 },
2028 {
2029 .name = "sync",
2030 .type = FIO_OPT_BOOL,
2031 .off1 = td_var_offset(sync_io),
2032 .help = "Use O_SYNC for buffered writes",
2033 .def = "0",
2034 .parent = "buffered",
2035 .category = FIO_OPT_G_IO | FIO_OPT_G_FILE,
2036 },
2037 {
2038 .name = "bwavgtime",
2039 .type = FIO_OPT_INT,
2040 .off1 = td_var_offset(bw_avg_time),
2041 .help = "Time window over which to calculate bandwidth"
2042 " (msec)",
2043 .def = "500",
2044 .parent = "write_bw_log",
2045 .category = FIO_OPT_G_LOG | FIO_OPT_G_STAT,
2046 },
2047 {
2048 .name = "iopsavgtime",
2049 .type = FIO_OPT_INT,
2050 .off1 = td_var_offset(iops_avg_time),
2051 .help = "Time window over which to calculate IOPS (msec)",
2052 .def = "500",
2053 .parent = "write_iops_log",
2054 .category = FIO_OPT_G_LOG | FIO_OPT_G_STAT,
2055 },
2056 {
2057 .name = "create_serialize",
2058 .type = FIO_OPT_BOOL,
2059 .off1 = td_var_offset(create_serialize),
2060 .help = "Serialize creating of job files",
2061 .def = "1",
2062 .category = FIO_OPT_G_FILE,
2063 },
2064 {
2065 .name = "create_fsync",
2066 .type = FIO_OPT_BOOL,
2067 .off1 = td_var_offset(create_fsync),
2068 .help = "fsync file after creation",
2069 .def = "1",
2070 .category = FIO_OPT_G_FILE,
2071 },
2072 {
2073 .name = "create_on_open",
2074 .type = FIO_OPT_BOOL,
2075 .off1 = td_var_offset(create_on_open),
2076 .help = "Create files when they are opened for IO",
2077 .def = "0",
2078 .category = FIO_OPT_G_FILE,
2079 },
2080 {
2081 .name = "pre_read",
2082 .type = FIO_OPT_BOOL,
2083 .off1 = td_var_offset(pre_read),
2084 .help = "Pre-read files before starting official testing",
2085 .def = "0",
2086 .category = FIO_OPT_G_FILE | FIO_OPT_G_CACHE,
2087 },
2088 {
2089 .name = "cpuload",
2090 .type = FIO_OPT_INT,
2091 .off1 = td_var_offset(cpuload),
2092 .help = "Use this percentage of CPU",
2093 .category = FIO_OPT_G_CPU,
2094 },
2095 {
2096 .name = "cpuchunks",
2097 .type = FIO_OPT_INT,
2098 .off1 = td_var_offset(cpucycle),
2099 .help = "Length of the CPU burn cycles (usecs)",
2100 .def = "50000",
2101 .parent = "cpuload",
2102 .category = FIO_OPT_G_CPU,
2103 },
2104#ifdef FIO_HAVE_CPU_AFFINITY
2105 {
2106 .name = "cpumask",
2107 .type = FIO_OPT_INT,
2108 .cb = str_cpumask_cb,
2109 .help = "CPU affinity mask",
2110 .category = FIO_OPT_G_CPU | FIO_OPT_G_OS,
2111 },
2112 {
2113 .name = "cpus_allowed",
2114 .type = FIO_OPT_STR,
2115 .cb = str_cpus_allowed_cb,
2116 .help = "Set CPUs allowed",
2117 .category = FIO_OPT_G_CPU | FIO_OPT_G_OS,
2118 },
2119#endif
2120 {
2121 .name = "end_fsync",
2122 .type = FIO_OPT_BOOL,
2123 .off1 = td_var_offset(end_fsync),
2124 .help = "Include fsync at the end of job",
2125 .def = "0",
2126 .category = FIO_OPT_G_FILE,
2127 },
2128 {
2129 .name = "fsync_on_close",
2130 .type = FIO_OPT_BOOL,
2131 .off1 = td_var_offset(fsync_on_close),
2132 .help = "fsync files on close",
2133 .def = "0",
2134 .category = FIO_OPT_G_FILE,
2135 },
2136 {
2137 .name = "unlink",
2138 .type = FIO_OPT_BOOL,
2139 .off1 = td_var_offset(unlink),
2140 .help = "Unlink created files after job has completed",
2141 .def = "0",
2142 .category = FIO_OPT_G_FILE,
2143 },
2144 {
2145 .name = "exitall",
2146 .type = FIO_OPT_STR_SET,
2147 .cb = str_exitall_cb,
2148 .help = "Terminate all jobs when one exits",
2149 .category = FIO_OPT_G_MISC | FIO_OPT_G_JOB,
2150 },
2151 {
2152 .name = "stonewall",
2153 .alias = "wait_for_previous",
2154 .type = FIO_OPT_STR_SET,
2155 .off1 = td_var_offset(stonewall),
2156 .help = "Insert a hard barrier between this job and previous",
2157 .category = FIO_OPT_G_MISC | FIO_OPT_G_JOB,
2158 },
2159 {
2160 .name = "new_group",
2161 .type = FIO_OPT_STR_SET,
2162 .off1 = td_var_offset(new_group),
2163 .help = "Mark the start of a new group (for reporting)",
2164 .category = FIO_OPT_G_MISC | FIO_OPT_G_JOB,
2165 },
2166 {
2167 .name = "thread",
2168 .type = FIO_OPT_STR_SET,
2169 .off1 = td_var_offset(use_thread),
2170 .help = "Use threads instead of forks",
2171 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS | FIO_OPT_G_JOB,
2172 },
2173 {
2174 .name = "write_bw_log",
2175 .type = FIO_OPT_STR,
2176 .off1 = td_var_offset(write_bw_log),
2177 .cb = str_write_bw_log_cb,
2178 .help = "Write log of bandwidth during run",
2179 .category = FIO_OPT_G_LOG,
2180 },
2181 {
2182 .name = "write_lat_log",
2183 .type = FIO_OPT_STR,
2184 .off1 = td_var_offset(write_lat_log),
2185 .cb = str_write_lat_log_cb,
2186 .help = "Write log of latency during run",
2187 .category = FIO_OPT_G_LOG,
2188 },
2189 {
2190 .name = "write_iops_log",
2191 .type = FIO_OPT_STR,
2192 .off1 = td_var_offset(write_iops_log),
2193 .cb = str_write_iops_log_cb,
2194 .help = "Write log of IOPS during run",
2195 .category = FIO_OPT_G_LOG,
2196 },
2197 {
2198 .name = "log_avg_msec",
2199 .type = FIO_OPT_INT,
2200 .off1 = td_var_offset(log_avg_msec),
2201 .help = "Average bw/iops/lat logs over this period of time",
2202 .def = "0",
2203 .category = FIO_OPT_G_LOG,
2204 },
2205 {
2206 .name = "hugepage-size",
2207 .type = FIO_OPT_INT,
2208 .off1 = td_var_offset(hugepage_size),
2209 .help = "When using hugepages, specify size of each page",
2210 .def = __fio_stringify(FIO_HUGE_PAGE),
2211 .category = FIO_OPT_G_OS | FIO_OPT_G_MEM,
2212 },
2213 {
2214 .name = "group_reporting",
2215 .type = FIO_OPT_STR_SET,
2216 .off1 = td_var_offset(group_reporting),
2217 .help = "Do reporting on a per-group basis",
2218 .category = FIO_OPT_G_MISC,
2219 },
2220 {
2221 .name = "zero_buffers",
2222 .type = FIO_OPT_STR_SET,
2223 .off1 = td_var_offset(zero_buffers),
2224 .help = "Init IO buffers to all zeroes",
2225 .category = FIO_OPT_G_IO_BUF,
2226 },
2227 {
2228 .name = "refill_buffers",
2229 .type = FIO_OPT_STR_SET,
2230 .off1 = td_var_offset(refill_buffers),
2231 .help = "Refill IO buffers on every IO submit",
2232 .category = FIO_OPT_G_IO_BUF,
2233 },
2234 {
2235 .name = "scramble_buffers",
2236 .type = FIO_OPT_BOOL,
2237 .off1 = td_var_offset(scramble_buffers),
2238 .help = "Slightly scramble buffers on every IO submit",
2239 .def = "1",
2240 .category = FIO_OPT_G_IO_BUF,
2241 },
2242 {
2243 .name = "buffer_compress_percentage",
2244 .type = FIO_OPT_INT,
2245 .off1 = td_var_offset(compress_percentage),
2246 .maxval = 100,
2247 .minval = 1,
2248 .help = "How compressible the buffer is (approximately)",
2249 .category = FIO_OPT_G_IO_BUF,
2250 },
2251 {
2252 .name = "buffer_compress_chunk",
2253 .type = FIO_OPT_INT,
2254 .off1 = td_var_offset(compress_chunk),
2255 .parent = "buffer_compress_percentage",
2256 .help = "Size of compressible region in buffer",
2257 .category = FIO_OPT_G_IO_BUF,
2258 },
2259 {
2260 .name = "clat_percentiles",
2261 .type = FIO_OPT_BOOL,
2262 .off1 = td_var_offset(clat_percentiles),
2263 .help = "Enable the reporting of completion latency percentiles",
2264 .def = "1",
2265 .category = FIO_OPT_G_STAT,
2266 },
2267 {
2268 .name = "percentile_list",
2269 .type = FIO_OPT_FLOAT_LIST,
2270 .off1 = td_var_offset(percentile_list),
2271 .off2 = td_var_offset(overwrite_plist),
2272 .help = "Specify a custom list of percentiles to report",
2273 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2274 .minfp = 0.0,
2275 .maxfp = 100.0,
2276 .category = FIO_OPT_G_STAT,
2277 },
2278
2279#ifdef FIO_HAVE_DISK_UTIL
2280 {
2281 .name = "disk_util",
2282 .type = FIO_OPT_BOOL,
2283 .off1 = td_var_offset(do_disk_util),
2284 .help = "Log disk utilization statistics",
2285 .def = "1",
2286 .category = FIO_OPT_G_OS | FIO_OPT_G_STAT,
2287 },
2288#endif
2289 {
2290 .name = "gtod_reduce",
2291 .type = FIO_OPT_BOOL,
2292 .help = "Greatly reduce number of gettimeofday() calls",
2293 .cb = str_gtod_reduce_cb,
2294 .def = "0",
2295 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2296 },
2297 {
2298 .name = "disable_lat",
2299 .type = FIO_OPT_BOOL,
2300 .off1 = td_var_offset(disable_lat),
2301 .help = "Disable latency numbers",
2302 .parent = "gtod_reduce",
2303 .def = "0",
2304 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2305 },
2306 {
2307 .name = "disable_clat",
2308 .type = FIO_OPT_BOOL,
2309 .off1 = td_var_offset(disable_clat),
2310 .help = "Disable completion latency numbers",
2311 .parent = "gtod_reduce",
2312 .def = "0",
2313 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2314 },
2315 {
2316 .name = "disable_slat",
2317 .type = FIO_OPT_BOOL,
2318 .off1 = td_var_offset(disable_slat),
2319 .help = "Disable submission latency numbers",
2320 .parent = "gtod_reduce",
2321 .def = "0",
2322 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2323 },
2324 {
2325 .name = "disable_bw_measurement",
2326 .type = FIO_OPT_BOOL,
2327 .off1 = td_var_offset(disable_bw),
2328 .help = "Disable bandwidth logging",
2329 .parent = "gtod_reduce",
2330 .def = "0",
2331 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2332 },
2333 {
2334 .name = "gtod_cpu",
2335 .type = FIO_OPT_INT,
2336 .cb = str_gtod_cpu_cb,
2337 .help = "Set up dedicated gettimeofday() thread on this CPU",
2338 .verify = gtod_cpu_verify,
2339 .category = FIO_OPT_G_OS | FIO_OPT_G_MISC | FIO_OPT_G_STAT,
2340 },
2341 {
2342 .name = "continue_on_error",
2343 .type = FIO_OPT_STR,
2344 .off1 = td_var_offset(continue_on_error),
2345 .help = "Continue on non-fatal errors during IO",
2346 .def = "none",
2347 .category = FIO_OPT_G_MISC | FIO_OPT_G_ERR,
2348 .posval = {
2349 { .ival = "none",
2350 .oval = ERROR_TYPE_NONE,
2351 .help = "Exit when an error is encountered",
2352 },
2353 { .ival = "read",
2354 .oval = ERROR_TYPE_READ,
2355 .help = "Continue on read errors only",
2356 },
2357 { .ival = "write",
2358 .oval = ERROR_TYPE_WRITE,
2359 .help = "Continue on write errors only",
2360 },
2361 { .ival = "io",
2362 .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2363 .help = "Continue on any IO errors",
2364 },
2365 { .ival = "verify",
2366 .oval = ERROR_TYPE_VERIFY,
2367 .help = "Continue on verify errors only",
2368 },
2369 { .ival = "all",
2370 .oval = ERROR_TYPE_ANY,
2371 .help = "Continue on all io and verify errors",
2372 },
2373 { .ival = "0",
2374 .oval = ERROR_TYPE_NONE,
2375 .help = "Alias for 'none'",
2376 },
2377 { .ival = "1",
2378 .oval = ERROR_TYPE_ANY,
2379 .help = "Alias for 'all'",
2380 },
2381 },
2382 },
2383 {
2384 .name = "profile",
2385 .type = FIO_OPT_STR_STORE,
2386 .off1 = td_var_offset(profile),
2387 .help = "Select a specific builtin performance test",
2388 .category = FIO_OPT_G_MISC | FIO_OPT_G_JOB,
2389 },
2390 {
2391 .name = "cgroup",
2392 .type = FIO_OPT_STR_STORE,
2393 .off1 = td_var_offset(cgroup),
2394 .help = "Add job to cgroup of this name",
2395 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
2396 },
2397 {
2398 .name = "cgroup_weight",
2399 .type = FIO_OPT_INT,
2400 .off1 = td_var_offset(cgroup_weight),
2401 .help = "Use given weight for cgroup",
2402 .minval = 100,
2403 .maxval = 1000,
2404 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
2405 },
2406 {
2407 .name = "cgroup_nodelete",
2408 .type = FIO_OPT_BOOL,
2409 .off1 = td_var_offset(cgroup_nodelete),
2410 .help = "Do not delete cgroups after job completion",
2411 .def = "0",
2412 .category = FIO_OPT_G_MISC | FIO_OPT_G_OS,
2413 },
2414 {
2415 .name = "uid",
2416 .type = FIO_OPT_INT,
2417 .off1 = td_var_offset(uid),
2418 .help = "Run job with this user ID",
2419 .category = FIO_OPT_G_OS | FIO_OPT_G_JOB,
2420 },
2421 {
2422 .name = "gid",
2423 .type = FIO_OPT_INT,
2424 .off1 = td_var_offset(gid),
2425 .help = "Run job with this group ID",
2426 .category = FIO_OPT_G_OS | FIO_OPT_G_JOB,
2427 },
2428 {
2429 .name = "flow_id",
2430 .type = FIO_OPT_INT,
2431 .off1 = td_var_offset(flow_id),
2432 .help = "The flow index ID to use",
2433 .def = "0",
2434 .category = FIO_OPT_G_IO,
2435 },
2436 {
2437 .name = "flow",
2438 .type = FIO_OPT_INT,
2439 .off1 = td_var_offset(flow),
2440 .help = "Weight for flow control of this job",
2441 .parent = "flow_id",
2442 .def = "0",
2443 .category = FIO_OPT_G_IO,
2444 },
2445 {
2446 .name = "flow_watermark",
2447 .type = FIO_OPT_INT,
2448 .off1 = td_var_offset(flow_watermark),
2449 .help = "High watermark for flow control. This option"
2450 " should be set to the same value for all threads"
2451 " with non-zero flow.",
2452 .parent = "flow_id",
2453 .def = "1024",
2454 .category = FIO_OPT_G_IO,
2455 },
2456 {
2457 .name = "flow_sleep",
2458 .type = FIO_OPT_INT,
2459 .off1 = td_var_offset(flow_sleep),
2460 .help = "How many microseconds to sleep after being held"
2461 " back by the flow control mechanism",
2462 .parent = "flow_id",
2463 .def = "0",
2464 .category = FIO_OPT_G_IO,
2465 },
2466 {
2467 .name = NULL,
2468 },
2469};
2470
2471static void add_to_lopt(struct option *lopt, struct fio_option *o,
2472 const char *name, int val)
2473{
2474 lopt->name = (char *) name;
2475 lopt->val = val;
2476 if (o->type == FIO_OPT_STR_SET)
2477 lopt->has_arg = no_argument;
2478 else
2479 lopt->has_arg = required_argument;
2480}
2481
2482static void options_to_lopts(struct fio_option *opts,
2483 struct option *long_options,
2484 int i, int option_type)
2485{
2486 struct fio_option *o = &opts[0];
2487 while (o->name) {
2488 add_to_lopt(&long_options[i], o, o->name, option_type);
2489 if (o->alias) {
2490 i++;
2491 add_to_lopt(&long_options[i], o, o->alias, option_type);
2492 }
2493
2494 i++;
2495 o++;
2496 assert(i < FIO_NR_OPTIONS);
2497 }
2498}
2499
2500void fio_options_set_ioengine_opts(struct option *long_options,
2501 struct thread_data *td)
2502{
2503 unsigned int i;
2504
2505 i = 0;
2506 while (long_options[i].name) {
2507 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2508 memset(&long_options[i], 0, sizeof(*long_options));
2509 break;
2510 }
2511 i++;
2512 }
2513
2514 /*
2515 * Just clear out the prior ioengine options.
2516 */
2517 if (!td || !td->eo)
2518 return;
2519
2520 options_to_lopts(td->io_ops->options, long_options, i,
2521 FIO_GETOPT_IOENGINE);
2522}
2523
2524void fio_options_dup_and_init(struct option *long_options)
2525{
2526 unsigned int i;
2527
2528 options_init(fio_options);
2529
2530 i = 0;
2531 while (long_options[i].name)
2532 i++;
2533
2534 options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
2535}
2536
2537struct fio_keyword {
2538 const char *word;
2539 const char *desc;
2540 char *replace;
2541};
2542
2543static struct fio_keyword fio_keywords[] = {
2544 {
2545 .word = "$pagesize",
2546 .desc = "Page size in the system",
2547 },
2548 {
2549 .word = "$mb_memory",
2550 .desc = "Megabytes of memory online",
2551 },
2552 {
2553 .word = "$ncpus",
2554 .desc = "Number of CPUs online in the system",
2555 },
2556 {
2557 .word = NULL,
2558 },
2559};
2560
2561void fio_keywords_init(void)
2562{
2563 unsigned long long mb_memory;
2564 char buf[128];
2565 long l;
2566
2567 sprintf(buf, "%lu", page_size);
2568 fio_keywords[0].replace = strdup(buf);
2569
2570 mb_memory = os_phys_mem() / (1024 * 1024);
2571 sprintf(buf, "%llu", mb_memory);
2572 fio_keywords[1].replace = strdup(buf);
2573
2574 l = cpus_online();
2575 sprintf(buf, "%lu", l);
2576 fio_keywords[2].replace = strdup(buf);
2577}
2578
2579#define BC_APP "bc"
2580
2581static char *bc_calc(char *str)
2582{
2583 char buf[128], *tmp;
2584 FILE *f;
2585 int ret;
2586
2587 /*
2588 * No math, just return string
2589 */
2590 if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2591 !strchr(str, '/')) || strchr(str, '\''))
2592 return str;
2593
2594 /*
2595 * Split option from value, we only need to calculate the value
2596 */
2597 tmp = strchr(str, '=');
2598 if (!tmp)
2599 return str;
2600
2601 tmp++;
2602
2603 /*
2604 * Prevent buffer overflows; such a case isn't reasonable anyway
2605 */
2606 if (strlen(str) >= 128 || strlen(tmp) > 100)
2607 return str;
2608
2609 sprintf(buf, "which %s > /dev/null", BC_APP);
2610 if (system(buf)) {
2611 log_err("fio: bc is needed for performing math\n");
2612 return NULL;
2613 }
2614
2615 sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
2616 f = popen(buf, "r");
2617 if (!f) {
2618 return NULL;
2619 }
2620
2621 ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
2622 if (ret <= 0) {
2623 return NULL;
2624 }
2625
2626 pclose(f);
2627 buf[(tmp - str) + ret - 1] = '\0';
2628 memcpy(buf, str, tmp - str);
2629 free(str);
2630 return strdup(buf);
2631}
2632
2633/*
2634 * Return a copy of the input string with substrings of the form ${VARNAME}
2635 * substituted with the value of the environment variable VARNAME. The
2636 * substitution always occurs, even if VARNAME is empty or the corresponding
2637 * environment variable undefined.
2638 */
2639static char *option_dup_subs(const char *opt)
2640{
2641 char out[OPT_LEN_MAX+1];
2642 char in[OPT_LEN_MAX+1];
2643 char *outptr = out;
2644 char *inptr = in;
2645 char *ch1, *ch2, *env;
2646 ssize_t nchr = OPT_LEN_MAX;
2647 size_t envlen;
2648
2649 if (strlen(opt) + 1 > OPT_LEN_MAX) {
2650 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2651 return NULL;
2652 }
2653
2654 in[OPT_LEN_MAX] = '\0';
2655 strncpy(in, opt, OPT_LEN_MAX);
2656
2657 while (*inptr && nchr > 0) {
2658 if (inptr[0] == '$' && inptr[1] == '{') {
2659 ch2 = strchr(inptr, '}');
2660 if (ch2 && inptr+1 < ch2) {
2661 ch1 = inptr+2;
2662 inptr = ch2+1;
2663 *ch2 = '\0';
2664
2665 env = getenv(ch1);
2666 if (env) {
2667 envlen = strlen(env);
2668 if (envlen <= nchr) {
2669 memcpy(outptr, env, envlen);
2670 outptr += envlen;
2671 nchr -= envlen;
2672 }
2673 }
2674
2675 continue;
2676 }
2677 }
2678
2679 *outptr++ = *inptr++;
2680 --nchr;
2681 }
2682
2683 *outptr = '\0';
2684 return strdup(out);
2685}
2686
2687/*
2688 * Look for reserved variable names and replace them with real values
2689 */
2690static char *fio_keyword_replace(char *opt)
2691{
2692 char *s;
2693 int i;
2694 int docalc = 0;
2695
2696 for (i = 0; fio_keywords[i].word != NULL; i++) {
2697 struct fio_keyword *kw = &fio_keywords[i];
2698
2699 while ((s = strstr(opt, kw->word)) != NULL) {
2700 char *new = malloc(strlen(opt) + 1);
2701 char *o_org = opt;
2702 int olen = s - opt;
2703 int len;
2704
2705 /*
2706 * Copy part of the string before the keyword and
2707 * sprintf() the replacement after it.
2708 */
2709 memcpy(new, opt, olen);
2710 len = sprintf(new + olen, "%s", kw->replace);
2711
2712 /*
2713 * If there's more in the original string, copy that
2714 * in too
2715 */
2716 opt += strlen(kw->word) + olen;
2717 if (strlen(opt))
2718 memcpy(new + olen + len, opt, opt - o_org - 1);
2719
2720 /*
2721 * replace opt and free the old opt
2722 */
2723 opt = new;
2724 free(o_org);
2725
2726 docalc = 1;
2727 }
2728 }
2729
2730 /*
2731 * Check for potential math and invoke bc, if possible
2732 */
2733 if (docalc)
2734 opt = bc_calc(opt);
2735
2736 return opt;
2737}
2738
2739static char **dup_and_sub_options(char **opts, int num_opts)
2740{
2741 int i;
2742 char **opts_copy = malloc(num_opts * sizeof(*opts));
2743 for (i = 0; i < num_opts; i++) {
2744 opts_copy[i] = option_dup_subs(opts[i]);
2745 if (!opts_copy[i])
2746 continue;
2747 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2748 }
2749 return opts_copy;
2750}
2751
2752int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2753{
2754 int i, ret, unknown;
2755 char **opts_copy;
2756
2757 sort_options(opts, fio_options, num_opts);
2758 opts_copy = dup_and_sub_options(opts, num_opts);
2759
2760 for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
2761 struct fio_option *o;
2762 int newret = parse_option(opts_copy[i], opts[i], fio_options,
2763 &o, td);
2764
2765 if (opts_copy[i]) {
2766 if (newret && !o) {
2767 unknown++;
2768 continue;
2769 }
2770 free(opts_copy[i]);
2771 opts_copy[i] = NULL;
2772 }
2773
2774 ret |= newret;
2775 }
2776
2777 if (unknown) {
2778 ret |= ioengine_load(td);
2779 if (td->eo) {
2780 sort_options(opts_copy, td->io_ops->options, num_opts);
2781 opts = opts_copy;
2782 }
2783 for (i = 0; i < num_opts; i++) {
2784 struct fio_option *o = NULL;
2785 int newret = 1;
2786 if (!opts_copy[i])
2787 continue;
2788
2789 if (td->eo)
2790 newret = parse_option(opts_copy[i], opts[i],
2791 td->io_ops->options, &o,
2792 td->eo);
2793
2794 ret |= newret;
2795 if (!o)
2796 log_err("Bad option <%s>\n", opts[i]);
2797
2798 free(opts_copy[i]);
2799 opts_copy[i] = NULL;
2800 }
2801 }
2802
2803 free(opts_copy);
2804 return ret;
2805}
2806
2807int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2808{
2809 return parse_cmd_option(opt, val, fio_options, td);
2810}
2811
2812int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
2813 char *val)
2814{
2815 return parse_cmd_option(opt, val, td->io_ops->options, td);
2816}
2817
2818void fio_fill_default_options(struct thread_data *td)
2819{
2820 fill_default_options(td, fio_options);
2821}
2822
2823int fio_show_option_help(const char *opt)
2824{
2825 return show_cmd_help(fio_options, opt);
2826}
2827
2828void options_mem_dupe(void *data, struct fio_option *options)
2829{
2830 struct fio_option *o;
2831 char **ptr;
2832
2833 for (o = &options[0]; o->name; o++) {
2834 if (o->type != FIO_OPT_STR_STORE)
2835 continue;
2836
2837 ptr = td_var(data, o->off1);
2838 if (*ptr)
2839 *ptr = strdup(*ptr);
2840 }
2841}
2842
2843/*
2844 * dupe FIO_OPT_STR_STORE options
2845 */
2846void fio_options_mem_dupe(struct thread_data *td)
2847{
2848 options_mem_dupe(&td->o, fio_options);
2849
2850 if (td->eo && td->io_ops) {
2851 void *oldeo = td->eo;
2852
2853 td->eo = malloc(td->io_ops->option_struct_size);
2854 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
2855 options_mem_dupe(td->eo, td->io_ops->options);
2856 }
2857}
2858
2859unsigned int fio_get_kb_base(void *data)
2860{
2861 struct thread_data *td = data;
2862 unsigned int kb_base = 0;
2863
2864 if (td)
2865 kb_base = td->o.kb_base;
2866 if (!kb_base)
2867 kb_base = 1024;
2868
2869 return kb_base;
2870}
2871
2872int add_option(struct fio_option *o)
2873{
2874 struct fio_option *__o;
2875 int opt_index = 0;
2876
2877 __o = fio_options;
2878 while (__o->name) {
2879 opt_index++;
2880 __o++;
2881 }
2882
2883 memcpy(&fio_options[opt_index], o, sizeof(*o));
2884 return 0;
2885}
2886
2887void invalidate_profile_options(const char *prof_name)
2888{
2889 struct fio_option *o;
2890
2891 o = fio_options;
2892 while (o->name) {
2893 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2894 o->type = FIO_OPT_INVALID;
2895 o->prof_name = NULL;
2896 }
2897 o++;
2898 }
2899}
2900
2901void add_opt_posval(const char *optname, const char *ival, const char *help)
2902{
2903 struct fio_option *o;
2904 unsigned int i;
2905
2906 o = find_option(fio_options, optname);
2907 if (!o)
2908 return;
2909
2910 for (i = 0; i < PARSE_MAX_VP; i++) {
2911 if (o->posval[i].ival)
2912 continue;
2913
2914 o->posval[i].ival = ival;
2915 o->posval[i].help = help;
2916 break;
2917 }
2918}
2919
2920void del_opt_posval(const char *optname, const char *ival)
2921{
2922 struct fio_option *o;
2923 unsigned int i;
2924
2925 o = find_option(fio_options, optname);
2926 if (!o)
2927 return;
2928
2929 for (i = 0; i < PARSE_MAX_VP; i++) {
2930 if (!o->posval[i].ival)
2931 continue;
2932 if (strcmp(o->posval[i].ival, ival))
2933 continue;
2934
2935 o->posval[i].ival = NULL;
2936 o->posval[i].help = NULL;
2937 }
2938}
2939
2940void fio_options_free(struct thread_data *td)
2941{
2942 options_free(fio_options, td);
2943 if (td->eo && td->io_ops && td->io_ops->options) {
2944 options_free(td->io_ops->options, td->eo);
2945 free(td->eo);
2946 td->eo = NULL;
2947 }
2948}