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