Avoid buildenv conditional in thread_option struct
[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_options *o, 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 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 == o->bssplit_nr[ddir]) {
88 o->bssplit_nr[ddir] <<= 1;
89 bssplit = realloc(bssplit, 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, o, 0)) {
106 log_err("fio: bssplit conversion failed\n");
107 free(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 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 < 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 < 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 o->min_bs[ddir] = min_bs;
155 o->max_bs[ddir] = max_bs;
156
157 /*
158 * now sort based on percentages, for ease of lookup
159 */
160 qsort(bssplit, o->bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161 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, *ddir;
169 int ret = 0;
170
171 if (parse_dryrun())
172 return 0;
173
174 p = str = strdup(input);
175
176 strip_blank_front(&str);
177 strip_blank_end(str);
178
179 odir = strchr(str, ',');
180 if (odir) {
181 ddir = strchr(odir + 1, ',');
182 if (ddir) {
183 ret = bssplit_ddir(&td->o, DDIR_TRIM, ddir + 1);
184 if (!ret)
185 *ddir = '\0';
186 } else {
187 char *op;
188
189 op = strdup(odir + 1);
190 ret = bssplit_ddir(&td->o, DDIR_TRIM, op);
191
192 free(op);
193 }
194 if (!ret)
195 ret = bssplit_ddir(&td->o, DDIR_WRITE, odir + 1);
196 if (!ret) {
197 *odir = '\0';
198 ret = bssplit_ddir(&td->o, DDIR_READ, str);
199 }
200 } else {
201 char *op;
202
203 op = strdup(str);
204 ret = bssplit_ddir(&td->o, DDIR_WRITE, op);
205 free(op);
206
207 if (!ret) {
208 op = strdup(str);
209 ret = bssplit_ddir(&td->o, DDIR_TRIM, op);
210 free(op);
211 }
212 ret = bssplit_ddir(&td->o, DDIR_READ, str);
213 }
214
215 free(p);
216 return ret;
217}
218
219static int str2error(char *str)
220{
221 const char *err[] = { "EPERM", "ENOENT", "ESRCH", "EINTR", "EIO",
222 "ENXIO", "E2BIG", "ENOEXEC", "EBADF",
223 "ECHILD", "EAGAIN", "ENOMEM", "EACCES",
224 "EFAULT", "ENOTBLK", "EBUSY", "EEXIST",
225 "EXDEV", "ENODEV", "ENOTDIR", "EISDIR",
226 "EINVAL", "ENFILE", "EMFILE", "ENOTTY",
227 "ETXTBSY","EFBIG", "ENOSPC", "ESPIPE",
228 "EROFS","EMLINK", "EPIPE", "EDOM", "ERANGE" };
229 int i = 0, num = sizeof(err) / sizeof(void *);
230
231 while (i < num) {
232 if (!strcmp(err[i], str))
233 return i + 1;
234 i++;
235 }
236 return 0;
237}
238
239static int ignore_error_type(struct thread_data *td, int etype, char *str)
240{
241 unsigned int i;
242 int *error;
243 char *fname;
244
245 if (etype >= ERROR_TYPE_CNT) {
246 log_err("Illegal error type\n");
247 return 1;
248 }
249
250 td->o.ignore_error_nr[etype] = 4;
251 error = malloc(4 * sizeof(struct bssplit));
252
253 i = 0;
254 while ((fname = strsep(&str, ":")) != NULL) {
255
256 if (!strlen(fname))
257 break;
258
259 /*
260 * grow struct buffer, if needed
261 */
262 if (i == td->o.ignore_error_nr[etype]) {
263 td->o.ignore_error_nr[etype] <<= 1;
264 error = realloc(error, td->o.ignore_error_nr[etype]
265 * sizeof(int));
266 }
267 if (fname[0] == 'E') {
268 error[i] = str2error(fname);
269 } else {
270 error[i] = atoi(fname);
271 if (error[i] < 0)
272 error[i] = -error[i];
273 }
274 if (!error[i]) {
275 log_err("Unknown error %s, please use number value \n",
276 fname);
277 free(error);
278 return 1;
279 }
280 i++;
281 }
282 if (i) {
283 td->o.continue_on_error |= 1 << etype;
284 td->o.ignore_error_nr[etype] = i;
285 td->o.ignore_error[etype] = error;
286 } else
287 free(error);
288
289 return 0;
290
291}
292
293static int str_ignore_error_cb(void *data, const char *input)
294{
295 struct thread_data *td = data;
296 char *str, *p, *n;
297 int type = 0, ret = 1;
298
299 if (parse_dryrun())
300 return 0;
301
302 p = str = strdup(input);
303
304 strip_blank_front(&str);
305 strip_blank_end(str);
306
307 while (p) {
308 n = strchr(p, ',');
309 if (n)
310 *n++ = '\0';
311 ret = ignore_error_type(td, type, p);
312 if (ret)
313 break;
314 p = n;
315 type++;
316 }
317 free(str);
318 return ret;
319}
320
321static int str_rw_cb(void *data, const char *str)
322{
323 struct thread_data *td = data;
324 struct thread_options *o = &td->o;
325 char *nr;
326
327 if (parse_dryrun())
328 return 0;
329
330 o->ddir_seq_nr = 1;
331 o->ddir_seq_add = 0;
332
333 nr = get_opt_postfix(str);
334 if (!nr)
335 return 0;
336
337 if (td_random(td))
338 o->ddir_seq_nr = atoi(nr);
339 else {
340 long long val;
341
342 if (str_to_decimal(nr, &val, 1, o, 0)) {
343 log_err("fio: rw postfix parsing failed\n");
344 free(nr);
345 return 1;
346 }
347
348 o->ddir_seq_add = val;
349 }
350
351 free(nr);
352 return 0;
353}
354
355static int str_mem_cb(void *data, const char *mem)
356{
357 struct thread_data *td = data;
358
359 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP)
360 td->o.mmapfile = get_opt_postfix(mem);
361
362 return 0;
363}
364
365static int fio_clock_source_cb(void *data, const char *str)
366{
367 struct thread_data *td = data;
368
369 fio_clock_source = td->o.clocksource;
370 fio_clock_source_set = 1;
371 fio_clock_init();
372 return 0;
373}
374
375static int str_rwmix_read_cb(void *data, unsigned long long *val)
376{
377 struct thread_data *td = data;
378
379 td->o.rwmix[DDIR_READ] = *val;
380 td->o.rwmix[DDIR_WRITE] = 100 - *val;
381 return 0;
382}
383
384static int str_rwmix_write_cb(void *data, unsigned long long *val)
385{
386 struct thread_data *td = data;
387
388 td->o.rwmix[DDIR_WRITE] = *val;
389 td->o.rwmix[DDIR_READ] = 100 - *val;
390 return 0;
391}
392
393static int str_exitall_cb(void)
394{
395 exitall_on_terminate = 1;
396 return 0;
397}
398
399#ifdef FIO_HAVE_CPU_AFFINITY
400int fio_cpus_split(os_cpu_mask_t *mask, unsigned int cpu_index)
401{
402 unsigned int i, index, cpus_in_mask;
403 const long max_cpu = cpus_online();
404
405 cpus_in_mask = fio_cpu_count(mask);
406 cpu_index = cpu_index % cpus_in_mask;
407
408 index = 0;
409 for (i = 0; i < max_cpu; i++) {
410 if (!fio_cpu_isset(mask, i))
411 continue;
412
413 if (cpu_index != index)
414 fio_cpu_clear(mask, i);
415
416 index++;
417 }
418
419 return fio_cpu_count(mask);
420}
421
422static int str_cpumask_cb(void *data, unsigned long long *val)
423{
424 struct thread_data *td = data;
425 unsigned int i;
426 long max_cpu;
427 int ret;
428
429 if (parse_dryrun())
430 return 0;
431
432 ret = fio_cpuset_init(&td->o.cpumask);
433 if (ret < 0) {
434 log_err("fio: cpuset_init failed\n");
435 td_verror(td, ret, "fio_cpuset_init");
436 return 1;
437 }
438
439 max_cpu = cpus_online();
440
441 for (i = 0; i < sizeof(int) * 8; i++) {
442 if ((1 << i) & *val) {
443 if (i > max_cpu) {
444 log_err("fio: CPU %d too large (max=%ld)\n", i,
445 max_cpu);
446 return 1;
447 }
448 dprint(FD_PARSE, "set cpu allowed %d\n", i);
449 fio_cpu_set(&td->o.cpumask, i);
450 }
451 }
452
453 td->o.cpumask_set = 1;
454 return 0;
455}
456
457static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
458 const char *input)
459{
460 char *cpu, *str, *p;
461 long max_cpu;
462 int ret = 0;
463
464 ret = fio_cpuset_init(mask);
465 if (ret < 0) {
466 log_err("fio: cpuset_init failed\n");
467 td_verror(td, ret, "fio_cpuset_init");
468 return 1;
469 }
470
471 p = str = strdup(input);
472
473 strip_blank_front(&str);
474 strip_blank_end(str);
475
476 max_cpu = cpus_online();
477
478 while ((cpu = strsep(&str, ",")) != NULL) {
479 char *str2, *cpu2;
480 int icpu, icpu2;
481
482 if (!strlen(cpu))
483 break;
484
485 str2 = cpu;
486 icpu2 = -1;
487 while ((cpu2 = strsep(&str2, "-")) != NULL) {
488 if (!strlen(cpu2))
489 break;
490
491 icpu2 = atoi(cpu2);
492 }
493
494 icpu = atoi(cpu);
495 if (icpu2 == -1)
496 icpu2 = icpu;
497 while (icpu <= icpu2) {
498 if (icpu >= FIO_MAX_CPUS) {
499 log_err("fio: your OS only supports up to"
500 " %d CPUs\n", (int) FIO_MAX_CPUS);
501 ret = 1;
502 break;
503 }
504 if (icpu > max_cpu) {
505 log_err("fio: CPU %d too large (max=%ld)\n",
506 icpu, max_cpu);
507 ret = 1;
508 break;
509 }
510
511 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
512 fio_cpu_set(mask, icpu);
513 icpu++;
514 }
515 if (ret)
516 break;
517 }
518
519 free(p);
520 if (!ret)
521 td->o.cpumask_set = 1;
522 return ret;
523}
524
525static int str_cpus_allowed_cb(void *data, const char *input)
526{
527 struct thread_data *td = data;
528 int ret;
529
530 if (parse_dryrun())
531 return 0;
532
533 ret = set_cpus_allowed(td, &td->o.cpumask, input);
534 if (!ret)
535 td->o.cpumask_set = 1;
536
537 return ret;
538}
539
540static int str_verify_cpus_allowed_cb(void *data, const char *input)
541{
542 struct thread_data *td = data;
543 int ret;
544
545 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
546 if (!ret)
547 td->o.verify_cpumask_set = 1;
548
549 return ret;
550}
551#endif
552
553#ifdef CONFIG_LIBNUMA
554static int str_numa_cpunodes_cb(void *data, char *input)
555{
556 struct thread_data *td = data;
557 struct bitmask *verify_bitmask;
558
559 if (parse_dryrun())
560 return 0;
561
562 /* numa_parse_nodestring() parses a character string list
563 * of nodes into a bit mask. The bit mask is allocated by
564 * numa_allocate_nodemask(), so it should be freed by
565 * numa_free_nodemask().
566 */
567 verify_bitmask = numa_parse_nodestring(input);
568 if (verify_bitmask == NULL) {
569 log_err("fio: numa_parse_nodestring failed\n");
570 td_verror(td, 1, "str_numa_cpunodes_cb");
571 return 1;
572 }
573 numa_free_nodemask(verify_bitmask);
574
575 td->o.numa_cpunodes = strdup(input);
576 td->o.numa_cpumask_set = 1;
577 return 0;
578}
579
580static int str_numa_mpol_cb(void *data, char *input)
581{
582 struct thread_data *td = data;
583 const char * const policy_types[] =
584 { "default", "prefer", "bind", "interleave", "local", NULL };
585 int i;
586 char *nodelist;
587 struct bitmask *verify_bitmask;
588
589 if (parse_dryrun())
590 return 0;
591
592 nodelist = strchr(input, ':');
593 if (nodelist) {
594 /* NUL-terminate mode */
595 *nodelist++ = '\0';
596 }
597
598 for (i = 0; i <= MPOL_LOCAL; i++) {
599 if (!strcmp(input, policy_types[i])) {
600 td->o.numa_mem_mode = i;
601 break;
602 }
603 }
604 if (i > MPOL_LOCAL) {
605 log_err("fio: memory policy should be: default, prefer, bind, interleave, local\n");
606 goto out;
607 }
608
609 switch (td->o.numa_mem_mode) {
610 case MPOL_PREFERRED:
611 /*
612 * Insist on a nodelist of one node only
613 */
614 if (nodelist) {
615 char *rest = nodelist;
616 while (isdigit(*rest))
617 rest++;
618 if (*rest) {
619 log_err("fio: one node only for \'prefer\'\n");
620 goto out;
621 }
622 } else {
623 log_err("fio: one node is needed for \'prefer\'\n");
624 goto out;
625 }
626 break;
627 case MPOL_INTERLEAVE:
628 /*
629 * Default to online nodes with memory if no nodelist
630 */
631 if (!nodelist)
632 nodelist = strdup("all");
633 break;
634 case MPOL_LOCAL:
635 case MPOL_DEFAULT:
636 /*
637 * Don't allow a nodelist
638 */
639 if (nodelist) {
640 log_err("fio: NO nodelist for \'local\'\n");
641 goto out;
642 }
643 break;
644 case MPOL_BIND:
645 /*
646 * Insist on a nodelist
647 */
648 if (!nodelist) {
649 log_err("fio: a nodelist is needed for \'bind\'\n");
650 goto out;
651 }
652 break;
653 }
654
655
656 /* numa_parse_nodestring() parses a character string list
657 * of nodes into a bit mask. The bit mask is allocated by
658 * numa_allocate_nodemask(), so it should be freed by
659 * numa_free_nodemask().
660 */
661 switch (td->o.numa_mem_mode) {
662 case MPOL_PREFERRED:
663 td->o.numa_mem_prefer_node = atoi(nodelist);
664 break;
665 case MPOL_INTERLEAVE:
666 case MPOL_BIND:
667 verify_bitmask = numa_parse_nodestring(nodelist);
668 if (verify_bitmask == NULL) {
669 log_err("fio: numa_parse_nodestring failed\n");
670 td_verror(td, 1, "str_numa_memnodes_cb");
671 return 1;
672 }
673 td->o.numa_memnodes = strdup(nodelist);
674 numa_free_nodemask(verify_bitmask);
675
676 break;
677 case MPOL_LOCAL:
678 case MPOL_DEFAULT:
679 default:
680 break;
681 }
682
683 td->o.numa_memmask_set = 1;
684 return 0;
685
686out:
687 return 1;
688}
689#endif
690
691static int str_fst_cb(void *data, const char *str)
692{
693 struct thread_data *td = data;
694 char *nr = get_opt_postfix(str);
695
696 td->file_service_nr = 1;
697 if (nr) {
698 td->file_service_nr = atoi(nr);
699 free(nr);
700 }
701
702 return 0;
703}
704
705#ifdef CONFIG_SYNC_FILE_RANGE
706static int str_sfr_cb(void *data, const char *str)
707{
708 struct thread_data *td = data;
709 char *nr = get_opt_postfix(str);
710
711 td->sync_file_range_nr = 1;
712 if (nr) {
713 td->sync_file_range_nr = atoi(nr);
714 free(nr);
715 }
716
717 return 0;
718}
719#endif
720
721static int str_random_distribution_cb(void *data, const char *str)
722{
723 struct thread_data *td = data;
724 double val;
725 char *nr;
726
727 if (parse_dryrun())
728 return 0;
729
730 if (td->o.random_distribution == FIO_RAND_DIST_ZIPF)
731 val = 1.1;
732 else if (td->o.random_distribution == FIO_RAND_DIST_PARETO)
733 val = 0.2;
734 else
735 return 0;
736
737 nr = get_opt_postfix(str);
738 if (nr && !str_to_float(nr, &val)) {
739 log_err("fio: random postfix parsing failed\n");
740 free(nr);
741 return 1;
742 }
743
744 free(nr);
745
746 if (td->o.random_distribution == FIO_RAND_DIST_ZIPF) {
747 if (val == 1.00) {
748 log_err("fio: zipf theta must different than 1.0\n");
749 return 1;
750 }
751 td->o.zipf_theta.u.f = val;
752 } else {
753 if (val <= 0.00 || val >= 1.00) {
754 log_err("fio: pareto input out of range (0 < input < 1.0)\n");
755 return 1;
756 }
757 td->o.pareto_h.u.f = val;
758 }
759
760 return 0;
761}
762
763/*
764 * Return next name in the string. Files are separated with ':'. If the ':'
765 * is escaped with a '\', then that ':' is part of the filename and does not
766 * indicate a new file.
767 */
768static char *get_next_name(char **ptr)
769{
770 char *str = *ptr;
771 char *p, *start;
772
773 if (!str || !strlen(str))
774 return NULL;
775
776 start = str;
777 do {
778 /*
779 * No colon, we are done
780 */
781 p = strchr(str, ':');
782 if (!p) {
783 *ptr = NULL;
784 break;
785 }
786
787 /*
788 * We got a colon, but it's the first character. Skip and
789 * continue
790 */
791 if (p == start) {
792 str = ++start;
793 continue;
794 }
795
796 if (*(p - 1) != '\\') {
797 *p = '\0';
798 *ptr = p + 1;
799 break;
800 }
801
802 memmove(p - 1, p, strlen(p) + 1);
803 str = p;
804 } while (1);
805
806 return start;
807}
808
809
810static int get_max_name_idx(char *input)
811{
812 unsigned int cur_idx;
813 char *str, *p;
814
815 p = str = strdup(input);
816 for (cur_idx = 0; ; cur_idx++)
817 if (get_next_name(&str) == NULL)
818 break;
819
820 free(p);
821 return cur_idx;
822}
823
824/*
825 * Returns the directory at the index, indexes > entires will be
826 * assigned via modulo division of the index
827 */
828int set_name_idx(char *target, char *input, int index)
829{
830 unsigned int cur_idx;
831 int len;
832 char *fname, *str, *p;
833
834 p = str = strdup(input);
835
836 index %= get_max_name_idx(input);
837 for (cur_idx = 0; cur_idx <= index; cur_idx++)
838 fname = get_next_name(&str);
839
840 len = sprintf(target, "%s/", fname);
841 free(p);
842
843 return len;
844}
845
846static int str_filename_cb(void *data, const char *input)
847{
848 struct thread_data *td = data;
849 char *fname, *str, *p;
850
851 p = str = strdup(input);
852
853 strip_blank_front(&str);
854 strip_blank_end(str);
855
856 if (!td->files_index)
857 td->o.nr_files = 0;
858
859 while ((fname = get_next_name(&str)) != NULL) {
860 if (!strlen(fname))
861 break;
862 add_file(td, fname, 0, 1);
863 }
864
865 free(p);
866 return 0;
867}
868
869static int str_directory_cb(void *data, const char fio_unused *unused)
870{
871 struct thread_data *td = data;
872 struct stat sb;
873 char *dirname, *str, *p;
874 int ret = 0;
875
876 if (parse_dryrun())
877 return 0;
878
879 p = str = strdup(td->o.directory);
880 while ((dirname = get_next_name(&str)) != NULL) {
881 if (lstat(dirname, &sb) < 0) {
882 ret = errno;
883
884 log_err("fio: %s is not a directory\n", dirname);
885 td_verror(td, ret, "lstat");
886 goto out;
887 }
888 if (!S_ISDIR(sb.st_mode)) {
889 log_err("fio: %s is not a directory\n", dirname);
890 ret = 1;
891 goto out;
892 }
893 }
894
895out:
896 free(p);
897 return ret;
898}
899
900static int str_lockfile_cb(void *data, const char fio_unused *str)
901{
902 struct thread_data *td = data;
903
904 if (td->files_index) {
905 log_err("fio: lockfile= option must precede filename=\n");
906 return 1;
907 }
908
909 return 0;
910}
911
912static int str_opendir_cb(void *data, const char fio_unused *str)
913{
914 struct thread_data *td = data;
915
916 if (parse_dryrun())
917 return 0;
918
919 if (!td->files_index)
920 td->o.nr_files = 0;
921
922 return add_dir_files(td, td->o.opendir);
923}
924
925static int pattern_cb(char *pattern, unsigned int max_size,
926 const char *input, unsigned int *pattern_bytes)
927{
928 long off;
929 int i = 0, j = 0, len, k, base = 10;
930 uint32_t pattern_length;
931 char *loc1, *loc2;
932
933 loc1 = strstr(input, "0x");
934 loc2 = strstr(input, "0X");
935 if (loc1 || loc2)
936 base = 16;
937 off = strtol(input, NULL, base);
938 if (off != LONG_MAX || errno != ERANGE) {
939 while (off) {
940 pattern[i] = off & 0xff;
941 off >>= 8;
942 i++;
943 }
944 } else {
945 len = strlen(input);
946 k = len - 1;
947 if (base == 16) {
948 if (loc1)
949 j = loc1 - input + 2;
950 else
951 j = loc2 - input + 2;
952 } else
953 return 1;
954 if (len - j < max_size * 2) {
955 while (k >= j) {
956 off = converthexchartoint(input[k--]);
957 if (k >= j)
958 off += (converthexchartoint(input[k--])
959 * 16);
960 pattern[i++] = (char) off;
961 }
962 }
963 }
964
965 /*
966 * Fill the pattern all the way to the end. This greatly reduces
967 * the number of memcpy's we have to do when verifying the IO.
968 */
969 pattern_length = i;
970 while (i > 1 && i * 2 <= max_size) {
971 memcpy(&pattern[i], &pattern[0], i);
972 i *= 2;
973 }
974
975 /*
976 * Fill remainder, if the pattern multiple ends up not being
977 * max_size.
978 */
979 while (i > 1 && i < max_size) {
980 unsigned int b = min(pattern_length, max_size - i);
981
982 memcpy(&pattern[i], &pattern[0], b);
983 i += b;
984 }
985
986 if (i == 1) {
987 /*
988 * The code in verify_io_u_pattern assumes a single byte pattern
989 * fills the whole verify pattern buffer.
990 */
991 memset(pattern, pattern[0], max_size);
992 }
993
994 *pattern_bytes = i;
995 return 0;
996}
997
998static int str_buffer_pattern_cb(void *data, const char *input)
999{
1000 struct thread_data *td = data;
1001 int ret;
1002
1003 ret = pattern_cb(td->o.buffer_pattern, MAX_PATTERN_SIZE, input,
1004 &td->o.buffer_pattern_bytes);
1005
1006 if (!ret) {
1007 td->o.refill_buffers = 0;
1008 td->o.scramble_buffers = 0;
1009 td->o.zero_buffers = 0;
1010 }
1011
1012 return ret;
1013}
1014
1015static int str_buffer_compress_cb(void *data, unsigned long long *il)
1016{
1017 struct thread_data *td = data;
1018
1019 td->flags |= TD_F_COMPRESS;
1020 td->o.compress_percentage = *il;
1021 return 0;
1022}
1023
1024static int str_verify_pattern_cb(void *data, const char *input)
1025{
1026 struct thread_data *td = data;
1027 int ret;
1028
1029 ret = pattern_cb(td->o.verify_pattern, MAX_PATTERN_SIZE, input,
1030 &td->o.verify_pattern_bytes);
1031
1032 /*
1033 * VERIFY_META could already be set
1034 */
1035 if (!ret && td->o.verify == VERIFY_NONE)
1036 td->o.verify = VERIFY_PATTERN;
1037
1038 return ret;
1039}
1040
1041static int str_gtod_reduce_cb(void *data, int *il)
1042{
1043 struct thread_data *td = data;
1044 int val = *il;
1045
1046 td->o.disable_lat = !!val;
1047 td->o.disable_clat = !!val;
1048 td->o.disable_slat = !!val;
1049 td->o.disable_bw = !!val;
1050 td->o.clat_percentiles = !val;
1051 if (val)
1052 td->tv_cache_mask = 63;
1053
1054 return 0;
1055}
1056
1057static int str_gtod_cpu_cb(void *data, long long *il)
1058{
1059 struct thread_data *td = data;
1060 int val = *il;
1061
1062 td->o.gtod_cpu = val;
1063 td->o.gtod_offload = 1;
1064 return 0;
1065}
1066
1067static int str_size_cb(void *data, unsigned long long *__val)
1068{
1069 struct thread_data *td = data;
1070 unsigned long long v = *__val;
1071
1072 if (parse_is_percent(v)) {
1073 td->o.size = 0;
1074 td->o.size_percent = -1ULL - v;
1075 } else
1076 td->o.size = v;
1077
1078 return 0;
1079}
1080
1081static int rw_verify(struct fio_option *o, void *data)
1082{
1083 struct thread_data *td = data;
1084
1085 if (read_only && td_write(td)) {
1086 log_err("fio: job <%s> has write bit set, but fio is in"
1087 " read-only mode\n", td->o.name);
1088 return 1;
1089 }
1090
1091 return 0;
1092}
1093
1094static int gtod_cpu_verify(struct fio_option *o, void *data)
1095{
1096#ifndef FIO_HAVE_CPU_AFFINITY
1097 struct thread_data *td = data;
1098
1099 if (td->o.gtod_cpu) {
1100 log_err("fio: platform must support CPU affinity for"
1101 "gettimeofday() offloading\n");
1102 return 1;
1103 }
1104#endif
1105
1106 return 0;
1107}
1108
1109/*
1110 * Option grouping
1111 */
1112static struct opt_group fio_opt_groups[] = {
1113 {
1114 .name = "General",
1115 .mask = FIO_OPT_C_GENERAL,
1116 },
1117 {
1118 .name = "I/O",
1119 .mask = FIO_OPT_C_IO,
1120 },
1121 {
1122 .name = "File",
1123 .mask = FIO_OPT_C_FILE,
1124 },
1125 {
1126 .name = "Statistics",
1127 .mask = FIO_OPT_C_STAT,
1128 },
1129 {
1130 .name = "Logging",
1131 .mask = FIO_OPT_C_LOG,
1132 },
1133 {
1134 .name = "Profiles",
1135 .mask = FIO_OPT_C_PROFILE,
1136 },
1137 {
1138 .name = NULL,
1139 },
1140};
1141
1142static struct opt_group *__opt_group_from_mask(struct opt_group *ogs, unsigned int *mask,
1143 unsigned int inv_mask)
1144{
1145 struct opt_group *og;
1146 int i;
1147
1148 if (*mask == inv_mask || !*mask)
1149 return NULL;
1150
1151 for (i = 0; ogs[i].name; i++) {
1152 og = &ogs[i];
1153
1154 if (*mask & og->mask) {
1155 *mask &= ~(og->mask);
1156 return og;
1157 }
1158 }
1159
1160 return NULL;
1161}
1162
1163struct opt_group *opt_group_from_mask(unsigned int *mask)
1164{
1165 return __opt_group_from_mask(fio_opt_groups, mask, FIO_OPT_C_INVALID);
1166}
1167
1168static struct opt_group fio_opt_cat_groups[] = {
1169 {
1170 .name = "Latency profiling",
1171 .mask = FIO_OPT_G_LATPROF,
1172 },
1173 {
1174 .name = "Rate",
1175 .mask = FIO_OPT_G_RATE,
1176 },
1177 {
1178 .name = "Zone",
1179 .mask = FIO_OPT_G_ZONE,
1180 },
1181 {
1182 .name = "Read/write mix",
1183 .mask = FIO_OPT_G_RWMIX,
1184 },
1185 {
1186 .name = "Verify",
1187 .mask = FIO_OPT_G_VERIFY,
1188 },
1189 {
1190 .name = "Trim",
1191 .mask = FIO_OPT_G_TRIM,
1192 },
1193 {
1194 .name = "I/O Logging",
1195 .mask = FIO_OPT_G_IOLOG,
1196 },
1197 {
1198 .name = "I/O Depth",
1199 .mask = FIO_OPT_G_IO_DEPTH,
1200 },
1201 {
1202 .name = "I/O Flow",
1203 .mask = FIO_OPT_G_IO_FLOW,
1204 },
1205 {
1206 .name = "Description",
1207 .mask = FIO_OPT_G_DESC,
1208 },
1209 {
1210 .name = "Filename",
1211 .mask = FIO_OPT_G_FILENAME,
1212 },
1213 {
1214 .name = "General I/O",
1215 .mask = FIO_OPT_G_IO_BASIC,
1216 },
1217 {
1218 .name = "Cgroups",
1219 .mask = FIO_OPT_G_CGROUP,
1220 },
1221 {
1222 .name = "Runtime",
1223 .mask = FIO_OPT_G_RUNTIME,
1224 },
1225 {
1226 .name = "Process",
1227 .mask = FIO_OPT_G_PROCESS,
1228 },
1229 {
1230 .name = "Job credentials / priority",
1231 .mask = FIO_OPT_G_CRED,
1232 },
1233 {
1234 .name = "Clock settings",
1235 .mask = FIO_OPT_G_CLOCK,
1236 },
1237 {
1238 .name = "I/O Type",
1239 .mask = FIO_OPT_G_IO_TYPE,
1240 },
1241 {
1242 .name = "I/O Thinktime",
1243 .mask = FIO_OPT_G_THINKTIME,
1244 },
1245 {
1246 .name = "Randomizations",
1247 .mask = FIO_OPT_G_RANDOM,
1248 },
1249 {
1250 .name = "I/O buffers",
1251 .mask = FIO_OPT_G_IO_BUF,
1252 },
1253 {
1254 .name = "Tiobench profile",
1255 .mask = FIO_OPT_G_TIOBENCH,
1256 },
1257
1258 {
1259 .name = NULL,
1260 }
1261};
1262
1263struct opt_group *opt_group_cat_from_mask(unsigned int *mask)
1264{
1265 return __opt_group_from_mask(fio_opt_cat_groups, mask, FIO_OPT_G_INVALID);
1266}
1267
1268/*
1269 * Map of job/command line options
1270 */
1271struct fio_option fio_options[FIO_MAX_OPTS] = {
1272 {
1273 .name = "description",
1274 .lname = "Description of job",
1275 .type = FIO_OPT_STR_STORE,
1276 .off1 = td_var_offset(description),
1277 .help = "Text job description",
1278 .category = FIO_OPT_C_GENERAL,
1279 .group = FIO_OPT_G_DESC,
1280 },
1281 {
1282 .name = "name",
1283 .lname = "Job name",
1284 .type = FIO_OPT_STR_STORE,
1285 .off1 = td_var_offset(name),
1286 .help = "Name of this job",
1287 .category = FIO_OPT_C_GENERAL,
1288 .group = FIO_OPT_G_DESC,
1289 },
1290 {
1291 .name = "filename",
1292 .lname = "Filename(s)",
1293 .type = FIO_OPT_STR_STORE,
1294 .off1 = td_var_offset(filename),
1295 .cb = str_filename_cb,
1296 .prio = -1, /* must come after "directory" */
1297 .help = "File(s) to use for the workload",
1298 .category = FIO_OPT_C_FILE,
1299 .group = FIO_OPT_G_FILENAME,
1300 },
1301 {
1302 .name = "directory",
1303 .lname = "Directory",
1304 .type = FIO_OPT_STR_STORE,
1305 .off1 = td_var_offset(directory),
1306 .cb = str_directory_cb,
1307 .help = "Directory to store files in",
1308 .category = FIO_OPT_C_FILE,
1309 .group = FIO_OPT_G_FILENAME,
1310 },
1311 {
1312 .name = "filename_format",
1313 .type = FIO_OPT_STR_STORE,
1314 .off1 = td_var_offset(filename_format),
1315 .prio = -1, /* must come after "directory" */
1316 .help = "Override default $jobname.$jobnum.$filenum naming",
1317 .def = "$jobname.$jobnum.$filenum",
1318 .category = FIO_OPT_C_FILE,
1319 .group = FIO_OPT_G_FILENAME,
1320 },
1321 {
1322 .name = "lockfile",
1323 .lname = "Lockfile",
1324 .type = FIO_OPT_STR,
1325 .off1 = td_var_offset(file_lock_mode),
1326 .help = "Lock file when doing IO to it",
1327 .prio = 1,
1328 .parent = "filename",
1329 .hide = 0,
1330 .def = "none",
1331 .cb = str_lockfile_cb,
1332 .category = FIO_OPT_C_FILE,
1333 .group = FIO_OPT_G_FILENAME,
1334 .posval = {
1335 { .ival = "none",
1336 .oval = FILE_LOCK_NONE,
1337 .help = "No file locking",
1338 },
1339 { .ival = "exclusive",
1340 .oval = FILE_LOCK_EXCLUSIVE,
1341 .help = "Exclusive file lock",
1342 },
1343 {
1344 .ival = "readwrite",
1345 .oval = FILE_LOCK_READWRITE,
1346 .help = "Read vs write lock",
1347 },
1348 },
1349 },
1350 {
1351 .name = "opendir",
1352 .lname = "Open directory",
1353 .type = FIO_OPT_STR_STORE,
1354 .off1 = td_var_offset(opendir),
1355 .cb = str_opendir_cb,
1356 .help = "Recursively add files from this directory and down",
1357 .category = FIO_OPT_C_FILE,
1358 .group = FIO_OPT_G_FILENAME,
1359 },
1360 {
1361 .name = "rw",
1362 .lname = "Read/write",
1363 .alias = "readwrite",
1364 .type = FIO_OPT_STR,
1365 .cb = str_rw_cb,
1366 .off1 = td_var_offset(td_ddir),
1367 .help = "IO direction",
1368 .def = "read",
1369 .verify = rw_verify,
1370 .category = FIO_OPT_C_IO,
1371 .group = FIO_OPT_G_IO_BASIC,
1372 .posval = {
1373 { .ival = "read",
1374 .oval = TD_DDIR_READ,
1375 .help = "Sequential read",
1376 },
1377 { .ival = "write",
1378 .oval = TD_DDIR_WRITE,
1379 .help = "Sequential write",
1380 },
1381 { .ival = "trim",
1382 .oval = TD_DDIR_TRIM,
1383 .help = "Sequential trim",
1384 },
1385 { .ival = "randread",
1386 .oval = TD_DDIR_RANDREAD,
1387 .help = "Random read",
1388 },
1389 { .ival = "randwrite",
1390 .oval = TD_DDIR_RANDWRITE,
1391 .help = "Random write",
1392 },
1393 { .ival = "randtrim",
1394 .oval = TD_DDIR_RANDTRIM,
1395 .help = "Random trim",
1396 },
1397 { .ival = "rw",
1398 .oval = TD_DDIR_RW,
1399 .help = "Sequential read and write mix",
1400 },
1401 { .ival = "readwrite",
1402 .oval = TD_DDIR_RW,
1403 .help = "Sequential read and write mix",
1404 },
1405 { .ival = "randrw",
1406 .oval = TD_DDIR_RANDRW,
1407 .help = "Random read and write mix"
1408 },
1409 },
1410 },
1411 {
1412 .name = "rw_sequencer",
1413 .lname = "RW Sequencer",
1414 .type = FIO_OPT_STR,
1415 .off1 = td_var_offset(rw_seq),
1416 .help = "IO offset generator modifier",
1417 .def = "sequential",
1418 .category = FIO_OPT_C_IO,
1419 .group = FIO_OPT_G_IO_BASIC,
1420 .posval = {
1421 { .ival = "sequential",
1422 .oval = RW_SEQ_SEQ,
1423 .help = "Generate sequential offsets",
1424 },
1425 { .ival = "identical",
1426 .oval = RW_SEQ_IDENT,
1427 .help = "Generate identical offsets",
1428 },
1429 },
1430 },
1431
1432 {
1433 .name = "ioengine",
1434 .lname = "IO Engine",
1435 .type = FIO_OPT_STR_STORE,
1436 .off1 = td_var_offset(ioengine),
1437 .help = "IO engine to use",
1438 .def = FIO_PREFERRED_ENGINE,
1439 .category = FIO_OPT_C_IO,
1440 .group = FIO_OPT_G_IO_BASIC,
1441 .posval = {
1442 { .ival = "sync",
1443 .help = "Use read/write",
1444 },
1445 { .ival = "psync",
1446 .help = "Use pread/pwrite",
1447 },
1448 { .ival = "vsync",
1449 .help = "Use readv/writev",
1450 },
1451#ifdef CONFIG_PWRITEV
1452 { .ival = "pvsync",
1453 .help = "Use preadv/pwritev",
1454 },
1455#endif
1456#ifdef CONFIG_LIBAIO
1457 { .ival = "libaio",
1458 .help = "Linux native asynchronous IO",
1459 },
1460#endif
1461#ifdef CONFIG_POSIXAIO
1462 { .ival = "posixaio",
1463 .help = "POSIX asynchronous IO",
1464 },
1465#endif
1466#ifdef CONFIG_SOLARISAIO
1467 { .ival = "solarisaio",
1468 .help = "Solaris native asynchronous IO",
1469 },
1470#endif
1471#ifdef CONFIG_WINDOWSAIO
1472 { .ival = "windowsaio",
1473 .help = "Windows native asynchronous IO"
1474 },
1475#endif
1476#ifdef CONFIG_RBD
1477 { .ival = "rbd",
1478 .help = "Rados Block Device asynchronous IO"
1479 },
1480#endif
1481 { .ival = "mmap",
1482 .help = "Memory mapped IO"
1483 },
1484#ifdef CONFIG_LINUX_SPLICE
1485 { .ival = "splice",
1486 .help = "splice/vmsplice based IO",
1487 },
1488 { .ival = "netsplice",
1489 .help = "splice/vmsplice to/from the network",
1490 },
1491#endif
1492#ifdef FIO_HAVE_SGIO
1493 { .ival = "sg",
1494 .help = "SCSI generic v3 IO",
1495 },
1496#endif
1497 { .ival = "null",
1498 .help = "Testing engine (no data transfer)",
1499 },
1500 { .ival = "net",
1501 .help = "Network IO",
1502 },
1503 { .ival = "cpuio",
1504 .help = "CPU cycle burner engine",
1505 },
1506#ifdef CONFIG_GUASI
1507 { .ival = "guasi",
1508 .help = "GUASI IO engine",
1509 },
1510#endif
1511#ifdef FIO_HAVE_BINJECT
1512 { .ival = "binject",
1513 .help = "binject direct inject block engine",
1514 },
1515#endif
1516#ifdef CONFIG_RDMA
1517 { .ival = "rdma",
1518 .help = "RDMA IO engine",
1519 },
1520#endif
1521#ifdef CONFIG_FUSION_AW
1522 { .ival = "fusion-aw-sync",
1523 .help = "Fusion-io atomic write engine",
1524 },
1525#endif
1526#ifdef CONFIG_LINUX_EXT4_MOVE_EXTENT
1527 { .ival = "e4defrag",
1528 .help = "ext4 defrag engine",
1529 },
1530#endif
1531#ifdef CONFIG_LINUX_FALLOCATE
1532 { .ival = "falloc",
1533 .help = "fallocate() file based engine",
1534 },
1535#endif
1536 { .ival = "external",
1537 .help = "Load external engine (append name)",
1538 },
1539 },
1540 },
1541 {
1542 .name = "iodepth",
1543 .lname = "IO Depth",
1544 .type = FIO_OPT_INT,
1545 .off1 = td_var_offset(iodepth),
1546 .help = "Number of IO buffers to keep in flight",
1547 .minval = 1,
1548 .interval = 1,
1549 .def = "1",
1550 .category = FIO_OPT_C_IO,
1551 .group = FIO_OPT_G_IO_BASIC,
1552 },
1553 {
1554 .name = "iodepth_batch",
1555 .lname = "IO Depth batch",
1556 .alias = "iodepth_batch_submit",
1557 .type = FIO_OPT_INT,
1558 .off1 = td_var_offset(iodepth_batch),
1559 .help = "Number of IO buffers to submit in one go",
1560 .parent = "iodepth",
1561 .hide = 1,
1562 .minval = 1,
1563 .interval = 1,
1564 .def = "1",
1565 .category = FIO_OPT_C_IO,
1566 .group = FIO_OPT_G_IO_BASIC,
1567 },
1568 {
1569 .name = "iodepth_batch_complete",
1570 .lname = "IO Depth batch complete",
1571 .type = FIO_OPT_INT,
1572 .off1 = td_var_offset(iodepth_batch_complete),
1573 .help = "Number of IO buffers to retrieve in one go",
1574 .parent = "iodepth",
1575 .hide = 1,
1576 .minval = 0,
1577 .interval = 1,
1578 .def = "1",
1579 .category = FIO_OPT_C_IO,
1580 .group = FIO_OPT_G_IO_BASIC,
1581 },
1582 {
1583 .name = "iodepth_low",
1584 .lname = "IO Depth batch low",
1585 .type = FIO_OPT_INT,
1586 .off1 = td_var_offset(iodepth_low),
1587 .help = "Low water mark for queuing depth",
1588 .parent = "iodepth",
1589 .hide = 1,
1590 .interval = 1,
1591 .category = FIO_OPT_C_IO,
1592 .group = FIO_OPT_G_IO_BASIC,
1593 },
1594 {
1595 .name = "size",
1596 .lname = "Size",
1597 .type = FIO_OPT_STR_VAL,
1598 .cb = str_size_cb,
1599 .help = "Total size of device or files",
1600 .interval = 1024 * 1024,
1601 .category = FIO_OPT_C_IO,
1602 .group = FIO_OPT_G_INVALID,
1603 },
1604 {
1605 .name = "io_limit",
1606 .lname = "IO Limit",
1607 .type = FIO_OPT_STR_VAL,
1608 .off1 = td_var_offset(io_limit),
1609 .interval = 1024 * 1024,
1610 .category = FIO_OPT_C_IO,
1611 .group = FIO_OPT_G_INVALID,
1612 },
1613 {
1614 .name = "fill_device",
1615 .lname = "Fill device",
1616 .alias = "fill_fs",
1617 .type = FIO_OPT_BOOL,
1618 .off1 = td_var_offset(fill_device),
1619 .help = "Write until an ENOSPC error occurs",
1620 .def = "0",
1621 .category = FIO_OPT_C_FILE,
1622 .group = FIO_OPT_G_INVALID,
1623 },
1624 {
1625 .name = "filesize",
1626 .lname = "File size",
1627 .type = FIO_OPT_STR_VAL,
1628 .off1 = td_var_offset(file_size_low),
1629 .off2 = td_var_offset(file_size_high),
1630 .minval = 1,
1631 .help = "Size of individual files",
1632 .interval = 1024 * 1024,
1633 .category = FIO_OPT_C_FILE,
1634 .group = FIO_OPT_G_INVALID,
1635 },
1636 {
1637 .name = "file_append",
1638 .lname = "File append",
1639 .type = FIO_OPT_BOOL,
1640 .off1 = td_var_offset(file_append),
1641 .help = "IO will start at the end of the file(s)",
1642 .def = "0",
1643 .category = FIO_OPT_C_FILE,
1644 .group = FIO_OPT_G_INVALID,
1645 },
1646 {
1647 .name = "offset",
1648 .lname = "IO offset",
1649 .alias = "fileoffset",
1650 .type = FIO_OPT_STR_VAL,
1651 .off1 = td_var_offset(start_offset),
1652 .help = "Start IO from this offset",
1653 .def = "0",
1654 .interval = 1024 * 1024,
1655 .category = FIO_OPT_C_IO,
1656 .group = FIO_OPT_G_INVALID,
1657 },
1658 {
1659 .name = "offset_increment",
1660 .lname = "IO offset increment",
1661 .type = FIO_OPT_STR_VAL,
1662 .off1 = td_var_offset(offset_increment),
1663 .help = "What is the increment from one offset to the next",
1664 .parent = "offset",
1665 .hide = 1,
1666 .def = "0",
1667 .interval = 1024 * 1024,
1668 .category = FIO_OPT_C_IO,
1669 .group = FIO_OPT_G_INVALID,
1670 },
1671 {
1672 .name = "number_ios",
1673 .lname = "Number of IOs to perform",
1674 .type = FIO_OPT_STR_VAL,
1675 .off1 = td_var_offset(number_ios),
1676 .help = "Force job completion of this number of IOs",
1677 .def = "0",
1678 .category = FIO_OPT_C_IO,
1679 .group = FIO_OPT_G_INVALID,
1680 },
1681 {
1682 .name = "bs",
1683 .lname = "Block size",
1684 .alias = "blocksize",
1685 .type = FIO_OPT_INT,
1686 .off1 = td_var_offset(bs[DDIR_READ]),
1687 .off2 = td_var_offset(bs[DDIR_WRITE]),
1688 .off3 = td_var_offset(bs[DDIR_TRIM]),
1689 .minval = 1,
1690 .help = "Block size unit",
1691 .def = "4k",
1692 .parent = "rw",
1693 .hide = 1,
1694 .interval = 512,
1695 .category = FIO_OPT_C_IO,
1696 .group = FIO_OPT_G_INVALID,
1697 },
1698 {
1699 .name = "ba",
1700 .lname = "Block size align",
1701 .alias = "blockalign",
1702 .type = FIO_OPT_INT,
1703 .off1 = td_var_offset(ba[DDIR_READ]),
1704 .off2 = td_var_offset(ba[DDIR_WRITE]),
1705 .off3 = td_var_offset(ba[DDIR_TRIM]),
1706 .minval = 1,
1707 .help = "IO block offset alignment",
1708 .parent = "rw",
1709 .hide = 1,
1710 .interval = 512,
1711 .category = FIO_OPT_C_IO,
1712 .group = FIO_OPT_G_INVALID,
1713 },
1714 {
1715 .name = "bsrange",
1716 .lname = "Block size range",
1717 .alias = "blocksize_range",
1718 .type = FIO_OPT_RANGE,
1719 .off1 = td_var_offset(min_bs[DDIR_READ]),
1720 .off2 = td_var_offset(max_bs[DDIR_READ]),
1721 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1722 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1723 .off5 = td_var_offset(min_bs[DDIR_TRIM]),
1724 .off6 = td_var_offset(max_bs[DDIR_TRIM]),
1725 .minval = 1,
1726 .help = "Set block size range (in more detail than bs)",
1727 .parent = "rw",
1728 .hide = 1,
1729 .interval = 4096,
1730 .category = FIO_OPT_C_IO,
1731 .group = FIO_OPT_G_INVALID,
1732 },
1733 {
1734 .name = "bssplit",
1735 .lname = "Block size split",
1736 .type = FIO_OPT_STR,
1737 .cb = str_bssplit_cb,
1738 .help = "Set a specific mix of block sizes",
1739 .parent = "rw",
1740 .hide = 1,
1741 .category = FIO_OPT_C_IO,
1742 .group = FIO_OPT_G_INVALID,
1743 },
1744 {
1745 .name = "bs_unaligned",
1746 .lname = "Block size unaligned",
1747 .alias = "blocksize_unaligned",
1748 .type = FIO_OPT_STR_SET,
1749 .off1 = td_var_offset(bs_unaligned),
1750 .help = "Don't sector align IO buffer sizes",
1751 .parent = "rw",
1752 .hide = 1,
1753 .category = FIO_OPT_C_IO,
1754 .group = FIO_OPT_G_INVALID,
1755 },
1756 {
1757 .name = "bs_is_seq_rand",
1758 .lname = "Block size division is seq/random (not read/write)",
1759 .type = FIO_OPT_BOOL,
1760 .off1 = td_var_offset(bs_is_seq_rand),
1761 .help = "Consider any blocksize setting to be sequential,ramdom",
1762 .def = "0",
1763 .parent = "blocksize",
1764 .category = FIO_OPT_C_IO,
1765 .group = FIO_OPT_G_INVALID,
1766 },
1767 {
1768 .name = "randrepeat",
1769 .lname = "Random repeatable",
1770 .type = FIO_OPT_BOOL,
1771 .off1 = td_var_offset(rand_repeatable),
1772 .help = "Use repeatable random IO pattern",
1773 .def = "1",
1774 .parent = "rw",
1775 .hide = 1,
1776 .category = FIO_OPT_C_IO,
1777 .group = FIO_OPT_G_RANDOM,
1778 },
1779 {
1780 .name = "randseed",
1781 .lname = "The random generator seed",
1782 .type = FIO_OPT_STR_VAL,
1783 .off1 = td_var_offset(rand_seed),
1784 .help = "Set the random generator seed value",
1785 .parent = "rw",
1786 .category = FIO_OPT_C_IO,
1787 .group = FIO_OPT_G_RANDOM,
1788 },
1789 {
1790 .name = "use_os_rand",
1791 .lname = "Use OS random",
1792 .type = FIO_OPT_BOOL,
1793 .off1 = td_var_offset(use_os_rand),
1794 .help = "Set to use OS random generator",
1795 .def = "0",
1796 .parent = "rw",
1797 .hide = 1,
1798 .category = FIO_OPT_C_IO,
1799 .group = FIO_OPT_G_RANDOM,
1800 },
1801 {
1802 .name = "norandommap",
1803 .lname = "No randommap",
1804 .type = FIO_OPT_STR_SET,
1805 .off1 = td_var_offset(norandommap),
1806 .help = "Accept potential duplicate random blocks",
1807 .parent = "rw",
1808 .hide = 1,
1809 .hide_on_set = 1,
1810 .category = FIO_OPT_C_IO,
1811 .group = FIO_OPT_G_RANDOM,
1812 },
1813 {
1814 .name = "softrandommap",
1815 .lname = "Soft randommap",
1816 .type = FIO_OPT_BOOL,
1817 .off1 = td_var_offset(softrandommap),
1818 .help = "Set norandommap if randommap allocation fails",
1819 .parent = "norandommap",
1820 .hide = 1,
1821 .def = "0",
1822 .category = FIO_OPT_C_IO,
1823 .group = FIO_OPT_G_RANDOM,
1824 },
1825 {
1826 .name = "random_generator",
1827 .type = FIO_OPT_STR,
1828 .off1 = td_var_offset(random_generator),
1829 .help = "Type of random number generator to use",
1830 .def = "tausworthe",
1831 .posval = {
1832 { .ival = "tausworthe",
1833 .oval = FIO_RAND_GEN_TAUSWORTHE,
1834 .help = "Strong Tausworthe generator",
1835 },
1836 { .ival = "lfsr",
1837 .oval = FIO_RAND_GEN_LFSR,
1838 .help = "Variable length LFSR",
1839 },
1840 },
1841 .category = FIO_OPT_C_IO,
1842 .group = FIO_OPT_G_RANDOM,
1843 },
1844 {
1845 .name = "random_distribution",
1846 .type = FIO_OPT_STR,
1847 .off1 = td_var_offset(random_distribution),
1848 .cb = str_random_distribution_cb,
1849 .help = "Random offset distribution generator",
1850 .def = "random",
1851 .posval = {
1852 { .ival = "random",
1853 .oval = FIO_RAND_DIST_RANDOM,
1854 .help = "Completely random",
1855 },
1856 { .ival = "zipf",
1857 .oval = FIO_RAND_DIST_ZIPF,
1858 .help = "Zipf distribution",
1859 },
1860 { .ival = "pareto",
1861 .oval = FIO_RAND_DIST_PARETO,
1862 .help = "Pareto distribution",
1863 },
1864 },
1865 .category = FIO_OPT_C_IO,
1866 .group = FIO_OPT_G_RANDOM,
1867 },
1868 {
1869 .name = "percentage_random",
1870 .lname = "Percentage Random",
1871 .type = FIO_OPT_INT,
1872 .off1 = td_var_offset(perc_rand[DDIR_READ]),
1873 .off2 = td_var_offset(perc_rand[DDIR_WRITE]),
1874 .off3 = td_var_offset(perc_rand[DDIR_TRIM]),
1875 .maxval = 100,
1876 .help = "Percentage of seq/random mix that should be random",
1877 .def = "100,100,100",
1878 .interval = 5,
1879 .inverse = "percentage_sequential",
1880 .category = FIO_OPT_C_IO,
1881 .group = FIO_OPT_G_RANDOM,
1882 },
1883 {
1884 .name = "percentage_sequential",
1885 .lname = "Percentage Sequential",
1886 .type = FIO_OPT_DEPRECATED,
1887 .category = FIO_OPT_C_IO,
1888 .group = FIO_OPT_G_RANDOM,
1889 },
1890 {
1891 .name = "allrandrepeat",
1892 .type = FIO_OPT_BOOL,
1893 .off1 = td_var_offset(allrand_repeatable),
1894 .help = "Use repeatable random numbers for everything",
1895 .def = "0",
1896 .category = FIO_OPT_C_IO,
1897 .group = FIO_OPT_G_RANDOM,
1898 },
1899 {
1900 .name = "nrfiles",
1901 .lname = "Number of files",
1902 .alias = "nr_files",
1903 .type = FIO_OPT_INT,
1904 .off1 = td_var_offset(nr_files),
1905 .help = "Split job workload between this number of files",
1906 .def = "1",
1907 .interval = 1,
1908 .category = FIO_OPT_C_FILE,
1909 .group = FIO_OPT_G_INVALID,
1910 },
1911 {
1912 .name = "openfiles",
1913 .lname = "Number of open files",
1914 .type = FIO_OPT_INT,
1915 .off1 = td_var_offset(open_files),
1916 .help = "Number of files to keep open at the same time",
1917 .category = FIO_OPT_C_FILE,
1918 .group = FIO_OPT_G_INVALID,
1919 },
1920 {
1921 .name = "file_service_type",
1922 .lname = "File service type",
1923 .type = FIO_OPT_STR,
1924 .cb = str_fst_cb,
1925 .off1 = td_var_offset(file_service_type),
1926 .help = "How to select which file to service next",
1927 .def = "roundrobin",
1928 .category = FIO_OPT_C_FILE,
1929 .group = FIO_OPT_G_INVALID,
1930 .posval = {
1931 { .ival = "random",
1932 .oval = FIO_FSERVICE_RANDOM,
1933 .help = "Choose a file at random",
1934 },
1935 { .ival = "roundrobin",
1936 .oval = FIO_FSERVICE_RR,
1937 .help = "Round robin select files",
1938 },
1939 { .ival = "sequential",
1940 .oval = FIO_FSERVICE_SEQ,
1941 .help = "Finish one file before moving to the next",
1942 },
1943 },
1944 .parent = "nrfiles",
1945 .hide = 1,
1946 },
1947#ifdef CONFIG_POSIX_FALLOCATE
1948 {
1949 .name = "fallocate",
1950 .lname = "Fallocate",
1951 .type = FIO_OPT_STR,
1952 .off1 = td_var_offset(fallocate_mode),
1953 .help = "Whether pre-allocation is performed when laying out files",
1954 .def = "posix",
1955 .category = FIO_OPT_C_FILE,
1956 .group = FIO_OPT_G_INVALID,
1957 .posval = {
1958 { .ival = "none",
1959 .oval = FIO_FALLOCATE_NONE,
1960 .help = "Do not pre-allocate space",
1961 },
1962 { .ival = "posix",
1963 .oval = FIO_FALLOCATE_POSIX,
1964 .help = "Use posix_fallocate()",
1965 },
1966#ifdef CONFIG_LINUX_FALLOCATE
1967 { .ival = "keep",
1968 .oval = FIO_FALLOCATE_KEEP_SIZE,
1969 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1970 },
1971#endif
1972 /* Compatibility with former boolean values */
1973 { .ival = "0",
1974 .oval = FIO_FALLOCATE_NONE,
1975 .help = "Alias for 'none'",
1976 },
1977 { .ival = "1",
1978 .oval = FIO_FALLOCATE_POSIX,
1979 .help = "Alias for 'posix'",
1980 },
1981 },
1982 },
1983#endif /* CONFIG_POSIX_FALLOCATE */
1984 {
1985 .name = "fadvise_hint",
1986 .lname = "Fadvise hint",
1987 .type = FIO_OPT_BOOL,
1988 .off1 = td_var_offset(fadvise_hint),
1989 .help = "Use fadvise() to advise the kernel on IO pattern",
1990 .def = "1",
1991 .category = FIO_OPT_C_FILE,
1992 .group = FIO_OPT_G_INVALID,
1993 },
1994 {
1995 .name = "fsync",
1996 .lname = "Fsync",
1997 .type = FIO_OPT_INT,
1998 .off1 = td_var_offset(fsync_blocks),
1999 .help = "Issue fsync for writes every given number of blocks",
2000 .def = "0",
2001 .interval = 1,
2002 .category = FIO_OPT_C_FILE,
2003 .group = FIO_OPT_G_INVALID,
2004 },
2005 {
2006 .name = "fdatasync",
2007 .lname = "Fdatasync",
2008 .type = FIO_OPT_INT,
2009 .off1 = td_var_offset(fdatasync_blocks),
2010 .help = "Issue fdatasync for writes every given number of blocks",
2011 .def = "0",
2012 .interval = 1,
2013 .category = FIO_OPT_C_FILE,
2014 .group = FIO_OPT_G_INVALID,
2015 },
2016 {
2017 .name = "write_barrier",
2018 .lname = "Write barrier",
2019 .type = FIO_OPT_INT,
2020 .off1 = td_var_offset(barrier_blocks),
2021 .help = "Make every Nth write a barrier write",
2022 .def = "0",
2023 .interval = 1,
2024 .category = FIO_OPT_C_IO,
2025 .group = FIO_OPT_G_INVALID,
2026 },
2027#ifdef CONFIG_SYNC_FILE_RANGE
2028 {
2029 .name = "sync_file_range",
2030 .lname = "Sync file range",
2031 .posval = {
2032 { .ival = "wait_before",
2033 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
2034 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
2035 .orval = 1,
2036 },
2037 { .ival = "write",
2038 .oval = SYNC_FILE_RANGE_WRITE,
2039 .help = "SYNC_FILE_RANGE_WRITE",
2040 .orval = 1,
2041 },
2042 {
2043 .ival = "wait_after",
2044 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
2045 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
2046 .orval = 1,
2047 },
2048 },
2049 .type = FIO_OPT_STR_MULTI,
2050 .cb = str_sfr_cb,
2051 .off1 = td_var_offset(sync_file_range),
2052 .help = "Use sync_file_range()",
2053 .category = FIO_OPT_C_FILE,
2054 .group = FIO_OPT_G_INVALID,
2055 },
2056#endif
2057 {
2058 .name = "direct",
2059 .lname = "Direct I/O",
2060 .type = FIO_OPT_BOOL,
2061 .off1 = td_var_offset(odirect),
2062 .help = "Use O_DIRECT IO (negates buffered)",
2063 .def = "0",
2064 .inverse = "buffered",
2065 .category = FIO_OPT_C_IO,
2066 .group = FIO_OPT_G_IO_TYPE,
2067 },
2068 {
2069 .name = "atomic",
2070 .lname = "Atomic I/O",
2071 .type = FIO_OPT_BOOL,
2072 .off1 = td_var_offset(oatomic),
2073 .help = "Use Atomic IO with O_DIRECT (implies O_DIRECT)",
2074 .def = "0",
2075 .category = FIO_OPT_C_IO,
2076 .group = FIO_OPT_G_IO_TYPE,
2077 },
2078 {
2079 .name = "buffered",
2080 .lname = "Buffered I/O",
2081 .type = FIO_OPT_BOOL,
2082 .off1 = td_var_offset(odirect),
2083 .neg = 1,
2084 .help = "Use buffered IO (negates direct)",
2085 .def = "1",
2086 .inverse = "direct",
2087 .category = FIO_OPT_C_IO,
2088 .group = FIO_OPT_G_IO_TYPE,
2089 },
2090 {
2091 .name = "overwrite",
2092 .lname = "Overwrite",
2093 .type = FIO_OPT_BOOL,
2094 .off1 = td_var_offset(overwrite),
2095 .help = "When writing, set whether to overwrite current data",
2096 .def = "0",
2097 .category = FIO_OPT_C_FILE,
2098 .group = FIO_OPT_G_INVALID,
2099 },
2100 {
2101 .name = "loops",
2102 .lname = "Loops",
2103 .type = FIO_OPT_INT,
2104 .off1 = td_var_offset(loops),
2105 .help = "Number of times to run the job",
2106 .def = "1",
2107 .interval = 1,
2108 .category = FIO_OPT_C_GENERAL,
2109 .group = FIO_OPT_G_RUNTIME,
2110 },
2111 {
2112 .name = "numjobs",
2113 .lname = "Number of jobs",
2114 .type = FIO_OPT_INT,
2115 .off1 = td_var_offset(numjobs),
2116 .help = "Duplicate this job this many times",
2117 .def = "1",
2118 .interval = 1,
2119 .category = FIO_OPT_C_GENERAL,
2120 .group = FIO_OPT_G_RUNTIME,
2121 },
2122 {
2123 .name = "startdelay",
2124 .lname = "Start delay",
2125 .type = FIO_OPT_STR_VAL_TIME,
2126 .off1 = td_var_offset(start_delay),
2127 .off2 = td_var_offset(start_delay_high),
2128 .help = "Only start job when this period has passed",
2129 .def = "0",
2130 .is_seconds = 1,
2131 .category = FIO_OPT_C_GENERAL,
2132 .group = FIO_OPT_G_RUNTIME,
2133 },
2134 {
2135 .name = "runtime",
2136 .lname = "Runtime",
2137 .alias = "timeout",
2138 .type = FIO_OPT_STR_VAL_TIME,
2139 .off1 = td_var_offset(timeout),
2140 .help = "Stop workload when this amount of time has passed",
2141 .def = "0",
2142 .is_seconds = 1,
2143 .category = FIO_OPT_C_GENERAL,
2144 .group = FIO_OPT_G_RUNTIME,
2145 },
2146 {
2147 .name = "time_based",
2148 .lname = "Time based",
2149 .type = FIO_OPT_STR_SET,
2150 .off1 = td_var_offset(time_based),
2151 .help = "Keep running until runtime/timeout is met",
2152 .category = FIO_OPT_C_GENERAL,
2153 .group = FIO_OPT_G_RUNTIME,
2154 },
2155 {
2156 .name = "verify_only",
2157 .lname = "Verify only",
2158 .type = FIO_OPT_STR_SET,
2159 .off1 = td_var_offset(verify_only),
2160 .help = "Verifies previously written data is still valid",
2161 .category = FIO_OPT_C_GENERAL,
2162 .group = FIO_OPT_G_RUNTIME,
2163 },
2164 {
2165 .name = "ramp_time",
2166 .lname = "Ramp time",
2167 .type = FIO_OPT_STR_VAL_TIME,
2168 .off1 = td_var_offset(ramp_time),
2169 .help = "Ramp up time before measuring performance",
2170 .is_seconds = 1,
2171 .category = FIO_OPT_C_GENERAL,
2172 .group = FIO_OPT_G_RUNTIME,
2173 },
2174 {
2175 .name = "clocksource",
2176 .lname = "Clock source",
2177 .type = FIO_OPT_STR,
2178 .cb = fio_clock_source_cb,
2179 .off1 = td_var_offset(clocksource),
2180 .help = "What type of timing source to use",
2181 .category = FIO_OPT_C_GENERAL,
2182 .group = FIO_OPT_G_CLOCK,
2183 .posval = {
2184#ifdef CONFIG_GETTIMEOFDAY
2185 { .ival = "gettimeofday",
2186 .oval = CS_GTOD,
2187 .help = "Use gettimeofday(2) for timing",
2188 },
2189#endif
2190#ifdef CONFIG_CLOCK_GETTIME
2191 { .ival = "clock_gettime",
2192 .oval = CS_CGETTIME,
2193 .help = "Use clock_gettime(2) for timing",
2194 },
2195#endif
2196#ifdef ARCH_HAVE_CPU_CLOCK
2197 { .ival = "cpu",
2198 .oval = CS_CPUCLOCK,
2199 .help = "Use CPU private clock",
2200 },
2201#endif
2202 },
2203 },
2204 {
2205 .name = "mem",
2206 .alias = "iomem",
2207 .lname = "I/O Memory",
2208 .type = FIO_OPT_STR,
2209 .cb = str_mem_cb,
2210 .off1 = td_var_offset(mem_type),
2211 .help = "Backing type for IO buffers",
2212 .def = "malloc",
2213 .category = FIO_OPT_C_IO,
2214 .group = FIO_OPT_G_INVALID,
2215 .posval = {
2216 { .ival = "malloc",
2217 .oval = MEM_MALLOC,
2218 .help = "Use malloc(3) for IO buffers",
2219 },
2220 { .ival = "shm",
2221 .oval = MEM_SHM,
2222 .help = "Use shared memory segments for IO buffers",
2223 },
2224#ifdef FIO_HAVE_HUGETLB
2225 { .ival = "shmhuge",
2226 .oval = MEM_SHMHUGE,
2227 .help = "Like shm, but use huge pages",
2228 },
2229#endif
2230 { .ival = "mmap",
2231 .oval = MEM_MMAP,
2232 .help = "Use mmap(2) (file or anon) for IO buffers",
2233 },
2234#ifdef FIO_HAVE_HUGETLB
2235 { .ival = "mmaphuge",
2236 .oval = MEM_MMAPHUGE,
2237 .help = "Like mmap, but use huge pages",
2238 },
2239#endif
2240 },
2241 },
2242 {
2243 .name = "iomem_align",
2244 .alias = "mem_align",
2245 .lname = "I/O memory alignment",
2246 .type = FIO_OPT_INT,
2247 .off1 = td_var_offset(mem_align),
2248 .minval = 0,
2249 .help = "IO memory buffer offset alignment",
2250 .def = "0",
2251 .parent = "iomem",
2252 .hide = 1,
2253 .category = FIO_OPT_C_IO,
2254 .group = FIO_OPT_G_INVALID,
2255 },
2256 {
2257 .name = "verify",
2258 .lname = "Verify",
2259 .type = FIO_OPT_STR,
2260 .off1 = td_var_offset(verify),
2261 .help = "Verify data written",
2262 .def = "0",
2263 .category = FIO_OPT_C_IO,
2264 .group = FIO_OPT_G_VERIFY,
2265 .posval = {
2266 { .ival = "0",
2267 .oval = VERIFY_NONE,
2268 .help = "Don't do IO verification",
2269 },
2270 { .ival = "md5",
2271 .oval = VERIFY_MD5,
2272 .help = "Use md5 checksums for verification",
2273 },
2274 { .ival = "crc64",
2275 .oval = VERIFY_CRC64,
2276 .help = "Use crc64 checksums for verification",
2277 },
2278 { .ival = "crc32",
2279 .oval = VERIFY_CRC32,
2280 .help = "Use crc32 checksums for verification",
2281 },
2282 { .ival = "crc32c-intel",
2283 .oval = VERIFY_CRC32C,
2284 .help = "Use crc32c checksums for verification (hw assisted, if available)",
2285 },
2286 { .ival = "crc32c",
2287 .oval = VERIFY_CRC32C,
2288 .help = "Use crc32c checksums for verification (hw assisted, if available)",
2289 },
2290 { .ival = "crc16",
2291 .oval = VERIFY_CRC16,
2292 .help = "Use crc16 checksums for verification",
2293 },
2294 { .ival = "crc7",
2295 .oval = VERIFY_CRC7,
2296 .help = "Use crc7 checksums for verification",
2297 },
2298 { .ival = "sha1",
2299 .oval = VERIFY_SHA1,
2300 .help = "Use sha1 checksums for verification",
2301 },
2302 { .ival = "sha256",
2303 .oval = VERIFY_SHA256,
2304 .help = "Use sha256 checksums for verification",
2305 },
2306 { .ival = "sha512",
2307 .oval = VERIFY_SHA512,
2308 .help = "Use sha512 checksums for verification",
2309 },
2310 { .ival = "xxhash",
2311 .oval = VERIFY_XXHASH,
2312 .help = "Use xxhash checksums for verification",
2313 },
2314 { .ival = "meta",
2315 .oval = VERIFY_META,
2316 .help = "Use io information",
2317 },
2318 {
2319 .ival = "null",
2320 .oval = VERIFY_NULL,
2321 .help = "Pretend to verify",
2322 },
2323 },
2324 },
2325 {
2326 .name = "do_verify",
2327 .lname = "Perform verify step",
2328 .type = FIO_OPT_BOOL,
2329 .off1 = td_var_offset(do_verify),
2330 .help = "Run verification stage after write",
2331 .def = "1",
2332 .parent = "verify",
2333 .hide = 1,
2334 .category = FIO_OPT_C_IO,
2335 .group = FIO_OPT_G_VERIFY,
2336 },
2337 {
2338 .name = "verifysort",
2339 .lname = "Verify sort",
2340 .type = FIO_OPT_BOOL,
2341 .off1 = td_var_offset(verifysort),
2342 .help = "Sort written verify blocks for read back",
2343 .def = "1",
2344 .parent = "verify",
2345 .hide = 1,
2346 .category = FIO_OPT_C_IO,
2347 .group = FIO_OPT_G_VERIFY,
2348 },
2349 {
2350 .name = "verifysort_nr",
2351 .type = FIO_OPT_INT,
2352 .off1 = td_var_offset(verifysort_nr),
2353 .help = "Pre-load and sort verify blocks for a read workload",
2354 .minval = 0,
2355 .maxval = 131072,
2356 .def = "1024",
2357 .parent = "verify",
2358 .category = FIO_OPT_C_IO,
2359 .group = FIO_OPT_G_VERIFY,
2360 },
2361 {
2362 .name = "verify_interval",
2363 .lname = "Verify interval",
2364 .type = FIO_OPT_INT,
2365 .off1 = td_var_offset(verify_interval),
2366 .minval = 2 * sizeof(struct verify_header),
2367 .help = "Store verify buffer header every N bytes",
2368 .parent = "verify",
2369 .hide = 1,
2370 .interval = 2 * sizeof(struct verify_header),
2371 .category = FIO_OPT_C_IO,
2372 .group = FIO_OPT_G_VERIFY,
2373 },
2374 {
2375 .name = "verify_offset",
2376 .lname = "Verify offset",
2377 .type = FIO_OPT_INT,
2378 .help = "Offset verify header location by N bytes",
2379 .off1 = td_var_offset(verify_offset),
2380 .minval = sizeof(struct verify_header),
2381 .parent = "verify",
2382 .hide = 1,
2383 .category = FIO_OPT_C_IO,
2384 .group = FIO_OPT_G_VERIFY,
2385 },
2386 {
2387 .name = "verify_pattern",
2388 .lname = "Verify pattern",
2389 .type = FIO_OPT_STR,
2390 .cb = str_verify_pattern_cb,
2391 .help = "Fill pattern for IO buffers",
2392 .parent = "verify",
2393 .hide = 1,
2394 .category = FIO_OPT_C_IO,
2395 .group = FIO_OPT_G_VERIFY,
2396 },
2397 {
2398 .name = "verify_fatal",
2399 .lname = "Verify fatal",
2400 .type = FIO_OPT_BOOL,
2401 .off1 = td_var_offset(verify_fatal),
2402 .def = "0",
2403 .help = "Exit on a single verify failure, don't continue",
2404 .parent = "verify",
2405 .hide = 1,
2406 .category = FIO_OPT_C_IO,
2407 .group = FIO_OPT_G_VERIFY,
2408 },
2409 {
2410 .name = "verify_dump",
2411 .lname = "Verify dump",
2412 .type = FIO_OPT_BOOL,
2413 .off1 = td_var_offset(verify_dump),
2414 .def = "0",
2415 .help = "Dump contents of good and bad blocks on failure",
2416 .parent = "verify",
2417 .hide = 1,
2418 .category = FIO_OPT_C_IO,
2419 .group = FIO_OPT_G_VERIFY,
2420 },
2421 {
2422 .name = "verify_async",
2423 .lname = "Verify asynchronously",
2424 .type = FIO_OPT_INT,
2425 .off1 = td_var_offset(verify_async),
2426 .def = "0",
2427 .help = "Number of async verifier threads to use",
2428 .parent = "verify",
2429 .hide = 1,
2430 .category = FIO_OPT_C_IO,
2431 .group = FIO_OPT_G_VERIFY,
2432 },
2433 {
2434 .name = "verify_backlog",
2435 .lname = "Verify backlog",
2436 .type = FIO_OPT_STR_VAL,
2437 .off1 = td_var_offset(verify_backlog),
2438 .help = "Verify after this number of blocks are written",
2439 .parent = "verify",
2440 .hide = 1,
2441 .category = FIO_OPT_C_IO,
2442 .group = FIO_OPT_G_VERIFY,
2443 },
2444 {
2445 .name = "verify_backlog_batch",
2446 .lname = "Verify backlog batch",
2447 .type = FIO_OPT_INT,
2448 .off1 = td_var_offset(verify_batch),
2449 .help = "Verify this number of IO blocks",
2450 .parent = "verify",
2451 .hide = 1,
2452 .category = FIO_OPT_C_IO,
2453 .group = FIO_OPT_G_VERIFY,
2454 },
2455#ifdef FIO_HAVE_CPU_AFFINITY
2456 {
2457 .name = "verify_async_cpus",
2458 .lname = "Async verify CPUs",
2459 .type = FIO_OPT_STR,
2460 .cb = str_verify_cpus_allowed_cb,
2461 .help = "Set CPUs allowed for async verify threads",
2462 .parent = "verify_async",
2463 .hide = 1,
2464 .category = FIO_OPT_C_IO,
2465 .group = FIO_OPT_G_VERIFY,
2466 },
2467#endif
2468 {
2469 .name = "experimental_verify",
2470 .off1 = td_var_offset(experimental_verify),
2471 .type = FIO_OPT_BOOL,
2472 .help = "Enable experimental verification",
2473 .category = FIO_OPT_C_IO,
2474 .group = FIO_OPT_G_VERIFY,
2475 },
2476#ifdef FIO_HAVE_TRIM
2477 {
2478 .name = "trim_percentage",
2479 .lname = "Trim percentage",
2480 .type = FIO_OPT_INT,
2481 .off1 = td_var_offset(trim_percentage),
2482 .minval = 0,
2483 .maxval = 100,
2484 .help = "Number of verify blocks to discard/trim",
2485 .parent = "verify",
2486 .def = "0",
2487 .interval = 1,
2488 .hide = 1,
2489 .category = FIO_OPT_C_IO,
2490 .group = FIO_OPT_G_TRIM,
2491 },
2492 {
2493 .name = "trim_verify_zero",
2494 .lname = "Verify trim zero",
2495 .type = FIO_OPT_BOOL,
2496 .help = "Verify that trim/discarded blocks are returned as zeroes",
2497 .off1 = td_var_offset(trim_zero),
2498 .parent = "trim_percentage",
2499 .hide = 1,
2500 .def = "1",
2501 .category = FIO_OPT_C_IO,
2502 .group = FIO_OPT_G_TRIM,
2503 },
2504 {
2505 .name = "trim_backlog",
2506 .lname = "Trim backlog",
2507 .type = FIO_OPT_STR_VAL,
2508 .off1 = td_var_offset(trim_backlog),
2509 .help = "Trim after this number of blocks are written",
2510 .parent = "trim_percentage",
2511 .hide = 1,
2512 .interval = 1,
2513 .category = FIO_OPT_C_IO,
2514 .group = FIO_OPT_G_TRIM,
2515 },
2516 {
2517 .name = "trim_backlog_batch",
2518 .lname = "Trim backlog batch",
2519 .type = FIO_OPT_INT,
2520 .off1 = td_var_offset(trim_batch),
2521 .help = "Trim this number of IO blocks",
2522 .parent = "trim_percentage",
2523 .hide = 1,
2524 .interval = 1,
2525 .category = FIO_OPT_C_IO,
2526 .group = FIO_OPT_G_TRIM,
2527 },
2528#endif
2529 {
2530 .name = "write_iolog",
2531 .lname = "Write I/O log",
2532 .type = FIO_OPT_STR_STORE,
2533 .off1 = td_var_offset(write_iolog_file),
2534 .help = "Store IO pattern to file",
2535 .category = FIO_OPT_C_IO,
2536 .group = FIO_OPT_G_IOLOG,
2537 },
2538 {
2539 .name = "read_iolog",
2540 .lname = "Read I/O log",
2541 .type = FIO_OPT_STR_STORE,
2542 .off1 = td_var_offset(read_iolog_file),
2543 .help = "Playback IO pattern from file",
2544 .category = FIO_OPT_C_IO,
2545 .group = FIO_OPT_G_IOLOG,
2546 },
2547 {
2548 .name = "replay_no_stall",
2549 .lname = "Don't stall on replay",
2550 .type = FIO_OPT_BOOL,
2551 .off1 = td_var_offset(no_stall),
2552 .def = "0",
2553 .parent = "read_iolog",
2554 .hide = 1,
2555 .help = "Playback IO pattern file as fast as possible without stalls",
2556 .category = FIO_OPT_C_IO,
2557 .group = FIO_OPT_G_IOLOG,
2558 },
2559 {
2560 .name = "replay_redirect",
2561 .lname = "Redirect device for replay",
2562 .type = FIO_OPT_STR_STORE,
2563 .off1 = td_var_offset(replay_redirect),
2564 .parent = "read_iolog",
2565 .hide = 1,
2566 .help = "Replay all I/O onto this device, regardless of trace device",
2567 .category = FIO_OPT_C_IO,
2568 .group = FIO_OPT_G_IOLOG,
2569 },
2570 {
2571 .name = "exec_prerun",
2572 .lname = "Pre-execute runnable",
2573 .type = FIO_OPT_STR_STORE,
2574 .off1 = td_var_offset(exec_prerun),
2575 .help = "Execute this file prior to running job",
2576 .category = FIO_OPT_C_GENERAL,
2577 .group = FIO_OPT_G_INVALID,
2578 },
2579 {
2580 .name = "exec_postrun",
2581 .lname = "Post-execute runnable",
2582 .type = FIO_OPT_STR_STORE,
2583 .off1 = td_var_offset(exec_postrun),
2584 .help = "Execute this file after running job",
2585 .category = FIO_OPT_C_GENERAL,
2586 .group = FIO_OPT_G_INVALID,
2587 },
2588#ifdef FIO_HAVE_IOSCHED_SWITCH
2589 {
2590 .name = "ioscheduler",
2591 .lname = "I/O scheduler",
2592 .type = FIO_OPT_STR_STORE,
2593 .off1 = td_var_offset(ioscheduler),
2594 .help = "Use this IO scheduler on the backing device",
2595 .category = FIO_OPT_C_FILE,
2596 .group = FIO_OPT_G_INVALID,
2597 },
2598#endif
2599 {
2600 .name = "zonesize",
2601 .lname = "Zone size",
2602 .type = FIO_OPT_STR_VAL,
2603 .off1 = td_var_offset(zone_size),
2604 .help = "Amount of data to read per zone",
2605 .def = "0",
2606 .interval = 1024 * 1024,
2607 .category = FIO_OPT_C_IO,
2608 .group = FIO_OPT_G_ZONE,
2609 },
2610 {
2611 .name = "zonerange",
2612 .lname = "Zone range",
2613 .type = FIO_OPT_STR_VAL,
2614 .off1 = td_var_offset(zone_range),
2615 .help = "Give size of an IO zone",
2616 .def = "0",
2617 .interval = 1024 * 1024,
2618 .category = FIO_OPT_C_IO,
2619 .group = FIO_OPT_G_ZONE,
2620 },
2621 {
2622 .name = "zoneskip",
2623 .lname = "Zone skip",
2624 .type = FIO_OPT_STR_VAL,
2625 .off1 = td_var_offset(zone_skip),
2626 .help = "Space between IO zones",
2627 .def = "0",
2628 .interval = 1024 * 1024,
2629 .category = FIO_OPT_C_IO,
2630 .group = FIO_OPT_G_ZONE,
2631 },
2632 {
2633 .name = "lockmem",
2634 .lname = "Lock memory",
2635 .type = FIO_OPT_STR_VAL,
2636 .off1 = td_var_offset(lockmem),
2637 .help = "Lock down this amount of memory (per worker)",
2638 .def = "0",
2639 .interval = 1024 * 1024,
2640 .category = FIO_OPT_C_GENERAL,
2641 .group = FIO_OPT_G_INVALID,
2642 },
2643 {
2644 .name = "rwmixread",
2645 .lname = "Read/write mix read",
2646 .type = FIO_OPT_INT,
2647 .cb = str_rwmix_read_cb,
2648 .maxval = 100,
2649 .help = "Percentage of mixed workload that is reads",
2650 .def = "50",
2651 .interval = 5,
2652 .inverse = "rwmixwrite",
2653 .category = FIO_OPT_C_IO,
2654 .group = FIO_OPT_G_RWMIX,
2655 },
2656 {
2657 .name = "rwmixwrite",
2658 .lname = "Read/write mix write",
2659 .type = FIO_OPT_INT,
2660 .cb = str_rwmix_write_cb,
2661 .maxval = 100,
2662 .help = "Percentage of mixed workload that is writes",
2663 .def = "50",
2664 .interval = 5,
2665 .inverse = "rwmixread",
2666 .category = FIO_OPT_C_IO,
2667 .group = FIO_OPT_G_RWMIX,
2668 },
2669 {
2670 .name = "rwmixcycle",
2671 .lname = "Read/write mix cycle",
2672 .type = FIO_OPT_DEPRECATED,
2673 .category = FIO_OPT_C_IO,
2674 .group = FIO_OPT_G_RWMIX,
2675 },
2676 {
2677 .name = "nice",
2678 .lname = "Nice",
2679 .type = FIO_OPT_INT,
2680 .off1 = td_var_offset(nice),
2681 .help = "Set job CPU nice value",
2682 .minval = -19,
2683 .maxval = 20,
2684 .def = "0",
2685 .interval = 1,
2686 .category = FIO_OPT_C_GENERAL,
2687 .group = FIO_OPT_G_CRED,
2688 },
2689#ifdef FIO_HAVE_IOPRIO
2690 {
2691 .name = "prio",
2692 .lname = "I/O nice priority",
2693 .type = FIO_OPT_INT,
2694 .off1 = td_var_offset(ioprio),
2695 .help = "Set job IO priority value",
2696 .minval = 0,
2697 .maxval = 7,
2698 .interval = 1,
2699 .category = FIO_OPT_C_GENERAL,
2700 .group = FIO_OPT_G_CRED,
2701 },
2702 {
2703 .name = "prioclass",
2704 .lname = "I/O nice priority class",
2705 .type = FIO_OPT_INT,
2706 .off1 = td_var_offset(ioprio_class),
2707 .help = "Set job IO priority class",
2708 .minval = 0,
2709 .maxval = 3,
2710 .interval = 1,
2711 .category = FIO_OPT_C_GENERAL,
2712 .group = FIO_OPT_G_CRED,
2713 },
2714#endif
2715 {
2716 .name = "thinktime",
2717 .lname = "Thinktime",
2718 .type = FIO_OPT_INT,
2719 .off1 = td_var_offset(thinktime),
2720 .help = "Idle time between IO buffers (usec)",
2721 .def = "0",
2722 .category = FIO_OPT_C_IO,
2723 .group = FIO_OPT_G_THINKTIME,
2724 },
2725 {
2726 .name = "thinktime_spin",
2727 .lname = "Thinktime spin",
2728 .type = FIO_OPT_INT,
2729 .off1 = td_var_offset(thinktime_spin),
2730 .help = "Start think time by spinning this amount (usec)",
2731 .def = "0",
2732 .parent = "thinktime",
2733 .hide = 1,
2734 .category = FIO_OPT_C_IO,
2735 .group = FIO_OPT_G_THINKTIME,
2736 },
2737 {
2738 .name = "thinktime_blocks",
2739 .lname = "Thinktime blocks",
2740 .type = FIO_OPT_INT,
2741 .off1 = td_var_offset(thinktime_blocks),
2742 .help = "IO buffer period between 'thinktime'",
2743 .def = "1",
2744 .parent = "thinktime",
2745 .hide = 1,
2746 .category = FIO_OPT_C_IO,
2747 .group = FIO_OPT_G_THINKTIME,
2748 },
2749 {
2750 .name = "rate",
2751 .lname = "I/O rate",
2752 .type = FIO_OPT_INT,
2753 .off1 = td_var_offset(rate[DDIR_READ]),
2754 .off2 = td_var_offset(rate[DDIR_WRITE]),
2755 .off3 = td_var_offset(rate[DDIR_TRIM]),
2756 .help = "Set bandwidth rate",
2757 .category = FIO_OPT_C_IO,
2758 .group = FIO_OPT_G_RATE,
2759 },
2760 {
2761 .name = "ratemin",
2762 .lname = "I/O min rate",
2763 .type = FIO_OPT_INT,
2764 .off1 = td_var_offset(ratemin[DDIR_READ]),
2765 .off2 = td_var_offset(ratemin[DDIR_WRITE]),
2766 .off3 = td_var_offset(ratemin[DDIR_TRIM]),
2767 .help = "Job must meet this rate or it will be shutdown",
2768 .parent = "rate",
2769 .hide = 1,
2770 .category = FIO_OPT_C_IO,
2771 .group = FIO_OPT_G_RATE,
2772 },
2773 {
2774 .name = "rate_iops",
2775 .lname = "I/O rate IOPS",
2776 .type = FIO_OPT_INT,
2777 .off1 = td_var_offset(rate_iops[DDIR_READ]),
2778 .off2 = td_var_offset(rate_iops[DDIR_WRITE]),
2779 .off3 = td_var_offset(rate_iops[DDIR_TRIM]),
2780 .help = "Limit IO used to this number of IO operations/sec",
2781 .hide = 1,
2782 .category = FIO_OPT_C_IO,
2783 .group = FIO_OPT_G_RATE,
2784 },
2785 {
2786 .name = "rate_iops_min",
2787 .lname = "I/O min rate IOPS",
2788 .type = FIO_OPT_INT,
2789 .off1 = td_var_offset(rate_iops_min[DDIR_READ]),
2790 .off2 = td_var_offset(rate_iops_min[DDIR_WRITE]),
2791 .off3 = td_var_offset(rate_iops_min[DDIR_TRIM]),
2792 .help = "Job must meet this rate or it will be shut down",
2793 .parent = "rate_iops",
2794 .hide = 1,
2795 .category = FIO_OPT_C_IO,
2796 .group = FIO_OPT_G_RATE,
2797 },
2798 {
2799 .name = "ratecycle",
2800 .lname = "I/O rate cycle",
2801 .type = FIO_OPT_INT,
2802 .off1 = td_var_offset(ratecycle),
2803 .help = "Window average for rate limits (msec)",
2804 .def = "1000",
2805 .parent = "rate",
2806 .hide = 1,
2807 .category = FIO_OPT_C_IO,
2808 .group = FIO_OPT_G_RATE,
2809 },
2810 {
2811 .name = "max_latency",
2812 .type = FIO_OPT_INT,
2813 .off1 = td_var_offset(max_latency),
2814 .help = "Maximum tolerated IO latency (usec)",
2815 .category = FIO_OPT_C_IO,
2816 .group = FIO_OPT_G_LATPROF,
2817 },
2818 {
2819 .name = "latency_target",
2820 .lname = "Latency Target (usec)",
2821 .type = FIO_OPT_STR_VAL_TIME,
2822 .off1 = td_var_offset(latency_target),
2823 .help = "Ramp to max queue depth supporting this latency",
2824 .category = FIO_OPT_C_IO,
2825 .group = FIO_OPT_G_LATPROF,
2826 },
2827 {
2828 .name = "latency_window",
2829 .lname = "Latency Window (usec)",
2830 .type = FIO_OPT_STR_VAL_TIME,
2831 .off1 = td_var_offset(latency_window),
2832 .help = "Time to sustain latency_target",
2833 .category = FIO_OPT_C_IO,
2834 .group = FIO_OPT_G_LATPROF,
2835 },
2836 {
2837 .name = "latency_percentile",
2838 .lname = "Latency Percentile",
2839 .type = FIO_OPT_FLOAT_LIST,
2840 .off1 = td_var_offset(latency_percentile),
2841 .help = "Percentile of IOs must be below latency_target",
2842 .def = "100",
2843 .maxlen = 1,
2844 .minfp = 0.0,
2845 .maxfp = 100.0,
2846 .category = FIO_OPT_C_IO,
2847 .group = FIO_OPT_G_LATPROF,
2848 },
2849 {
2850 .name = "invalidate",
2851 .lname = "Cache invalidate",
2852 .type = FIO_OPT_BOOL,
2853 .off1 = td_var_offset(invalidate_cache),
2854 .help = "Invalidate buffer/page cache prior to running job",
2855 .def = "1",
2856 .category = FIO_OPT_C_IO,
2857 .group = FIO_OPT_G_IO_TYPE,
2858 },
2859 {
2860 .name = "sync",
2861 .lname = "Synchronous I/O",
2862 .type = FIO_OPT_BOOL,
2863 .off1 = td_var_offset(sync_io),
2864 .help = "Use O_SYNC for buffered writes",
2865 .def = "0",
2866 .parent = "buffered",
2867 .hide = 1,
2868 .category = FIO_OPT_C_IO,
2869 .group = FIO_OPT_G_IO_TYPE,
2870 },
2871 {
2872 .name = "create_serialize",
2873 .lname = "Create serialize",
2874 .type = FIO_OPT_BOOL,
2875 .off1 = td_var_offset(create_serialize),
2876 .help = "Serialize creating of job files",
2877 .def = "1",
2878 .category = FIO_OPT_C_FILE,
2879 .group = FIO_OPT_G_INVALID,
2880 },
2881 {
2882 .name = "create_fsync",
2883 .lname = "Create fsync",
2884 .type = FIO_OPT_BOOL,
2885 .off1 = td_var_offset(create_fsync),
2886 .help = "fsync file after creation",
2887 .def = "1",
2888 .category = FIO_OPT_C_FILE,
2889 .group = FIO_OPT_G_INVALID,
2890 },
2891 {
2892 .name = "create_on_open",
2893 .lname = "Create on open",
2894 .type = FIO_OPT_BOOL,
2895 .off1 = td_var_offset(create_on_open),
2896 .help = "Create files when they are opened for IO",
2897 .def = "0",
2898 .category = FIO_OPT_C_FILE,
2899 .group = FIO_OPT_G_INVALID,
2900 },
2901 {
2902 .name = "create_only",
2903 .type = FIO_OPT_BOOL,
2904 .off1 = td_var_offset(create_only),
2905 .help = "Only perform file creation phase",
2906 .category = FIO_OPT_C_FILE,
2907 .def = "0",
2908 },
2909 {
2910 .name = "pre_read",
2911 .lname = "Pre-read files",
2912 .type = FIO_OPT_BOOL,
2913 .off1 = td_var_offset(pre_read),
2914 .help = "Pre-read files before starting official testing",
2915 .def = "0",
2916 .category = FIO_OPT_C_FILE,
2917 .group = FIO_OPT_G_INVALID,
2918 },
2919#ifdef FIO_HAVE_CPU_AFFINITY
2920 {
2921 .name = "cpumask",
2922 .lname = "CPU mask",
2923 .type = FIO_OPT_INT,
2924 .cb = str_cpumask_cb,
2925 .help = "CPU affinity mask",
2926 .category = FIO_OPT_C_GENERAL,
2927 .group = FIO_OPT_G_CRED,
2928 },
2929 {
2930 .name = "cpus_allowed",
2931 .lname = "CPUs allowed",
2932 .type = FIO_OPT_STR,
2933 .cb = str_cpus_allowed_cb,
2934 .help = "Set CPUs allowed",
2935 .category = FIO_OPT_C_GENERAL,
2936 .group = FIO_OPT_G_CRED,
2937 },
2938 {
2939 .name = "cpus_allowed_policy",
2940 .lname = "CPUs allowed distribution policy",
2941 .type = FIO_OPT_STR,
2942 .off1 = td_var_offset(cpus_allowed_policy),
2943 .help = "Distribution policy for cpus_allowed",
2944 .parent = "cpus_allowed",
2945 .prio = 1,
2946 .posval = {
2947 { .ival = "shared",
2948 .oval = FIO_CPUS_SHARED,
2949 .help = "Mask shared between threads",
2950 },
2951 { .ival = "split",
2952 .oval = FIO_CPUS_SPLIT,
2953 .help = "Mask split between threads",
2954 },
2955 },
2956 .category = FIO_OPT_C_GENERAL,
2957 .group = FIO_OPT_G_CRED,
2958 },
2959#endif
2960#ifdef CONFIG_LIBNUMA
2961 {
2962 .name = "numa_cpu_nodes",
2963 .type = FIO_OPT_STR,
2964 .cb = str_numa_cpunodes_cb,
2965 .help = "NUMA CPU nodes bind",
2966 .category = FIO_OPT_C_GENERAL,
2967 .group = FIO_OPT_G_INVALID,
2968 },
2969 {
2970 .name = "numa_mem_policy",
2971 .type = FIO_OPT_STR,
2972 .cb = str_numa_mpol_cb,
2973 .help = "NUMA memory policy setup",
2974 .category = FIO_OPT_C_GENERAL,
2975 .group = FIO_OPT_G_INVALID,
2976 },
2977#endif
2978 {
2979 .name = "end_fsync",
2980 .lname = "End fsync",
2981 .type = FIO_OPT_BOOL,
2982 .off1 = td_var_offset(end_fsync),
2983 .help = "Include fsync at the end of job",
2984 .def = "0",
2985 .category = FIO_OPT_C_FILE,
2986 .group = FIO_OPT_G_INVALID,
2987 },
2988 {
2989 .name = "fsync_on_close",
2990 .lname = "Fsync on close",
2991 .type = FIO_OPT_BOOL,
2992 .off1 = td_var_offset(fsync_on_close),
2993 .help = "fsync files on close",
2994 .def = "0",
2995 .category = FIO_OPT_C_FILE,
2996 .group = FIO_OPT_G_INVALID,
2997 },
2998 {
2999 .name = "unlink",
3000 .lname = "Unlink file",
3001 .type = FIO_OPT_BOOL,
3002 .off1 = td_var_offset(unlink),
3003 .help = "Unlink created files after job has completed",
3004 .def = "0",
3005 .category = FIO_OPT_C_FILE,
3006 .group = FIO_OPT_G_INVALID,
3007 },
3008 {
3009 .name = "exitall",
3010 .lname = "Exit-all on terminate",
3011 .type = FIO_OPT_STR_SET,
3012 .cb = str_exitall_cb,
3013 .help = "Terminate all jobs when one exits",
3014 .category = FIO_OPT_C_GENERAL,
3015 .group = FIO_OPT_G_PROCESS,
3016 },
3017 {
3018 .name = "stonewall",
3019 .lname = "Wait for previous",
3020 .alias = "wait_for_previous",
3021 .type = FIO_OPT_STR_SET,
3022 .off1 = td_var_offset(stonewall),
3023 .help = "Insert a hard barrier between this job and previous",
3024 .category = FIO_OPT_C_GENERAL,
3025 .group = FIO_OPT_G_PROCESS,
3026 },
3027 {
3028 .name = "new_group",
3029 .lname = "New group",
3030 .type = FIO_OPT_STR_SET,
3031 .off1 = td_var_offset(new_group),
3032 .help = "Mark the start of a new group (for reporting)",
3033 .category = FIO_OPT_C_GENERAL,
3034 .group = FIO_OPT_G_PROCESS,
3035 },
3036 {
3037 .name = "thread",
3038 .lname = "Thread",
3039 .type = FIO_OPT_STR_SET,
3040 .off1 = td_var_offset(use_thread),
3041 .help = "Use threads instead of processes",
3042 .category = FIO_OPT_C_GENERAL,
3043 .group = FIO_OPT_G_PROCESS,
3044 },
3045 {
3046 .name = "write_bw_log",
3047 .lname = "Write bandwidth log",
3048 .type = FIO_OPT_STR_STORE,
3049 .off1 = td_var_offset(bw_log_file),
3050 .help = "Write log of bandwidth during run",
3051 .category = FIO_OPT_C_LOG,
3052 .group = FIO_OPT_G_INVALID,
3053 },
3054 {
3055 .name = "write_lat_log",
3056 .lname = "Write latency log",
3057 .type = FIO_OPT_STR_STORE,
3058 .off1 = td_var_offset(lat_log_file),
3059 .help = "Write log of latency during run",
3060 .category = FIO_OPT_C_LOG,
3061 .group = FIO_OPT_G_INVALID,
3062 },
3063 {
3064 .name = "write_iops_log",
3065 .lname = "Write IOPS log",
3066 .type = FIO_OPT_STR_STORE,
3067 .off1 = td_var_offset(iops_log_file),
3068 .help = "Write log of IOPS during run",
3069 .category = FIO_OPT_C_LOG,
3070 .group = FIO_OPT_G_INVALID,
3071 },
3072 {
3073 .name = "log_avg_msec",
3074 .lname = "Log averaging (msec)",
3075 .type = FIO_OPT_INT,
3076 .off1 = td_var_offset(log_avg_msec),
3077 .help = "Average bw/iops/lat logs over this period of time",
3078 .def = "0",
3079 .category = FIO_OPT_C_LOG,
3080 .group = FIO_OPT_G_INVALID,
3081 },
3082 {
3083 .name = "bwavgtime",
3084 .lname = "Bandwidth average time",
3085 .type = FIO_OPT_INT,
3086 .off1 = td_var_offset(bw_avg_time),
3087 .help = "Time window over which to calculate bandwidth"
3088 " (msec)",
3089 .def = "500",
3090 .parent = "write_bw_log",
3091 .hide = 1,
3092 .interval = 100,
3093 .category = FIO_OPT_C_LOG,
3094 .group = FIO_OPT_G_INVALID,
3095 },
3096 {
3097 .name = "iopsavgtime",
3098 .lname = "IOPS average time",
3099 .type = FIO_OPT_INT,
3100 .off1 = td_var_offset(iops_avg_time),
3101 .help = "Time window over which to calculate IOPS (msec)",
3102 .def = "500",
3103 .parent = "write_iops_log",
3104 .hide = 1,
3105 .interval = 100,
3106 .category = FIO_OPT_C_LOG,
3107 .group = FIO_OPT_G_INVALID,
3108 },
3109 {
3110 .name = "group_reporting",
3111 .lname = "Group reporting",
3112 .type = FIO_OPT_STR_SET,
3113 .off1 = td_var_offset(group_reporting),
3114 .help = "Do reporting on a per-group basis",
3115 .category = FIO_OPT_C_STAT,
3116 .group = FIO_OPT_G_INVALID,
3117 },
3118 {
3119 .name = "zero_buffers",
3120 .lname = "Zero I/O buffers",
3121 .type = FIO_OPT_STR_SET,
3122 .off1 = td_var_offset(zero_buffers),
3123 .help = "Init IO buffers to all zeroes",
3124 .category = FIO_OPT_C_IO,
3125 .group = FIO_OPT_G_IO_BUF,
3126 },
3127 {
3128 .name = "refill_buffers",
3129 .lname = "Refill I/O buffers",
3130 .type = FIO_OPT_STR_SET,
3131 .off1 = td_var_offset(refill_buffers),
3132 .help = "Refill IO buffers on every IO submit",
3133 .category = FIO_OPT_C_IO,
3134 .group = FIO_OPT_G_IO_BUF,
3135 },
3136 {
3137 .name = "scramble_buffers",
3138 .lname = "Scramble I/O buffers",
3139 .type = FIO_OPT_BOOL,
3140 .off1 = td_var_offset(scramble_buffers),
3141 .help = "Slightly scramble buffers on every IO submit",
3142 .def = "1",
3143 .category = FIO_OPT_C_IO,
3144 .group = FIO_OPT_G_IO_BUF,
3145 },
3146 {
3147 .name = "buffer_pattern",
3148 .lname = "Buffer pattern",
3149 .type = FIO_OPT_STR,
3150 .cb = str_buffer_pattern_cb,
3151 .help = "Fill pattern for IO buffers",
3152 .category = FIO_OPT_C_IO,
3153 .group = FIO_OPT_G_IO_BUF,
3154 },
3155 {
3156 .name = "buffer_compress_percentage",
3157 .lname = "Buffer compression percentage",
3158 .type = FIO_OPT_INT,
3159 .cb = str_buffer_compress_cb,
3160 .maxval = 100,
3161 .minval = 0,
3162 .help = "How compressible the buffer is (approximately)",
3163 .interval = 5,
3164 .category = FIO_OPT_C_IO,
3165 .group = FIO_OPT_G_IO_BUF,
3166 },
3167 {
3168 .name = "buffer_compress_chunk",
3169 .lname = "Buffer compression chunk size",
3170 .type = FIO_OPT_INT,
3171 .off1 = td_var_offset(compress_chunk),
3172 .parent = "buffer_compress_percentage",
3173 .hide = 1,
3174 .help = "Size of compressible region in buffer",
3175 .interval = 256,
3176 .category = FIO_OPT_C_IO,
3177 .group = FIO_OPT_G_IO_BUF,
3178 },
3179 {
3180 .name = "clat_percentiles",
3181 .lname = "Completion latency percentiles",
3182 .type = FIO_OPT_BOOL,
3183 .off1 = td_var_offset(clat_percentiles),
3184 .help = "Enable the reporting of completion latency percentiles",
3185 .def = "1",
3186 .category = FIO_OPT_C_STAT,
3187 .group = FIO_OPT_G_INVALID,
3188 },
3189 {
3190 .name = "percentile_list",
3191 .lname = "Completion latency percentile list",
3192 .type = FIO_OPT_FLOAT_LIST,
3193 .off1 = td_var_offset(percentile_list),
3194 .off2 = td_var_offset(percentile_precision),
3195 .help = "Specify a custom list of percentiles to report",
3196 .def = "1:5:10:20:30:40:50:60:70:80:90:95:99:99.5:99.9:99.95:99.99",
3197 .maxlen = FIO_IO_U_LIST_MAX_LEN,
3198 .minfp = 0.0,
3199 .maxfp = 100.0,
3200 .category = FIO_OPT_C_STAT,
3201 .group = FIO_OPT_G_INVALID,
3202 },
3203
3204#ifdef FIO_HAVE_DISK_UTIL
3205 {
3206 .name = "disk_util",
3207 .lname = "Disk utilization",
3208 .type = FIO_OPT_BOOL,
3209 .off1 = td_var_offset(do_disk_util),
3210 .help = "Log disk utilization statistics",
3211 .def = "1",
3212 .category = FIO_OPT_C_STAT,
3213 .group = FIO_OPT_G_INVALID,
3214 },
3215#endif
3216 {
3217 .name = "gtod_reduce",
3218 .lname = "Reduce gettimeofday() calls",
3219 .type = FIO_OPT_BOOL,
3220 .help = "Greatly reduce number of gettimeofday() calls",
3221 .cb = str_gtod_reduce_cb,
3222 .def = "0",
3223 .hide_on_set = 1,
3224 .category = FIO_OPT_C_STAT,
3225 .group = FIO_OPT_G_INVALID,
3226 },
3227 {
3228 .name = "disable_lat",
3229 .lname = "Disable all latency stats",
3230 .type = FIO_OPT_BOOL,
3231 .off1 = td_var_offset(disable_lat),
3232 .help = "Disable latency numbers",
3233 .parent = "gtod_reduce",
3234 .hide = 1,
3235 .def = "0",
3236 .category = FIO_OPT_C_STAT,
3237 .group = FIO_OPT_G_INVALID,
3238 },
3239 {
3240 .name = "disable_clat",
3241 .lname = "Disable completion latency stats",
3242 .type = FIO_OPT_BOOL,
3243 .off1 = td_var_offset(disable_clat),
3244 .help = "Disable completion latency numbers",
3245 .parent = "gtod_reduce",
3246 .hide = 1,
3247 .def = "0",
3248 .category = FIO_OPT_C_STAT,
3249 .group = FIO_OPT_G_INVALID,
3250 },
3251 {
3252 .name = "disable_slat",
3253 .lname = "Disable submission latency stats",
3254 .type = FIO_OPT_BOOL,
3255 .off1 = td_var_offset(disable_slat),
3256 .help = "Disable submission latency numbers",
3257 .parent = "gtod_reduce",
3258 .hide = 1,
3259 .def = "0",
3260 .category = FIO_OPT_C_STAT,
3261 .group = FIO_OPT_G_INVALID,
3262 },
3263 {
3264 .name = "disable_bw_measurement",
3265 .lname = "Disable bandwidth stats",
3266 .type = FIO_OPT_BOOL,
3267 .off1 = td_var_offset(disable_bw),
3268 .help = "Disable bandwidth logging",
3269 .parent = "gtod_reduce",
3270 .hide = 1,
3271 .def = "0",
3272 .category = FIO_OPT_C_STAT,
3273 .group = FIO_OPT_G_INVALID,
3274 },
3275 {
3276 .name = "gtod_cpu",
3277 .lname = "Dedicated gettimeofday() CPU",
3278 .type = FIO_OPT_INT,
3279 .cb = str_gtod_cpu_cb,
3280 .help = "Set up dedicated gettimeofday() thread on this CPU",
3281 .verify = gtod_cpu_verify,
3282 .category = FIO_OPT_C_GENERAL,
3283 .group = FIO_OPT_G_CLOCK,
3284 },
3285 {
3286 .name = "unified_rw_reporting",
3287 .type = FIO_OPT_BOOL,
3288 .off1 = td_var_offset(unified_rw_rep),
3289 .help = "Unify reporting across data direction",
3290 .def = "0",
3291 .category = FIO_OPT_C_GENERAL,
3292 .group = FIO_OPT_G_INVALID,
3293 },
3294 {
3295 .name = "continue_on_error",
3296 .lname = "Continue on error",
3297 .type = FIO_OPT_STR,
3298 .off1 = td_var_offset(continue_on_error),
3299 .help = "Continue on non-fatal errors during IO",
3300 .def = "none",
3301 .category = FIO_OPT_C_GENERAL,
3302 .group = FIO_OPT_G_ERR,
3303 .posval = {
3304 { .ival = "none",
3305 .oval = ERROR_TYPE_NONE,
3306 .help = "Exit when an error is encountered",
3307 },
3308 { .ival = "read",
3309 .oval = ERROR_TYPE_READ,
3310 .help = "Continue on read errors only",
3311 },
3312 { .ival = "write",
3313 .oval = ERROR_TYPE_WRITE,
3314 .help = "Continue on write errors only",
3315 },
3316 { .ival = "io",
3317 .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
3318 .help = "Continue on any IO errors",
3319 },
3320 { .ival = "verify",
3321 .oval = ERROR_TYPE_VERIFY,
3322 .help = "Continue on verify errors only",
3323 },
3324 { .ival = "all",
3325 .oval = ERROR_TYPE_ANY,
3326 .help = "Continue on all io and verify errors",
3327 },
3328 { .ival = "0",
3329 .oval = ERROR_TYPE_NONE,
3330 .help = "Alias for 'none'",
3331 },
3332 { .ival = "1",
3333 .oval = ERROR_TYPE_ANY,
3334 .help = "Alias for 'all'",
3335 },
3336 },
3337 },
3338 {
3339 .name = "ignore_error",
3340 .type = FIO_OPT_STR,
3341 .cb = str_ignore_error_cb,
3342 .help = "Set a specific list of errors to ignore",
3343 .parent = "rw",
3344 .category = FIO_OPT_C_GENERAL,
3345 .group = FIO_OPT_G_ERR,
3346 },
3347 {
3348 .name = "error_dump",
3349 .type = FIO_OPT_BOOL,
3350 .off1 = td_var_offset(error_dump),
3351 .def = "0",
3352 .help = "Dump info on each error",
3353 .category = FIO_OPT_C_GENERAL,
3354 .group = FIO_OPT_G_ERR,
3355 },
3356 {
3357 .name = "profile",
3358 .lname = "Profile",
3359 .type = FIO_OPT_STR_STORE,
3360 .off1 = td_var_offset(profile),
3361 .help = "Select a specific builtin performance test",
3362 .category = FIO_OPT_C_PROFILE,
3363 .group = FIO_OPT_G_INVALID,
3364 },
3365 {
3366 .name = "cgroup",
3367 .lname = "Cgroup",
3368 .type = FIO_OPT_STR_STORE,
3369 .off1 = td_var_offset(cgroup),
3370 .help = "Add job to cgroup of this name",
3371 .category = FIO_OPT_C_GENERAL,
3372 .group = FIO_OPT_G_CGROUP,
3373 },
3374 {
3375 .name = "cgroup_nodelete",
3376 .lname = "Cgroup no-delete",
3377 .type = FIO_OPT_BOOL,
3378 .off1 = td_var_offset(cgroup_nodelete),
3379 .help = "Do not delete cgroups after job completion",
3380 .def = "0",
3381 .parent = "cgroup",
3382 .category = FIO_OPT_C_GENERAL,
3383 .group = FIO_OPT_G_CGROUP,
3384 },
3385 {
3386 .name = "cgroup_weight",
3387 .lname = "Cgroup weight",
3388 .type = FIO_OPT_INT,
3389 .off1 = td_var_offset(cgroup_weight),
3390 .help = "Use given weight for cgroup",
3391 .minval = 100,
3392 .maxval = 1000,
3393 .parent = "cgroup",
3394 .category = FIO_OPT_C_GENERAL,
3395 .group = FIO_OPT_G_CGROUP,
3396 },
3397 {
3398 .name = "uid",
3399 .lname = "User ID",
3400 .type = FIO_OPT_INT,
3401 .off1 = td_var_offset(uid),
3402 .help = "Run job with this user ID",
3403 .category = FIO_OPT_C_GENERAL,
3404 .group = FIO_OPT_G_CRED,
3405 },
3406 {
3407 .name = "gid",
3408 .lname = "Group ID",
3409 .type = FIO_OPT_INT,
3410 .off1 = td_var_offset(gid),
3411 .help = "Run job with this group ID",
3412 .category = FIO_OPT_C_GENERAL,
3413 .group = FIO_OPT_G_CRED,
3414 },
3415 {
3416 .name = "kb_base",
3417 .lname = "KB Base",
3418 .type = FIO_OPT_INT,
3419 .off1 = td_var_offset(kb_base),
3420 .prio = 1,
3421 .def = "1024",
3422 .posval = {
3423 { .ival = "1024",
3424 .oval = 1024,
3425 .help = "Use 1024 as the K base",
3426 },
3427 { .ival = "1000",
3428 .oval = 1000,
3429 .help = "Use 1000 as the K base",
3430 },
3431 },
3432 .help = "How many bytes per KB for reporting (1000 or 1024)",
3433 .category = FIO_OPT_C_GENERAL,
3434 .group = FIO_OPT_G_INVALID,
3435 },
3436 {
3437 .name = "unit_base",
3438 .lname = "Base unit for reporting (Bits or Bytes)",
3439 .type = FIO_OPT_INT,
3440 .off1 = td_var_offset(unit_base),
3441 .prio = 1,
3442 .posval = {
3443 { .ival = "0",
3444 .oval = 0,
3445 .help = "Auto-detect",
3446 },
3447 { .ival = "8",
3448 .oval = 8,
3449 .help = "Normal (byte based)",
3450 },
3451 { .ival = "1",
3452 .oval = 1,
3453 .help = "Bit based",
3454 },
3455 },
3456 .help = "Bit multiple of result summary data (8 for byte, 1 for bit)",
3457 .category = FIO_OPT_C_GENERAL,
3458 .group = FIO_OPT_G_INVALID,
3459 },
3460 {
3461 .name = "hugepage-size",
3462 .lname = "Hugepage size",
3463 .type = FIO_OPT_INT,
3464 .off1 = td_var_offset(hugepage_size),
3465 .help = "When using hugepages, specify size of each page",
3466 .def = __fio_stringify(FIO_HUGE_PAGE),
3467 .interval = 1024 * 1024,
3468 .category = FIO_OPT_C_GENERAL,
3469 .group = FIO_OPT_G_INVALID,
3470 },
3471 {
3472 .name = "flow_id",
3473 .lname = "I/O flow ID",
3474 .type = FIO_OPT_INT,
3475 .off1 = td_var_offset(flow_id),
3476 .help = "The flow index ID to use",
3477 .def = "0",
3478 .category = FIO_OPT_C_IO,
3479 .group = FIO_OPT_G_IO_FLOW,
3480 },
3481 {
3482 .name = "flow",
3483 .lname = "I/O flow weight",
3484 .type = FIO_OPT_INT,
3485 .off1 = td_var_offset(flow),
3486 .help = "Weight for flow control of this job",
3487 .parent = "flow_id",
3488 .hide = 1,
3489 .def = "0",
3490 .category = FIO_OPT_C_IO,
3491 .group = FIO_OPT_G_IO_FLOW,
3492 },
3493 {
3494 .name = "flow_watermark",
3495 .lname = "I/O flow watermark",
3496 .type = FIO_OPT_INT,
3497 .off1 = td_var_offset(flow_watermark),
3498 .help = "High watermark for flow control. This option"
3499 " should be set to the same value for all threads"
3500 " with non-zero flow.",
3501 .parent = "flow_id",
3502 .hide = 1,
3503 .def = "1024",
3504 .category = FIO_OPT_C_IO,
3505 .group = FIO_OPT_G_IO_FLOW,
3506 },
3507 {
3508 .name = "flow_sleep",
3509 .lname = "I/O flow sleep",
3510 .type = FIO_OPT_INT,
3511 .off1 = td_var_offset(flow_sleep),
3512 .help = "How many microseconds to sleep after being held"
3513 " back by the flow control mechanism",
3514 .parent = "flow_id",
3515 .hide = 1,
3516 .def = "0",
3517 .category = FIO_OPT_C_IO,
3518 .group = FIO_OPT_G_IO_FLOW,
3519 },
3520 {
3521 .name = NULL,
3522 },
3523};
3524
3525static void add_to_lopt(struct option *lopt, struct fio_option *o,
3526 const char *name, int val)
3527{
3528 lopt->name = (char *) name;
3529 lopt->val = val;
3530 if (o->type == FIO_OPT_STR_SET)
3531 lopt->has_arg = optional_argument;
3532 else
3533 lopt->has_arg = required_argument;
3534}
3535
3536static void options_to_lopts(struct fio_option *opts,
3537 struct option *long_options,
3538 int i, int option_type)
3539{
3540 struct fio_option *o = &opts[0];
3541 while (o->name) {
3542 add_to_lopt(&long_options[i], o, o->name, option_type);
3543 if (o->alias) {
3544 i++;
3545 add_to_lopt(&long_options[i], o, o->alias, option_type);
3546 }
3547
3548 i++;
3549 o++;
3550 assert(i < FIO_NR_OPTIONS);
3551 }
3552}
3553
3554void fio_options_set_ioengine_opts(struct option *long_options,
3555 struct thread_data *td)
3556{
3557 unsigned int i;
3558
3559 i = 0;
3560 while (long_options[i].name) {
3561 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
3562 memset(&long_options[i], 0, sizeof(*long_options));
3563 break;
3564 }
3565 i++;
3566 }
3567
3568 /*
3569 * Just clear out the prior ioengine options.
3570 */
3571 if (!td || !td->eo)
3572 return;
3573
3574 options_to_lopts(td->io_ops->options, long_options, i,
3575 FIO_GETOPT_IOENGINE);
3576}
3577
3578void fio_options_dup_and_init(struct option *long_options)
3579{
3580 unsigned int i;
3581
3582 options_init(fio_options);
3583
3584 i = 0;
3585 while (long_options[i].name)
3586 i++;
3587
3588 options_to_lopts(fio_options, long_options, i, FIO_GETOPT_JOB);
3589}
3590
3591struct fio_keyword {
3592 const char *word;
3593 const char *desc;
3594 char *replace;
3595};
3596
3597static struct fio_keyword fio_keywords[] = {
3598 {
3599 .word = "$pagesize",
3600 .desc = "Page size in the system",
3601 },
3602 {
3603 .word = "$mb_memory",
3604 .desc = "Megabytes of memory online",
3605 },
3606 {
3607 .word = "$ncpus",
3608 .desc = "Number of CPUs online in the system",
3609 },
3610 {
3611 .word = NULL,
3612 },
3613};
3614
3615void fio_keywords_init(void)
3616{
3617 unsigned long long mb_memory;
3618 char buf[128];
3619 long l;
3620
3621 sprintf(buf, "%lu", (unsigned long) page_size);
3622 fio_keywords[0].replace = strdup(buf);
3623
3624 mb_memory = os_phys_mem() / (1024 * 1024);
3625 sprintf(buf, "%llu", mb_memory);
3626 fio_keywords[1].replace = strdup(buf);
3627
3628 l = cpus_online();
3629 sprintf(buf, "%lu", l);
3630 fio_keywords[2].replace = strdup(buf);
3631}
3632
3633#define BC_APP "bc"
3634
3635static char *bc_calc(char *str)
3636{
3637 char buf[128], *tmp;
3638 FILE *f;
3639 int ret;
3640
3641 /*
3642 * No math, just return string
3643 */
3644 if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
3645 !strchr(str, '/')) || strchr(str, '\''))
3646 return str;
3647
3648 /*
3649 * Split option from value, we only need to calculate the value
3650 */
3651 tmp = strchr(str, '=');
3652 if (!tmp)
3653 return str;
3654
3655 tmp++;
3656
3657 /*
3658 * Prevent buffer overflows; such a case isn't reasonable anyway
3659 */
3660 if (strlen(str) >= 128 || strlen(tmp) > 100)
3661 return str;
3662
3663 sprintf(buf, "which %s > /dev/null", BC_APP);
3664 if (system(buf)) {
3665 log_err("fio: bc is needed for performing math\n");
3666 return NULL;
3667 }
3668
3669 sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
3670 f = popen(buf, "r");
3671 if (!f)
3672 return NULL;
3673
3674 ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
3675 if (ret <= 0) {
3676 pclose(f);
3677 return NULL;
3678 }
3679
3680 pclose(f);
3681 buf[(tmp - str) + ret - 1] = '\0';
3682 memcpy(buf, str, tmp - str);
3683 free(str);
3684 return strdup(buf);
3685}
3686
3687/*
3688 * Return a copy of the input string with substrings of the form ${VARNAME}
3689 * substituted with the value of the environment variable VARNAME. The
3690 * substitution always occurs, even if VARNAME is empty or the corresponding
3691 * environment variable undefined.
3692 */
3693static char *option_dup_subs(const char *opt)
3694{
3695 char out[OPT_LEN_MAX+1];
3696 char in[OPT_LEN_MAX+1];
3697 char *outptr = out;
3698 char *inptr = in;
3699 char *ch1, *ch2, *env;
3700 ssize_t nchr = OPT_LEN_MAX;
3701 size_t envlen;
3702
3703 if (strlen(opt) + 1 > OPT_LEN_MAX) {
3704 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
3705 return NULL;
3706 }
3707
3708 in[OPT_LEN_MAX] = '\0';
3709 strncpy(in, opt, OPT_LEN_MAX);
3710
3711 while (*inptr && nchr > 0) {
3712 if (inptr[0] == '$' && inptr[1] == '{') {
3713 ch2 = strchr(inptr, '}');
3714 if (ch2 && inptr+1 < ch2) {
3715 ch1 = inptr+2;
3716 inptr = ch2+1;
3717 *ch2 = '\0';
3718
3719 env = getenv(ch1);
3720 if (env) {
3721 envlen = strlen(env);
3722 if (envlen <= nchr) {
3723 memcpy(outptr, env, envlen);
3724 outptr += envlen;
3725 nchr -= envlen;
3726 }
3727 }
3728
3729 continue;
3730 }
3731 }
3732
3733 *outptr++ = *inptr++;
3734 --nchr;
3735 }
3736
3737 *outptr = '\0';
3738 return strdup(out);
3739}
3740
3741/*
3742 * Look for reserved variable names and replace them with real values
3743 */
3744static char *fio_keyword_replace(char *opt)
3745{
3746 char *s;
3747 int i;
3748 int docalc = 0;
3749
3750 for (i = 0; fio_keywords[i].word != NULL; i++) {
3751 struct fio_keyword *kw = &fio_keywords[i];
3752
3753 while ((s = strstr(opt, kw->word)) != NULL) {
3754 char *new = malloc(strlen(opt) + 1);
3755 char *o_org = opt;
3756 int olen = s - opt;
3757 int len;
3758
3759 /*
3760 * Copy part of the string before the keyword and
3761 * sprintf() the replacement after it.
3762 */
3763 memcpy(new, opt, olen);
3764 len = sprintf(new + olen, "%s", kw->replace);
3765
3766 /*
3767 * If there's more in the original string, copy that
3768 * in too
3769 */
3770 opt += strlen(kw->word) + olen;
3771 if (strlen(opt))
3772 memcpy(new + olen + len, opt, opt - o_org - 1);
3773
3774 /*
3775 * replace opt and free the old opt
3776 */
3777 opt = new;
3778 free(o_org);
3779
3780 docalc = 1;
3781 }
3782 }
3783
3784 /*
3785 * Check for potential math and invoke bc, if possible
3786 */
3787 if (docalc)
3788 opt = bc_calc(opt);
3789
3790 return opt;
3791}
3792
3793static char **dup_and_sub_options(char **opts, int num_opts)
3794{
3795 int i;
3796 char **opts_copy = malloc(num_opts * sizeof(*opts));
3797 for (i = 0; i < num_opts; i++) {
3798 opts_copy[i] = option_dup_subs(opts[i]);
3799 if (!opts_copy[i])
3800 continue;
3801 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
3802 }
3803 return opts_copy;
3804}
3805
3806int fio_options_parse(struct thread_data *td, char **opts, int num_opts,
3807 int dump_cmdline)
3808{
3809 int i, ret, unknown;
3810 char **opts_copy;
3811
3812 sort_options(opts, fio_options, num_opts);
3813 opts_copy = dup_and_sub_options(opts, num_opts);
3814
3815 for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
3816 struct fio_option *o;
3817 int newret = parse_option(opts_copy[i], opts[i], fio_options,
3818 &o, td, dump_cmdline);
3819
3820 if (opts_copy[i]) {
3821 if (newret && !o) {
3822 unknown++;
3823 continue;
3824 }
3825 free(opts_copy[i]);
3826 opts_copy[i] = NULL;
3827 }
3828
3829 ret |= newret;
3830 }
3831
3832 if (unknown) {
3833 ret |= ioengine_load(td);
3834 if (td->eo) {
3835 sort_options(opts_copy, td->io_ops->options, num_opts);
3836 opts = opts_copy;
3837 }
3838 for (i = 0; i < num_opts; i++) {
3839 struct fio_option *o = NULL;
3840 int newret = 1;
3841 if (!opts_copy[i])
3842 continue;
3843
3844 if (td->eo)
3845 newret = parse_option(opts_copy[i], opts[i],
3846 td->io_ops->options, &o,
3847 td->eo, dump_cmdline);
3848
3849 ret |= newret;
3850 if (!o)
3851 log_err("Bad option <%s>\n", opts[i]);
3852
3853 free(opts_copy[i]);
3854 opts_copy[i] = NULL;
3855 }
3856 }
3857
3858 free(opts_copy);
3859 return ret;
3860}
3861
3862int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
3863{
3864 return parse_cmd_option(opt, val, fio_options, td);
3865}
3866
3867int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
3868 char *val)
3869{
3870 return parse_cmd_option(opt, val, td->io_ops->options, td->eo);
3871}
3872
3873void fio_fill_default_options(struct thread_data *td)
3874{
3875 td->o.magic = OPT_MAGIC;
3876 fill_default_options(td, fio_options);
3877}
3878
3879int fio_show_option_help(const char *opt)
3880{
3881 return show_cmd_help(fio_options, opt);
3882}
3883
3884void options_mem_dupe(void *data, struct fio_option *options)
3885{
3886 struct fio_option *o;
3887 char **ptr;
3888
3889 for (o = &options[0]; o->name; o++) {
3890 if (o->type != FIO_OPT_STR_STORE)
3891 continue;
3892
3893 ptr = td_var(data, o, o->off1);
3894 if (*ptr)
3895 *ptr = strdup(*ptr);
3896 }
3897}
3898
3899/*
3900 * dupe FIO_OPT_STR_STORE options
3901 */
3902void fio_options_mem_dupe(struct thread_data *td)
3903{
3904 options_mem_dupe(&td->o, fio_options);
3905
3906 if (td->eo && td->io_ops) {
3907 void *oldeo = td->eo;
3908
3909 td->eo = malloc(td->io_ops->option_struct_size);
3910 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
3911 options_mem_dupe(td->eo, td->io_ops->options);
3912 }
3913}
3914
3915unsigned int fio_get_kb_base(void *data)
3916{
3917 struct thread_options *o = data;
3918 unsigned int kb_base = 0;
3919
3920 /*
3921 * This is a hack... For private options, *data is not holding
3922 * a pointer to the thread_options, but to private data. This means
3923 * we can't safely dereference it, but magic is first so mem wise
3924 * it is valid. But this also means that if the job first sets
3925 * kb_base and expects that to be honored by private options,
3926 * it will be disappointed. We will return the global default
3927 * for this.
3928 */
3929 if (o && o->magic == OPT_MAGIC)
3930 kb_base = o->kb_base;
3931 if (!kb_base)
3932 kb_base = 1024;
3933
3934 return kb_base;
3935}
3936
3937int add_option(struct fio_option *o)
3938{
3939 struct fio_option *__o;
3940 int opt_index = 0;
3941
3942 __o = fio_options;
3943 while (__o->name) {
3944 opt_index++;
3945 __o++;
3946 }
3947
3948 if (opt_index + 1 == FIO_MAX_OPTS) {
3949 log_err("fio: FIO_MAX_OPTS is too small\n");
3950 return 1;
3951 }
3952
3953 memcpy(&fio_options[opt_index], o, sizeof(*o));
3954 fio_options[opt_index + 1].name = NULL;
3955 return 0;
3956}
3957
3958void invalidate_profile_options(const char *prof_name)
3959{
3960 struct fio_option *o;
3961
3962 o = fio_options;
3963 while (o->name) {
3964 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
3965 o->type = FIO_OPT_INVALID;
3966 o->prof_name = NULL;
3967 }
3968 o++;
3969 }
3970}
3971
3972void add_opt_posval(const char *optname, const char *ival, const char *help)
3973{
3974 struct fio_option *o;
3975 unsigned int i;
3976
3977 o = find_option(fio_options, optname);
3978 if (!o)
3979 return;
3980
3981 for (i = 0; i < PARSE_MAX_VP; i++) {
3982 if (o->posval[i].ival)
3983 continue;
3984
3985 o->posval[i].ival = ival;
3986 o->posval[i].help = help;
3987 break;
3988 }
3989}
3990
3991void del_opt_posval(const char *optname, const char *ival)
3992{
3993 struct fio_option *o;
3994 unsigned int i;
3995
3996 o = find_option(fio_options, optname);
3997 if (!o)
3998 return;
3999
4000 for (i = 0; i < PARSE_MAX_VP; i++) {
4001 if (!o->posval[i].ival)
4002 continue;
4003 if (strcmp(o->posval[i].ival, ival))
4004 continue;
4005
4006 o->posval[i].ival = NULL;
4007 o->posval[i].help = NULL;
4008 }
4009}
4010
4011void fio_options_free(struct thread_data *td)
4012{
4013 options_free(fio_options, td);
4014 if (td->eo && td->io_ops && td->io_ops->options) {
4015 options_free(td->io_ops->options, td->eo);
4016 free(td->eo);
4017 td->eo = NULL;
4018 }
4019}
4020
4021struct fio_option *fio_option_find(const char *name)
4022{
4023 return find_option(fio_options, name);
4024}
4025