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 | ||
c44b1ff5 JA |
229 | #ifdef FIO_HAVE_LIBAIO |
230 | static 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 |
244 | static 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 |
259 | static 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 |
274 | static 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 | 283 | static 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 | 289 | static 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 | 298 | static 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 | 308 | static 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 | 324 | static 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 | ||
341 | static int str_exitall_cb(void) | |
342 | { | |
343 | exitall_on_terminate = 1; | |
344 | return 0; | |
345 | } | |
346 | ||
214e1eca | 347 | #ifdef FIO_HAVE_CPU_AFFINITY |
85bc833b | 348 | static 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 |
380 | static 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 | |
448 | static 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 | ||
460 | static 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 |
474 | static 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 |
483 | static 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 |
498 | static 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 |
513 | static 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 | */ | |
557 | static 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 | ||
0fd666bf JA |
598 | static int str_hostname_cb(void *data, const char *input) |
599 | { | |
600 | struct thread_data *td = data; | |
601 | ||
602 | td->o.filename = strdup(input); | |
603 | return 0; | |
604 | } | |
605 | ||
214e1eca JA |
606 | static int str_filename_cb(void *data, const char *input) |
607 | { | |
608 | struct thread_data *td = data; | |
609 | char *fname, *str, *p; | |
610 | ||
611 | p = str = strdup(input); | |
612 | ||
613 | strip_blank_front(&str); | |
614 | strip_blank_end(str); | |
615 | ||
616 | if (!td->files_index) | |
2dc1bbeb | 617 | td->o.nr_files = 0; |
214e1eca | 618 | |
8e827d35 | 619 | while ((fname = get_next_file_name(&str)) != NULL) { |
214e1eca JA |
620 | if (!strlen(fname)) |
621 | break; | |
921c766f JA |
622 | if (check_dir(td, fname)) { |
623 | free(p); | |
624 | return 1; | |
625 | } | |
214e1eca | 626 | add_file(td, fname); |
2dc1bbeb | 627 | td->o.nr_files++; |
214e1eca JA |
628 | } |
629 | ||
630 | free(p); | |
631 | return 0; | |
632 | } | |
633 | ||
634 | static int str_directory_cb(void *data, const char fio_unused *str) | |
635 | { | |
636 | struct thread_data *td = data; | |
637 | struct stat sb; | |
638 | ||
2dc1bbeb | 639 | if (lstat(td->o.directory, &sb) < 0) { |
921c766f JA |
640 | int ret = errno; |
641 | ||
2dc1bbeb | 642 | log_err("fio: %s is not a directory\n", td->o.directory); |
921c766f | 643 | td_verror(td, ret, "lstat"); |
214e1eca JA |
644 | return 1; |
645 | } | |
646 | if (!S_ISDIR(sb.st_mode)) { | |
2dc1bbeb | 647 | log_err("fio: %s is not a directory\n", td->o.directory); |
214e1eca JA |
648 | return 1; |
649 | } | |
650 | ||
651 | return 0; | |
652 | } | |
653 | ||
654 | static int str_opendir_cb(void *data, const char fio_unused *str) | |
655 | { | |
656 | struct thread_data *td = data; | |
657 | ||
658 | if (!td->files_index) | |
2dc1bbeb | 659 | td->o.nr_files = 0; |
214e1eca | 660 | |
2dc1bbeb | 661 | return add_dir_files(td, td->o.opendir); |
214e1eca JA |
662 | } |
663 | ||
85bc833b | 664 | static int str_verify_offset_cb(void *data, unsigned long long *off) |
546a9142 SL |
665 | { |
666 | struct thread_data *td = data; | |
a59e170d | 667 | |
546a9142 | 668 | if (*off && *off < sizeof(struct verify_header)) { |
a59e170d | 669 | log_err("fio: verify_offset too small\n"); |
546a9142 SL |
670 | return 1; |
671 | } | |
a59e170d JA |
672 | |
673 | td->o.verify_offset = *off; | |
546a9142 SL |
674 | return 0; |
675 | } | |
676 | ||
0e92f873 | 677 | static int str_verify_pattern_cb(void *data, const char *input) |
90059d65 JA |
678 | { |
679 | struct thread_data *td = data; | |
0e92f873 RR |
680 | long off; |
681 | int i = 0, j = 0, len, k, base = 10; | |
682 | char* loc1, * loc2; | |
683 | ||
684 | loc1 = strstr(input, "0x"); | |
685 | loc2 = strstr(input, "0X"); | |
686 | if (loc1 || loc2) | |
687 | base = 16; | |
688 | off = strtol(input, NULL, base); | |
689 | if (off != LONG_MAX || errno != ERANGE) { | |
690 | while (off) { | |
691 | td->o.verify_pattern[i] = off & 0xff; | |
692 | off >>= 8; | |
693 | i++; | |
694 | } | |
695 | } else { | |
696 | len = strlen(input); | |
697 | k = len - 1; | |
698 | if (base == 16) { | |
699 | if (loc1) | |
700 | j = loc1 - input + 2; | |
701 | else | |
702 | j = loc2 - input + 2; | |
703 | } else | |
704 | return 1; | |
705 | if (len - j < MAX_PATTERN_SIZE * 2) { | |
706 | while (k >= j) { | |
707 | off = converthexchartoint(input[k--]); | |
708 | if (k >= j) | |
709 | off += (converthexchartoint(input[k--]) | |
710 | * 16); | |
711 | td->o.verify_pattern[i++] = (char) off; | |
712 | } | |
713 | } | |
714 | } | |
715 | td->o.verify_pattern_bytes = i; | |
92bf48d5 JA |
716 | /* |
717 | * VERIFY_META could already be set | |
718 | */ | |
719 | if (td->o.verify == VERIFY_NONE) | |
720 | td->o.verify = VERIFY_PATTERN; | |
90059d65 JA |
721 | return 0; |
722 | } | |
214e1eca | 723 | |
4d4e80f2 JA |
724 | static int str_lockfile_cb(void *data, const char *str) |
725 | { | |
726 | struct thread_data *td = data; | |
727 | char *nr = get_opt_postfix(str); | |
728 | ||
729 | td->o.lockfile_batch = 1; | |
182ec6ee | 730 | if (nr) { |
4d4e80f2 | 731 | td->o.lockfile_batch = atoi(nr); |
182ec6ee JA |
732 | free(nr); |
733 | } | |
4d4e80f2 JA |
734 | |
735 | return 0; | |
736 | } | |
737 | ||
e3cedca7 JA |
738 | static int str_write_bw_log_cb(void *data, const char *str) |
739 | { | |
740 | struct thread_data *td = data; | |
741 | ||
742 | if (str) | |
743 | td->o.bw_log_file = strdup(str); | |
744 | ||
745 | td->o.write_bw_log = 1; | |
746 | return 0; | |
747 | } | |
748 | ||
749 | static int str_write_lat_log_cb(void *data, const char *str) | |
750 | { | |
751 | struct thread_data *td = data; | |
752 | ||
753 | if (str) | |
754 | td->o.lat_log_file = strdup(str); | |
755 | ||
756 | td->o.write_lat_log = 1; | |
757 | return 0; | |
758 | } | |
759 | ||
c8eeb9df JA |
760 | static int str_write_iops_log_cb(void *data, const char *str) |
761 | { | |
762 | struct thread_data *td = data; | |
763 | ||
764 | if (str) | |
765 | td->o.iops_log_file = strdup(str); | |
766 | ||
767 | td->o.write_iops_log = 1; | |
768 | return 0; | |
769 | } | |
770 | ||
993bf48b JA |
771 | static int str_gtod_reduce_cb(void *data, int *il) |
772 | { | |
773 | struct thread_data *td = data; | |
774 | int val = *il; | |
775 | ||
02af0988 | 776 | td->o.disable_lat = !!val; |
993bf48b JA |
777 | td->o.disable_clat = !!val; |
778 | td->o.disable_slat = !!val; | |
779 | td->o.disable_bw = !!val; | |
780 | if (val) | |
781 | td->tv_cache_mask = 63; | |
782 | ||
783 | return 0; | |
784 | } | |
785 | ||
85bc833b | 786 | static int str_gtod_cpu_cb(void *data, long long *il) |
be4ecfdf JA |
787 | { |
788 | struct thread_data *td = data; | |
789 | int val = *il; | |
790 | ||
791 | td->o.gtod_cpu = val; | |
792 | td->o.gtod_offload = 1; | |
793 | return 0; | |
794 | } | |
795 | ||
7bb59102 JA |
796 | static int str_size_cb(void *data, unsigned long long *__val) |
797 | { | |
798 | struct thread_data *td = data; | |
799 | unsigned long long v = *__val; | |
800 | ||
801 | if (parse_is_percent(v)) { | |
802 | td->o.size = 0; | |
803 | td->o.size_percent = -1ULL - v; | |
804 | } else | |
805 | td->o.size = v; | |
806 | ||
807 | return 0; | |
808 | } | |
809 | ||
896cac2a JA |
810 | static int rw_verify(struct fio_option *o, void *data) |
811 | { | |
812 | struct thread_data *td = data; | |
813 | ||
814 | if (read_only && td_write(td)) { | |
815 | log_err("fio: job <%s> has write bit set, but fio is in" | |
816 | " read-only mode\n", td->o.name); | |
817 | return 1; | |
818 | } | |
819 | ||
820 | return 0; | |
821 | } | |
822 | ||
276ca4f7 | 823 | static int gtod_cpu_verify(struct fio_option *o, void *data) |
29d43ff9 | 824 | { |
276ca4f7 | 825 | #ifndef FIO_HAVE_CPU_AFFINITY |
29d43ff9 JA |
826 | struct thread_data *td = data; |
827 | ||
29d43ff9 JA |
828 | if (td->o.gtod_cpu) { |
829 | log_err("fio: platform must support CPU affinity for" | |
830 | "gettimeofday() offloading\n"); | |
831 | return 1; | |
832 | } | |
833 | #endif | |
834 | ||
835 | return 0; | |
836 | } | |
837 | ||
90fef2d1 JA |
838 | static int kb_base_verify(struct fio_option *o, void *data) |
839 | { | |
840 | struct thread_data *td = data; | |
841 | ||
842 | if (td->o.kb_base != 1024 && td->o.kb_base != 1000) { | |
843 | log_err("fio: kb_base set to nonsensical value: %u\n", | |
844 | td->o.kb_base); | |
845 | return 1; | |
846 | } | |
847 | ||
848 | return 0; | |
849 | } | |
850 | ||
214e1eca JA |
851 | /* |
852 | * Map of job/command line options | |
853 | */ | |
07b3232d | 854 | static struct fio_option options[FIO_MAX_OPTS] = { |
214e1eca JA |
855 | { |
856 | .name = "description", | |
857 | .type = FIO_OPT_STR_STORE, | |
858 | .off1 = td_var_offset(description), | |
859 | .help = "Text job description", | |
860 | }, | |
861 | { | |
862 | .name = "name", | |
863 | .type = FIO_OPT_STR_STORE, | |
864 | .off1 = td_var_offset(name), | |
865 | .help = "Name of this job", | |
866 | }, | |
867 | { | |
868 | .name = "directory", | |
869 | .type = FIO_OPT_STR_STORE, | |
870 | .off1 = td_var_offset(directory), | |
871 | .cb = str_directory_cb, | |
872 | .help = "Directory to store files in", | |
873 | }, | |
874 | { | |
875 | .name = "filename", | |
876 | .type = FIO_OPT_STR_STORE, | |
877 | .off1 = td_var_offset(filename), | |
878 | .cb = str_filename_cb, | |
f0d524b0 | 879 | .prio = -1, /* must come after "directory" */ |
214e1eca JA |
880 | .help = "File(s) to use for the workload", |
881 | }, | |
0fd666bf JA |
882 | { |
883 | .name = "hostname", | |
884 | .type = FIO_OPT_STR_STORE, | |
885 | .cb = str_hostname_cb, | |
886 | .help = "Hostname for net IO engine", | |
887 | }, | |
90fef2d1 JA |
888 | { |
889 | .name = "kb_base", | |
890 | .type = FIO_OPT_INT, | |
891 | .off1 = td_var_offset(kb_base), | |
90fef2d1 | 892 | .verify = kb_base_verify, |
a639f0bb | 893 | .prio = 1, |
90fef2d1 | 894 | .def = "1024", |
a639f0bb | 895 | .help = "How many bytes per KB for reporting (1000 or 1024)", |
90fef2d1 | 896 | }, |
29c1349f JA |
897 | { |
898 | .name = "lockfile", | |
4d4e80f2 JA |
899 | .type = FIO_OPT_STR, |
900 | .cb = str_lockfile_cb, | |
901 | .off1 = td_var_offset(file_lock_mode), | |
29c1349f JA |
902 | .help = "Lock file when doing IO to it", |
903 | .parent = "filename", | |
4d4e80f2 JA |
904 | .def = "none", |
905 | .posval = { | |
906 | { .ival = "none", | |
907 | .oval = FILE_LOCK_NONE, | |
908 | .help = "No file locking", | |
909 | }, | |
910 | { .ival = "exclusive", | |
911 | .oval = FILE_LOCK_EXCLUSIVE, | |
912 | .help = "Exclusive file lock", | |
913 | }, | |
914 | { | |
915 | .ival = "readwrite", | |
916 | .oval = FILE_LOCK_READWRITE, | |
917 | .help = "Read vs write lock", | |
918 | }, | |
919 | }, | |
29c1349f | 920 | }, |
214e1eca JA |
921 | { |
922 | .name = "opendir", | |
923 | .type = FIO_OPT_STR_STORE, | |
924 | .off1 = td_var_offset(opendir), | |
925 | .cb = str_opendir_cb, | |
926 | .help = "Recursively add files from this directory and down", | |
927 | }, | |
928 | { | |
929 | .name = "rw", | |
d3aad8f2 | 930 | .alias = "readwrite", |
214e1eca | 931 | .type = FIO_OPT_STR, |
211097b2 | 932 | .cb = str_rw_cb, |
214e1eca JA |
933 | .off1 = td_var_offset(td_ddir), |
934 | .help = "IO direction", | |
935 | .def = "read", | |
896cac2a | 936 | .verify = rw_verify, |
214e1eca JA |
937 | .posval = { |
938 | { .ival = "read", | |
939 | .oval = TD_DDIR_READ, | |
940 | .help = "Sequential read", | |
941 | }, | |
942 | { .ival = "write", | |
943 | .oval = TD_DDIR_WRITE, | |
944 | .help = "Sequential write", | |
945 | }, | |
946 | { .ival = "randread", | |
947 | .oval = TD_DDIR_RANDREAD, | |
948 | .help = "Random read", | |
949 | }, | |
950 | { .ival = "randwrite", | |
951 | .oval = TD_DDIR_RANDWRITE, | |
952 | .help = "Random write", | |
953 | }, | |
954 | { .ival = "rw", | |
955 | .oval = TD_DDIR_RW, | |
956 | .help = "Sequential read and write mix", | |
957 | }, | |
958 | { .ival = "randrw", | |
959 | .oval = TD_DDIR_RANDRW, | |
960 | .help = "Random read and write mix" | |
961 | }, | |
962 | }, | |
963 | }, | |
38dad62d JA |
964 | { |
965 | .name = "rw_sequencer", | |
966 | .type = FIO_OPT_STR, | |
967 | .off1 = td_var_offset(rw_seq), | |
968 | .help = "IO offset generator modifier", | |
969 | .def = "sequential", | |
970 | .posval = { | |
971 | { .ival = "sequential", | |
972 | .oval = RW_SEQ_SEQ, | |
973 | .help = "Generate sequential offsets", | |
974 | }, | |
975 | { .ival = "identical", | |
976 | .oval = RW_SEQ_IDENT, | |
977 | .help = "Generate identical offsets", | |
978 | }, | |
979 | }, | |
980 | }, | |
981 | ||
214e1eca JA |
982 | { |
983 | .name = "ioengine", | |
984 | .type = FIO_OPT_STR_STORE, | |
985 | .off1 = td_var_offset(ioengine), | |
986 | .help = "IO engine to use", | |
58483fa4 | 987 | .def = FIO_PREFERRED_ENGINE, |
214e1eca JA |
988 | .posval = { |
989 | { .ival = "sync", | |
990 | .help = "Use read/write", | |
991 | }, | |
a31041ea | 992 | { .ival = "psync", |
993 | .help = "Use pread/pwrite", | |
994 | }, | |
1d2af02a | 995 | { .ival = "vsync", |
03e20d68 | 996 | .help = "Use readv/writev", |
1d2af02a | 997 | }, |
214e1eca JA |
998 | #ifdef FIO_HAVE_LIBAIO |
999 | { .ival = "libaio", | |
1000 | .help = "Linux native asynchronous IO", | |
c44b1ff5 | 1001 | .cb = str_libaio_cb, |
214e1eca JA |
1002 | }, |
1003 | #endif | |
1004 | #ifdef FIO_HAVE_POSIXAIO | |
1005 | { .ival = "posixaio", | |
1006 | .help = "POSIX asynchronous IO", | |
1007 | }, | |
417f0068 JA |
1008 | #endif |
1009 | #ifdef FIO_HAVE_SOLARISAIO | |
1010 | { .ival = "solarisaio", | |
1011 | .help = "Solaris native asynchronous IO", | |
1012 | }, | |
214e1eca | 1013 | #endif |
03e20d68 BC |
1014 | #ifdef FIO_HAVE_WINDOWSAIO |
1015 | { .ival = "windowsaio", | |
3be80071 | 1016 | .help = "Windows native asynchronous IO" |
03e20d68 | 1017 | }, |
3be80071 | 1018 | #endif |
214e1eca | 1019 | { .ival = "mmap", |
03e20d68 | 1020 | .help = "Memory mapped IO" |
214e1eca JA |
1021 | }, |
1022 | #ifdef FIO_HAVE_SPLICE | |
1023 | { .ival = "splice", | |
1024 | .help = "splice/vmsplice based IO", | |
1025 | }, | |
9cce02e8 JA |
1026 | { .ival = "netsplice", |
1027 | .help = "splice/vmsplice to/from the network", | |
1028 | }, | |
214e1eca JA |
1029 | #endif |
1030 | #ifdef FIO_HAVE_SGIO | |
1031 | { .ival = "sg", | |
1032 | .help = "SCSI generic v3 IO", | |
1033 | }, | |
1034 | #endif | |
1035 | { .ival = "null", | |
1036 | .help = "Testing engine (no data transfer)", | |
1037 | }, | |
1038 | { .ival = "net", | |
1039 | .help = "Network IO", | |
1040 | }, | |
1041 | #ifdef FIO_HAVE_SYSLET | |
1042 | { .ival = "syslet-rw", | |
1043 | .help = "syslet enabled async pread/pwrite IO", | |
1044 | }, | |
1045 | #endif | |
1046 | { .ival = "cpuio", | |
03e20d68 | 1047 | .help = "CPU cycle burner engine", |
214e1eca | 1048 | }, |
b8c82a46 JA |
1049 | #ifdef FIO_HAVE_GUASI |
1050 | { .ival = "guasi", | |
1051 | .help = "GUASI IO engine", | |
1052 | }, | |
79a43187 JA |
1053 | #endif |
1054 | #ifdef FIO_HAVE_BINJECT | |
1055 | { .ival = "binject", | |
1056 | .help = "binject direct inject block engine", | |
1057 | }, | |
21b8aee8 | 1058 | #endif |
1059 | #ifdef FIO_HAVE_RDMA | |
1060 | { .ival = "rdma", | |
1061 | .help = "RDMA IO engine", | |
1062 | }, | |
b8c82a46 | 1063 | #endif |
214e1eca JA |
1064 | { .ival = "external", |
1065 | .help = "Load external engine (append name)", | |
1066 | }, | |
1067 | }, | |
1068 | }, | |
1069 | { | |
1070 | .name = "iodepth", | |
1071 | .type = FIO_OPT_INT, | |
1072 | .off1 = td_var_offset(iodepth), | |
03e20d68 | 1073 | .help = "Number of IO buffers to keep in flight", |
757aff4f | 1074 | .minval = 1, |
214e1eca JA |
1075 | .def = "1", |
1076 | }, | |
1077 | { | |
1078 | .name = "iodepth_batch", | |
4950421a | 1079 | .alias = "iodepth_batch_submit", |
214e1eca JA |
1080 | .type = FIO_OPT_INT, |
1081 | .off1 = td_var_offset(iodepth_batch), | |
d65db441 | 1082 | .help = "Number of IO buffers to submit in one go", |
afdf9352 | 1083 | .parent = "iodepth", |
a2e6f8ac JA |
1084 | .minval = 1, |
1085 | .def = "1", | |
4950421a JA |
1086 | }, |
1087 | { | |
1088 | .name = "iodepth_batch_complete", | |
1089 | .type = FIO_OPT_INT, | |
1090 | .off1 = td_var_offset(iodepth_batch_complete), | |
d65db441 | 1091 | .help = "Number of IO buffers to retrieve in one go", |
4950421a JA |
1092 | .parent = "iodepth", |
1093 | .minval = 0, | |
1094 | .def = "1", | |
214e1eca JA |
1095 | }, |
1096 | { | |
1097 | .name = "iodepth_low", | |
1098 | .type = FIO_OPT_INT, | |
1099 | .off1 = td_var_offset(iodepth_low), | |
1100 | .help = "Low water mark for queuing depth", | |
afdf9352 | 1101 | .parent = "iodepth", |
214e1eca JA |
1102 | }, |
1103 | { | |
1104 | .name = "size", | |
1105 | .type = FIO_OPT_STR_VAL, | |
7bb59102 | 1106 | .cb = str_size_cb, |
214e1eca JA |
1107 | .help = "Total size of device or files", |
1108 | }, | |
aa31f1f1 SL |
1109 | { |
1110 | .name = "fill_device", | |
74586c1e | 1111 | .alias = "fill_fs", |
aa31f1f1 SL |
1112 | .type = FIO_OPT_BOOL, |
1113 | .off1 = td_var_offset(fill_device), | |
1114 | .help = "Write until an ENOSPC error occurs", | |
1115 | .def = "0", | |
1116 | }, | |
214e1eca JA |
1117 | { |
1118 | .name = "filesize", | |
1119 | .type = FIO_OPT_STR_VAL, | |
1120 | .off1 = td_var_offset(file_size_low), | |
1121 | .off2 = td_var_offset(file_size_high), | |
c3edbdba | 1122 | .minval = 1, |
214e1eca JA |
1123 | .help = "Size of individual files", |
1124 | }, | |
67a1000f JA |
1125 | { |
1126 | .name = "offset", | |
1127 | .alias = "fileoffset", | |
1128 | .type = FIO_OPT_STR_VAL, | |
1129 | .off1 = td_var_offset(start_offset), | |
1130 | .help = "Start IO from this 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 JA |
1493 | { .ival = "crc32c-intel", |
1494 | .oval = VERIFY_CRC32C_INTEL, | |
1495 | .help = "Use hw crc32c checksums for verification", | |
1496 | }, | |
bac39e0e JA |
1497 | { .ival = "crc32c", |
1498 | .oval = VERIFY_CRC32C, | |
1499 | .help = "Use crc32c checksums for verification", | |
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), | |
1583 | .def = "1", | |
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), | |
1702 | .help = "Give size of an IO zone", | |
1703 | .def = "0", | |
1704 | }, | |
1705 | { | |
1706 | .name = "zoneskip", | |
1707 | .type = FIO_OPT_STR_VAL, | |
1708 | .off1 = td_var_offset(zone_skip), | |
1709 | .help = "Space between IO zones", | |
1710 | .def = "0", | |
1711 | }, | |
1712 | { | |
1713 | .name = "lockmem", | |
1714 | .type = FIO_OPT_STR_VAL, | |
1715 | .cb = str_lockmem_cb, | |
1716 | .help = "Lock down this amount of memory", | |
1717 | .def = "0", | |
1718 | }, | |
214e1eca JA |
1719 | { |
1720 | .name = "rwmixread", | |
1721 | .type = FIO_OPT_INT, | |
cb499fc4 | 1722 | .cb = str_rwmix_read_cb, |
214e1eca JA |
1723 | .maxval = 100, |
1724 | .help = "Percentage of mixed workload that is reads", | |
1725 | .def = "50", | |
1726 | }, | |
1727 | { | |
1728 | .name = "rwmixwrite", | |
1729 | .type = FIO_OPT_INT, | |
cb499fc4 | 1730 | .cb = str_rwmix_write_cb, |
214e1eca JA |
1731 | .maxval = 100, |
1732 | .help = "Percentage of mixed workload that is writes", | |
1733 | .def = "50", | |
1734 | }, | |
afdf9352 JA |
1735 | { |
1736 | .name = "rwmixcycle", | |
15ca150e | 1737 | .type = FIO_OPT_DEPRECATED, |
afdf9352 | 1738 | }, |
214e1eca JA |
1739 | { |
1740 | .name = "nice", | |
1741 | .type = FIO_OPT_INT, | |
1742 | .off1 = td_var_offset(nice), | |
1743 | .help = "Set job CPU nice value", | |
1744 | .minval = -19, | |
1745 | .maxval = 20, | |
1746 | .def = "0", | |
1747 | }, | |
1748 | #ifdef FIO_HAVE_IOPRIO | |
1749 | { | |
1750 | .name = "prio", | |
1751 | .type = FIO_OPT_INT, | |
1752 | .cb = str_prio_cb, | |
1753 | .help = "Set job IO priority value", | |
1754 | .minval = 0, | |
1755 | .maxval = 7, | |
1756 | }, | |
1757 | { | |
1758 | .name = "prioclass", | |
1759 | .type = FIO_OPT_INT, | |
1760 | .cb = str_prioclass_cb, | |
1761 | .help = "Set job IO priority class", | |
1762 | .minval = 0, | |
1763 | .maxval = 3, | |
1764 | }, | |
1765 | #endif | |
1766 | { | |
1767 | .name = "thinktime", | |
1768 | .type = FIO_OPT_INT, | |
1769 | .off1 = td_var_offset(thinktime), | |
1770 | .help = "Idle time between IO buffers (usec)", | |
1771 | .def = "0", | |
1772 | }, | |
1773 | { | |
1774 | .name = "thinktime_spin", | |
1775 | .type = FIO_OPT_INT, | |
1776 | .off1 = td_var_offset(thinktime_spin), | |
1777 | .help = "Start think time by spinning this amount (usec)", | |
1778 | .def = "0", | |
afdf9352 | 1779 | .parent = "thinktime", |
214e1eca JA |
1780 | }, |
1781 | { | |
1782 | .name = "thinktime_blocks", | |
1783 | .type = FIO_OPT_INT, | |
1784 | .off1 = td_var_offset(thinktime_blocks), | |
1785 | .help = "IO buffer period between 'thinktime'", | |
1786 | .def = "1", | |
afdf9352 | 1787 | .parent = "thinktime", |
214e1eca JA |
1788 | }, |
1789 | { | |
1790 | .name = "rate", | |
e01b22b8 | 1791 | .type = FIO_OPT_INT, |
581e7141 JA |
1792 | .off1 = td_var_offset(rate[0]), |
1793 | .off2 = td_var_offset(rate[1]), | |
214e1eca JA |
1794 | .help = "Set bandwidth rate", |
1795 | }, | |
1796 | { | |
1797 | .name = "ratemin", | |
e01b22b8 | 1798 | .type = FIO_OPT_INT, |
581e7141 JA |
1799 | .off1 = td_var_offset(ratemin[0]), |
1800 | .off2 = td_var_offset(ratemin[1]), | |
4e991c23 | 1801 | .help = "Job must meet this rate or it will be shutdown", |
afdf9352 | 1802 | .parent = "rate", |
4e991c23 JA |
1803 | }, |
1804 | { | |
1805 | .name = "rate_iops", | |
e01b22b8 | 1806 | .type = FIO_OPT_INT, |
581e7141 JA |
1807 | .off1 = td_var_offset(rate_iops[0]), |
1808 | .off2 = td_var_offset(rate_iops[1]), | |
4e991c23 JA |
1809 | .help = "Limit IO used to this number of IO operations/sec", |
1810 | }, | |
1811 | { | |
1812 | .name = "rate_iops_min", | |
e01b22b8 | 1813 | .type = FIO_OPT_INT, |
581e7141 JA |
1814 | .off1 = td_var_offset(rate_iops_min[0]), |
1815 | .off2 = td_var_offset(rate_iops_min[1]), | |
03e20d68 | 1816 | .help = "Job must meet this rate or it will be shut down", |
afdf9352 | 1817 | .parent = "rate_iops", |
214e1eca JA |
1818 | }, |
1819 | { | |
1820 | .name = "ratecycle", | |
1821 | .type = FIO_OPT_INT, | |
1822 | .off1 = td_var_offset(ratecycle), | |
1823 | .help = "Window average for rate limits (msec)", | |
1824 | .def = "1000", | |
afdf9352 | 1825 | .parent = "rate", |
214e1eca JA |
1826 | }, |
1827 | { | |
1828 | .name = "invalidate", | |
1829 | .type = FIO_OPT_BOOL, | |
1830 | .off1 = td_var_offset(invalidate_cache), | |
1831 | .help = "Invalidate buffer/page cache prior to running job", | |
1832 | .def = "1", | |
1833 | }, | |
1834 | { | |
1835 | .name = "sync", | |
1836 | .type = FIO_OPT_BOOL, | |
1837 | .off1 = td_var_offset(sync_io), | |
1838 | .help = "Use O_SYNC for buffered writes", | |
1839 | .def = "0", | |
67a1000f | 1840 | .parent = "buffered", |
214e1eca JA |
1841 | }, |
1842 | { | |
1843 | .name = "bwavgtime", | |
1844 | .type = FIO_OPT_INT, | |
1845 | .off1 = td_var_offset(bw_avg_time), | |
5ec10eaa JA |
1846 | .help = "Time window over which to calculate bandwidth" |
1847 | " (msec)", | |
214e1eca | 1848 | .def = "500", |
c8eeb9df JA |
1849 | .parent = "write_bw_log", |
1850 | }, | |
1851 | { | |
1852 | .name = "iopsavgtime", | |
1853 | .type = FIO_OPT_INT, | |
1854 | .off1 = td_var_offset(iops_avg_time), | |
1855 | .help = "Time window over which to calculate IOPS (msec)", | |
1856 | .def = "500", | |
1857 | .parent = "write_iops_log", | |
214e1eca JA |
1858 | }, |
1859 | { | |
1860 | .name = "create_serialize", | |
1861 | .type = FIO_OPT_BOOL, | |
1862 | .off1 = td_var_offset(create_serialize), | |
1863 | .help = "Serialize creating of job files", | |
1864 | .def = "1", | |
1865 | }, | |
1866 | { | |
1867 | .name = "create_fsync", | |
1868 | .type = FIO_OPT_BOOL, | |
1869 | .off1 = td_var_offset(create_fsync), | |
03e20d68 | 1870 | .help = "fsync file after creation", |
214e1eca JA |
1871 | .def = "1", |
1872 | }, | |
814452bd JA |
1873 | { |
1874 | .name = "create_on_open", | |
1875 | .type = FIO_OPT_BOOL, | |
1876 | .off1 = td_var_offset(create_on_open), | |
1877 | .help = "Create files when they are opened for IO", | |
1878 | .def = "0", | |
1879 | }, | |
0b9d69ec | 1880 | { |
afad68f7 ZY |
1881 | .name = "pre_read", |
1882 | .type = FIO_OPT_BOOL, | |
1883 | .off1 = td_var_offset(pre_read), | |
03e20d68 | 1884 | .help = "Pre-read files before starting official testing", |
afad68f7 ZY |
1885 | .def = "0", |
1886 | }, | |
214e1eca JA |
1887 | { |
1888 | .name = "cpuload", | |
1889 | .type = FIO_OPT_INT, | |
1890 | .off1 = td_var_offset(cpuload), | |
1891 | .help = "Use this percentage of CPU", | |
1892 | }, | |
1893 | { | |
1894 | .name = "cpuchunks", | |
1895 | .type = FIO_OPT_INT, | |
1896 | .off1 = td_var_offset(cpucycle), | |
1897 | .help = "Length of the CPU burn cycles (usecs)", | |
1898 | .def = "50000", | |
67a1000f | 1899 | .parent = "cpuload", |
214e1eca JA |
1900 | }, |
1901 | #ifdef FIO_HAVE_CPU_AFFINITY | |
1902 | { | |
1903 | .name = "cpumask", | |
1904 | .type = FIO_OPT_INT, | |
1905 | .cb = str_cpumask_cb, | |
1906 | .help = "CPU affinity mask", | |
1907 | }, | |
d2e268b0 JA |
1908 | { |
1909 | .name = "cpus_allowed", | |
1910 | .type = FIO_OPT_STR, | |
1911 | .cb = str_cpus_allowed_cb, | |
1912 | .help = "Set CPUs allowed", | |
1913 | }, | |
214e1eca JA |
1914 | #endif |
1915 | { | |
1916 | .name = "end_fsync", | |
1917 | .type = FIO_OPT_BOOL, | |
1918 | .off1 = td_var_offset(end_fsync), | |
1919 | .help = "Include fsync at the end of job", | |
1920 | .def = "0", | |
1921 | }, | |
1922 | { | |
1923 | .name = "fsync_on_close", | |
1924 | .type = FIO_OPT_BOOL, | |
1925 | .off1 = td_var_offset(fsync_on_close), | |
1926 | .help = "fsync files on close", | |
1927 | .def = "0", | |
1928 | }, | |
1929 | { | |
1930 | .name = "unlink", | |
1931 | .type = FIO_OPT_BOOL, | |
1932 | .off1 = td_var_offset(unlink), | |
1933 | .help = "Unlink created files after job has completed", | |
1934 | .def = "0", | |
1935 | }, | |
1936 | { | |
1937 | .name = "exitall", | |
1938 | .type = FIO_OPT_STR_SET, | |
1939 | .cb = str_exitall_cb, | |
1940 | .help = "Terminate all jobs when one exits", | |
1941 | }, | |
1942 | { | |
1943 | .name = "stonewall", | |
d392365e | 1944 | .alias = "wait_for_previous", |
214e1eca JA |
1945 | .type = FIO_OPT_STR_SET, |
1946 | .off1 = td_var_offset(stonewall), | |
1947 | .help = "Insert a hard barrier between this job and previous", | |
1948 | }, | |
b3d62a75 JA |
1949 | { |
1950 | .name = "new_group", | |
1951 | .type = FIO_OPT_STR_SET, | |
1952 | .off1 = td_var_offset(new_group), | |
1953 | .help = "Mark the start of a new group (for reporting)", | |
1954 | }, | |
214e1eca JA |
1955 | { |
1956 | .name = "thread", | |
1957 | .type = FIO_OPT_STR_SET, | |
1958 | .off1 = td_var_offset(use_thread), | |
1959 | .help = "Use threads instead of forks", | |
1960 | }, | |
1961 | { | |
1962 | .name = "write_bw_log", | |
e3cedca7 | 1963 | .type = FIO_OPT_STR, |
214e1eca | 1964 | .off1 = td_var_offset(write_bw_log), |
e3cedca7 | 1965 | .cb = str_write_bw_log_cb, |
214e1eca JA |
1966 | .help = "Write log of bandwidth during run", |
1967 | }, | |
1968 | { | |
1969 | .name = "write_lat_log", | |
e3cedca7 | 1970 | .type = FIO_OPT_STR, |
214e1eca | 1971 | .off1 = td_var_offset(write_lat_log), |
e3cedca7 | 1972 | .cb = str_write_lat_log_cb, |
214e1eca JA |
1973 | .help = "Write log of latency during run", |
1974 | }, | |
c8eeb9df JA |
1975 | { |
1976 | .name = "write_iops_log", | |
1977 | .type = FIO_OPT_STR, | |
1978 | .off1 = td_var_offset(write_iops_log), | |
1979 | .cb = str_write_iops_log_cb, | |
1980 | .help = "Write log of IOPS during run", | |
1981 | }, | |
214e1eca JA |
1982 | { |
1983 | .name = "hugepage-size", | |
e01b22b8 | 1984 | .type = FIO_OPT_INT, |
214e1eca JA |
1985 | .off1 = td_var_offset(hugepage_size), |
1986 | .help = "When using hugepages, specify size of each page", | |
81179eec | 1987 | .def = __fio_stringify(FIO_HUGE_PAGE), |
214e1eca JA |
1988 | }, |
1989 | { | |
1990 | .name = "group_reporting", | |
1991 | .type = FIO_OPT_STR_SET, | |
1992 | .off1 = td_var_offset(group_reporting), | |
1993 | .help = "Do reporting on a per-group basis", | |
1994 | }, | |
e9459e5a JA |
1995 | { |
1996 | .name = "zero_buffers", | |
1997 | .type = FIO_OPT_STR_SET, | |
1998 | .off1 = td_var_offset(zero_buffers), | |
1999 | .help = "Init IO buffers to all zeroes", | |
2000 | }, | |
5973cafb JA |
2001 | { |
2002 | .name = "refill_buffers", | |
2003 | .type = FIO_OPT_STR_SET, | |
2004 | .off1 = td_var_offset(refill_buffers), | |
2005 | .help = "Refill IO buffers on every IO submit", | |
2006 | }, | |
fd68418e JA |
2007 | { |
2008 | .name = "scramble_buffers", | |
2009 | .type = FIO_OPT_BOOL, | |
2010 | .off1 = td_var_offset(scramble_buffers), | |
2011 | .help = "Slightly scramble buffers on every IO submit", | |
2012 | .def = "1", | |
2013 | }, | |
83349190 YH |
2014 | { |
2015 | .name = "clat_percentiles", | |
2016 | .type = FIO_OPT_BOOL, | |
2017 | .off1 = td_var_offset(clat_percentiles), | |
2018 | .help = "Enable the reporting of completion latency percentiles", | |
2019 | .def = "0", | |
2020 | }, | |
2021 | { | |
2022 | .name = "percentile_list", | |
2023 | .type = FIO_OPT_FLOAT_LIST, | |
2024 | .off1 = td_var_offset(percentile_list), | |
2025 | .off2 = td_var_offset(overwrite_plist), | |
2026 | .help = "Specify a custom list of percentiles to report", | |
2027 | .maxlen = FIO_IO_U_LIST_MAX_LEN, | |
2028 | .minfp = 0.0, | |
2029 | .maxfp = 100.0, | |
2030 | }, | |
2031 | ||
0a839f30 JA |
2032 | #ifdef FIO_HAVE_DISK_UTIL |
2033 | { | |
2034 | .name = "disk_util", | |
2035 | .type = FIO_OPT_BOOL, | |
2036 | .off1 = td_var_offset(do_disk_util), | |
f66ab3c8 | 2037 | .help = "Log disk utilization statistics", |
0a839f30 JA |
2038 | .def = "1", |
2039 | }, | |
2040 | #endif | |
993bf48b JA |
2041 | { |
2042 | .name = "gtod_reduce", | |
2043 | .type = FIO_OPT_BOOL, | |
2044 | .help = "Greatly reduce number of gettimeofday() calls", | |
2045 | .cb = str_gtod_reduce_cb, | |
2046 | .def = "0", | |
2047 | }, | |
02af0988 JA |
2048 | { |
2049 | .name = "disable_lat", | |
2050 | .type = FIO_OPT_BOOL, | |
2051 | .off1 = td_var_offset(disable_lat), | |
2052 | .help = "Disable latency numbers", | |
2053 | .parent = "gtod_reduce", | |
2054 | .def = "0", | |
2055 | }, | |
9520ebb9 JA |
2056 | { |
2057 | .name = "disable_clat", | |
2058 | .type = FIO_OPT_BOOL, | |
2059 | .off1 = td_var_offset(disable_clat), | |
2060 | .help = "Disable completion latency numbers", | |
993bf48b | 2061 | .parent = "gtod_reduce", |
9520ebb9 JA |
2062 | .def = "0", |
2063 | }, | |
2064 | { | |
2065 | .name = "disable_slat", | |
2066 | .type = FIO_OPT_BOOL, | |
2067 | .off1 = td_var_offset(disable_slat), | |
03e20d68 | 2068 | .help = "Disable submission latency numbers", |
993bf48b | 2069 | .parent = "gtod_reduce", |
9520ebb9 JA |
2070 | .def = "0", |
2071 | }, | |
2072 | { | |
2073 | .name = "disable_bw_measurement", | |
2074 | .type = FIO_OPT_BOOL, | |
2075 | .off1 = td_var_offset(disable_bw), | |
2076 | .help = "Disable bandwidth logging", | |
993bf48b | 2077 | .parent = "gtod_reduce", |
9520ebb9 JA |
2078 | .def = "0", |
2079 | }, | |
be4ecfdf JA |
2080 | { |
2081 | .name = "gtod_cpu", | |
2082 | .type = FIO_OPT_INT, | |
2083 | .cb = str_gtod_cpu_cb, | |
03e20d68 | 2084 | .help = "Set up dedicated gettimeofday() thread on this CPU", |
29d43ff9 | 2085 | .verify = gtod_cpu_verify, |
be4ecfdf | 2086 | }, |
f2bba182 RR |
2087 | { |
2088 | .name = "continue_on_error", | |
2089 | .type = FIO_OPT_BOOL, | |
2090 | .off1 = td_var_offset(continue_on_error), | |
03e20d68 | 2091 | .help = "Continue on non-fatal errors during IO", |
f2bba182 RR |
2092 | .def = "0", |
2093 | }, | |
9ac8a797 JA |
2094 | { |
2095 | .name = "profile", | |
79d16311 | 2096 | .type = FIO_OPT_STR_STORE, |
9ac8a797 | 2097 | .off1 = td_var_offset(profile), |
9ac8a797 JA |
2098 | .help = "Select a specific builtin performance test", |
2099 | }, | |
a696fa2a JA |
2100 | { |
2101 | .name = "cgroup", | |
2102 | .type = FIO_OPT_STR_STORE, | |
2103 | .off1 = td_var_offset(cgroup), | |
2104 | .help = "Add job to cgroup of this name", | |
2105 | }, | |
2106 | { | |
2107 | .name = "cgroup_weight", | |
2108 | .type = FIO_OPT_INT, | |
2109 | .off1 = td_var_offset(cgroup_weight), | |
2110 | .help = "Use given weight for cgroup", | |
2111 | .minval = 100, | |
2112 | .maxval = 1000, | |
a696fa2a | 2113 | }, |
7de87099 VG |
2114 | { |
2115 | .name = "cgroup_nodelete", | |
2116 | .type = FIO_OPT_BOOL, | |
2117 | .off1 = td_var_offset(cgroup_nodelete), | |
2118 | .help = "Do not delete cgroups after job completion", | |
2119 | .def = "0", | |
2120 | }, | |
e0b0d892 JA |
2121 | { |
2122 | .name = "uid", | |
2123 | .type = FIO_OPT_INT, | |
2124 | .off1 = td_var_offset(uid), | |
2125 | .help = "Run job with this user ID", | |
2126 | }, | |
2127 | { | |
2128 | .name = "gid", | |
2129 | .type = FIO_OPT_INT, | |
2130 | .off1 = td_var_offset(gid), | |
2131 | .help = "Run job with this group ID", | |
2132 | }, | |
214e1eca JA |
2133 | { |
2134 | .name = NULL, | |
2135 | }, | |
2136 | }; | |
2137 | ||
17af15d4 JA |
2138 | static void add_to_lopt(struct option *lopt, struct fio_option *o, |
2139 | const char *name) | |
9f81736c | 2140 | { |
17af15d4 | 2141 | lopt->name = (char *) name; |
9f81736c JA |
2142 | lopt->val = FIO_GETOPT_JOB; |
2143 | if (o->type == FIO_OPT_STR_SET) | |
2144 | lopt->has_arg = no_argument; | |
2145 | else | |
2146 | lopt->has_arg = required_argument; | |
2147 | } | |
2148 | ||
214e1eca JA |
2149 | void fio_options_dup_and_init(struct option *long_options) |
2150 | { | |
2151 | struct fio_option *o; | |
2152 | unsigned int i; | |
2153 | ||
2154 | options_init(options); | |
2155 | ||
2156 | i = 0; | |
2157 | while (long_options[i].name) | |
2158 | i++; | |
2159 | ||
2160 | o = &options[0]; | |
2161 | while (o->name) { | |
17af15d4 JA |
2162 | add_to_lopt(&long_options[i], o, o->name); |
2163 | if (o->alias) { | |
2164 | i++; | |
2165 | add_to_lopt(&long_options[i], o, o->alias); | |
2166 | } | |
214e1eca JA |
2167 | |
2168 | i++; | |
2169 | o++; | |
2170 | assert(i < FIO_NR_OPTIONS); | |
2171 | } | |
2172 | } | |
2173 | ||
74929ac2 JA |
2174 | struct fio_keyword { |
2175 | const char *word; | |
2176 | const char *desc; | |
2177 | char *replace; | |
2178 | }; | |
2179 | ||
2180 | static struct fio_keyword fio_keywords[] = { | |
2181 | { | |
2182 | .word = "$pagesize", | |
2183 | .desc = "Page size in the system", | |
2184 | }, | |
2185 | { | |
2186 | .word = "$mb_memory", | |
2187 | .desc = "Megabytes of memory online", | |
2188 | }, | |
2189 | { | |
2190 | .word = "$ncpus", | |
2191 | .desc = "Number of CPUs online in the system", | |
2192 | }, | |
2193 | { | |
2194 | .word = NULL, | |
2195 | }, | |
2196 | }; | |
2197 | ||
2198 | void fio_keywords_init(void) | |
2199 | { | |
3b2e1464 | 2200 | unsigned long long mb_memory; |
74929ac2 JA |
2201 | char buf[128]; |
2202 | long l; | |
2203 | ||
2204 | sprintf(buf, "%lu", page_size); | |
2205 | fio_keywords[0].replace = strdup(buf); | |
2206 | ||
8eb016d3 | 2207 | mb_memory = os_phys_mem() / (1024 * 1024); |
3b2e1464 | 2208 | sprintf(buf, "%llu", mb_memory); |
74929ac2 JA |
2209 | fio_keywords[1].replace = strdup(buf); |
2210 | ||
c00a2289 | 2211 | l = cpus_online(); |
74929ac2 JA |
2212 | sprintf(buf, "%lu", l); |
2213 | fio_keywords[2].replace = strdup(buf); | |
2214 | } | |
2215 | ||
892a6ffc JA |
2216 | #define BC_APP "bc" |
2217 | ||
2218 | static char *bc_calc(char *str) | |
2219 | { | |
2220 | char *buf, *tmp, opt[80]; | |
2221 | FILE *f; | |
2222 | int ret; | |
2223 | ||
2224 | /* | |
2225 | * No math, just return string | |
2226 | */ | |
2227 | if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') && | |
2228 | !strchr(str, '/')) | |
2229 | return str; | |
2230 | ||
2231 | /* | |
2232 | * Split option from value, we only need to calculate the value | |
2233 | */ | |
2234 | tmp = strchr(str, '='); | |
2235 | if (!tmp) | |
2236 | return str; | |
2237 | ||
2238 | tmp++; | |
9ac8a797 | 2239 | memset(opt, 0, sizeof(opt)); |
892a6ffc JA |
2240 | strncpy(opt, str, tmp - str); |
2241 | ||
2242 | buf = malloc(128); | |
2243 | ||
2244 | sprintf(buf, "which %s > /dev/null", BC_APP); | |
2245 | if (system(buf)) { | |
2246 | log_err("fio: bc is needed for performing math\n"); | |
2247 | free(buf); | |
2248 | return NULL; | |
2249 | } | |
2250 | ||
2251 | sprintf(buf, "echo %s | %s", tmp, BC_APP); | |
2252 | f = popen(buf, "r"); | |
2253 | if (!f) { | |
2254 | free(buf); | |
2255 | return NULL; | |
2256 | } | |
2257 | ||
2258 | ret = fread(buf, 1, 128, f); | |
2259 | if (ret <= 0) { | |
2260 | free(buf); | |
2261 | return NULL; | |
2262 | } | |
2263 | ||
2264 | buf[ret - 1] = '\0'; | |
2265 | strcat(opt, buf); | |
2266 | strcpy(buf, opt); | |
2267 | pclose(f); | |
2268 | free(str); | |
2269 | return buf; | |
2270 | } | |
2271 | ||
74929ac2 JA |
2272 | /* |
2273 | * Look for reserved variable names and replace them with real values | |
2274 | */ | |
2275 | static char *fio_keyword_replace(char *opt) | |
2276 | { | |
2277 | char *s; | |
2278 | int i; | |
2279 | ||
2280 | for (i = 0; fio_keywords[i].word != NULL; i++) { | |
2281 | struct fio_keyword *kw = &fio_keywords[i]; | |
2282 | ||
2283 | while ((s = strstr(opt, kw->word)) != NULL) { | |
2284 | char *new = malloc(strlen(opt) + 1); | |
2285 | char *o_org = opt; | |
2286 | int olen = s - opt; | |
2287 | int len; | |
2288 | ||
2289 | /* | |
2290 | * Copy part of the string before the keyword and | |
2291 | * sprintf() the replacement after it. | |
2292 | */ | |
2293 | memcpy(new, opt, olen); | |
2294 | len = sprintf(new + olen, "%s", kw->replace); | |
2295 | ||
2296 | /* | |
2297 | * If there's more in the original string, copy that | |
2298 | * in too | |
2299 | */ | |
2300 | opt += strlen(kw->word) + olen; | |
2301 | if (strlen(opt)) | |
2302 | memcpy(new + olen + len, opt, opt - o_org - 1); | |
2303 | ||
2304 | /* | |
2305 | * replace opt and free the old opt | |
2306 | */ | |
2307 | opt = new; | |
9ac8a797 | 2308 | //free(o_org); |
7a958bd5 JA |
2309 | |
2310 | /* | |
2311 | * Check for potential math and invoke bc, if possible | |
2312 | */ | |
2313 | opt = bc_calc(opt); | |
74929ac2 JA |
2314 | } |
2315 | } | |
2316 | ||
7a958bd5 | 2317 | return opt; |
74929ac2 JA |
2318 | } |
2319 | ||
3b8b7135 | 2320 | int fio_options_parse(struct thread_data *td, char **opts, int num_opts) |
214e1eca | 2321 | { |
3b8b7135 JA |
2322 | int i, ret; |
2323 | ||
2324 | sort_options(opts, options, num_opts); | |
2325 | ||
74929ac2 JA |
2326 | for (ret = 0, i = 0; i < num_opts; i++) { |
2327 | opts[i] = fio_keyword_replace(opts[i]); | |
07b3232d | 2328 | ret |= parse_option(opts[i], options, td); |
74929ac2 | 2329 | } |
3b8b7135 JA |
2330 | |
2331 | return ret; | |
214e1eca JA |
2332 | } |
2333 | ||
2334 | int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val) | |
2335 | { | |
07b3232d | 2336 | return parse_cmd_option(opt, val, options, td); |
214e1eca JA |
2337 | } |
2338 | ||
2339 | void fio_fill_default_options(struct thread_data *td) | |
2340 | { | |
2341 | fill_default_options(td, options); | |
2342 | } | |
2343 | ||
2344 | int fio_show_option_help(const char *opt) | |
2345 | { | |
07b3232d | 2346 | return show_cmd_help(options, opt); |
214e1eca | 2347 | } |
d23bb327 JA |
2348 | |
2349 | static void __options_mem(struct thread_data *td, int alloc) | |
2350 | { | |
2351 | struct thread_options *o = &td->o; | |
2352 | struct fio_option *opt; | |
2353 | char **ptr; | |
2354 | int i; | |
2355 | ||
2356 | for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) { | |
2357 | if (opt->type != FIO_OPT_STR_STORE) | |
2358 | continue; | |
2359 | ||
2360 | ptr = (void *) o + opt->off1; | |
2361 | if (*ptr) { | |
2362 | if (alloc) | |
2363 | *ptr = strdup(*ptr); | |
2364 | else { | |
2365 | free(*ptr); | |
2366 | *ptr = NULL; | |
2367 | } | |
2368 | } | |
2369 | } | |
2370 | } | |
2371 | ||
2372 | /* | |
2373 | * dupe FIO_OPT_STR_STORE options | |
2374 | */ | |
2375 | void options_mem_dupe(struct thread_data *td) | |
2376 | { | |
2377 | __options_mem(td, 1); | |
2378 | } | |
2379 | ||
22d66213 | 2380 | void options_mem_free(struct thread_data fio_unused *td) |
d23bb327 | 2381 | { |
22d66213 | 2382 | #if 0 |
d23bb327 | 2383 | __options_mem(td, 0); |
22d66213 | 2384 | #endif |
d23bb327 | 2385 | } |
d6978a32 JA |
2386 | |
2387 | unsigned int fio_get_kb_base(void *data) | |
2388 | { | |
2389 | struct thread_data *td = data; | |
2390 | unsigned int kb_base = 0; | |
2391 | ||
2392 | if (td) | |
2393 | kb_base = td->o.kb_base; | |
2394 | if (!kb_base) | |
2395 | kb_base = 1024; | |
2396 | ||
2397 | return kb_base; | |
2398 | } | |
9f988e2e | 2399 | |
07b3232d | 2400 | int add_option(struct fio_option *o) |
9f988e2e | 2401 | { |
07b3232d JA |
2402 | struct fio_option *__o; |
2403 | int opt_index = 0; | |
2404 | ||
2405 | __o = options; | |
2406 | while (__o->name) { | |
2407 | opt_index++; | |
2408 | __o++; | |
2409 | } | |
2410 | ||
2411 | memcpy(&options[opt_index], o, sizeof(*o)); | |
2412 | return 0; | |
9f988e2e | 2413 | } |
e2de69da | 2414 | |
07b3232d | 2415 | void invalidate_profile_options(const char *prof_name) |
e2de69da | 2416 | { |
07b3232d | 2417 | struct fio_option *o; |
e2de69da | 2418 | |
07b3232d JA |
2419 | o = options; |
2420 | while (o->name) { | |
2421 | if (o->prof_name && !strcmp(o->prof_name, prof_name)) { | |
2422 | o->type = FIO_OPT_INVALID; | |
2423 | o->prof_name = NULL; | |
2424 | } | |
2425 | o++; | |
e2de69da JA |
2426 | } |
2427 | } | |
f5b6bb85 JA |
2428 | |
2429 | void add_opt_posval(const char *optname, const char *ival, const char *help) | |
2430 | { | |
2431 | struct fio_option *o; | |
2432 | unsigned int i; | |
2433 | ||
2434 | o = find_option(options, optname); | |
2435 | if (!o) | |
2436 | return; | |
2437 | ||
2438 | for (i = 0; i < PARSE_MAX_VP; i++) { | |
2439 | if (o->posval[i].ival) | |
2440 | continue; | |
2441 | ||
2442 | o->posval[i].ival = ival; | |
2443 | o->posval[i].help = help; | |
2444 | break; | |
2445 | } | |
2446 | } | |
2447 | ||
2448 | void del_opt_posval(const char *optname, const char *ival) | |
2449 | { | |
2450 | struct fio_option *o; | |
2451 | unsigned int i; | |
2452 | ||
2453 | o = find_option(options, optname); | |
2454 | if (!o) | |
2455 | return; | |
2456 | ||
2457 | for (i = 0; i < PARSE_MAX_VP; i++) { | |
2458 | if (!o->posval[i].ival) | |
2459 | continue; | |
2460 | if (strcmp(o->posval[i].ival, ival)) | |
2461 | continue; | |
2462 | ||
2463 | o->posval[i].ival = NULL; | |
2464 | o->posval[i].help = NULL; | |
2465 | } | |
2466 | } |