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