__dprint() fixup
[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>
6#include <getopt.h>
7#include <assert.h>
921c766f 8#include <libgen.h>
5921e80c
JA
9#include <fcntl.h>
10#include <sys/types.h>
11#include <sys/stat.h>
214e1eca
JA
12
13#include "fio.h"
4f5af7b2 14#include "verify.h"
214e1eca 15#include "parse.h"
eef32359 16#include "lib/fls.h"
9f988e2e 17#include "options.h"
214e1eca 18
214e1eca
JA
19/*
20 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
21 */
22static char *get_opt_postfix(const char *str)
23{
24 char *p = strstr(str, ":");
25
26 if (!p)
27 return NULL;
28
29 p++;
30 strip_blank_front(&p);
31 strip_blank_end(p);
32 return strdup(p);
33}
34
0e92f873
RR
35static int converthexchartoint(char a)
36{
37 int base;
38
39 switch(a) {
40 case '0'...'9':
41 base = '0';
42 break;
43 case 'A'...'F':
44 base = 'A' - 10;
45 break;
46 case 'a'...'f':
47 base = 'a' - 10;
48 break;
49 default:
50 base = 0;
51 }
52 return (a - base);
53}
54
564ca972
JA
55static int bs_cmp(const void *p1, const void *p2)
56{
57 const struct bssplit *bsp1 = p1;
58 const struct bssplit *bsp2 = p2;
59
60 return bsp1->perc < bsp2->perc;
61}
62
720e84ad 63static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
564ca972 64{
720e84ad 65 struct bssplit *bssplit;
564ca972
JA
66 unsigned int i, perc, perc_missing;
67 unsigned int max_bs, min_bs;
68 long long val;
720e84ad 69 char *fname;
564ca972 70
720e84ad
JA
71 td->o.bssplit_nr[ddir] = 4;
72 bssplit = malloc(4 * sizeof(struct bssplit));
564ca972
JA
73
74 i = 0;
75 max_bs = 0;
76 min_bs = -1;
77 while ((fname = strsep(&str, ":")) != NULL) {
78 char *perc_str;
79
80 if (!strlen(fname))
81 break;
82
83 /*
84 * grow struct buffer, if needed
85 */
720e84ad
JA
86 if (i == td->o.bssplit_nr[ddir]) {
87 td->o.bssplit_nr[ddir] <<= 1;
88 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
5ec10eaa 89 * sizeof(struct bssplit));
564ca972
JA
90 }
91
92 perc_str = strstr(fname, "/");
93 if (perc_str) {
94 *perc_str = '\0';
95 perc_str++;
96 perc = atoi(perc_str);
97 if (perc > 100)
98 perc = 100;
99 else if (!perc)
100 perc = -1;
101 } else
102 perc = -1;
103
df9cf928 104 if (str_to_decimal(fname, &val, 1, td)) {
564ca972
JA
105 log_err("fio: bssplit conversion failed\n");
106 free(td->o.bssplit);
107 return 1;
108 }
109
110 if (val > max_bs)
111 max_bs = val;
112 if (val < min_bs)
113 min_bs = val;
114
720e84ad
JA
115 bssplit[i].bs = val;
116 bssplit[i].perc = perc;
564ca972
JA
117 i++;
118 }
119
720e84ad 120 td->o.bssplit_nr[ddir] = i;
564ca972
JA
121
122 /*
123 * Now check if the percentages add up, and how much is missing
124 */
125 perc = perc_missing = 0;
720e84ad
JA
126 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
127 struct bssplit *bsp = &bssplit[i];
564ca972
JA
128
129 if (bsp->perc == (unsigned char) -1)
130 perc_missing++;
131 else
132 perc += bsp->perc;
133 }
134
135 if (perc > 100) {
136 log_err("fio: bssplit percentages add to more than 100%%\n");
720e84ad 137 free(bssplit);
564ca972
JA
138 return 1;
139 }
140 /*
141 * If values didn't have a percentage set, divide the remains between
142 * them.
143 */
144 if (perc_missing) {
720e84ad
JA
145 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
146 struct bssplit *bsp = &bssplit[i];
564ca972
JA
147
148 if (bsp->perc == (unsigned char) -1)
149 bsp->perc = (100 - perc) / perc_missing;
150 }
151 }
152
720e84ad
JA
153 td->o.min_bs[ddir] = min_bs;
154 td->o.max_bs[ddir] = max_bs;
564ca972
JA
155
156 /*
157 * now sort based on percentages, for ease of lookup
158 */
720e84ad
JA
159 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
160 td->o.bssplit[ddir] = bssplit;
161 return 0;
162
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
fafdba3c 204 td->o.ddir_nr = 1;
182ec6ee 205 if (nr) {
211097b2 206 td->o.ddir_nr = atoi(nr);
182ec6ee
JA
207 free(nr);
208 }
211097b2 209
211097b2
JA
210 return 0;
211}
212
214e1eca
JA
213static int str_mem_cb(void *data, const char *mem)
214{
215 struct thread_data *td = data;
216
2dc1bbeb 217 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
214e1eca 218 td->mmapfile = get_opt_postfix(mem);
2dc1bbeb 219 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
214e1eca
JA
220 log_err("fio: mmaphuge:/path/to/file\n");
221 return 1;
222 }
223 }
224
225 return 0;
226}
227
228static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
229{
230 mlock_size = *val;
231 return 0;
232}
233
cb499fc4
JA
234static int str_rwmix_read_cb(void *data, unsigned int *val)
235{
236 struct thread_data *td = data;
237
238 td->o.rwmix[DDIR_READ] = *val;
239 td->o.rwmix[DDIR_WRITE] = 100 - *val;
240 return 0;
241}
242
243static int str_rwmix_write_cb(void *data, unsigned int *val)
244{
245 struct thread_data *td = data;
246
247 td->o.rwmix[DDIR_WRITE] = *val;
248 td->o.rwmix[DDIR_READ] = 100 - *val;
249 return 0;
250}
251
214e1eca
JA
252#ifdef FIO_HAVE_IOPRIO
253static int str_prioclass_cb(void *data, unsigned int *val)
254{
255 struct thread_data *td = data;
6cefbe33
JA
256 unsigned short mask;
257
258 /*
259 * mask off old class bits, str_prio_cb() may have set a default class
260 */
261 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
262 td->ioprio &= mask;
214e1eca
JA
263
264 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
ac684785 265 td->ioprio_set = 1;
214e1eca
JA
266 return 0;
267}
268
269static int str_prio_cb(void *data, unsigned int *val)
270{
271 struct thread_data *td = data;
272
273 td->ioprio |= *val;
6cefbe33
JA
274
275 /*
276 * If no class is set, assume BE
277 */
278 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
279 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
280
ac684785 281 td->ioprio_set = 1;
214e1eca
JA
282 return 0;
283}
284#endif
285
286static int str_exitall_cb(void)
287{
288 exitall_on_terminate = 1;
289 return 0;
290}
291
214e1eca 292#ifdef FIO_HAVE_CPU_AFFINITY
d2e268b0
JA
293static int str_cpumask_cb(void *data, unsigned int *val)
294{
295 struct thread_data *td = data;
214e1eca 296 unsigned int i;
b03daafb 297 long max_cpu;
d2ce18b5
JA
298 int ret;
299
300 ret = fio_cpuset_init(&td->o.cpumask);
301 if (ret < 0) {
302 log_err("fio: cpuset_init failed\n");
303 td_verror(td, ret, "fio_cpuset_init");
304 return 1;
305 }
214e1eca 306
b03daafb 307 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
214e1eca 308
62a7273d
JA
309 for (i = 0; i < sizeof(int) * 8; i++) {
310 if ((1 << i) & *val) {
b03daafb
JA
311 if (i > max_cpu) {
312 log_err("fio: CPU %d too large (max=%ld)\n", i,
313 max_cpu);
314 return 1;
315 }
62a7273d 316 dprint(FD_PARSE, "set cpu allowed %d\n", i);
6d459ee7 317 fio_cpu_set(&td->o.cpumask, i);
62a7273d
JA
318 }
319 }
d2e268b0
JA
320
321 td->o.cpumask_set = 1;
322 return 0;
214e1eca
JA
323}
324
e8462bd8
JA
325static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
326 const char *input)
214e1eca 327{
d2e268b0 328 char *cpu, *str, *p;
b03daafb 329 long max_cpu;
19608d6c 330 int ret = 0;
d2e268b0 331
e8462bd8 332 ret = fio_cpuset_init(mask);
d2ce18b5
JA
333 if (ret < 0) {
334 log_err("fio: cpuset_init failed\n");
335 td_verror(td, ret, "fio_cpuset_init");
336 return 1;
337 }
d2e268b0
JA
338
339 p = str = strdup(input);
214e1eca 340
d2e268b0
JA
341 strip_blank_front(&str);
342 strip_blank_end(str);
343
b03daafb
JA
344 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
345
d2e268b0 346 while ((cpu = strsep(&str, ",")) != NULL) {
62a7273d
JA
347 char *str2, *cpu2;
348 int icpu, icpu2;
349
d2e268b0
JA
350 if (!strlen(cpu))
351 break;
62a7273d
JA
352
353 str2 = cpu;
354 icpu2 = -1;
355 while ((cpu2 = strsep(&str2, "-")) != NULL) {
356 if (!strlen(cpu2))
357 break;
358
359 icpu2 = atoi(cpu2);
360 }
361
362 icpu = atoi(cpu);
363 if (icpu2 == -1)
364 icpu2 = icpu;
365 while (icpu <= icpu2) {
6d459ee7 366 if (icpu >= FIO_MAX_CPUS) {
19608d6c 367 log_err("fio: your OS only supports up to"
6d459ee7 368 " %d CPUs\n", (int) FIO_MAX_CPUS);
19608d6c
JA
369 ret = 1;
370 break;
371 }
b03daafb
JA
372 if (icpu > max_cpu) {
373 log_err("fio: CPU %d too large (max=%ld)\n",
374 icpu, max_cpu);
375 ret = 1;
376 break;
377 }
0b9d69ec 378
62a7273d 379 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
e8462bd8 380 fio_cpu_set(mask, icpu);
62a7273d
JA
381 icpu++;
382 }
19608d6c
JA
383 if (ret)
384 break;
d2e268b0
JA
385 }
386
387 free(p);
19608d6c
JA
388 if (!ret)
389 td->o.cpumask_set = 1;
390 return ret;
214e1eca 391}
e8462bd8
JA
392
393static int str_cpus_allowed_cb(void *data, const char *input)
394{
395 struct thread_data *td = data;
396 int ret;
397
398 ret = set_cpus_allowed(td, &td->o.cpumask, input);
399 if (!ret)
400 td->o.cpumask_set = 1;
401
402 return ret;
403}
404
405static int str_verify_cpus_allowed_cb(void *data, const char *input)
406{
407 struct thread_data *td = data;
408 int ret;
409
410 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
411 if (!ret)
412 td->o.verify_cpumask_set = 1;
413
414 return ret;
415}
d2e268b0 416#endif
214e1eca
JA
417
418static int str_fst_cb(void *data, const char *str)
419{
420 struct thread_data *td = data;
421 char *nr = get_opt_postfix(str);
422
423 td->file_service_nr = 1;
182ec6ee 424 if (nr) {
214e1eca 425 td->file_service_nr = atoi(nr);
182ec6ee
JA
426 free(nr);
427 }
214e1eca
JA
428
429 return 0;
430}
431
44f29692
JA
432static int str_sfr_cb(void *data, const char *str)
433{
434 struct thread_data *td = data;
435 char *nr = get_opt_postfix(str);
436
437 td->sync_file_range_nr = 1;
438 if (nr) {
439 td->sync_file_range_nr = atoi(nr);
440 free(nr);
441 }
442
443 return 0;
444}
445
921c766f
JA
446static int check_dir(struct thread_data *td, char *fname)
447{
448 char file[PATH_MAX], *dir;
bc838919 449 int elen = 0;
921c766f 450
bc838919
JA
451 if (td->o.directory) {
452 strcpy(file, td->o.directory);
fcef0b35 453 strcat(file, "/");
bc838919
JA
454 elen = strlen(file);
455 }
456
fcef0b35 457 sprintf(file + elen, "%s", fname);
921c766f
JA
458 dir = dirname(file);
459
fcef0b35
JA
460#if 0
461 {
462 struct stat sb;
463 /*
464 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
465 * yet, so we can't do this check right here...
466 */
921c766f
JA
467 if (lstat(dir, &sb) < 0) {
468 int ret = errno;
469
470 log_err("fio: %s is not a directory\n", dir);
471 td_verror(td, ret, "lstat");
472 return 1;
473 }
474
475 if (!S_ISDIR(sb.st_mode)) {
476 log_err("fio: %s is not a directory\n", dir);
477 return 1;
478 }
fcef0b35
JA
479 }
480#endif
921c766f
JA
481
482 return 0;
483}
484
8e827d35
JA
485/*
486 * Return next file in the string. Files are separated with ':'. If the ':'
487 * is escaped with a '\', then that ':' is part of the filename and does not
488 * indicate a new file.
489 */
490static char *get_next_file_name(char **ptr)
491{
492 char *str = *ptr;
493 char *p, *start;
494
495 if (!str || !strlen(str))
496 return NULL;
497
498 start = str;
499 do {
500 /*
501 * No colon, we are done
502 */
503 p = strchr(str, ':');
504 if (!p) {
505 *ptr = NULL;
506 break;
507 }
508
509 /*
510 * We got a colon, but it's the first character. Skip and
511 * continue
512 */
513 if (p == start) {
514 str = ++start;
515 continue;
516 }
517
518 if (*(p - 1) != '\\') {
519 *p = '\0';
520 *ptr = p + 1;
521 break;
522 }
523
524 memmove(p - 1, p, strlen(p) + 1);
525 str = p;
526 } while (1);
527
528 return start;
529}
530
214e1eca
JA
531static int str_filename_cb(void *data, const char *input)
532{
533 struct thread_data *td = data;
534 char *fname, *str, *p;
535
536 p = str = strdup(input);
537
538 strip_blank_front(&str);
539 strip_blank_end(str);
540
541 if (!td->files_index)
2dc1bbeb 542 td->o.nr_files = 0;
214e1eca 543
8e827d35 544 while ((fname = get_next_file_name(&str)) != NULL) {
214e1eca
JA
545 if (!strlen(fname))
546 break;
921c766f
JA
547 if (check_dir(td, fname)) {
548 free(p);
549 return 1;
550 }
214e1eca 551 add_file(td, fname);
2dc1bbeb 552 td->o.nr_files++;
214e1eca
JA
553 }
554
555 free(p);
556 return 0;
557}
558
559static int str_directory_cb(void *data, const char fio_unused *str)
560{
561 struct thread_data *td = data;
562 struct stat sb;
563
2dc1bbeb 564 if (lstat(td->o.directory, &sb) < 0) {
921c766f
JA
565 int ret = errno;
566
2dc1bbeb 567 log_err("fio: %s is not a directory\n", td->o.directory);
921c766f 568 td_verror(td, ret, "lstat");
214e1eca
JA
569 return 1;
570 }
571 if (!S_ISDIR(sb.st_mode)) {
2dc1bbeb 572 log_err("fio: %s is not a directory\n", td->o.directory);
214e1eca
JA
573 return 1;
574 }
575
576 return 0;
577}
578
579static int str_opendir_cb(void *data, const char fio_unused *str)
580{
581 struct thread_data *td = data;
582
583 if (!td->files_index)
2dc1bbeb 584 td->o.nr_files = 0;
214e1eca 585
2dc1bbeb 586 return add_dir_files(td, td->o.opendir);
214e1eca
JA
587}
588
a59e170d 589static int str_verify_offset_cb(void *data, unsigned int *off)
546a9142
SL
590{
591 struct thread_data *td = data;
a59e170d 592
546a9142 593 if (*off && *off < sizeof(struct verify_header)) {
a59e170d 594 log_err("fio: verify_offset too small\n");
546a9142
SL
595 return 1;
596 }
a59e170d
JA
597
598 td->o.verify_offset = *off;
546a9142
SL
599 return 0;
600}
601
0e92f873 602static int str_verify_pattern_cb(void *data, const char *input)
90059d65
JA
603{
604 struct thread_data *td = data;
0e92f873
RR
605 long off;
606 int i = 0, j = 0, len, k, base = 10;
607 char* loc1, * loc2;
608
609 loc1 = strstr(input, "0x");
610 loc2 = strstr(input, "0X");
611 if (loc1 || loc2)
612 base = 16;
613 off = strtol(input, NULL, base);
614 if (off != LONG_MAX || errno != ERANGE) {
615 while (off) {
616 td->o.verify_pattern[i] = off & 0xff;
617 off >>= 8;
618 i++;
619 }
620 } else {
621 len = strlen(input);
622 k = len - 1;
623 if (base == 16) {
624 if (loc1)
625 j = loc1 - input + 2;
626 else
627 j = loc2 - input + 2;
628 } else
629 return 1;
630 if (len - j < MAX_PATTERN_SIZE * 2) {
631 while (k >= j) {
632 off = converthexchartoint(input[k--]);
633 if (k >= j)
634 off += (converthexchartoint(input[k--])
635 * 16);
636 td->o.verify_pattern[i++] = (char) off;
637 }
638 }
639 }
640 td->o.verify_pattern_bytes = i;
90059d65
JA
641 return 0;
642}
214e1eca 643
4d4e80f2
JA
644static int str_lockfile_cb(void *data, const char *str)
645{
646 struct thread_data *td = data;
647 char *nr = get_opt_postfix(str);
648
649 td->o.lockfile_batch = 1;
182ec6ee 650 if (nr) {
4d4e80f2 651 td->o.lockfile_batch = atoi(nr);
182ec6ee
JA
652 free(nr);
653 }
4d4e80f2
JA
654
655 return 0;
656}
657
e3cedca7
JA
658static int str_write_bw_log_cb(void *data, const char *str)
659{
660 struct thread_data *td = data;
661
662 if (str)
663 td->o.bw_log_file = strdup(str);
664
665 td->o.write_bw_log = 1;
666 return 0;
667}
668
669static int str_write_lat_log_cb(void *data, const char *str)
670{
671 struct thread_data *td = data;
672
673 if (str)
674 td->o.lat_log_file = strdup(str);
675
676 td->o.write_lat_log = 1;
677 return 0;
678}
679
993bf48b
JA
680static int str_gtod_reduce_cb(void *data, int *il)
681{
682 struct thread_data *td = data;
683 int val = *il;
684
685 td->o.disable_clat = !!val;
686 td->o.disable_slat = !!val;
687 td->o.disable_bw = !!val;
688 if (val)
689 td->tv_cache_mask = 63;
690
691 return 0;
692}
693
be4ecfdf
JA
694static int str_gtod_cpu_cb(void *data, int *il)
695{
696 struct thread_data *td = data;
697 int val = *il;
698
699 td->o.gtod_cpu = val;
700 td->o.gtod_offload = 1;
701 return 0;
702}
703
896cac2a
JA
704static int rw_verify(struct fio_option *o, void *data)
705{
706 struct thread_data *td = data;
707
708 if (read_only && td_write(td)) {
709 log_err("fio: job <%s> has write bit set, but fio is in"
710 " read-only mode\n", td->o.name);
711 return 1;
712 }
713
714 return 0;
715}
716
276ca4f7 717static int gtod_cpu_verify(struct fio_option *o, void *data)
29d43ff9 718{
276ca4f7 719#ifndef FIO_HAVE_CPU_AFFINITY
29d43ff9
JA
720 struct thread_data *td = data;
721
29d43ff9
JA
722 if (td->o.gtod_cpu) {
723 log_err("fio: platform must support CPU affinity for"
724 "gettimeofday() offloading\n");
725 return 1;
726 }
727#endif
728
729 return 0;
730}
731
90fef2d1
JA
732static int kb_base_verify(struct fio_option *o, void *data)
733{
734 struct thread_data *td = data;
735
736 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
737 log_err("fio: kb_base set to nonsensical value: %u\n",
738 td->o.kb_base);
739 return 1;
740 }
741
742 return 0;
743}
744
214e1eca
JA
745#define __stringify_1(x) #x
746#define __stringify(x) __stringify_1(x)
747
748/*
749 * Map of job/command line options
750 */
07b3232d 751static struct fio_option options[FIO_MAX_OPTS] = {
214e1eca
JA
752 {
753 .name = "description",
754 .type = FIO_OPT_STR_STORE,
755 .off1 = td_var_offset(description),
756 .help = "Text job description",
757 },
758 {
759 .name = "name",
760 .type = FIO_OPT_STR_STORE,
761 .off1 = td_var_offset(name),
762 .help = "Name of this job",
763 },
764 {
765 .name = "directory",
766 .type = FIO_OPT_STR_STORE,
767 .off1 = td_var_offset(directory),
768 .cb = str_directory_cb,
769 .help = "Directory to store files in",
770 },
771 {
772 .name = "filename",
773 .type = FIO_OPT_STR_STORE,
774 .off1 = td_var_offset(filename),
775 .cb = str_filename_cb,
f0d524b0 776 .prio = -1, /* must come after "directory" */
214e1eca
JA
777 .help = "File(s) to use for the workload",
778 },
90fef2d1
JA
779 {
780 .name = "kb_base",
781 .type = FIO_OPT_INT,
782 .off1 = td_var_offset(kb_base),
90fef2d1 783 .verify = kb_base_verify,
a639f0bb 784 .prio = 1,
90fef2d1 785 .def = "1024",
a639f0bb 786 .help = "How many bytes per KB for reporting (1000 or 1024)",
90fef2d1 787 },
29c1349f
JA
788 {
789 .name = "lockfile",
4d4e80f2
JA
790 .type = FIO_OPT_STR,
791 .cb = str_lockfile_cb,
792 .off1 = td_var_offset(file_lock_mode),
29c1349f
JA
793 .help = "Lock file when doing IO to it",
794 .parent = "filename",
4d4e80f2
JA
795 .def = "none",
796 .posval = {
797 { .ival = "none",
798 .oval = FILE_LOCK_NONE,
799 .help = "No file locking",
800 },
801 { .ival = "exclusive",
802 .oval = FILE_LOCK_EXCLUSIVE,
803 .help = "Exclusive file lock",
804 },
805 {
806 .ival = "readwrite",
807 .oval = FILE_LOCK_READWRITE,
808 .help = "Read vs write lock",
809 },
810 },
29c1349f 811 },
214e1eca
JA
812 {
813 .name = "opendir",
814 .type = FIO_OPT_STR_STORE,
815 .off1 = td_var_offset(opendir),
816 .cb = str_opendir_cb,
817 .help = "Recursively add files from this directory and down",
818 },
819 {
820 .name = "rw",
d3aad8f2 821 .alias = "readwrite",
214e1eca 822 .type = FIO_OPT_STR,
211097b2 823 .cb = str_rw_cb,
214e1eca
JA
824 .off1 = td_var_offset(td_ddir),
825 .help = "IO direction",
826 .def = "read",
896cac2a 827 .verify = rw_verify,
214e1eca
JA
828 .posval = {
829 { .ival = "read",
830 .oval = TD_DDIR_READ,
831 .help = "Sequential read",
832 },
833 { .ival = "write",
834 .oval = TD_DDIR_WRITE,
835 .help = "Sequential write",
836 },
837 { .ival = "randread",
838 .oval = TD_DDIR_RANDREAD,
839 .help = "Random read",
840 },
841 { .ival = "randwrite",
842 .oval = TD_DDIR_RANDWRITE,
843 .help = "Random write",
844 },
845 { .ival = "rw",
846 .oval = TD_DDIR_RW,
847 .help = "Sequential read and write mix",
848 },
849 { .ival = "randrw",
850 .oval = TD_DDIR_RANDRW,
851 .help = "Random read and write mix"
852 },
853 },
854 },
855 {
856 .name = "ioengine",
857 .type = FIO_OPT_STR_STORE,
858 .off1 = td_var_offset(ioengine),
859 .help = "IO engine to use",
860 .def = "sync",
861 .posval = {
862 { .ival = "sync",
863 .help = "Use read/write",
864 },
a31041ea 865 { .ival = "psync",
866 .help = "Use pread/pwrite",
867 },
1d2af02a
JA
868 { .ival = "vsync",
869 .help = "Use readv/writev",
870 },
214e1eca
JA
871#ifdef FIO_HAVE_LIBAIO
872 { .ival = "libaio",
873 .help = "Linux native asynchronous IO",
874 },
875#endif
876#ifdef FIO_HAVE_POSIXAIO
877 { .ival = "posixaio",
878 .help = "POSIX asynchronous IO",
879 },
417f0068
JA
880#endif
881#ifdef FIO_HAVE_SOLARISAIO
882 { .ival = "solarisaio",
883 .help = "Solaris native asynchronous IO",
884 },
214e1eca
JA
885#endif
886 { .ival = "mmap",
887 .help = "Memory mapped IO",
888 },
889#ifdef FIO_HAVE_SPLICE
890 { .ival = "splice",
891 .help = "splice/vmsplice based IO",
892 },
9cce02e8
JA
893 { .ival = "netsplice",
894 .help = "splice/vmsplice to/from the network",
895 },
214e1eca
JA
896#endif
897#ifdef FIO_HAVE_SGIO
898 { .ival = "sg",
899 .help = "SCSI generic v3 IO",
900 },
901#endif
902 { .ival = "null",
903 .help = "Testing engine (no data transfer)",
904 },
905 { .ival = "net",
906 .help = "Network IO",
907 },
908#ifdef FIO_HAVE_SYSLET
909 { .ival = "syslet-rw",
910 .help = "syslet enabled async pread/pwrite IO",
911 },
912#endif
913 { .ival = "cpuio",
914 .help = "CPU cycler burner engine",
915 },
b8c82a46
JA
916#ifdef FIO_HAVE_GUASI
917 { .ival = "guasi",
918 .help = "GUASI IO engine",
919 },
920#endif
214e1eca
JA
921 { .ival = "external",
922 .help = "Load external engine (append name)",
923 },
924 },
925 },
926 {
927 .name = "iodepth",
928 .type = FIO_OPT_INT,
929 .off1 = td_var_offset(iodepth),
930 .help = "Amount of IO buffers to keep in flight",
757aff4f 931 .minval = 1,
214e1eca
JA
932 .def = "1",
933 },
934 {
935 .name = "iodepth_batch",
4950421a 936 .alias = "iodepth_batch_submit",
214e1eca
JA
937 .type = FIO_OPT_INT,
938 .off1 = td_var_offset(iodepth_batch),
d65db441 939 .help = "Number of IO buffers to submit in one go",
afdf9352 940 .parent = "iodepth",
a2e6f8ac
JA
941 .minval = 1,
942 .def = "1",
4950421a
JA
943 },
944 {
945 .name = "iodepth_batch_complete",
946 .type = FIO_OPT_INT,
947 .off1 = td_var_offset(iodepth_batch_complete),
d65db441 948 .help = "Number of IO buffers to retrieve in one go",
4950421a
JA
949 .parent = "iodepth",
950 .minval = 0,
951 .def = "1",
214e1eca
JA
952 },
953 {
954 .name = "iodepth_low",
955 .type = FIO_OPT_INT,
956 .off1 = td_var_offset(iodepth_low),
957 .help = "Low water mark for queuing depth",
afdf9352 958 .parent = "iodepth",
214e1eca
JA
959 },
960 {
961 .name = "size",
962 .type = FIO_OPT_STR_VAL,
2dc1bbeb 963 .off1 = td_var_offset(size),
c3edbdba 964 .minval = 1,
214e1eca
JA
965 .help = "Total size of device or files",
966 },
aa31f1f1
SL
967 {
968 .name = "fill_device",
969 .type = FIO_OPT_BOOL,
970 .off1 = td_var_offset(fill_device),
971 .help = "Write until an ENOSPC error occurs",
972 .def = "0",
973 },
214e1eca
JA
974 {
975 .name = "filesize",
976 .type = FIO_OPT_STR_VAL,
977 .off1 = td_var_offset(file_size_low),
978 .off2 = td_var_offset(file_size_high),
c3edbdba 979 .minval = 1,
214e1eca
JA
980 .help = "Size of individual files",
981 },
67a1000f
JA
982 {
983 .name = "offset",
984 .alias = "fileoffset",
985 .type = FIO_OPT_STR_VAL,
986 .off1 = td_var_offset(start_offset),
987 .help = "Start IO from this offset",
988 .def = "0",
989 },
214e1eca
JA
990 {
991 .name = "bs",
d3aad8f2 992 .alias = "blocksize",
e01b22b8 993 .type = FIO_OPT_INT,
214e1eca
JA
994 .off1 = td_var_offset(bs[DDIR_READ]),
995 .off2 = td_var_offset(bs[DDIR_WRITE]),
c3edbdba 996 .minval = 1,
214e1eca
JA
997 .help = "Block size unit",
998 .def = "4k",
67a1000f 999 .parent = "rw",
214e1eca 1000 },
2b7a01d0
JA
1001 {
1002 .name = "ba",
1003 .alias = "blockalign",
e01b22b8 1004 .type = FIO_OPT_INT,
2b7a01d0
JA
1005 .off1 = td_var_offset(ba[DDIR_READ]),
1006 .off2 = td_var_offset(ba[DDIR_WRITE]),
1007 .minval = 1,
1008 .help = "IO block offset alignment",
1009 .parent = "rw",
1010 },
214e1eca
JA
1011 {
1012 .name = "bsrange",
d3aad8f2 1013 .alias = "blocksize_range",
214e1eca
JA
1014 .type = FIO_OPT_RANGE,
1015 .off1 = td_var_offset(min_bs[DDIR_READ]),
1016 .off2 = td_var_offset(max_bs[DDIR_READ]),
1017 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1018 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
c3edbdba 1019 .minval = 1,
214e1eca 1020 .help = "Set block size range (in more detail than bs)",
67a1000f 1021 .parent = "rw",
214e1eca 1022 },
564ca972
JA
1023 {
1024 .name = "bssplit",
1025 .type = FIO_OPT_STR,
1026 .cb = str_bssplit_cb,
1027 .help = "Set a specific mix of block sizes",
1028 .parent = "rw",
1029 },
214e1eca
JA
1030 {
1031 .name = "bs_unaligned",
d3aad8f2 1032 .alias = "blocksize_unaligned",
214e1eca
JA
1033 .type = FIO_OPT_STR_SET,
1034 .off1 = td_var_offset(bs_unaligned),
1035 .help = "Don't sector align IO buffer sizes",
67a1000f 1036 .parent = "rw",
214e1eca
JA
1037 },
1038 {
1039 .name = "randrepeat",
1040 .type = FIO_OPT_BOOL,
1041 .off1 = td_var_offset(rand_repeatable),
1042 .help = "Use repeatable random IO pattern",
1043 .def = "1",
67a1000f 1044 .parent = "rw",
214e1eca
JA
1045 },
1046 {
1047 .name = "norandommap",
1048 .type = FIO_OPT_STR_SET,
1049 .off1 = td_var_offset(norandommap),
1050 .help = "Accept potential duplicate random blocks",
67a1000f 1051 .parent = "rw",
214e1eca 1052 },
2b386d25
JA
1053 {
1054 .name = "softrandommap",
1055 .type = FIO_OPT_BOOL,
1056 .off1 = td_var_offset(softrandommap),
f66ab3c8 1057 .help = "Set norandommap if randommap allocation fails",
2b386d25
JA
1058 .parent = "norandommap",
1059 .def = "0",
1060 },
214e1eca
JA
1061 {
1062 .name = "nrfiles",
1063 .type = FIO_OPT_INT,
1064 .off1 = td_var_offset(nr_files),
1065 .help = "Split job workload between this number of files",
1066 .def = "1",
1067 },
1068 {
1069 .name = "openfiles",
1070 .type = FIO_OPT_INT,
1071 .off1 = td_var_offset(open_files),
1072 .help = "Number of files to keep open at the same time",
1073 },
1074 {
1075 .name = "file_service_type",
1076 .type = FIO_OPT_STR,
1077 .cb = str_fst_cb,
1078 .off1 = td_var_offset(file_service_type),
1079 .help = "How to select which file to service next",
1080 .def = "roundrobin",
1081 .posval = {
1082 { .ival = "random",
1083 .oval = FIO_FSERVICE_RANDOM,
1084 .help = "Choose a file at random",
1085 },
1086 { .ival = "roundrobin",
1087 .oval = FIO_FSERVICE_RR,
1088 .help = "Round robin select files",
1089 },
a086c257
JA
1090 { .ival = "sequential",
1091 .oval = FIO_FSERVICE_SEQ,
1092 .help = "Finish one file before moving to the next",
1093 },
214e1eca 1094 },
67a1000f
JA
1095 .parent = "nrfiles",
1096 },
7bc8c2cf
JA
1097#ifdef FIO_HAVE_FALLOCATE
1098 {
1099 .name = "fallocate",
1100 .type = FIO_OPT_BOOL,
1101 .off1 = td_var_offset(fallocate),
1102 .help = "Use fallocate() when laying out files",
1103 .def = "1",
1104 },
1105#endif
67a1000f
JA
1106 {
1107 .name = "fadvise_hint",
1108 .type = FIO_OPT_BOOL,
1109 .off1 = td_var_offset(fadvise_hint),
1110 .help = "Use fadvise() to advise the kernel on IO pattern",
1111 .def = "1",
214e1eca
JA
1112 },
1113 {
1114 .name = "fsync",
1115 .type = FIO_OPT_INT,
1116 .off1 = td_var_offset(fsync_blocks),
1117 .help = "Issue fsync for writes every given number of blocks",
1118 .def = "0",
1119 },
5f9099ea
JA
1120 {
1121 .name = "fdatasync",
1122 .type = FIO_OPT_INT,
1123 .off1 = td_var_offset(fdatasync_blocks),
1124 .help = "Issue fdatasync for writes every given number of blocks",
1125 .def = "0",
1126 },
44f29692
JA
1127#ifdef FIO_HAVE_SYNC_FILE_RANGE
1128 {
1129 .name = "sync_file_range",
1130 .posval = {
1131 { .ival = "wait_before",
1132 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1133 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
3843deb3 1134 .or = 1,
44f29692
JA
1135 },
1136 { .ival = "write",
1137 .oval = SYNC_FILE_RANGE_WRITE,
1138 .help = "SYNC_FILE_RANGE_WRITE",
3843deb3 1139 .or = 1,
44f29692
JA
1140 },
1141 {
1142 .ival = "wait_after",
1143 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1144 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
3843deb3 1145 .or = 1,
44f29692
JA
1146 },
1147 },
3843deb3 1148 .type = FIO_OPT_STR_MULTI,
44f29692
JA
1149 .cb = str_sfr_cb,
1150 .off1 = td_var_offset(sync_file_range),
1151 .help = "Use sync_file_range()",
1152 },
1153#endif
214e1eca
JA
1154 {
1155 .name = "direct",
1156 .type = FIO_OPT_BOOL,
1157 .off1 = td_var_offset(odirect),
1158 .help = "Use O_DIRECT IO (negates buffered)",
1159 .def = "0",
1160 },
1161 {
1162 .name = "buffered",
1163 .type = FIO_OPT_BOOL,
1164 .off1 = td_var_offset(odirect),
1165 .neg = 1,
1166 .help = "Use buffered IO (negates direct)",
1167 .def = "1",
1168 },
1169 {
1170 .name = "overwrite",
1171 .type = FIO_OPT_BOOL,
1172 .off1 = td_var_offset(overwrite),
1173 .help = "When writing, set whether to overwrite current data",
1174 .def = "0",
1175 },
1176 {
1177 .name = "loops",
1178 .type = FIO_OPT_INT,
1179 .off1 = td_var_offset(loops),
1180 .help = "Number of times to run the job",
1181 .def = "1",
1182 },
1183 {
1184 .name = "numjobs",
1185 .type = FIO_OPT_INT,
1186 .off1 = td_var_offset(numjobs),
1187 .help = "Duplicate this job this many times",
1188 .def = "1",
1189 },
1190 {
1191 .name = "startdelay",
1192 .type = FIO_OPT_INT,
1193 .off1 = td_var_offset(start_delay),
1194 .help = "Only start job when this period has passed",
1195 .def = "0",
1196 },
1197 {
1198 .name = "runtime",
1199 .alias = "timeout",
1200 .type = FIO_OPT_STR_VAL_TIME,
1201 .off1 = td_var_offset(timeout),
1202 .help = "Stop workload when this amount of time has passed",
1203 .def = "0",
1204 },
cf4464ca
JA
1205 {
1206 .name = "time_based",
1207 .type = FIO_OPT_STR_SET,
1208 .off1 = td_var_offset(time_based),
1209 .help = "Keep running until runtime/timeout is met",
1210 },
721938ae
JA
1211 {
1212 .name = "ramp_time",
1213 .type = FIO_OPT_STR_VAL_TIME,
1214 .off1 = td_var_offset(ramp_time),
1215 .help = "Ramp up time before measuring performance",
1216 },
214e1eca
JA
1217 {
1218 .name = "mem",
d3aad8f2 1219 .alias = "iomem",
214e1eca
JA
1220 .type = FIO_OPT_STR,
1221 .cb = str_mem_cb,
1222 .off1 = td_var_offset(mem_type),
1223 .help = "Backing type for IO buffers",
1224 .def = "malloc",
1225 .posval = {
1226 { .ival = "malloc",
1227 .oval = MEM_MALLOC,
1228 .help = "Use malloc(3) for IO buffers",
1229 },
37c8cdfe
JA
1230 { .ival = "shm",
1231 .oval = MEM_SHM,
1232 .help = "Use shared memory segments for IO buffers",
1233 },
214e1eca
JA
1234#ifdef FIO_HAVE_HUGETLB
1235 { .ival = "shmhuge",
1236 .oval = MEM_SHMHUGE,
1237 .help = "Like shm, but use huge pages",
1238 },
b370e46a 1239#endif
37c8cdfe
JA
1240 { .ival = "mmap",
1241 .oval = MEM_MMAP,
1242 .help = "Use mmap(2) (file or anon) for IO buffers",
1243 },
214e1eca
JA
1244#ifdef FIO_HAVE_HUGETLB
1245 { .ival = "mmaphuge",
1246 .oval = MEM_MMAPHUGE,
1247 .help = "Like mmap, but use huge pages",
1248 },
1249#endif
1250 },
1251 },
d529ee19
JA
1252 {
1253 .name = "iomem_align",
1254 .alias = "mem_align",
1255 .type = FIO_OPT_INT,
1256 .off1 = td_var_offset(mem_align),
1257 .minval = 0,
1258 .help = "IO memory buffer offset alignment",
1259 .def = "0",
1260 .parent = "iomem",
1261 },
214e1eca
JA
1262 {
1263 .name = "verify",
1264 .type = FIO_OPT_STR,
1265 .off1 = td_var_offset(verify),
1266 .help = "Verify data written",
1267 .def = "0",
1268 .posval = {
1269 { .ival = "0",
1270 .oval = VERIFY_NONE,
1271 .help = "Don't do IO verification",
1272 },
fcca4b58
JA
1273 { .ival = "md5",
1274 .oval = VERIFY_MD5,
1275 .help = "Use md5 checksums for verification",
1276 },
d77a7af3
JA
1277 { .ival = "crc64",
1278 .oval = VERIFY_CRC64,
1279 .help = "Use crc64 checksums for verification",
1280 },
214e1eca
JA
1281 { .ival = "crc32",
1282 .oval = VERIFY_CRC32,
1283 .help = "Use crc32 checksums for verification",
1284 },
af497e6a
JA
1285 { .ival = "crc32c-intel",
1286 .oval = VERIFY_CRC32C_INTEL,
1287 .help = "Use hw crc32c checksums for verification",
1288 },
bac39e0e
JA
1289 { .ival = "crc32c",
1290 .oval = VERIFY_CRC32C,
1291 .help = "Use crc32c checksums for verification",
1292 },
969f7ed3
JA
1293 { .ival = "crc16",
1294 .oval = VERIFY_CRC16,
1295 .help = "Use crc16 checksums for verification",
1296 },
1e154bdb
JA
1297 { .ival = "crc7",
1298 .oval = VERIFY_CRC7,
1299 .help = "Use crc7 checksums for verification",
1300 },
7c353ceb
JA
1301 { .ival = "sha1",
1302 .oval = VERIFY_SHA1,
1303 .help = "Use sha1 checksums for verification",
1304 },
cd14cc10
JA
1305 { .ival = "sha256",
1306 .oval = VERIFY_SHA256,
1307 .help = "Use sha256 checksums for verification",
1308 },
1309 { .ival = "sha512",
1310 .oval = VERIFY_SHA512,
1311 .help = "Use sha512 checksums for verification",
1312 },
7437ee87
SL
1313 { .ival = "meta",
1314 .oval = VERIFY_META,
1315 .help = "Use io information",
1316 },
36690c9b
JA
1317 {
1318 .ival = "null",
1319 .oval = VERIFY_NULL,
1320 .help = "Pretend to verify",
1321 },
214e1eca
JA
1322 },
1323 },
005c565a
JA
1324 {
1325 .name = "do_verify",
68e1f29a 1326 .type = FIO_OPT_BOOL,
005c565a
JA
1327 .off1 = td_var_offset(do_verify),
1328 .help = "Run verification stage after write",
1329 .def = "1",
1330 .parent = "verify",
1331 },
160b966d
JA
1332 {
1333 .name = "verifysort",
1334 .type = FIO_OPT_BOOL,
1335 .off1 = td_var_offset(verifysort),
1336 .help = "Sort written verify blocks for read back",
1337 .def = "1",
c83f2df1 1338 .parent = "verify",
160b966d 1339 },
3f9f4e26 1340 {
a59e170d 1341 .name = "verify_interval",
e01b22b8 1342 .type = FIO_OPT_INT,
a59e170d 1343 .off1 = td_var_offset(verify_interval),
819a9680 1344 .minval = 2 * sizeof(struct verify_header),
a59e170d 1345 .help = "Store verify buffer header every N bytes",
afdf9352 1346 .parent = "verify",
3f9f4e26 1347 },
546a9142 1348 {
a59e170d 1349 .name = "verify_offset",
e01b22b8 1350 .type = FIO_OPT_INT,
a59e170d 1351 .help = "Offset verify header location by N bytes",
546a9142 1352 .def = "0",
5ec10eaa 1353 .cb = str_verify_offset_cb,
afdf9352 1354 .parent = "verify",
546a9142 1355 },
e28218f3
SL
1356 {
1357 .name = "verify_pattern",
0e92f873 1358 .type = FIO_OPT_STR,
e28218f3
SL
1359 .cb = str_verify_pattern_cb,
1360 .help = "Fill pattern for IO buffers",
1361 .parent = "verify",
1362 },
a12a3b4d
JA
1363 {
1364 .name = "verify_fatal",
68e1f29a 1365 .type = FIO_OPT_BOOL,
a12a3b4d
JA
1366 .off1 = td_var_offset(verify_fatal),
1367 .def = "0",
1368 .help = "Exit on a single verify failure, don't continue",
1369 .parent = "verify",
1370 },
e8462bd8
JA
1371 {
1372 .name = "verify_async",
1373 .type = FIO_OPT_INT,
1374 .off1 = td_var_offset(verify_async),
1375 .def = "0",
1376 .help = "Number of async verifier threads to use",
1377 .parent = "verify",
1378 },
1379#ifdef FIO_HAVE_CPU_AFFINITY
1380 {
1381 .name = "verify_async_cpus",
1382 .type = FIO_OPT_STR,
1383 .cb = str_verify_cpus_allowed_cb,
1384 .help = "Set CPUs allowed for async verify threads",
1385 .parent = "verify_async",
1386 },
1387#endif
214e1eca
JA
1388 {
1389 .name = "write_iolog",
1390 .type = FIO_OPT_STR_STORE,
1391 .off1 = td_var_offset(write_iolog_file),
1392 .help = "Store IO pattern to file",
1393 },
1394 {
1395 .name = "read_iolog",
1396 .type = FIO_OPT_STR_STORE,
1397 .off1 = td_var_offset(read_iolog_file),
1398 .help = "Playback IO pattern from file",
1399 },
1400 {
1401 .name = "exec_prerun",
1402 .type = FIO_OPT_STR_STORE,
1403 .off1 = td_var_offset(exec_prerun),
1404 .help = "Execute this file prior to running job",
1405 },
1406 {
1407 .name = "exec_postrun",
1408 .type = FIO_OPT_STR_STORE,
1409 .off1 = td_var_offset(exec_postrun),
1410 .help = "Execute this file after running job",
1411 },
1412#ifdef FIO_HAVE_IOSCHED_SWITCH
1413 {
1414 .name = "ioscheduler",
1415 .type = FIO_OPT_STR_STORE,
1416 .off1 = td_var_offset(ioscheduler),
1417 .help = "Use this IO scheduler on the backing device",
1418 },
1419#endif
1420 {
1421 .name = "zonesize",
1422 .type = FIO_OPT_STR_VAL,
1423 .off1 = td_var_offset(zone_size),
1424 .help = "Give size of an IO zone",
1425 .def = "0",
1426 },
1427 {
1428 .name = "zoneskip",
1429 .type = FIO_OPT_STR_VAL,
1430 .off1 = td_var_offset(zone_skip),
1431 .help = "Space between IO zones",
1432 .def = "0",
1433 },
1434 {
1435 .name = "lockmem",
1436 .type = FIO_OPT_STR_VAL,
1437 .cb = str_lockmem_cb,
1438 .help = "Lock down this amount of memory",
1439 .def = "0",
1440 },
214e1eca
JA
1441 {
1442 .name = "rwmixread",
1443 .type = FIO_OPT_INT,
cb499fc4 1444 .cb = str_rwmix_read_cb,
214e1eca
JA
1445 .maxval = 100,
1446 .help = "Percentage of mixed workload that is reads",
1447 .def = "50",
1448 },
1449 {
1450 .name = "rwmixwrite",
1451 .type = FIO_OPT_INT,
cb499fc4 1452 .cb = str_rwmix_write_cb,
214e1eca
JA
1453 .maxval = 100,
1454 .help = "Percentage of mixed workload that is writes",
1455 .def = "50",
1456 },
afdf9352
JA
1457 {
1458 .name = "rwmixcycle",
15ca150e 1459 .type = FIO_OPT_DEPRECATED,
afdf9352 1460 },
214e1eca
JA
1461 {
1462 .name = "nice",
1463 .type = FIO_OPT_INT,
1464 .off1 = td_var_offset(nice),
1465 .help = "Set job CPU nice value",
1466 .minval = -19,
1467 .maxval = 20,
1468 .def = "0",
1469 },
1470#ifdef FIO_HAVE_IOPRIO
1471 {
1472 .name = "prio",
1473 .type = FIO_OPT_INT,
1474 .cb = str_prio_cb,
1475 .help = "Set job IO priority value",
1476 .minval = 0,
1477 .maxval = 7,
1478 },
1479 {
1480 .name = "prioclass",
1481 .type = FIO_OPT_INT,
1482 .cb = str_prioclass_cb,
1483 .help = "Set job IO priority class",
1484 .minval = 0,
1485 .maxval = 3,
1486 },
1487#endif
1488 {
1489 .name = "thinktime",
1490 .type = FIO_OPT_INT,
1491 .off1 = td_var_offset(thinktime),
1492 .help = "Idle time between IO buffers (usec)",
1493 .def = "0",
1494 },
1495 {
1496 .name = "thinktime_spin",
1497 .type = FIO_OPT_INT,
1498 .off1 = td_var_offset(thinktime_spin),
1499 .help = "Start think time by spinning this amount (usec)",
1500 .def = "0",
afdf9352 1501 .parent = "thinktime",
214e1eca
JA
1502 },
1503 {
1504 .name = "thinktime_blocks",
1505 .type = FIO_OPT_INT,
1506 .off1 = td_var_offset(thinktime_blocks),
1507 .help = "IO buffer period between 'thinktime'",
1508 .def = "1",
afdf9352 1509 .parent = "thinktime",
214e1eca
JA
1510 },
1511 {
1512 .name = "rate",
e01b22b8 1513 .type = FIO_OPT_INT,
581e7141
JA
1514 .off1 = td_var_offset(rate[0]),
1515 .off2 = td_var_offset(rate[1]),
214e1eca
JA
1516 .help = "Set bandwidth rate",
1517 },
1518 {
1519 .name = "ratemin",
e01b22b8 1520 .type = FIO_OPT_INT,
581e7141
JA
1521 .off1 = td_var_offset(ratemin[0]),
1522 .off2 = td_var_offset(ratemin[1]),
4e991c23 1523 .help = "Job must meet this rate or it will be shutdown",
afdf9352 1524 .parent = "rate",
4e991c23
JA
1525 },
1526 {
1527 .name = "rate_iops",
e01b22b8 1528 .type = FIO_OPT_INT,
581e7141
JA
1529 .off1 = td_var_offset(rate_iops[0]),
1530 .off2 = td_var_offset(rate_iops[1]),
4e991c23
JA
1531 .help = "Limit IO used to this number of IO operations/sec",
1532 },
1533 {
1534 .name = "rate_iops_min",
e01b22b8 1535 .type = FIO_OPT_INT,
581e7141
JA
1536 .off1 = td_var_offset(rate_iops_min[0]),
1537 .off2 = td_var_offset(rate_iops_min[1]),
4e991c23 1538 .help = "Job must meet this rate or it will be shutdown",
afdf9352 1539 .parent = "rate_iops",
214e1eca
JA
1540 },
1541 {
1542 .name = "ratecycle",
1543 .type = FIO_OPT_INT,
1544 .off1 = td_var_offset(ratecycle),
1545 .help = "Window average for rate limits (msec)",
1546 .def = "1000",
afdf9352 1547 .parent = "rate",
214e1eca
JA
1548 },
1549 {
1550 .name = "invalidate",
1551 .type = FIO_OPT_BOOL,
1552 .off1 = td_var_offset(invalidate_cache),
1553 .help = "Invalidate buffer/page cache prior to running job",
1554 .def = "1",
1555 },
1556 {
1557 .name = "sync",
1558 .type = FIO_OPT_BOOL,
1559 .off1 = td_var_offset(sync_io),
1560 .help = "Use O_SYNC for buffered writes",
1561 .def = "0",
67a1000f 1562 .parent = "buffered",
214e1eca
JA
1563 },
1564 {
1565 .name = "bwavgtime",
1566 .type = FIO_OPT_INT,
1567 .off1 = td_var_offset(bw_avg_time),
5ec10eaa
JA
1568 .help = "Time window over which to calculate bandwidth"
1569 " (msec)",
214e1eca
JA
1570 .def = "500",
1571 },
1572 {
1573 .name = "create_serialize",
1574 .type = FIO_OPT_BOOL,
1575 .off1 = td_var_offset(create_serialize),
1576 .help = "Serialize creating of job files",
1577 .def = "1",
1578 },
1579 {
1580 .name = "create_fsync",
1581 .type = FIO_OPT_BOOL,
1582 .off1 = td_var_offset(create_fsync),
1583 .help = "Fsync file after creation",
1584 .def = "1",
1585 },
814452bd
JA
1586 {
1587 .name = "create_on_open",
1588 .type = FIO_OPT_BOOL,
1589 .off1 = td_var_offset(create_on_open),
1590 .help = "Create files when they are opened for IO",
1591 .def = "0",
1592 },
0b9d69ec 1593 {
afad68f7
ZY
1594 .name = "pre_read",
1595 .type = FIO_OPT_BOOL,
1596 .off1 = td_var_offset(pre_read),
1597 .help = "Preread files before starting official testing",
1598 .def = "0",
1599 },
214e1eca
JA
1600 {
1601 .name = "cpuload",
1602 .type = FIO_OPT_INT,
1603 .off1 = td_var_offset(cpuload),
1604 .help = "Use this percentage of CPU",
1605 },
1606 {
1607 .name = "cpuchunks",
1608 .type = FIO_OPT_INT,
1609 .off1 = td_var_offset(cpucycle),
1610 .help = "Length of the CPU burn cycles (usecs)",
1611 .def = "50000",
67a1000f 1612 .parent = "cpuload",
214e1eca
JA
1613 },
1614#ifdef FIO_HAVE_CPU_AFFINITY
1615 {
1616 .name = "cpumask",
1617 .type = FIO_OPT_INT,
1618 .cb = str_cpumask_cb,
1619 .help = "CPU affinity mask",
1620 },
d2e268b0
JA
1621 {
1622 .name = "cpus_allowed",
1623 .type = FIO_OPT_STR,
1624 .cb = str_cpus_allowed_cb,
1625 .help = "Set CPUs allowed",
1626 },
214e1eca
JA
1627#endif
1628 {
1629 .name = "end_fsync",
1630 .type = FIO_OPT_BOOL,
1631 .off1 = td_var_offset(end_fsync),
1632 .help = "Include fsync at the end of job",
1633 .def = "0",
1634 },
1635 {
1636 .name = "fsync_on_close",
1637 .type = FIO_OPT_BOOL,
1638 .off1 = td_var_offset(fsync_on_close),
1639 .help = "fsync files on close",
1640 .def = "0",
1641 },
1642 {
1643 .name = "unlink",
1644 .type = FIO_OPT_BOOL,
1645 .off1 = td_var_offset(unlink),
1646 .help = "Unlink created files after job has completed",
1647 .def = "0",
1648 },
1649 {
1650 .name = "exitall",
1651 .type = FIO_OPT_STR_SET,
1652 .cb = str_exitall_cb,
1653 .help = "Terminate all jobs when one exits",
1654 },
1655 {
1656 .name = "stonewall",
1657 .type = FIO_OPT_STR_SET,
1658 .off1 = td_var_offset(stonewall),
1659 .help = "Insert a hard barrier between this job and previous",
1660 },
b3d62a75
JA
1661 {
1662 .name = "new_group",
1663 .type = FIO_OPT_STR_SET,
1664 .off1 = td_var_offset(new_group),
1665 .help = "Mark the start of a new group (for reporting)",
1666 },
214e1eca
JA
1667 {
1668 .name = "thread",
1669 .type = FIO_OPT_STR_SET,
1670 .off1 = td_var_offset(use_thread),
1671 .help = "Use threads instead of forks",
1672 },
1673 {
1674 .name = "write_bw_log",
e3cedca7 1675 .type = FIO_OPT_STR,
214e1eca 1676 .off1 = td_var_offset(write_bw_log),
e3cedca7 1677 .cb = str_write_bw_log_cb,
214e1eca
JA
1678 .help = "Write log of bandwidth during run",
1679 },
1680 {
1681 .name = "write_lat_log",
e3cedca7 1682 .type = FIO_OPT_STR,
214e1eca 1683 .off1 = td_var_offset(write_lat_log),
e3cedca7 1684 .cb = str_write_lat_log_cb,
214e1eca
JA
1685 .help = "Write log of latency during run",
1686 },
1687 {
1688 .name = "hugepage-size",
e01b22b8 1689 .type = FIO_OPT_INT,
214e1eca
JA
1690 .off1 = td_var_offset(hugepage_size),
1691 .help = "When using hugepages, specify size of each page",
1692 .def = __stringify(FIO_HUGE_PAGE),
1693 },
1694 {
1695 .name = "group_reporting",
1696 .type = FIO_OPT_STR_SET,
1697 .off1 = td_var_offset(group_reporting),
1698 .help = "Do reporting on a per-group basis",
1699 },
e9459e5a
JA
1700 {
1701 .name = "zero_buffers",
1702 .type = FIO_OPT_STR_SET,
1703 .off1 = td_var_offset(zero_buffers),
1704 .help = "Init IO buffers to all zeroes",
1705 },
5973cafb
JA
1706 {
1707 .name = "refill_buffers",
1708 .type = FIO_OPT_STR_SET,
1709 .off1 = td_var_offset(refill_buffers),
1710 .help = "Refill IO buffers on every IO submit",
1711 },
0a839f30
JA
1712#ifdef FIO_HAVE_DISK_UTIL
1713 {
1714 .name = "disk_util",
1715 .type = FIO_OPT_BOOL,
1716 .off1 = td_var_offset(do_disk_util),
f66ab3c8 1717 .help = "Log disk utilization statistics",
0a839f30
JA
1718 .def = "1",
1719 },
1720#endif
993bf48b
JA
1721 {
1722 .name = "gtod_reduce",
1723 .type = FIO_OPT_BOOL,
1724 .help = "Greatly reduce number of gettimeofday() calls",
1725 .cb = str_gtod_reduce_cb,
1726 .def = "0",
1727 },
9520ebb9
JA
1728 {
1729 .name = "disable_clat",
1730 .type = FIO_OPT_BOOL,
1731 .off1 = td_var_offset(disable_clat),
1732 .help = "Disable completion latency numbers",
993bf48b 1733 .parent = "gtod_reduce",
9520ebb9
JA
1734 .def = "0",
1735 },
1736 {
1737 .name = "disable_slat",
1738 .type = FIO_OPT_BOOL,
1739 .off1 = td_var_offset(disable_slat),
1740 .help = "Disable submissionn latency numbers",
993bf48b 1741 .parent = "gtod_reduce",
9520ebb9
JA
1742 .def = "0",
1743 },
1744 {
1745 .name = "disable_bw_measurement",
1746 .type = FIO_OPT_BOOL,
1747 .off1 = td_var_offset(disable_bw),
1748 .help = "Disable bandwidth logging",
993bf48b 1749 .parent = "gtod_reduce",
9520ebb9
JA
1750 .def = "0",
1751 },
be4ecfdf
JA
1752 {
1753 .name = "gtod_cpu",
1754 .type = FIO_OPT_INT,
1755 .cb = str_gtod_cpu_cb,
1756 .help = "Setup dedicated gettimeofday() thread on this CPU",
29d43ff9 1757 .verify = gtod_cpu_verify,
be4ecfdf 1758 },
f2bba182
RR
1759 {
1760 .name = "continue_on_error",
1761 .type = FIO_OPT_BOOL,
1762 .off1 = td_var_offset(continue_on_error),
1763 .help = "Continue on non-fatal errors during I/O",
1764 .def = "0",
1765 },
9ac8a797
JA
1766 {
1767 .name = "profile",
79d16311 1768 .type = FIO_OPT_STR_STORE,
9ac8a797 1769 .off1 = td_var_offset(profile),
9ac8a797
JA
1770 .help = "Select a specific builtin performance test",
1771 },
a696fa2a
JA
1772 {
1773 .name = "cgroup",
1774 .type = FIO_OPT_STR_STORE,
1775 .off1 = td_var_offset(cgroup),
1776 .help = "Add job to cgroup of this name",
1777 },
1778 {
1779 .name = "cgroup_weight",
1780 .type = FIO_OPT_INT,
1781 .off1 = td_var_offset(cgroup_weight),
1782 .help = "Use given weight for cgroup",
1783 .minval = 100,
1784 .maxval = 1000,
a696fa2a 1785 },
e0b0d892
JA
1786 {
1787 .name = "uid",
1788 .type = FIO_OPT_INT,
1789 .off1 = td_var_offset(uid),
1790 .help = "Run job with this user ID",
1791 },
1792 {
1793 .name = "gid",
1794 .type = FIO_OPT_INT,
1795 .off1 = td_var_offset(gid),
1796 .help = "Run job with this group ID",
1797 },
214e1eca
JA
1798 {
1799 .name = NULL,
1800 },
1801};
1802
9f81736c
JA
1803static void add_to_lopt(struct option *lopt, struct fio_option *o)
1804{
1805 lopt->name = (char *) o->name;
1806 lopt->val = FIO_GETOPT_JOB;
1807 if (o->type == FIO_OPT_STR_SET)
1808 lopt->has_arg = no_argument;
1809 else
1810 lopt->has_arg = required_argument;
1811}
1812
214e1eca
JA
1813void fio_options_dup_and_init(struct option *long_options)
1814{
1815 struct fio_option *o;
1816 unsigned int i;
1817
1818 options_init(options);
1819
1820 i = 0;
1821 while (long_options[i].name)
1822 i++;
1823
1824 o = &options[0];
1825 while (o->name) {
9f81736c 1826 add_to_lopt(&long_options[i], o);
214e1eca
JA
1827
1828 i++;
1829 o++;
1830 assert(i < FIO_NR_OPTIONS);
1831 }
1832}
1833
74929ac2
JA
1834struct fio_keyword {
1835 const char *word;
1836 const char *desc;
1837 char *replace;
1838};
1839
1840static struct fio_keyword fio_keywords[] = {
1841 {
1842 .word = "$pagesize",
1843 .desc = "Page size in the system",
1844 },
1845 {
1846 .word = "$mb_memory",
1847 .desc = "Megabytes of memory online",
1848 },
1849 {
1850 .word = "$ncpus",
1851 .desc = "Number of CPUs online in the system",
1852 },
1853 {
1854 .word = NULL,
1855 },
1856};
1857
1858void fio_keywords_init(void)
1859{
3b2e1464 1860 unsigned long long mb_memory;
74929ac2
JA
1861 char buf[128];
1862 long l;
1863
1864 sprintf(buf, "%lu", page_size);
1865 fio_keywords[0].replace = strdup(buf);
1866
3b2e1464
JA
1867 mb_memory = os_phys_mem() / page_size;
1868 sprintf(buf, "%llu", mb_memory);
74929ac2
JA
1869 fio_keywords[1].replace = strdup(buf);
1870
1871 l = sysconf(_SC_NPROCESSORS_ONLN);
1872 sprintf(buf, "%lu", l);
1873 fio_keywords[2].replace = strdup(buf);
1874}
1875
892a6ffc
JA
1876#define BC_APP "bc"
1877
1878static char *bc_calc(char *str)
1879{
1880 char *buf, *tmp, opt[80];
1881 FILE *f;
1882 int ret;
1883
1884 /*
1885 * No math, just return string
1886 */
1887 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
1888 !strchr(str, '/'))
1889 return str;
1890
1891 /*
1892 * Split option from value, we only need to calculate the value
1893 */
1894 tmp = strchr(str, '=');
1895 if (!tmp)
1896 return str;
1897
1898 tmp++;
9ac8a797 1899 memset(opt, 0, sizeof(opt));
892a6ffc
JA
1900 strncpy(opt, str, tmp - str);
1901
1902 buf = malloc(128);
1903
1904 sprintf(buf, "which %s > /dev/null", BC_APP);
1905 if (system(buf)) {
1906 log_err("fio: bc is needed for performing math\n");
1907 free(buf);
1908 return NULL;
1909 }
1910
1911 sprintf(buf, "echo %s | %s", tmp, BC_APP);
1912 f = popen(buf, "r");
1913 if (!f) {
1914 free(buf);
1915 return NULL;
1916 }
1917
1918 ret = fread(buf, 1, 128, f);
1919 if (ret <= 0) {
1920 free(buf);
1921 return NULL;
1922 }
1923
1924 buf[ret - 1] = '\0';
1925 strcat(opt, buf);
1926 strcpy(buf, opt);
1927 pclose(f);
1928 free(str);
1929 return buf;
1930}
1931
74929ac2
JA
1932/*
1933 * Look for reserved variable names and replace them with real values
1934 */
1935static char *fio_keyword_replace(char *opt)
1936{
1937 char *s;
1938 int i;
1939
1940 for (i = 0; fio_keywords[i].word != NULL; i++) {
1941 struct fio_keyword *kw = &fio_keywords[i];
1942
1943 while ((s = strstr(opt, kw->word)) != NULL) {
1944 char *new = malloc(strlen(opt) + 1);
1945 char *o_org = opt;
1946 int olen = s - opt;
1947 int len;
1948
1949 /*
1950 * Copy part of the string before the keyword and
1951 * sprintf() the replacement after it.
1952 */
1953 memcpy(new, opt, olen);
1954 len = sprintf(new + olen, "%s", kw->replace);
1955
1956 /*
1957 * If there's more in the original string, copy that
1958 * in too
1959 */
1960 opt += strlen(kw->word) + olen;
1961 if (strlen(opt))
1962 memcpy(new + olen + len, opt, opt - o_org - 1);
1963
1964 /*
1965 * replace opt and free the old opt
1966 */
1967 opt = new;
9ac8a797 1968 //free(o_org);
7a958bd5
JA
1969
1970 /*
1971 * Check for potential math and invoke bc, if possible
1972 */
1973 opt = bc_calc(opt);
74929ac2
JA
1974 }
1975 }
1976
7a958bd5 1977 return opt;
74929ac2
JA
1978}
1979
3b8b7135 1980int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
214e1eca 1981{
3b8b7135
JA
1982 int i, ret;
1983
1984 sort_options(opts, options, num_opts);
1985
74929ac2
JA
1986 for (ret = 0, i = 0; i < num_opts; i++) {
1987 opts[i] = fio_keyword_replace(opts[i]);
07b3232d 1988 ret |= parse_option(opts[i], options, td);
74929ac2 1989 }
3b8b7135
JA
1990
1991 return ret;
214e1eca
JA
1992}
1993
1994int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1995{
07b3232d 1996 return parse_cmd_option(opt, val, options, td);
214e1eca
JA
1997}
1998
1999void fio_fill_default_options(struct thread_data *td)
2000{
2001 fill_default_options(td, options);
2002}
2003
2004int fio_show_option_help(const char *opt)
2005{
07b3232d 2006 return show_cmd_help(options, opt);
214e1eca 2007}
d23bb327
JA
2008
2009static void __options_mem(struct thread_data *td, int alloc)
2010{
2011 struct thread_options *o = &td->o;
2012 struct fio_option *opt;
2013 char **ptr;
2014 int i;
2015
2016 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
2017 if (opt->type != FIO_OPT_STR_STORE)
2018 continue;
2019
2020 ptr = (void *) o + opt->off1;
2021 if (*ptr) {
2022 if (alloc)
2023 *ptr = strdup(*ptr);
2024 else {
2025 free(*ptr);
2026 *ptr = NULL;
2027 }
2028 }
2029 }
2030}
2031
2032/*
2033 * dupe FIO_OPT_STR_STORE options
2034 */
2035void options_mem_dupe(struct thread_data *td)
2036{
2037 __options_mem(td, 1);
2038}
2039
22d66213 2040void options_mem_free(struct thread_data fio_unused *td)
d23bb327 2041{
22d66213 2042#if 0
d23bb327 2043 __options_mem(td, 0);
22d66213 2044#endif
d23bb327 2045}
d6978a32
JA
2046
2047unsigned int fio_get_kb_base(void *data)
2048{
2049 struct thread_data *td = data;
2050 unsigned int kb_base = 0;
2051
2052 if (td)
2053 kb_base = td->o.kb_base;
2054 if (!kb_base)
2055 kb_base = 1024;
2056
2057 return kb_base;
2058}
9f988e2e 2059
07b3232d 2060int add_option(struct fio_option *o)
9f988e2e 2061{
07b3232d
JA
2062 struct fio_option *__o;
2063 int opt_index = 0;
2064
2065 __o = options;
2066 while (__o->name) {
2067 opt_index++;
2068 __o++;
2069 }
2070
2071 memcpy(&options[opt_index], o, sizeof(*o));
2072 return 0;
9f988e2e 2073}
e2de69da 2074
07b3232d 2075void invalidate_profile_options(const char *prof_name)
e2de69da 2076{
07b3232d 2077 struct fio_option *o;
e2de69da 2078
07b3232d
JA
2079 o = options;
2080 while (o->name) {
2081 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2082 o->type = FIO_OPT_INVALID;
2083 o->prof_name = NULL;
2084 }
2085 o++;
e2de69da
JA
2086 }
2087}
f5b6bb85
JA
2088
2089void add_opt_posval(const char *optname, const char *ival, const char *help)
2090{
2091 struct fio_option *o;
2092 unsigned int i;
2093
2094 o = find_option(options, optname);
2095 if (!o)
2096 return;
2097
2098 for (i = 0; i < PARSE_MAX_VP; i++) {
2099 if (o->posval[i].ival)
2100 continue;
2101
2102 o->posval[i].ival = ival;
2103 o->posval[i].help = help;
2104 break;
2105 }
2106}
2107
2108void del_opt_posval(const char *optname, const char *ival)
2109{
2110 struct fio_option *o;
2111 unsigned int i;
2112
2113 o = find_option(options, optname);
2114 if (!o)
2115 return;
2116
2117 for (i = 0; i < PARSE_MAX_VP; i++) {
2118 if (!o->posval[i].ival)
2119 continue;
2120 if (strcmp(o->posval[i].ival, ival))
2121 continue;
2122
2123 o->posval[i].ival = NULL;
2124 o->posval[i].help = NULL;
2125 }
2126}