gfio: apply inverse options to buffered/direct
[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 = "General",
851 .mask = FIO_OPT_C_GENERAL,
852 },
853 {
854 .name = "I/O",
855 .mask = FIO_OPT_C_IO,
856 },
857 {
858 .name = "File",
859 .mask = FIO_OPT_C_FILE,
860 },
861 {
862 .name = "Statistics",
863 .mask = FIO_OPT_C_STAT,
864 },
865 {
866 .name = "Logging",
867 .mask = FIO_OPT_C_LOG,
868 },
869 {
870 .name = NULL,
871 },
872};
873
874static struct opt_group *__opt_group_from_mask(struct opt_group *ogs, unsigned int *mask,
875 unsigned int inv_mask)
876{
877 struct opt_group *og;
878 int i;
879
880 if (*mask == inv_mask || !*mask)
881 return NULL;
882
883 for (i = 0; ogs[i].name; i++) {
884 og = &ogs[i];
885
886 if (*mask & og->mask) {
887 *mask &= ~(og->mask);
888 return og;
889 }
890 }
891
892 return NULL;
893}
894
895struct opt_group *opt_group_from_mask(unsigned int *mask)
896{
897 return __opt_group_from_mask(fio_opt_groups, mask, FIO_OPT_C_INVALID);
898}
899
900static struct opt_group fio_opt_cat_groups[] = {
901 {
902 .name = "Rate",
903 .mask = FIO_OPT_G_RATE,
904 },
905 {
906 .name = "Zone",
907 .mask = FIO_OPT_G_ZONE,
908 },
909 {
910 .name = "Read/write mix",
911 .mask = FIO_OPT_G_RWMIX,
912 },
913 {
914 .name = "Verify",
915 .mask = FIO_OPT_G_VERIFY,
916 },
917 {
918 .name = "Trim",
919 .mask = FIO_OPT_G_TRIM,
920 },
921 {
922 .name = "I/O Logging",
923 .mask = FIO_OPT_G_IOLOG,
924 },
925 {
926 .name = "I/O Depth",
927 .mask = FIO_OPT_G_IO_DEPTH,
928 },
929 {
930 .name = "I/O Flow",
931 .mask = FIO_OPT_G_IO_FLOW,
932 },
933 {
934 .name = "Description",
935 .mask = FIO_OPT_G_DESC,
936 },
937 {
938 .name = "Filename",
939 .mask = FIO_OPT_G_FILENAME,
940 },
941 {
942 .name = "General I/O",
943 .mask = FIO_OPT_G_IO_BASIC,
944 },
945 {
946 .name = "Cgroups",
947 .mask = FIO_OPT_G_CGROUP,
948 },
949 {
950 .name = "Runtime",
951 .mask = FIO_OPT_G_RUNTIME,
952 },
953 {
954 .name = "Process",
955 .mask = FIO_OPT_G_PROCESS,
956 },
957 {
958 .name = "Job credentials / priority",
959 .mask = FIO_OPT_G_CRED,
960 },
961 {
962 .name = "Clock settings",
963 .mask = FIO_OPT_G_CLOCK,
964 },
965 {
966 .name = NULL,
967 }
968};
969
970struct opt_group *opt_group_cat_from_mask(unsigned int *mask)
971{
972 return __opt_group_from_mask(fio_opt_cat_groups, mask, FIO_OPT_G_INVALID);
973}
974
975/*
976 * Map of job/command line options
977 */
978struct fio_option fio_options[FIO_MAX_OPTS] = {
979 {
980 .name = "description",
981 .lname = "Description of job",
982 .type = FIO_OPT_STR_STORE,
983 .off1 = td_var_offset(description),
984 .help = "Text job description",
985 .category = FIO_OPT_C_GENERAL,
986 .group = FIO_OPT_G_DESC,
987 },
988 {
989 .name = "name",
990 .lname = "Job name",
991 .type = FIO_OPT_STR_STORE,
992 .off1 = td_var_offset(name),
993 .help = "Name of this job",
994 .category = FIO_OPT_C_GENERAL,
995 .group = FIO_OPT_G_DESC,
996 },
997 {
998 .name = "filename",
999 .lname = "Filename(s)",
1000 .type = FIO_OPT_STR_STORE,
1001 .off1 = td_var_offset(filename),
1002 .cb = str_filename_cb,
1003 .prio = -1, /* must come after "directory" */
1004 .help = "File(s) to use for the workload",
1005 .category = FIO_OPT_C_FILE,
1006 .group = FIO_OPT_G_FILENAME,
1007 },
1008 {
1009 .name = "directory",
1010 .lname = "Directory",
1011 .type = FIO_OPT_STR_STORE,
1012 .off1 = td_var_offset(directory),
1013 .cb = str_directory_cb,
1014 .help = "Directory to store files in",
1015 .category = FIO_OPT_C_FILE,
1016 .group = FIO_OPT_G_FILENAME,
1017 },
1018 {
1019 .name = "lockfile",
1020 .lname = "Lockfile",
1021 .type = FIO_OPT_STR,
1022 .cb = str_lockfile_cb,
1023 .off1 = td_var_offset(file_lock_mode),
1024 .help = "Lock file when doing IO to it",
1025 .parent = "filename",
1026 .hide = 0,
1027 .def = "none",
1028 .category = FIO_OPT_C_FILE,
1029 .group = FIO_OPT_G_FILENAME,
1030 .posval = {
1031 { .ival = "none",
1032 .oval = FILE_LOCK_NONE,
1033 .help = "No file locking",
1034 },
1035 { .ival = "exclusive",
1036 .oval = FILE_LOCK_EXCLUSIVE,
1037 .help = "Exclusive file lock",
1038 },
1039 {
1040 .ival = "readwrite",
1041 .oval = FILE_LOCK_READWRITE,
1042 .help = "Read vs write lock",
1043 },
1044 },
1045 },
1046 {
1047 .name = "opendir",
1048 .lname = "Open directory",
1049 .type = FIO_OPT_STR_STORE,
1050 .off1 = td_var_offset(opendir),
1051 .cb = str_opendir_cb,
1052 .help = "Recursively add files from this directory and down",
1053 .category = FIO_OPT_C_FILE,
1054 .group = FIO_OPT_G_FILENAME,
1055 },
1056 {
1057 .name = "rw",
1058 .lname = "Read/write",
1059 .alias = "readwrite",
1060 .type = FIO_OPT_STR,
1061 .cb = str_rw_cb,
1062 .off1 = td_var_offset(td_ddir),
1063 .help = "IO direction",
1064 .def = "read",
1065 .verify = rw_verify,
1066 .category = FIO_OPT_C_IO,
1067 .group = FIO_OPT_G_IO_BASIC,
1068 .posval = {
1069 { .ival = "read",
1070 .oval = TD_DDIR_READ,
1071 .help = "Sequential read",
1072 },
1073 { .ival = "write",
1074 .oval = TD_DDIR_WRITE,
1075 .help = "Sequential write",
1076 },
1077 { .ival = "randread",
1078 .oval = TD_DDIR_RANDREAD,
1079 .help = "Random read",
1080 },
1081 { .ival = "randwrite",
1082 .oval = TD_DDIR_RANDWRITE,
1083 .help = "Random write",
1084 },
1085 { .ival = "rw",
1086 .oval = TD_DDIR_RW,
1087 .help = "Sequential read and write mix",
1088 },
1089 { .ival = "randrw",
1090 .oval = TD_DDIR_RANDRW,
1091 .help = "Random read and write mix"
1092 },
1093 },
1094 },
1095 {
1096 .name = "rw_sequencer",
1097 .lname = "RW Sequencer",
1098 .type = FIO_OPT_STR,
1099 .off1 = td_var_offset(rw_seq),
1100 .help = "IO offset generator modifier",
1101 .def = "sequential",
1102 .category = FIO_OPT_C_IO,
1103 .group = FIO_OPT_G_IO_BASIC,
1104 .posval = {
1105 { .ival = "sequential",
1106 .oval = RW_SEQ_SEQ,
1107 .help = "Generate sequential offsets",
1108 },
1109 { .ival = "identical",
1110 .oval = RW_SEQ_IDENT,
1111 .help = "Generate identical offsets",
1112 },
1113 },
1114 },
1115
1116 {
1117 .name = "ioengine",
1118 .lname = "IO Engine",
1119 .type = FIO_OPT_STR_STORE,
1120 .off1 = td_var_offset(ioengine),
1121 .help = "IO engine to use",
1122 .def = FIO_PREFERRED_ENGINE,
1123 .category = FIO_OPT_C_IO,
1124 .group = FIO_OPT_G_IO_BASIC,
1125 .posval = {
1126 { .ival = "sync",
1127 .help = "Use read/write",
1128 },
1129 { .ival = "psync",
1130 .help = "Use pread/pwrite",
1131 },
1132 { .ival = "vsync",
1133 .help = "Use readv/writev",
1134 },
1135#ifdef FIO_HAVE_LIBAIO
1136 { .ival = "libaio",
1137 .help = "Linux native asynchronous IO",
1138 },
1139#endif
1140#ifdef FIO_HAVE_POSIXAIO
1141 { .ival = "posixaio",
1142 .help = "POSIX asynchronous IO",
1143 },
1144#endif
1145#ifdef FIO_HAVE_SOLARISAIO
1146 { .ival = "solarisaio",
1147 .help = "Solaris native asynchronous IO",
1148 },
1149#endif
1150#ifdef FIO_HAVE_WINDOWSAIO
1151 { .ival = "windowsaio",
1152 .help = "Windows native asynchronous IO"
1153 },
1154#endif
1155 { .ival = "mmap",
1156 .help = "Memory mapped IO"
1157 },
1158#ifdef FIO_HAVE_SPLICE
1159 { .ival = "splice",
1160 .help = "splice/vmsplice based IO",
1161 },
1162 { .ival = "netsplice",
1163 .help = "splice/vmsplice to/from the network",
1164 },
1165#endif
1166#ifdef FIO_HAVE_SGIO
1167 { .ival = "sg",
1168 .help = "SCSI generic v3 IO",
1169 },
1170#endif
1171 { .ival = "null",
1172 .help = "Testing engine (no data transfer)",
1173 },
1174 { .ival = "net",
1175 .help = "Network IO",
1176 },
1177#ifdef FIO_HAVE_SYSLET
1178 { .ival = "syslet-rw",
1179 .help = "syslet enabled async pread/pwrite IO",
1180 },
1181#endif
1182 { .ival = "cpuio",
1183 .help = "CPU cycle burner engine",
1184 },
1185#ifdef FIO_HAVE_GUASI
1186 { .ival = "guasi",
1187 .help = "GUASI IO engine",
1188 },
1189#endif
1190#ifdef FIO_HAVE_BINJECT
1191 { .ival = "binject",
1192 .help = "binject direct inject block engine",
1193 },
1194#endif
1195#ifdef FIO_HAVE_RDMA
1196 { .ival = "rdma",
1197 .help = "RDMA IO engine",
1198 },
1199#endif
1200 { .ival = "external",
1201 .help = "Load external engine (append name)",
1202 },
1203 },
1204 },
1205 {
1206 .name = "iodepth",
1207 .lname = "IO Depth",
1208 .type = FIO_OPT_INT,
1209 .off1 = td_var_offset(iodepth),
1210 .help = "Number of IO buffers to keep in flight",
1211 .minval = 1,
1212 .interval = 1,
1213 .def = "1",
1214 .category = FIO_OPT_C_IO,
1215 .group = FIO_OPT_G_IO_BASIC,
1216 },
1217 {
1218 .name = "iodepth_batch",
1219 .lname = "IO Depth batch",
1220 .alias = "iodepth_batch_submit",
1221 .type = FIO_OPT_INT,
1222 .off1 = td_var_offset(iodepth_batch),
1223 .help = "Number of IO buffers to submit in one go",
1224 .parent = "iodepth",
1225 .hide = 1,
1226 .minval = 1,
1227 .interval = 1,
1228 .def = "1",
1229 .category = FIO_OPT_C_IO,
1230 .group = FIO_OPT_G_IO_BASIC,
1231 },
1232 {
1233 .name = "iodepth_batch_complete",
1234 .lname = "IO Depth batch complete",
1235 .type = FIO_OPT_INT,
1236 .off1 = td_var_offset(iodepth_batch_complete),
1237 .help = "Number of IO buffers to retrieve in one go",
1238 .parent = "iodepth",
1239 .hide = 1,
1240 .minval = 0,
1241 .interval = 1,
1242 .def = "1",
1243 .category = FIO_OPT_C_IO,
1244 .group = FIO_OPT_G_IO_BASIC,
1245 },
1246 {
1247 .name = "iodepth_low",
1248 .lname = "IO Depth batch low",
1249 .type = FIO_OPT_INT,
1250 .off1 = td_var_offset(iodepth_low),
1251 .help = "Low water mark for queuing depth",
1252 .parent = "iodepth",
1253 .hide = 1,
1254 .interval = 1,
1255 .category = FIO_OPT_C_IO,
1256 .group = FIO_OPT_G_IO_BASIC,
1257 },
1258 {
1259 .name = "size",
1260 .lname = "Size",
1261 .type = FIO_OPT_STR_VAL,
1262 .cb = str_size_cb,
1263 .help = "Total size of device or files",
1264 .interval = 1024 * 1024,
1265 .category = FIO_OPT_C_IO,
1266 .group = FIO_OPT_G_INVALID,
1267 },
1268 {
1269 .name = "fill_device",
1270 .lname = "Fill device",
1271 .alias = "fill_fs",
1272 .type = FIO_OPT_BOOL,
1273 .off1 = td_var_offset(fill_device),
1274 .help = "Write until an ENOSPC error occurs",
1275 .def = "0",
1276 .category = FIO_OPT_C_FILE,
1277 .group = FIO_OPT_G_INVALID,
1278 },
1279 {
1280 .name = "filesize",
1281 .lname = "File size",
1282 .type = FIO_OPT_STR_VAL,
1283 .off1 = td_var_offset(file_size_low),
1284 .off2 = td_var_offset(file_size_high),
1285 .minval = 1,
1286 .help = "Size of individual files",
1287 .interval = 1024 * 1024,
1288 .category = FIO_OPT_C_FILE,
1289 .group = FIO_OPT_G_INVALID,
1290 },
1291 {
1292 .name = "offset",
1293 .lname = "IO offset",
1294 .alias = "fileoffset",
1295 .type = FIO_OPT_STR_VAL,
1296 .off1 = td_var_offset(start_offset),
1297 .help = "Start IO from this offset",
1298 .def = "0",
1299 .interval = 1024 * 1024,
1300 .category = FIO_OPT_C_IO,
1301 .group = FIO_OPT_G_INVALID,
1302 },
1303 {
1304 .name = "offset_increment",
1305 .lname = "IO offset increment",
1306 .type = FIO_OPT_STR_VAL,
1307 .off1 = td_var_offset(offset_increment),
1308 .help = "What is the increment from one offset to the next",
1309 .parent = "offset",
1310 .hide = 1,
1311 .def = "0",
1312 .interval = 1024 * 1024,
1313 .category = FIO_OPT_C_IO,
1314 .group = FIO_OPT_G_INVALID,
1315 },
1316 {
1317 .name = "bs",
1318 .lname = "Block size",
1319 .alias = "blocksize",
1320 .type = FIO_OPT_INT,
1321 .off1 = td_var_offset(bs[DDIR_READ]),
1322 .off2 = td_var_offset(bs[DDIR_WRITE]),
1323 .minval = 1,
1324 .help = "Block size unit",
1325 .def = "4k",
1326 .parent = "rw",
1327 .hide = 1,
1328 .interval = 512,
1329 .category = FIO_OPT_C_IO,
1330 .group = FIO_OPT_G_INVALID,
1331 },
1332 {
1333 .name = "ba",
1334 .lname = "Block size align",
1335 .alias = "blockalign",
1336 .type = FIO_OPT_INT,
1337 .off1 = td_var_offset(ba[DDIR_READ]),
1338 .off2 = td_var_offset(ba[DDIR_WRITE]),
1339 .minval = 1,
1340 .help = "IO block offset alignment",
1341 .parent = "rw",
1342 .hide = 1,
1343 .interval = 512,
1344 .category = FIO_OPT_C_IO,
1345 .group = FIO_OPT_G_INVALID,
1346 },
1347 {
1348 .name = "bsrange",
1349 .lname = "Block size range",
1350 .alias = "blocksize_range",
1351 .type = FIO_OPT_RANGE,
1352 .off1 = td_var_offset(min_bs[DDIR_READ]),
1353 .off2 = td_var_offset(max_bs[DDIR_READ]),
1354 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1355 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1356 .minval = 1,
1357 .help = "Set block size range (in more detail than bs)",
1358 .parent = "rw",
1359 .hide = 1,
1360 .interval = 4096,
1361 .category = FIO_OPT_C_IO,
1362 .group = FIO_OPT_G_INVALID,
1363 },
1364 {
1365 .name = "bssplit",
1366 .lname = "Block size split",
1367 .type = FIO_OPT_STR,
1368 .cb = str_bssplit_cb,
1369 .help = "Set a specific mix of block sizes",
1370 .parent = "rw",
1371 .hide = 1,
1372 .category = FIO_OPT_C_IO,
1373 .group = FIO_OPT_G_INVALID,
1374 },
1375 {
1376 .name = "bs_unaligned",
1377 .lname = "Block size unaligned",
1378 .alias = "blocksize_unaligned",
1379 .type = FIO_OPT_STR_SET,
1380 .off1 = td_var_offset(bs_unaligned),
1381 .help = "Don't sector align IO buffer sizes",
1382 .parent = "rw",
1383 .hide = 1,
1384 .category = FIO_OPT_C_IO,
1385 .group = FIO_OPT_G_INVALID,
1386 },
1387 {
1388 .name = "randrepeat",
1389 .lname = "Random repeatable",
1390 .type = FIO_OPT_BOOL,
1391 .off1 = td_var_offset(rand_repeatable),
1392 .help = "Use repeatable random IO pattern",
1393 .def = "1",
1394 .parent = "rw",
1395 .hide = 1,
1396 .category = FIO_OPT_C_IO,
1397 .group = FIO_OPT_G_INVALID,
1398 },
1399 {
1400 .name = "use_os_rand",
1401 .lname = "Use OS random",
1402 .type = FIO_OPT_BOOL,
1403 .off1 = td_var_offset(use_os_rand),
1404 .help = "Set to use OS random generator",
1405 .def = "0",
1406 .parent = "rw",
1407 .hide = 1,
1408 .category = FIO_OPT_C_IO,
1409 .group = FIO_OPT_G_INVALID,
1410 },
1411 {
1412 .name = "norandommap",
1413 .lname = "No randommap",
1414 .type = FIO_OPT_STR_SET,
1415 .off1 = td_var_offset(norandommap),
1416 .help = "Accept potential duplicate random blocks",
1417 .parent = "rw",
1418 .hide = 1,
1419 .category = FIO_OPT_C_IO,
1420 .group = FIO_OPT_G_INVALID,
1421 },
1422 {
1423 .name = "softrandommap",
1424 .lname = "Soft randommap",
1425 .type = FIO_OPT_BOOL,
1426 .off1 = td_var_offset(softrandommap),
1427 .help = "Set norandommap if randommap allocation fails",
1428 .parent = "norandommap",
1429 .hide = 1,
1430 .def = "0",
1431 .category = FIO_OPT_C_IO,
1432 .group = FIO_OPT_G_INVALID,
1433 },
1434 {
1435 .name = "nrfiles",
1436 .lname = "Number of files",
1437 .alias = "nr_files",
1438 .type = FIO_OPT_INT,
1439 .off1 = td_var_offset(nr_files),
1440 .help = "Split job workload between this number of files",
1441 .def = "1",
1442 .interval = 1,
1443 .category = FIO_OPT_C_FILE,
1444 .group = FIO_OPT_G_INVALID,
1445 },
1446 {
1447 .name = "openfiles",
1448 .lname = "Number of open files",
1449 .type = FIO_OPT_INT,
1450 .off1 = td_var_offset(open_files),
1451 .help = "Number of files to keep open at the same time",
1452 .category = FIO_OPT_C_FILE,
1453 .group = FIO_OPT_G_INVALID,
1454 },
1455 {
1456 .name = "file_service_type",
1457 .lname = "File service type",
1458 .type = FIO_OPT_STR,
1459 .cb = str_fst_cb,
1460 .off1 = td_var_offset(file_service_type),
1461 .help = "How to select which file to service next",
1462 .def = "roundrobin",
1463 .category = FIO_OPT_C_FILE,
1464 .group = FIO_OPT_G_INVALID,
1465 .posval = {
1466 { .ival = "random",
1467 .oval = FIO_FSERVICE_RANDOM,
1468 .help = "Choose a file at random",
1469 },
1470 { .ival = "roundrobin",
1471 .oval = FIO_FSERVICE_RR,
1472 .help = "Round robin select files",
1473 },
1474 { .ival = "sequential",
1475 .oval = FIO_FSERVICE_SEQ,
1476 .help = "Finish one file before moving to the next",
1477 },
1478 },
1479 .parent = "nrfiles",
1480 .hide = 1,
1481 },
1482#ifdef FIO_HAVE_FALLOCATE
1483 {
1484 .name = "fallocate",
1485 .lname = "Fallocate",
1486 .type = FIO_OPT_STR,
1487 .off1 = td_var_offset(fallocate_mode),
1488 .help = "Whether pre-allocation is performed when laying out files",
1489 .def = "posix",
1490 .category = FIO_OPT_C_FILE,
1491 .group = FIO_OPT_G_INVALID,
1492 .posval = {
1493 { .ival = "none",
1494 .oval = FIO_FALLOCATE_NONE,
1495 .help = "Do not pre-allocate space",
1496 },
1497 { .ival = "posix",
1498 .oval = FIO_FALLOCATE_POSIX,
1499 .help = "Use posix_fallocate()",
1500 },
1501#ifdef FIO_HAVE_LINUX_FALLOCATE
1502 { .ival = "keep",
1503 .oval = FIO_FALLOCATE_KEEP_SIZE,
1504 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1505 },
1506#endif
1507 /* Compatibility with former boolean values */
1508 { .ival = "0",
1509 .oval = FIO_FALLOCATE_NONE,
1510 .help = "Alias for 'none'",
1511 },
1512 { .ival = "1",
1513 .oval = FIO_FALLOCATE_POSIX,
1514 .help = "Alias for 'posix'",
1515 },
1516 },
1517 },
1518#endif /* FIO_HAVE_FALLOCATE */
1519 {
1520 .name = "fadvise_hint",
1521 .lname = "Fadvise hint",
1522 .type = FIO_OPT_BOOL,
1523 .off1 = td_var_offset(fadvise_hint),
1524 .help = "Use fadvise() to advise the kernel on IO pattern",
1525 .def = "1",
1526 .category = FIO_OPT_C_FILE,
1527 .group = FIO_OPT_G_INVALID,
1528 },
1529 {
1530 .name = "fsync",
1531 .lname = "Fsync",
1532 .type = FIO_OPT_INT,
1533 .off1 = td_var_offset(fsync_blocks),
1534 .help = "Issue fsync for writes every given number of blocks",
1535 .def = "0",
1536 .interval = 1,
1537 .category = FIO_OPT_C_FILE,
1538 .group = FIO_OPT_G_INVALID,
1539 },
1540 {
1541 .name = "fdatasync",
1542 .lname = "Fdatasync",
1543 .type = FIO_OPT_INT,
1544 .off1 = td_var_offset(fdatasync_blocks),
1545 .help = "Issue fdatasync for writes every given number of blocks",
1546 .def = "0",
1547 .interval = 1,
1548 .category = FIO_OPT_C_FILE,
1549 .group = FIO_OPT_G_INVALID,
1550 },
1551 {
1552 .name = "write_barrier",
1553 .lname = "Write barrier",
1554 .type = FIO_OPT_INT,
1555 .off1 = td_var_offset(barrier_blocks),
1556 .help = "Make every Nth write a barrier write",
1557 .def = "0",
1558 .interval = 1,
1559 .category = FIO_OPT_C_IO,
1560 .group = FIO_OPT_G_INVALID,
1561 },
1562#ifdef FIO_HAVE_SYNC_FILE_RANGE
1563 {
1564 .name = "sync_file_range",
1565 .lname = "Sync file range",
1566 .posval = {
1567 { .ival = "wait_before",
1568 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1569 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1570 .or = 1,
1571 },
1572 { .ival = "write",
1573 .oval = SYNC_FILE_RANGE_WRITE,
1574 .help = "SYNC_FILE_RANGE_WRITE",
1575 .or = 1,
1576 },
1577 {
1578 .ival = "wait_after",
1579 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1580 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1581 .or = 1,
1582 },
1583 },
1584 .type = FIO_OPT_STR_MULTI,
1585 .cb = str_sfr_cb,
1586 .off1 = td_var_offset(sync_file_range),
1587 .help = "Use sync_file_range()",
1588 .category = FIO_OPT_C_FILE,
1589 .group = FIO_OPT_G_INVALID,
1590 },
1591#endif
1592 {
1593 .name = "direct",
1594 .lname = "Direct I/O",
1595 .type = FIO_OPT_BOOL,
1596 .off1 = td_var_offset(odirect),
1597 .help = "Use O_DIRECT IO (negates buffered)",
1598 .def = "0",
1599 .inverse = "buffered",
1600 .category = FIO_OPT_C_IO,
1601 .group = FIO_OPT_G_INVALID,
1602 },
1603 {
1604 .name = "buffered",
1605 .lname = "Buffered I/O",
1606 .type = FIO_OPT_BOOL,
1607 .off1 = td_var_offset(odirect),
1608 .neg = 1,
1609 .help = "Use buffered IO (negates direct)",
1610 .def = "1",
1611 .inverse = "direct",
1612 .category = FIO_OPT_C_IO,
1613 .group = FIO_OPT_G_INVALID,
1614 },
1615 {
1616 .name = "overwrite",
1617 .lname = "Overwrite",
1618 .type = FIO_OPT_BOOL,
1619 .off1 = td_var_offset(overwrite),
1620 .help = "When writing, set whether to overwrite current data",
1621 .def = "0",
1622 .category = FIO_OPT_C_FILE,
1623 .group = FIO_OPT_G_INVALID,
1624 },
1625 {
1626 .name = "loops",
1627 .lname = "Loops",
1628 .type = FIO_OPT_INT,
1629 .off1 = td_var_offset(loops),
1630 .help = "Number of times to run the job",
1631 .def = "1",
1632 .interval = 1,
1633 .category = FIO_OPT_C_GENERAL,
1634 .group = FIO_OPT_G_RUNTIME,
1635 },
1636 {
1637 .name = "numjobs",
1638 .lname = "Number of jobs",
1639 .type = FIO_OPT_INT,
1640 .off1 = td_var_offset(numjobs),
1641 .help = "Duplicate this job this many times",
1642 .def = "1",
1643 .interval = 1,
1644 .category = FIO_OPT_C_GENERAL,
1645 .group = FIO_OPT_G_RUNTIME,
1646 },
1647 {
1648 .name = "startdelay",
1649 .lname = "Start delay",
1650 .type = FIO_OPT_STR_VAL_TIME,
1651 .off1 = td_var_offset(start_delay),
1652 .help = "Only start job when this period has passed",
1653 .def = "0",
1654 .category = FIO_OPT_C_GENERAL,
1655 .group = FIO_OPT_G_RUNTIME,
1656 },
1657 {
1658 .name = "runtime",
1659 .lname = "Runtime",
1660 .alias = "timeout",
1661 .type = FIO_OPT_STR_VAL_TIME,
1662 .off1 = td_var_offset(timeout),
1663 .help = "Stop workload when this amount of time has passed",
1664 .def = "0",
1665 .category = FIO_OPT_C_GENERAL,
1666 .group = FIO_OPT_G_RUNTIME,
1667 },
1668 {
1669 .name = "time_based",
1670 .lname = "Time based",
1671 .type = FIO_OPT_STR_SET,
1672 .off1 = td_var_offset(time_based),
1673 .help = "Keep running until runtime/timeout is met",
1674 .category = FIO_OPT_C_GENERAL,
1675 .group = FIO_OPT_G_RUNTIME,
1676 },
1677 {
1678 .name = "ramp_time",
1679 .lname = "Ramp time",
1680 .type = FIO_OPT_STR_VAL_TIME,
1681 .off1 = td_var_offset(ramp_time),
1682 .help = "Ramp up time before measuring performance",
1683 .category = FIO_OPT_C_GENERAL,
1684 .group = FIO_OPT_G_RUNTIME,
1685 },
1686 {
1687 .name = "clocksource",
1688 .lname = "Clock source",
1689 .type = FIO_OPT_STR,
1690 .cb = fio_clock_source_cb,
1691 .off1 = td_var_offset(clocksource),
1692 .help = "What type of timing source to use",
1693 .category = FIO_OPT_C_GENERAL,
1694 .group = FIO_OPT_G_CLOCK,
1695 .posval = {
1696 { .ival = "gettimeofday",
1697 .oval = CS_GTOD,
1698 .help = "Use gettimeofday(2) for timing",
1699 },
1700 { .ival = "clock_gettime",
1701 .oval = CS_CGETTIME,
1702 .help = "Use clock_gettime(2) for timing",
1703 },
1704#ifdef ARCH_HAVE_CPU_CLOCK
1705 { .ival = "cpu",
1706 .oval = CS_CPUCLOCK,
1707 .help = "Use CPU private clock",
1708 },
1709#endif
1710 },
1711 },
1712 {
1713 .name = "mem",
1714 .alias = "iomem",
1715 .lname = "I/O Memory",
1716 .type = FIO_OPT_STR,
1717 .cb = str_mem_cb,
1718 .off1 = td_var_offset(mem_type),
1719 .help = "Backing type for IO buffers",
1720 .def = "malloc",
1721 .category = FIO_OPT_C_IO,
1722 .group = FIO_OPT_G_INVALID,
1723 .posval = {
1724 { .ival = "malloc",
1725 .oval = MEM_MALLOC,
1726 .help = "Use malloc(3) for IO buffers",
1727 },
1728 { .ival = "shm",
1729 .oval = MEM_SHM,
1730 .help = "Use shared memory segments for IO buffers",
1731 },
1732#ifdef FIO_HAVE_HUGETLB
1733 { .ival = "shmhuge",
1734 .oval = MEM_SHMHUGE,
1735 .help = "Like shm, but use huge pages",
1736 },
1737#endif
1738 { .ival = "mmap",
1739 .oval = MEM_MMAP,
1740 .help = "Use mmap(2) (file or anon) for IO buffers",
1741 },
1742#ifdef FIO_HAVE_HUGETLB
1743 { .ival = "mmaphuge",
1744 .oval = MEM_MMAPHUGE,
1745 .help = "Like mmap, but use huge pages",
1746 },
1747#endif
1748 },
1749 },
1750 {
1751 .name = "iomem_align",
1752 .alias = "mem_align",
1753 .lname = "I/O memory alignment",
1754 .type = FIO_OPT_INT,
1755 .off1 = td_var_offset(mem_align),
1756 .minval = 0,
1757 .help = "IO memory buffer offset alignment",
1758 .def = "0",
1759 .parent = "iomem",
1760 .hide = 1,
1761 .category = FIO_OPT_C_IO,
1762 .group = FIO_OPT_G_INVALID,
1763 },
1764 {
1765 .name = "verify",
1766 .lname = "Verify",
1767 .type = FIO_OPT_STR,
1768 .off1 = td_var_offset(verify),
1769 .help = "Verify data written",
1770 .cb = str_verify_cb,
1771 .def = "0",
1772 .category = FIO_OPT_C_IO,
1773 .group = FIO_OPT_G_INVALID,
1774 .posval = {
1775 { .ival = "0",
1776 .oval = VERIFY_NONE,
1777 .help = "Don't do IO verification",
1778 },
1779 { .ival = "md5",
1780 .oval = VERIFY_MD5,
1781 .help = "Use md5 checksums for verification",
1782 },
1783 { .ival = "crc64",
1784 .oval = VERIFY_CRC64,
1785 .help = "Use crc64 checksums for verification",
1786 },
1787 { .ival = "crc32",
1788 .oval = VERIFY_CRC32,
1789 .help = "Use crc32 checksums for verification",
1790 },
1791 { .ival = "crc32c-intel",
1792 .oval = VERIFY_CRC32C,
1793 .help = "Use crc32c checksums for verification (hw assisted, if available)",
1794 },
1795 { .ival = "crc32c",
1796 .oval = VERIFY_CRC32C,
1797 .help = "Use crc32c checksums for verification (hw assisted, if available)",
1798 },
1799 { .ival = "crc16",
1800 .oval = VERIFY_CRC16,
1801 .help = "Use crc16 checksums for verification",
1802 },
1803 { .ival = "crc7",
1804 .oval = VERIFY_CRC7,
1805 .help = "Use crc7 checksums for verification",
1806 },
1807 { .ival = "sha1",
1808 .oval = VERIFY_SHA1,
1809 .help = "Use sha1 checksums for verification",
1810 },
1811 { .ival = "sha256",
1812 .oval = VERIFY_SHA256,
1813 .help = "Use sha256 checksums for verification",
1814 },
1815 { .ival = "sha512",
1816 .oval = VERIFY_SHA512,
1817 .help = "Use sha512 checksums for verification",
1818 },
1819 { .ival = "meta",
1820 .oval = VERIFY_META,
1821 .help = "Use io information",
1822 },
1823 {
1824 .ival = "null",
1825 .oval = VERIFY_NULL,
1826 .help = "Pretend to verify",
1827 },
1828 },
1829 },
1830 {
1831 .name = "do_verify",
1832 .lname = "Perform verify step",
1833 .type = FIO_OPT_BOOL,
1834 .off1 = td_var_offset(do_verify),
1835 .help = "Run verification stage after write",
1836 .def = "1",
1837 .parent = "verify",
1838 .hide = 1,
1839 .category = FIO_OPT_C_IO,
1840 .group = FIO_OPT_G_VERIFY,
1841 },
1842 {
1843 .name = "verifysort",
1844 .lname = "Verify sort",
1845 .type = FIO_OPT_BOOL,
1846 .off1 = td_var_offset(verifysort),
1847 .help = "Sort written verify blocks for read back",
1848 .def = "1",
1849 .parent = "verify",
1850 .hide = 1,
1851 .category = FIO_OPT_C_IO,
1852 .group = FIO_OPT_G_VERIFY,
1853 },
1854 {
1855 .name = "verify_interval",
1856 .lname = "Verify interval",
1857 .type = FIO_OPT_INT,
1858 .off1 = td_var_offset(verify_interval),
1859 .minval = 2 * sizeof(struct verify_header),
1860 .help = "Store verify buffer header every N bytes",
1861 .parent = "verify",
1862 .hide = 1,
1863 .interval = 2 * sizeof(struct verify_header),
1864 .category = FIO_OPT_C_IO,
1865 .group = FIO_OPT_G_VERIFY,
1866 },
1867 {
1868 .name = "verify_offset",
1869 .lname = "Verify offset",
1870 .type = FIO_OPT_INT,
1871 .help = "Offset verify header location by N bytes",
1872 .def = "0",
1873 .cb = str_verify_offset_cb,
1874 .parent = "verify",
1875 .hide = 1,
1876 .category = FIO_OPT_C_IO,
1877 .group = FIO_OPT_G_VERIFY,
1878 },
1879 {
1880 .name = "verify_pattern",
1881 .lname = "Verify pattern",
1882 .type = FIO_OPT_STR,
1883 .cb = str_verify_pattern_cb,
1884 .help = "Fill pattern for IO buffers",
1885 .parent = "verify",
1886 .hide = 1,
1887 .category = FIO_OPT_C_IO,
1888 .group = FIO_OPT_G_VERIFY,
1889 },
1890 {
1891 .name = "verify_fatal",
1892 .lname = "Verify fatal",
1893 .type = FIO_OPT_BOOL,
1894 .off1 = td_var_offset(verify_fatal),
1895 .def = "0",
1896 .help = "Exit on a single verify failure, don't continue",
1897 .parent = "verify",
1898 .hide = 1,
1899 .category = FIO_OPT_C_IO,
1900 .group = FIO_OPT_G_VERIFY,
1901 },
1902 {
1903 .name = "verify_dump",
1904 .lname = "Verify dump",
1905 .type = FIO_OPT_BOOL,
1906 .off1 = td_var_offset(verify_dump),
1907 .def = "0",
1908 .help = "Dump contents of good and bad blocks on failure",
1909 .parent = "verify",
1910 .hide = 1,
1911 .category = FIO_OPT_C_IO,
1912 .group = FIO_OPT_G_VERIFY,
1913 },
1914 {
1915 .name = "verify_async",
1916 .lname = "Verify asynchronously",
1917 .type = FIO_OPT_INT,
1918 .off1 = td_var_offset(verify_async),
1919 .def = "0",
1920 .help = "Number of async verifier threads to use",
1921 .parent = "verify",
1922 .hide = 1,
1923 .category = FIO_OPT_C_IO,
1924 .group = FIO_OPT_G_VERIFY,
1925 },
1926 {
1927 .name = "verify_backlog",
1928 .lname = "Verify backlog",
1929 .type = FIO_OPT_STR_VAL,
1930 .off1 = td_var_offset(verify_backlog),
1931 .help = "Verify after this number of blocks are written",
1932 .parent = "verify",
1933 .hide = 1,
1934 .category = FIO_OPT_C_IO,
1935 .group = FIO_OPT_G_VERIFY,
1936 },
1937 {
1938 .name = "verify_backlog_batch",
1939 .lname = "Verify backlog batch",
1940 .type = FIO_OPT_INT,
1941 .off1 = td_var_offset(verify_batch),
1942 .help = "Verify this number of IO blocks",
1943 .parent = "verify",
1944 .hide = 1,
1945 .category = FIO_OPT_C_IO,
1946 .group = FIO_OPT_G_VERIFY,
1947 },
1948#ifdef FIO_HAVE_CPU_AFFINITY
1949 {
1950 .name = "verify_async_cpus",
1951 .lname = "Async verify CPUs",
1952 .type = FIO_OPT_STR,
1953 .cb = str_verify_cpus_allowed_cb,
1954 .help = "Set CPUs allowed for async verify threads",
1955 .parent = "verify_async",
1956 .hide = 1,
1957 .category = FIO_OPT_C_IO,
1958 .group = FIO_OPT_G_VERIFY,
1959 },
1960#endif
1961#ifdef FIO_HAVE_TRIM
1962 {
1963 .name = "trim_percentage",
1964 .lname = "Trim percentage",
1965 .type = FIO_OPT_INT,
1966 .cb = str_verify_trim_cb,
1967 .minval = 0,
1968 .maxval = 100,
1969 .help = "Number of verify blocks to discard/trim",
1970 .parent = "verify",
1971 .def = "0",
1972 .interval = 1,
1973 .hide = 1,
1974 .category = FIO_OPT_C_IO,
1975 .group = FIO_OPT_G_TRIM,
1976 },
1977 {
1978 .name = "trim_verify_zero",
1979 .lname = "Verify trim zero",
1980 .type = FIO_OPT_BOOL,
1981 .help = "Verify that trim/discarded blocks are returned as zeroes",
1982 .off1 = td_var_offset(trim_zero),
1983 .parent = "trim_percentage",
1984 .hide = 1,
1985 .def = "1",
1986 .category = FIO_OPT_C_IO,
1987 .group = FIO_OPT_G_TRIM,
1988 },
1989 {
1990 .name = "trim_backlog",
1991 .lname = "Trim backlog",
1992 .type = FIO_OPT_STR_VAL,
1993 .off1 = td_var_offset(trim_backlog),
1994 .help = "Trim after this number of blocks are written",
1995 .parent = "trim_percentage",
1996 .hide = 1,
1997 .interval = 1,
1998 .category = FIO_OPT_C_IO,
1999 .group = FIO_OPT_G_TRIM,
2000 },
2001 {
2002 .name = "trim_backlog_batch",
2003 .lname = "Trim backlog batch",
2004 .type = FIO_OPT_INT,
2005 .off1 = td_var_offset(trim_batch),
2006 .help = "Trim this number of IO blocks",
2007 .parent = "trim_percentage",
2008 .hide = 1,
2009 .interval = 1,
2010 .category = FIO_OPT_C_IO,
2011 .group = FIO_OPT_G_TRIM,
2012 },
2013#endif
2014 {
2015 .name = "write_iolog",
2016 .lname = "Write I/O log",
2017 .type = FIO_OPT_STR_STORE,
2018 .off1 = td_var_offset(write_iolog_file),
2019 .help = "Store IO pattern to file",
2020 .category = FIO_OPT_C_IO,
2021 .group = FIO_OPT_G_IOLOG,
2022 },
2023 {
2024 .name = "read_iolog",
2025 .lname = "Read I/O log",
2026 .type = FIO_OPT_STR_STORE,
2027 .off1 = td_var_offset(read_iolog_file),
2028 .help = "Playback IO pattern from file",
2029 .category = FIO_OPT_C_IO,
2030 .group = FIO_OPT_G_IOLOG,
2031 },
2032 {
2033 .name = "replay_no_stall",
2034 .lname = "Don't stall on replay",
2035 .type = FIO_OPT_BOOL,
2036 .off1 = td_var_offset(no_stall),
2037 .def = "0",
2038 .parent = "read_iolog",
2039 .hide = 1,
2040 .help = "Playback IO pattern file as fast as possible without stalls",
2041 .category = FIO_OPT_C_IO,
2042 .group = FIO_OPT_G_IOLOG,
2043 },
2044 {
2045 .name = "replay_redirect",
2046 .lname = "Redirect device for replay",
2047 .type = FIO_OPT_STR_STORE,
2048 .off1 = td_var_offset(replay_redirect),
2049 .parent = "read_iolog",
2050 .hide = 1,
2051 .help = "Replay all I/O onto this device, regardless of trace device",
2052 .category = FIO_OPT_C_IO,
2053 .group = FIO_OPT_G_IOLOG,
2054 },
2055 {
2056 .name = "exec_prerun",
2057 .lname = "Pre-execute runnable",
2058 .type = FIO_OPT_STR_STORE,
2059 .off1 = td_var_offset(exec_prerun),
2060 .help = "Execute this file prior to running job",
2061 .category = FIO_OPT_C_GENERAL,
2062 .group = FIO_OPT_G_INVALID,
2063 },
2064 {
2065 .name = "exec_postrun",
2066 .lname = "Post-execute runnable",
2067 .type = FIO_OPT_STR_STORE,
2068 .off1 = td_var_offset(exec_postrun),
2069 .help = "Execute this file after running job",
2070 .category = FIO_OPT_C_GENERAL,
2071 .group = FIO_OPT_G_INVALID,
2072 },
2073#ifdef FIO_HAVE_IOSCHED_SWITCH
2074 {
2075 .name = "ioscheduler",
2076 .lname = "I/O scheduler",
2077 .type = FIO_OPT_STR_STORE,
2078 .off1 = td_var_offset(ioscheduler),
2079 .help = "Use this IO scheduler on the backing device",
2080 .category = FIO_OPT_C_FILE,
2081 .group = FIO_OPT_G_INVALID,
2082 },
2083#endif
2084 {
2085 .name = "zonesize",
2086 .lname = "Zone size",
2087 .type = FIO_OPT_STR_VAL,
2088 .off1 = td_var_offset(zone_size),
2089 .help = "Amount of data to read per zone",
2090 .def = "0",
2091 .interval = 1024 * 1024,
2092 .category = FIO_OPT_C_IO,
2093 .group = FIO_OPT_G_ZONE,
2094 },
2095 {
2096 .name = "zonerange",
2097 .lname = "Zone range",
2098 .type = FIO_OPT_STR_VAL,
2099 .off1 = td_var_offset(zone_range),
2100 .help = "Give size of an IO zone",
2101 .def = "0",
2102 .interval = 1024 * 1024,
2103 .category = FIO_OPT_C_IO,
2104 .group = FIO_OPT_G_ZONE,
2105 },
2106 {
2107 .name = "zoneskip",
2108 .lname = "Zone skip",
2109 .type = FIO_OPT_STR_VAL,
2110 .off1 = td_var_offset(zone_skip),
2111 .help = "Space between IO zones",
2112 .def = "0",
2113 .interval = 1024 * 1024,
2114 .category = FIO_OPT_C_IO,
2115 .group = FIO_OPT_G_ZONE,
2116 },
2117 {
2118 .name = "lockmem",
2119 .lname = "Lock memory",
2120 .type = FIO_OPT_STR_VAL,
2121 .cb = str_lockmem_cb,
2122 .help = "Lock down this amount of memory",
2123 .def = "0",
2124 .interval = 1024 * 1024,
2125 .category = FIO_OPT_C_GENERAL,
2126 .group = FIO_OPT_G_INVALID,
2127 },
2128 {
2129 .name = "rwmixread",
2130 .lname = "Read/write mix read",
2131 .type = FIO_OPT_INT,
2132 .cb = str_rwmix_read_cb,
2133 .maxval = 100,
2134 .help = "Percentage of mixed workload that is reads",
2135 .def = "50",
2136 .interval = 5,
2137 .inverse = "rwmixwrite",
2138 .category = FIO_OPT_C_IO,
2139 .group = FIO_OPT_G_RWMIX,
2140 },
2141 {
2142 .name = "rwmixwrite",
2143 .lname = "Read/write mix write",
2144 .type = FIO_OPT_INT,
2145 .cb = str_rwmix_write_cb,
2146 .maxval = 100,
2147 .help = "Percentage of mixed workload that is writes",
2148 .def = "50",
2149 .interval = 5,
2150 .inverse = "rwmixread",
2151 .category = FIO_OPT_C_IO,
2152 .group = FIO_OPT_G_RWMIX,
2153 },
2154 {
2155 .name = "rwmixcycle",
2156 .lname = "Read/write mix cycle",
2157 .type = FIO_OPT_DEPRECATED,
2158 .category = FIO_OPT_C_IO,
2159 .group = FIO_OPT_G_RWMIX,
2160 },
2161 {
2162 .name = "nice",
2163 .lname = "Nice",
2164 .type = FIO_OPT_INT,
2165 .off1 = td_var_offset(nice),
2166 .help = "Set job CPU nice value",
2167 .minval = -19,
2168 .maxval = 20,
2169 .def = "0",
2170 .interval = 1,
2171 .category = FIO_OPT_C_GENERAL,
2172 .group = FIO_OPT_G_CRED,
2173 },
2174#ifdef FIO_HAVE_IOPRIO
2175 {
2176 .name = "prio",
2177 .lname = "I/O nice priority",
2178 .type = FIO_OPT_INT,
2179 .cb = str_prio_cb,
2180 .help = "Set job IO priority value",
2181 .minval = 0,
2182 .maxval = 7,
2183 .interval = 1,
2184 .category = FIO_OPT_C_GENERAL,
2185 .group = FIO_OPT_G_CRED,
2186 },
2187 {
2188 .name = "prioclass",
2189 .lname = "I/O nice priority class",
2190 .type = FIO_OPT_INT,
2191 .cb = str_prioclass_cb,
2192 .help = "Set job IO priority class",
2193 .minval = 0,
2194 .maxval = 3,
2195 .interval = 1,
2196 .category = FIO_OPT_C_GENERAL,
2197 .group = FIO_OPT_G_CRED,
2198 },
2199#endif
2200 {
2201 .name = "thinktime",
2202 .lname = "Thinktime",
2203 .type = FIO_OPT_INT,
2204 .off1 = td_var_offset(thinktime),
2205 .help = "Idle time between IO buffers (usec)",
2206 .def = "0",
2207 .category = FIO_OPT_C_IO,
2208 .group = FIO_OPT_G_INVALID,
2209 },
2210 {
2211 .name = "thinktime_spin",
2212 .lname = "Thinktime spin",
2213 .type = FIO_OPT_INT,
2214 .off1 = td_var_offset(thinktime_spin),
2215 .help = "Start think time by spinning this amount (usec)",
2216 .def = "0",
2217 .parent = "thinktime",
2218 .hide = 1,
2219 .category = FIO_OPT_C_IO,
2220 .group = FIO_OPT_G_INVALID,
2221 },
2222 {
2223 .name = "thinktime_blocks",
2224 .lname = "Thinktime blocks",
2225 .type = FIO_OPT_INT,
2226 .off1 = td_var_offset(thinktime_blocks),
2227 .help = "IO buffer period between 'thinktime'",
2228 .def = "1",
2229 .parent = "thinktime",
2230 .hide = 1,
2231 .category = FIO_OPT_C_IO,
2232 .group = FIO_OPT_G_INVALID,
2233 },
2234 {
2235 .name = "rate",
2236 .lname = "I/O rate",
2237 .type = FIO_OPT_INT,
2238 .off1 = td_var_offset(rate[0]),
2239 .off2 = td_var_offset(rate[1]),
2240 .help = "Set bandwidth rate",
2241 .category = FIO_OPT_C_IO,
2242 .group = FIO_OPT_G_RATE,
2243 },
2244 {
2245 .name = "ratemin",
2246 .lname = "I/O min rate",
2247 .type = FIO_OPT_INT,
2248 .off1 = td_var_offset(ratemin[0]),
2249 .off2 = td_var_offset(ratemin[1]),
2250 .help = "Job must meet this rate or it will be shutdown",
2251 .parent = "rate",
2252 .hide = 1,
2253 .category = FIO_OPT_C_IO,
2254 .group = FIO_OPT_G_RATE,
2255 },
2256 {
2257 .name = "rate_iops",
2258 .lname = "I/O rate IOPS",
2259 .type = FIO_OPT_INT,
2260 .off1 = td_var_offset(rate_iops[0]),
2261 .off2 = td_var_offset(rate_iops[1]),
2262 .help = "Limit IO used to this number of IO operations/sec",
2263 .hide = 1,
2264 .category = FIO_OPT_C_IO,
2265 .group = FIO_OPT_G_RATE,
2266 },
2267 {
2268 .name = "rate_iops_min",
2269 .lname = "I/O min rate IOPS",
2270 .type = FIO_OPT_INT,
2271 .off1 = td_var_offset(rate_iops_min[0]),
2272 .off2 = td_var_offset(rate_iops_min[1]),
2273 .help = "Job must meet this rate or it will be shut down",
2274 .parent = "rate_iops",
2275 .hide = 1,
2276 .category = FIO_OPT_C_IO,
2277 .group = FIO_OPT_G_RATE,
2278 },
2279 {
2280 .name = "ratecycle",
2281 .lname = "I/O rate cycle",
2282 .type = FIO_OPT_INT,
2283 .off1 = td_var_offset(ratecycle),
2284 .help = "Window average for rate limits (msec)",
2285 .def = "1000",
2286 .parent = "rate",
2287 .hide = 1,
2288 .category = FIO_OPT_C_IO,
2289 .group = FIO_OPT_G_RATE,
2290 },
2291 {
2292 .name = "invalidate",
2293 .lname = "Cache invalidate",
2294 .type = FIO_OPT_BOOL,
2295 .off1 = td_var_offset(invalidate_cache),
2296 .help = "Invalidate buffer/page cache prior to running job",
2297 .def = "1",
2298 .category = FIO_OPT_C_IO,
2299 .group = FIO_OPT_G_INVALID,
2300 },
2301 {
2302 .name = "sync",
2303 .lname = "Synchronous I/O",
2304 .type = FIO_OPT_BOOL,
2305 .off1 = td_var_offset(sync_io),
2306 .help = "Use O_SYNC for buffered writes",
2307 .def = "0",
2308 .parent = "buffered",
2309 .hide = 1,
2310 .category = FIO_OPT_C_IO,
2311 .group = FIO_OPT_G_INVALID,
2312 },
2313 {
2314 .name = "bwavgtime",
2315 .lname = "Bandwidth average time",
2316 .type = FIO_OPT_INT,
2317 .off1 = td_var_offset(bw_avg_time),
2318 .help = "Time window over which to calculate bandwidth"
2319 " (msec)",
2320 .def = "500",
2321 .parent = "write_bw_log",
2322 .hide = 1,
2323 .interval = 100,
2324 .category = FIO_OPT_C_LOG,
2325 .group = FIO_OPT_G_INVALID,
2326 },
2327 {
2328 .name = "iopsavgtime",
2329 .lname = "IOPS average time",
2330 .type = FIO_OPT_INT,
2331 .off1 = td_var_offset(iops_avg_time),
2332 .help = "Time window over which to calculate IOPS (msec)",
2333 .def = "500",
2334 .parent = "write_iops_log",
2335 .hide = 1,
2336 .interval = 100,
2337 .category = FIO_OPT_C_LOG,
2338 .group = FIO_OPT_G_INVALID,
2339 },
2340 {
2341 .name = "create_serialize",
2342 .lname = "Create serialize",
2343 .type = FIO_OPT_BOOL,
2344 .off1 = td_var_offset(create_serialize),
2345 .help = "Serialize creating of job files",
2346 .def = "1",
2347 .category = FIO_OPT_C_FILE,
2348 .group = FIO_OPT_G_INVALID,
2349 },
2350 {
2351 .name = "create_fsync",
2352 .lname = "Create fsync",
2353 .type = FIO_OPT_BOOL,
2354 .off1 = td_var_offset(create_fsync),
2355 .help = "fsync file after creation",
2356 .def = "1",
2357 .category = FIO_OPT_C_FILE,
2358 .group = FIO_OPT_G_INVALID,
2359 },
2360 {
2361 .name = "create_on_open",
2362 .lname = "Create on open",
2363 .type = FIO_OPT_BOOL,
2364 .off1 = td_var_offset(create_on_open),
2365 .help = "Create files when they are opened for IO",
2366 .def = "0",
2367 .category = FIO_OPT_C_FILE,
2368 .group = FIO_OPT_G_INVALID,
2369 },
2370 {
2371 .name = "pre_read",
2372 .lname = "Pre-read files",
2373 .type = FIO_OPT_BOOL,
2374 .off1 = td_var_offset(pre_read),
2375 .help = "Pre-read files before starting official testing",
2376 .def = "0",
2377 .category = FIO_OPT_C_FILE,
2378 .group = FIO_OPT_G_INVALID,
2379 },
2380 {
2381 .name = "cpuload",
2382 .lname = "CPU load",
2383 .type = FIO_OPT_INT,
2384 .off1 = td_var_offset(cpuload),
2385 .help = "Use this percentage of CPU",
2386 .category = FIO_OPT_C_GENERAL,
2387 .group = FIO_OPT_G_INVALID,
2388 },
2389 {
2390 .name = "cpuchunks",
2391 .lname = "CPU chunk",
2392 .type = FIO_OPT_INT,
2393 .off1 = td_var_offset(cpucycle),
2394 .help = "Length of the CPU burn cycles (usecs)",
2395 .def = "50000",
2396 .parent = "cpuload",
2397 .hide = 1,
2398 .category = FIO_OPT_C_GENERAL,
2399 .group = FIO_OPT_G_INVALID,
2400 },
2401#ifdef FIO_HAVE_CPU_AFFINITY
2402 {
2403 .name = "cpumask",
2404 .lname = "CPU mask",
2405 .type = FIO_OPT_INT,
2406 .cb = str_cpumask_cb,
2407 .help = "CPU affinity mask",
2408 .category = FIO_OPT_C_GENERAL,
2409 .group = FIO_OPT_G_CRED,
2410 },
2411 {
2412 .name = "cpus_allowed",
2413 .lname = "CPUs allowed",
2414 .type = FIO_OPT_STR,
2415 .cb = str_cpus_allowed_cb,
2416 .help = "Set CPUs allowed",
2417 .category = FIO_OPT_C_GENERAL,
2418 .group = FIO_OPT_G_CRED,
2419 },
2420#endif
2421 {
2422 .name = "end_fsync",
2423 .lname = "End fsync",
2424 .type = FIO_OPT_BOOL,
2425 .off1 = td_var_offset(end_fsync),
2426 .help = "Include fsync at the end of job",
2427 .def = "0",
2428 .category = FIO_OPT_C_FILE,
2429 .group = FIO_OPT_G_INVALID,
2430 },
2431 {
2432 .name = "fsync_on_close",
2433 .lname = "Fsync on close",
2434 .type = FIO_OPT_BOOL,
2435 .off1 = td_var_offset(fsync_on_close),
2436 .help = "fsync files on close",
2437 .def = "0",
2438 .category = FIO_OPT_C_FILE,
2439 .group = FIO_OPT_G_INVALID,
2440 },
2441 {
2442 .name = "unlink",
2443 .lname = "Unlink file",
2444 .type = FIO_OPT_BOOL,
2445 .off1 = td_var_offset(unlink),
2446 .help = "Unlink created files after job has completed",
2447 .def = "0",
2448 .category = FIO_OPT_C_FILE,
2449 .group = FIO_OPT_G_INVALID,
2450 },
2451 {
2452 .name = "exitall",
2453 .lname = "Exit-all on terminate",
2454 .type = FIO_OPT_STR_SET,
2455 .cb = str_exitall_cb,
2456 .help = "Terminate all jobs when one exits",
2457 .category = FIO_OPT_C_GENERAL,
2458 .group = FIO_OPT_G_PROCESS,
2459 },
2460 {
2461 .name = "stonewall",
2462 .lname = "Wait for previous",
2463 .alias = "wait_for_previous",
2464 .type = FIO_OPT_STR_SET,
2465 .off1 = td_var_offset(stonewall),
2466 .help = "Insert a hard barrier between this job and previous",
2467 .category = FIO_OPT_C_GENERAL,
2468 .group = FIO_OPT_G_PROCESS,
2469 },
2470 {
2471 .name = "new_group",
2472 .lname = "New group",
2473 .type = FIO_OPT_STR_SET,
2474 .off1 = td_var_offset(new_group),
2475 .help = "Mark the start of a new group (for reporting)",
2476 .category = FIO_OPT_C_GENERAL,
2477 .group = FIO_OPT_G_PROCESS,
2478 },
2479 {
2480 .name = "thread",
2481 .lname = "Thread",
2482 .type = FIO_OPT_STR_SET,
2483 .off1 = td_var_offset(use_thread),
2484 .help = "Use threads instead of processes",
2485 .category = FIO_OPT_C_GENERAL,
2486 .group = FIO_OPT_G_PROCESS,
2487 },
2488 {
2489 .name = "write_bw_log",
2490 .lname = "Write bandwidth log",
2491 .type = FIO_OPT_STR,
2492 .off1 = td_var_offset(write_bw_log),
2493 .cb = str_write_bw_log_cb,
2494 .help = "Write log of bandwidth during run",
2495 .category = FIO_OPT_C_LOG,
2496 .group = FIO_OPT_G_INVALID,
2497 },
2498 {
2499 .name = "write_lat_log",
2500 .lname = "Write latency log",
2501 .type = FIO_OPT_STR,
2502 .off1 = td_var_offset(write_lat_log),
2503 .cb = str_write_lat_log_cb,
2504 .help = "Write log of latency during run",
2505 .category = FIO_OPT_C_LOG,
2506 .group = FIO_OPT_G_INVALID,
2507 },
2508 {
2509 .name = "write_iops_log",
2510 .lname = "Write IOPS log",
2511 .type = FIO_OPT_STR,
2512 .off1 = td_var_offset(write_iops_log),
2513 .cb = str_write_iops_log_cb,
2514 .help = "Write log of IOPS during run",
2515 .category = FIO_OPT_C_LOG,
2516 .group = FIO_OPT_G_INVALID,
2517 },
2518 {
2519 .name = "log_avg_msec",
2520 .lname = "Log averaging (msec)",
2521 .type = FIO_OPT_INT,
2522 .off1 = td_var_offset(log_avg_msec),
2523 .help = "Average bw/iops/lat logs over this period of time",
2524 .def = "0",
2525 .category = FIO_OPT_C_LOG,
2526 .group = FIO_OPT_G_INVALID,
2527 },
2528 {
2529 .name = "hugepage-size",
2530 .lname = "Hugepage size",
2531 .type = FIO_OPT_INT,
2532 .off1 = td_var_offset(hugepage_size),
2533 .help = "When using hugepages, specify size of each page",
2534 .def = __fio_stringify(FIO_HUGE_PAGE),
2535 .interval = 1024 * 1024,
2536 .category = FIO_OPT_C_GENERAL,
2537 .group = FIO_OPT_G_INVALID,
2538 },
2539 {
2540 .name = "group_reporting",
2541 .lname = "Group reporting",
2542 .type = FIO_OPT_BOOL,
2543 .off1 = td_var_offset(group_reporting),
2544 .help = "Do reporting on a per-group basis",
2545 .def = "1",
2546 .category = FIO_OPT_C_STAT,
2547 .group = FIO_OPT_G_INVALID,
2548 },
2549 {
2550 .name = "zero_buffers",
2551 .lname = "Zero I/O buffers",
2552 .type = FIO_OPT_STR_SET,
2553 .off1 = td_var_offset(zero_buffers),
2554 .help = "Init IO buffers to all zeroes",
2555 .category = FIO_OPT_C_IO,
2556 .group = FIO_OPT_G_INVALID,
2557 },
2558 {
2559 .name = "refill_buffers",
2560 .lname = "Refill I/O buffers",
2561 .type = FIO_OPT_STR_SET,
2562 .off1 = td_var_offset(refill_buffers),
2563 .help = "Refill IO buffers on every IO submit",
2564 .category = FIO_OPT_C_IO,
2565 .group = FIO_OPT_G_INVALID,
2566 },
2567 {
2568 .name = "scramble_buffers",
2569 .lname = "Scramble I/O buffers",
2570 .type = FIO_OPT_BOOL,
2571 .off1 = td_var_offset(scramble_buffers),
2572 .help = "Slightly scramble buffers on every IO submit",
2573 .def = "1",
2574 .category = FIO_OPT_C_IO,
2575 .group = FIO_OPT_G_INVALID,
2576 },
2577 {
2578 .name = "buffer_compress_percentage",
2579 .lname = "Buffer compression percentage",
2580 .type = FIO_OPT_INT,
2581 .off1 = td_var_offset(compress_percentage),
2582 .maxval = 100,
2583 .minval = 1,
2584 .help = "How compressible the buffer is (approximately)",
2585 .interval = 5,
2586 .category = FIO_OPT_C_IO,
2587 .group = FIO_OPT_G_INVALID,
2588 },
2589 {
2590 .name = "buffer_compress_chunk",
2591 .lname = "Buffer compression chunk size",
2592 .type = FIO_OPT_INT,
2593 .off1 = td_var_offset(compress_chunk),
2594 .parent = "buffer_compress_percentage",
2595 .hide = 1,
2596 .help = "Size of compressible region in buffer",
2597 .interval = 256,
2598 .category = FIO_OPT_C_IO,
2599 .group = FIO_OPT_G_INVALID,
2600 },
2601 {
2602 .name = "clat_percentiles",
2603 .lname = "Completion latency percentiles",
2604 .type = FIO_OPT_BOOL,
2605 .off1 = td_var_offset(clat_percentiles),
2606 .help = "Enable the reporting of completion latency percentiles",
2607 .def = "1",
2608 .category = FIO_OPT_C_STAT,
2609 .group = FIO_OPT_G_INVALID,
2610 },
2611 {
2612 .name = "percentile_list",
2613 .lname = "Completion latency percentile list",
2614 .type = FIO_OPT_FLOAT_LIST,
2615 .off1 = td_var_offset(percentile_list),
2616 .off2 = td_var_offset(overwrite_plist),
2617 .help = "Specify a custom list of percentiles to report",
2618 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2619 .minfp = 0.0,
2620 .maxfp = 100.0,
2621 .category = FIO_OPT_C_STAT,
2622 .group = FIO_OPT_G_INVALID,
2623 },
2624
2625#ifdef FIO_HAVE_DISK_UTIL
2626 {
2627 .name = "disk_util",
2628 .lname = "Disk utilization",
2629 .type = FIO_OPT_BOOL,
2630 .off1 = td_var_offset(do_disk_util),
2631 .help = "Log disk utilization statistics",
2632 .def = "1",
2633 .category = FIO_OPT_C_STAT,
2634 .group = FIO_OPT_G_INVALID,
2635 },
2636#endif
2637 {
2638 .name = "gtod_reduce",
2639 .lname = "Reduce gettimeofday() calls",
2640 .type = FIO_OPT_BOOL,
2641 .help = "Greatly reduce number of gettimeofday() calls",
2642 .cb = str_gtod_reduce_cb,
2643 .def = "0",
2644 .category = FIO_OPT_C_STAT,
2645 .group = FIO_OPT_G_INVALID,
2646 },
2647 {
2648 .name = "disable_lat",
2649 .lname = "Disable all latency stats",
2650 .type = FIO_OPT_BOOL,
2651 .off1 = td_var_offset(disable_lat),
2652 .help = "Disable latency numbers",
2653 .parent = "gtod_reduce",
2654 .hide = 1,
2655 .def = "0",
2656 .category = FIO_OPT_C_STAT,
2657 .group = FIO_OPT_G_INVALID,
2658 },
2659 {
2660 .name = "disable_clat",
2661 .lname = "Disable completion latency stats",
2662 .type = FIO_OPT_BOOL,
2663 .off1 = td_var_offset(disable_clat),
2664 .help = "Disable completion latency numbers",
2665 .parent = "gtod_reduce",
2666 .hide = 1,
2667 .def = "0",
2668 .category = FIO_OPT_C_STAT,
2669 .group = FIO_OPT_G_INVALID,
2670 },
2671 {
2672 .name = "disable_slat",
2673 .lname = "Disable submission latency stats",
2674 .type = FIO_OPT_BOOL,
2675 .off1 = td_var_offset(disable_slat),
2676 .help = "Disable submission latency numbers",
2677 .parent = "gtod_reduce",
2678 .hide = 1,
2679 .def = "0",
2680 .category = FIO_OPT_C_STAT,
2681 .group = FIO_OPT_G_INVALID,
2682 },
2683 {
2684 .name = "disable_bw_measurement",
2685 .lname = "Disable bandwidth stats",
2686 .type = FIO_OPT_BOOL,
2687 .off1 = td_var_offset(disable_bw),
2688 .help = "Disable bandwidth logging",
2689 .parent = "gtod_reduce",
2690 .hide = 1,
2691 .def = "0",
2692 .category = FIO_OPT_C_STAT,
2693 .group = FIO_OPT_G_INVALID,
2694 },
2695 {
2696 .name = "gtod_cpu",
2697 .lname = "Dedicated gettimeofday() CPU",
2698 .type = FIO_OPT_INT,
2699 .cb = str_gtod_cpu_cb,
2700 .help = "Set up dedicated gettimeofday() thread on this CPU",
2701 .verify = gtod_cpu_verify,
2702 .category = FIO_OPT_C_GENERAL,
2703 .group = FIO_OPT_G_CLOCK,
2704 },
2705 {
2706 .name = "continue_on_error",
2707 .lname = "Continue on error",
2708 .type = FIO_OPT_STR,
2709 .off1 = td_var_offset(continue_on_error),
2710 .help = "Continue on non-fatal errors during IO",
2711 .def = "none",
2712 .category = FIO_OPT_C_GENERAL,
2713 .group = FIO_OPT_G_INVALID,
2714 .posval = {
2715 { .ival = "none",
2716 .oval = ERROR_TYPE_NONE,
2717 .help = "Exit when an error is encountered",
2718 },
2719 { .ival = "read",
2720 .oval = ERROR_TYPE_READ,
2721 .help = "Continue on read errors only",
2722 },
2723 { .ival = "write",
2724 .oval = ERROR_TYPE_WRITE,
2725 .help = "Continue on write errors only",
2726 },
2727 { .ival = "io",
2728 .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2729 .help = "Continue on any IO errors",
2730 },
2731 { .ival = "verify",
2732 .oval = ERROR_TYPE_VERIFY,
2733 .help = "Continue on verify errors only",
2734 },
2735 { .ival = "all",
2736 .oval = ERROR_TYPE_ANY,
2737 .help = "Continue on all io and verify errors",
2738 },
2739 { .ival = "0",
2740 .oval = ERROR_TYPE_NONE,
2741 .help = "Alias for 'none'",
2742 },
2743 { .ival = "1",
2744 .oval = ERROR_TYPE_ANY,
2745 .help = "Alias for 'all'",
2746 },
2747 },
2748 },
2749 {
2750 .name = "profile",
2751 .lname = "Profile",
2752 .type = FIO_OPT_STR_STORE,
2753 .off1 = td_var_offset(profile),
2754 .help = "Select a specific builtin performance test",
2755 .category = FIO_OPT_C_GENERAL,
2756 .group = FIO_OPT_G_INVALID,
2757 },
2758 {
2759 .name = "cgroup",
2760 .lname = "Cgroup",
2761 .type = FIO_OPT_STR_STORE,
2762 .off1 = td_var_offset(cgroup),
2763 .help = "Add job to cgroup of this name",
2764 .category = FIO_OPT_C_GENERAL,
2765 .group = FIO_OPT_G_CGROUP,
2766 },
2767 {
2768 .name = "cgroup_nodelete",
2769 .lname = "Cgroup no-delete",
2770 .type = FIO_OPT_BOOL,
2771 .off1 = td_var_offset(cgroup_nodelete),
2772 .help = "Do not delete cgroups after job completion",
2773 .def = "0",
2774 .parent = "cgroup",
2775 .category = FIO_OPT_C_GENERAL,
2776 .group = FIO_OPT_G_CGROUP,
2777 },
2778 {
2779 .name = "cgroup_weight",
2780 .lname = "Cgroup weight",
2781 .type = FIO_OPT_INT,
2782 .off1 = td_var_offset(cgroup_weight),
2783 .help = "Use given weight for cgroup",
2784 .minval = 100,
2785 .maxval = 1000,
2786 .parent = "cgroup",
2787 .category = FIO_OPT_C_GENERAL,
2788 .group = FIO_OPT_G_CGROUP,
2789 },
2790 {
2791 .name = "uid",
2792 .lname = "User ID",
2793 .type = FIO_OPT_INT,
2794 .off1 = td_var_offset(uid),
2795 .help = "Run job with this user ID",
2796 .category = FIO_OPT_C_GENERAL,
2797 .group = FIO_OPT_G_CRED,
2798 },
2799 {
2800 .name = "gid",
2801 .lname = "Group ID",
2802 .type = FIO_OPT_INT,
2803 .off1 = td_var_offset(gid),
2804 .help = "Run job with this group ID",
2805 .category = FIO_OPT_C_GENERAL,
2806 .group = FIO_OPT_G_CRED,
2807 },
2808 {
2809 .name = "kb_base",
2810 .lname = "KB Base",
2811 .type = FIO_OPT_INT,
2812 .off1 = td_var_offset(kb_base),
2813 .verify = kb_base_verify,
2814 .prio = 1,
2815 .def = "1024",
2816 .help = "How many bytes per KB for reporting (1000 or 1024)",
2817 .category = FIO_OPT_C_GENERAL,
2818 .group = FIO_OPT_G_INVALID,
2819 },
2820 {
2821 .name = "flow_id",
2822 .lname = "I/O flow ID",
2823 .type = FIO_OPT_INT,
2824 .off1 = td_var_offset(flow_id),
2825 .help = "The flow index ID to use",
2826 .def = "0",
2827 .category = FIO_OPT_C_IO,
2828 .group = FIO_OPT_G_IO_FLOW,
2829 },
2830 {
2831 .name = "flow",
2832 .lname = "I/O flow weight",
2833 .type = FIO_OPT_INT,
2834 .off1 = td_var_offset(flow),
2835 .help = "Weight for flow control of this job",
2836 .parent = "flow_id",
2837 .hide = 1,
2838 .def = "0",
2839 .category = FIO_OPT_C_IO,
2840 .group = FIO_OPT_G_IO_FLOW,
2841 },
2842 {
2843 .name = "flow_watermark",
2844 .lname = "I/O flow watermark",
2845 .type = FIO_OPT_INT,
2846 .off1 = td_var_offset(flow_watermark),
2847 .help = "High watermark for flow control. This option"
2848 " should be set to the same value for all threads"
2849 " with non-zero flow.",
2850 .parent = "flow_id",
2851 .hide = 1,
2852 .def = "1024",
2853 .category = FIO_OPT_C_IO,
2854 .group = FIO_OPT_G_IO_FLOW,
2855 },
2856 {
2857 .name = "flow_sleep",
2858 .lname = "I/O flow sleep",
2859 .type = FIO_OPT_INT,
2860 .off1 = td_var_offset(flow_sleep),
2861 .help = "How many microseconds to sleep after being held"
2862 " back by the flow control mechanism",
2863 .parent = "flow_id",
2864 .hide = 1,
2865 .def = "0",
2866 .category = FIO_OPT_C_IO,
2867 .group = FIO_OPT_G_IO_FLOW,
2868 },
2869 {
2870 .name = NULL,
2871 },
2872};
2873
2874static void add_to_lopt(struct option *lopt, struct fio_option *o,
2875 const char *name, int val)
2876{
2877 lopt->name = (char *) name;
2878 lopt->val = val;
2879 if (o->type == FIO_OPT_STR_SET)
2880 lopt->has_arg = no_argument;
2881 else
2882 lopt->has_arg = required_argument;
2883}
2884
2885static void options_to_lopts(struct fio_option *opts,
2886 struct option *long_options,
2887 int i, int option_type)
2888{
2889 struct fio_option *o = &opts[0];
2890 while (o->name) {
2891 add_to_lopt(&long_options[i], o, o->name, option_type);
2892 if (o->alias) {
2893 i++;
2894 add_to_lopt(&long_options[i], o, o->alias, option_type);
2895 }
2896
2897 i++;
2898 o++;
2899 assert(i < FIO_NR_OPTIONS);
2900 }
2901}
2902
2903void fio_options_set_ioengine_opts(struct option *long_options,
2904 struct thread_data *td)
2905{
2906 unsigned int i;
2907
2908 i = 0;
2909 while (long_options[i].name) {
2910 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2911 memset(&long_options[i], 0, sizeof(*long_options));
2912 break;
2913 }
2914 i++;
2915 }
2916
2917 /*
2918 * Just clear out the prior ioengine options.
2919 */
2920 if (!td || !td->eo)
2921 return;
2922
2923 options_to_lopts(td->io_ops->options, long_options, i,
2924 FIO_GETOPT_IOENGINE);
2925}
2926
2927void fio_options_dup_and_init(struct option *long_options)
2928{
2929 unsigned int i;
2930
2931 options_init(fio_options);
2932
2933 i = 0;
2934 while (long_options[i].name)
2935 i++;
2936
2937 options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
2938}
2939
2940struct fio_keyword {
2941 const char *word;
2942 const char *desc;
2943 char *replace;
2944};
2945
2946static struct fio_keyword fio_keywords[] = {
2947 {
2948 .word = "$pagesize",
2949 .desc = "Page size in the system",
2950 },
2951 {
2952 .word = "$mb_memory",
2953 .desc = "Megabytes of memory online",
2954 },
2955 {
2956 .word = "$ncpus",
2957 .desc = "Number of CPUs online in the system",
2958 },
2959 {
2960 .word = NULL,
2961 },
2962};
2963
2964void fio_keywords_init(void)
2965{
2966 unsigned long long mb_memory;
2967 char buf[128];
2968 long l;
2969
2970 sprintf(buf, "%lu", page_size);
2971 fio_keywords[0].replace = strdup(buf);
2972
2973 mb_memory = os_phys_mem() / (1024 * 1024);
2974 sprintf(buf, "%llu", mb_memory);
2975 fio_keywords[1].replace = strdup(buf);
2976
2977 l = cpus_online();
2978 sprintf(buf, "%lu", l);
2979 fio_keywords[2].replace = strdup(buf);
2980}
2981
2982#define BC_APP "bc"
2983
2984static char *bc_calc(char *str)
2985{
2986 char buf[128], *tmp;
2987 FILE *f;
2988 int ret;
2989
2990 /*
2991 * No math, just return string
2992 */
2993 if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2994 !strchr(str, '/')) || strchr(str, '\''))
2995 return str;
2996
2997 /*
2998 * Split option from value, we only need to calculate the value
2999 */
3000 tmp = strchr(str, '=');
3001 if (!tmp)
3002 return str;
3003
3004 tmp++;
3005
3006 /*
3007 * Prevent buffer overflows; such a case isn't reasonable anyway
3008 */
3009 if (strlen(str) >= 128 || strlen(tmp) > 100)
3010 return str;
3011
3012 sprintf(buf, "which %s > /dev/null", BC_APP);
3013 if (system(buf)) {
3014 log_err("fio: bc is needed for performing math\n");
3015 return NULL;
3016 }
3017
3018 sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
3019 f = popen(buf, "r");
3020 if (!f) {
3021 return NULL;
3022 }
3023
3024 ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
3025 if (ret <= 0) {
3026 return NULL;
3027 }
3028
3029 pclose(f);
3030 buf[(tmp - str) + ret - 1] = '\0';
3031 memcpy(buf, str, tmp - str);
3032 free(str);
3033 return strdup(buf);
3034}
3035
3036/*
3037 * Return a copy of the input string with substrings of the form ${VARNAME}
3038 * substituted with the value of the environment variable VARNAME. The
3039 * substitution always occurs, even if VARNAME is empty or the corresponding
3040 * environment variable undefined.
3041 */
3042static char *option_dup_subs(const char *opt)
3043{
3044 char out[OPT_LEN_MAX+1];
3045 char in[OPT_LEN_MAX+1];
3046 char *outptr = out;
3047 char *inptr = in;
3048 char *ch1, *ch2, *env;
3049 ssize_t nchr = OPT_LEN_MAX;
3050 size_t envlen;
3051
3052 if (strlen(opt) + 1 > OPT_LEN_MAX) {
3053 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
3054 return NULL;
3055 }
3056
3057 in[OPT_LEN_MAX] = '\0';
3058 strncpy(in, opt, OPT_LEN_MAX);
3059
3060 while (*inptr && nchr > 0) {
3061 if (inptr[0] == '$' && inptr[1] == '{') {
3062 ch2 = strchr(inptr, '}');
3063 if (ch2 && inptr+1 < ch2) {
3064 ch1 = inptr+2;
3065 inptr = ch2+1;
3066 *ch2 = '\0';
3067
3068 env = getenv(ch1);
3069 if (env) {
3070 envlen = strlen(env);
3071 if (envlen <= nchr) {
3072 memcpy(outptr, env, envlen);
3073 outptr += envlen;
3074 nchr -= envlen;
3075 }
3076 }
3077
3078 continue;
3079 }
3080 }
3081
3082 *outptr++ = *inptr++;
3083 --nchr;
3084 }
3085
3086 *outptr = '\0';
3087 return strdup(out);
3088}
3089
3090/*
3091 * Look for reserved variable names and replace them with real values
3092 */
3093static char *fio_keyword_replace(char *opt)
3094{
3095 char *s;
3096 int i;
3097 int docalc = 0;
3098
3099 for (i = 0; fio_keywords[i].word != NULL; i++) {
3100 struct fio_keyword *kw = &fio_keywords[i];
3101
3102 while ((s = strstr(opt, kw->word)) != NULL) {
3103 char *new = malloc(strlen(opt) + 1);
3104 char *o_org = opt;
3105 int olen = s - opt;
3106 int len;
3107
3108 /*
3109 * Copy part of the string before the keyword and
3110 * sprintf() the replacement after it.
3111 */
3112 memcpy(new, opt, olen);
3113 len = sprintf(new + olen, "%s", kw->replace);
3114
3115 /*
3116 * If there's more in the original string, copy that
3117 * in too
3118 */
3119 opt += strlen(kw->word) + olen;
3120 if (strlen(opt))
3121 memcpy(new + olen + len, opt, opt - o_org - 1);
3122
3123 /*
3124 * replace opt and free the old opt
3125 */
3126 opt = new;
3127 free(o_org);
3128
3129 docalc = 1;
3130 }
3131 }
3132
3133 /*
3134 * Check for potential math and invoke bc, if possible
3135 */
3136 if (docalc)
3137 opt = bc_calc(opt);
3138
3139 return opt;
3140}
3141
3142static char **dup_and_sub_options(char **opts, int num_opts)
3143{
3144 int i;
3145 char **opts_copy = malloc(num_opts * sizeof(*opts));
3146 for (i = 0; i < num_opts; i++) {
3147 opts_copy[i] = option_dup_subs(opts[i]);
3148 if (!opts_copy[i])
3149 continue;
3150 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
3151 }
3152 return opts_copy;
3153}
3154
3155int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
3156{
3157 int i, ret, unknown;
3158 char **opts_copy;
3159
3160 sort_options(opts, fio_options, num_opts);
3161 opts_copy = dup_and_sub_options(opts, num_opts);
3162
3163 for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
3164 struct fio_option *o;
3165 int newret = parse_option(opts_copy[i], opts[i], fio_options,
3166 &o, td);
3167
3168 if (opts_copy[i]) {
3169 if (newret && !o) {
3170 unknown++;
3171 continue;
3172 }
3173 free(opts_copy[i]);
3174 opts_copy[i] = NULL;
3175 }
3176
3177 ret |= newret;
3178 }
3179
3180 if (unknown) {
3181 ret |= ioengine_load(td);
3182 if (td->eo) {
3183 sort_options(opts_copy, td->io_ops->options, num_opts);
3184 opts = opts_copy;
3185 }
3186 for (i = 0; i < num_opts; i++) {
3187 struct fio_option *o = NULL;
3188 int newret = 1;
3189 if (!opts_copy[i])
3190 continue;
3191
3192 if (td->eo)
3193 newret = parse_option(opts_copy[i], opts[i],
3194 td->io_ops->options, &o,
3195 td->eo);
3196
3197 ret |= newret;
3198 if (!o)
3199 log_err("Bad option <%s>\n", opts[i]);
3200
3201 free(opts_copy[i]);
3202 opts_copy[i] = NULL;
3203 }
3204 }
3205
3206 free(opts_copy);
3207 return ret;
3208}
3209
3210int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
3211{
3212 return parse_cmd_option(opt, val, fio_options, td);
3213}
3214
3215int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
3216 char *val)
3217{
3218 return parse_cmd_option(opt, val, td->io_ops->options, td);
3219}
3220
3221void fio_fill_default_options(struct thread_data *td)
3222{
3223 fill_default_options(td, fio_options);
3224}
3225
3226int fio_show_option_help(const char *opt)
3227{
3228 return show_cmd_help(fio_options, opt);
3229}
3230
3231void options_mem_dupe(void *data, struct fio_option *options)
3232{
3233 struct fio_option *o;
3234 char **ptr;
3235
3236 for (o = &options[0]; o->name; o++) {
3237 if (o->type != FIO_OPT_STR_STORE)
3238 continue;
3239
3240 ptr = td_var(data, o->off1);
3241 if (*ptr)
3242 *ptr = strdup(*ptr);
3243 }
3244}
3245
3246/*
3247 * dupe FIO_OPT_STR_STORE options
3248 */
3249void fio_options_mem_dupe(struct thread_data *td)
3250{
3251 options_mem_dupe(&td->o, fio_options);
3252
3253 if (td->eo && td->io_ops) {
3254 void *oldeo = td->eo;
3255
3256 td->eo = malloc(td->io_ops->option_struct_size);
3257 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
3258 options_mem_dupe(td->eo, td->io_ops->options);
3259 }
3260}
3261
3262unsigned int fio_get_kb_base(void *data)
3263{
3264 struct thread_data *td = data;
3265 unsigned int kb_base = 0;
3266
3267 if (td)
3268 kb_base = td->o.kb_base;
3269 if (!kb_base)
3270 kb_base = 1024;
3271
3272 return kb_base;
3273}
3274
3275int add_option(struct fio_option *o)
3276{
3277 struct fio_option *__o;
3278 int opt_index = 0;
3279
3280 __o = fio_options;
3281 while (__o->name) {
3282 opt_index++;
3283 __o++;
3284 }
3285
3286 memcpy(&fio_options[opt_index], o, sizeof(*o));
3287 return 0;
3288}
3289
3290void invalidate_profile_options(const char *prof_name)
3291{
3292 struct fio_option *o;
3293
3294 o = fio_options;
3295 while (o->name) {
3296 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
3297 o->type = FIO_OPT_INVALID;
3298 o->prof_name = NULL;
3299 }
3300 o++;
3301 }
3302}
3303
3304void add_opt_posval(const char *optname, const char *ival, const char *help)
3305{
3306 struct fio_option *o;
3307 unsigned int i;
3308
3309 o = find_option(fio_options, optname);
3310 if (!o)
3311 return;
3312
3313 for (i = 0; i < PARSE_MAX_VP; i++) {
3314 if (o->posval[i].ival)
3315 continue;
3316
3317 o->posval[i].ival = ival;
3318 o->posval[i].help = help;
3319 break;
3320 }
3321}
3322
3323void del_opt_posval(const char *optname, const char *ival)
3324{
3325 struct fio_option *o;
3326 unsigned int i;
3327
3328 o = find_option(fio_options, optname);
3329 if (!o)
3330 return;
3331
3332 for (i = 0; i < PARSE_MAX_VP; i++) {
3333 if (!o->posval[i].ival)
3334 continue;
3335 if (strcmp(o->posval[i].ival, ival))
3336 continue;
3337
3338 o->posval[i].ival = NULL;
3339 o->posval[i].help = NULL;
3340 }
3341}
3342
3343void fio_options_free(struct thread_data *td)
3344{
3345 options_free(fio_options, td);
3346 if (td->eo && td->io_ops && td->io_ops->options) {
3347 options_free(td->io_ops->options, td->eo);
3348 free(td->eo);
3349 td->eo = NULL;
3350 }
3351}