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