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