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