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