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