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