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