blob: 05a6a5081fa576810c9071506e634077ec27a401 [file] [log] [blame]
Jens Axboe214e1ec2007-03-15 10:48:13 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <ctype.h>
5#include <string.h>
Jens Axboe214e1ec2007-03-15 10:48:13 +01006#include <assert.h>
Jens Axboe921c7662008-03-26 09:17:55 +01007#include <libgen.h>
Jens Axboe5921e802008-05-30 15:02:38 +02008#include <fcntl.h>
9#include <sys/types.h>
10#include <sys/stat.h>
Jens Axboe214e1ec2007-03-15 10:48:13 +010011
12#include "fio.h"
Jens Axboe4f5af7b2009-06-03 08:45:40 +020013#include "verify.h"
Jens Axboe214e1ec2007-03-15 10:48:13 +010014#include "parse.h"
Jens Axboeeef32352008-06-02 13:31:26 +020015#include "lib/fls.h"
Jens Axboe9f988e22010-03-04 10:42:38 +010016#include "options.h"
Jens Axboe214e1ec2007-03-15 10:48:13 +010017
Jens Axboe5d7c5d32010-06-21 15:08:17 +020018#include "crc/crc32c.h"
19
Jens Axboe214e1ec2007-03-15 10:48:13 +010020/*
21 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
22 */
23static char *get_opt_postfix(const char *str)
24{
25 char *p = strstr(str, ":");
26
27 if (!p)
28 return NULL;
29
30 p++;
31 strip_blank_front(&p);
32 strip_blank_end(p);
33 return strdup(p);
34}
35
Radha Ramachandran0e92f872009-10-27 20:14:27 +010036static int converthexchartoint(char a)
37{
38 int base;
39
40 switch(a) {
41 case '0'...'9':
42 base = '0';
43 break;
44 case 'A'...'F':
45 base = 'A' - 10;
46 break;
47 case 'a'...'f':
48 base = 'a' - 10;
49 break;
50 default:
51 base = 0;
52 }
53 return (a - base);
54}
55
Jens Axboe564ca972007-12-14 12:21:19 +010056static int bs_cmp(const void *p1, const void *p2)
57{
58 const struct bssplit *bsp1 = p1;
59 const struct bssplit *bsp2 = p2;
60
61 return bsp1->perc < bsp2->perc;
62}
63
Jens Axboe720e84a2009-04-21 08:29:55 +020064static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
Jens Axboe564ca972007-12-14 12:21:19 +010065{
Jens Axboe720e84a2009-04-21 08:29:55 +020066 struct bssplit *bssplit;
Jens Axboe564ca972007-12-14 12:21:19 +010067 unsigned int i, perc, perc_missing;
68 unsigned int max_bs, min_bs;
69 long long val;
Jens Axboe720e84a2009-04-21 08:29:55 +020070 char *fname;
Jens Axboe564ca972007-12-14 12:21:19 +010071
Jens Axboe720e84a2009-04-21 08:29:55 +020072 td->o.bssplit_nr[ddir] = 4;
73 bssplit = malloc(4 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010074
75 i = 0;
76 max_bs = 0;
77 min_bs = -1;
78 while ((fname = strsep(&str, ":")) != NULL) {
79 char *perc_str;
80
81 if (!strlen(fname))
82 break;
83
84 /*
85 * grow struct buffer, if needed
86 */
Jens Axboe720e84a2009-04-21 08:29:55 +020087 if (i == td->o.bssplit_nr[ddir]) {
88 td->o.bssplit_nr[ddir] <<= 1;
89 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
Jens Axboe5ec10ea2008-03-06 15:42:00 +010090 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010091 }
92
93 perc_str = strstr(fname, "/");
94 if (perc_str) {
95 *perc_str = '\0';
96 perc_str++;
97 perc = atoi(perc_str);
98 if (perc > 100)
99 perc = 100;
100 else if (!perc)
101 perc = -1;
102 } else
103 perc = -1;
104
Jens Axboe6925dd32011-09-07 22:10:11 +0200105 if (str_to_decimal(fname, &val, 1, td)) {
Jens Axboe564ca972007-12-14 12:21:19 +0100106 log_err("fio: bssplit conversion failed\n");
107 free(td->o.bssplit);
108 return 1;
109 }
110
111 if (val > max_bs)
112 max_bs = val;
113 if (val < min_bs)
114 min_bs = val;
115
Jens Axboe720e84a2009-04-21 08:29:55 +0200116 bssplit[i].bs = val;
117 bssplit[i].perc = perc;
Jens Axboe564ca972007-12-14 12:21:19 +0100118 i++;
119 }
120
Jens Axboe720e84a2009-04-21 08:29:55 +0200121 td->o.bssplit_nr[ddir] = i;
Jens Axboe564ca972007-12-14 12:21:19 +0100122
123 /*
124 * Now check if the percentages add up, and how much is missing
125 */
126 perc = perc_missing = 0;
Jens Axboe720e84a2009-04-21 08:29:55 +0200127 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
128 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100129
130 if (bsp->perc == (unsigned char) -1)
131 perc_missing++;
132 else
133 perc += bsp->perc;
134 }
135
136 if (perc > 100) {
137 log_err("fio: bssplit percentages add to more than 100%%\n");
Jens Axboe720e84a2009-04-21 08:29:55 +0200138 free(bssplit);
Jens Axboe564ca972007-12-14 12:21:19 +0100139 return 1;
140 }
141 /*
142 * If values didn't have a percentage set, divide the remains between
143 * them.
144 */
145 if (perc_missing) {
Jens Axboe720e84a2009-04-21 08:29:55 +0200146 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
147 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100148
149 if (bsp->perc == (unsigned char) -1)
150 bsp->perc = (100 - perc) / perc_missing;
151 }
152 }
153
Jens Axboe720e84a2009-04-21 08:29:55 +0200154 td->o.min_bs[ddir] = min_bs;
155 td->o.max_bs[ddir] = max_bs;
Jens Axboe564ca972007-12-14 12:21:19 +0100156
157 /*
158 * now sort based on percentages, for ease of lookup
159 */
Jens Axboe720e84a2009-04-21 08:29:55 +0200160 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161 td->o.bssplit[ddir] = bssplit;
162 return 0;
163
164}
165
166static int str_bssplit_cb(void *data, const char *input)
167{
168 struct thread_data *td = data;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200169 char *str, *p, *odir, *ddir;
Jens Axboe720e84a2009-04-21 08:29:55 +0200170 int ret = 0;
171
172 p = str = strdup(input);
173
174 strip_blank_front(&str);
175 strip_blank_end(str);
176
177 odir = strchr(str, ',');
178 if (odir) {
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200179 ddir = strchr(odir + 1, ',');
180 if (ddir) {
181 ret = bssplit_ddir(td, DDIR_TRIM, ddir + 1);
182 if (!ret)
183 *ddir = '\0';
184 } else {
185 char *op;
186
187 op = strdup(odir + 1);
188 ret = bssplit_ddir(td, DDIR_TRIM, op);
189
190 free(op);
191 }
192 if (!ret)
193 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
Jens Axboe720e84a2009-04-21 08:29:55 +0200194 if (!ret) {
195 *odir = '\0';
196 ret = bssplit_ddir(td, DDIR_READ, str);
197 }
198 } else {
199 char *op;
200
201 op = strdup(str);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200202 ret = bssplit_ddir(td, DDIR_WRITE, op);
Jens Axboe720e84a2009-04-21 08:29:55 +0200203 free(op);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200204
205 if (!ret) {
206 op = strdup(str);
207 ret = bssplit_ddir(td, DDIR_TRIM, op);
208 free(op);
209 }
210 ret = bssplit_ddir(td, DDIR_READ, str);
Jens Axboe720e84a2009-04-21 08:29:55 +0200211 }
Jens Axboe564ca972007-12-14 12:21:19 +0100212
213 free(p);
Jens Axboe720e84a2009-04-21 08:29:55 +0200214 return ret;
Jens Axboe564ca972007-12-14 12:21:19 +0100215}
216
Dmitry Monakhov8b28bd42012-09-23 15:46:09 +0400217static int str2error(char *str)
218{
219 const char * err[] = {"EPERM", "ENOENT", "ESRCH", "EINTR", "EIO",
220 "ENXIO", "E2BIG", "ENOEXEC", "EBADF",
221 "ECHILD", "EAGAIN", "ENOMEM", "EACCES",
222 "EFAULT", "ENOTBLK", "EBUSY", "EEXIST",
223 "EXDEV", "ENODEV", "ENOTDIR", "EISDIR",
224 "EINVAL", "ENFILE", "EMFILE", "ENOTTY",
225 "ETXTBSY","EFBIG", "ENOSPC", "ESPIPE",
226 "EROFS","EMLINK", "EPIPE", "EDOM", "ERANGE"};
227 int i = 0, num = sizeof(err) / sizeof(void *);
228
229 while( i < num) {
230 if (!strcmp(err[i], str))
231 return i + 1;
232 i++;
233 }
234 return 0;
235}
236
237static int ignore_error_type(struct thread_data *td, int etype, char *str)
238{
239 unsigned int i;
240 int *error;
241 char *fname;
242
243 if (etype >= ERROR_TYPE_CNT) {
244 log_err("Illegal error type\n");
245 return 1;
246 }
247
248 td->o.ignore_error_nr[etype] = 4;
249 error = malloc(4 * sizeof(struct bssplit));
250
251 i = 0;
252 while ((fname = strsep(&str, ":")) != NULL) {
253
254 if (!strlen(fname))
255 break;
256
257 /*
258 * grow struct buffer, if needed
259 */
260 if (i == td->o.ignore_error_nr[etype]) {
261 td->o.ignore_error_nr[etype] <<= 1;
262 error = realloc(error, td->o.ignore_error_nr[etype]
263 * sizeof(int));
264 }
265 if (fname[0] == 'E') {
266 error[i] = str2error(fname);
267 } else {
268 error[i] = atoi(fname);
269 if (error[i] < 0)
270 error[i] = error[i];
271 }
272 if (!error[i]) {
273 log_err("Unknown error %s, please use number value \n",
274 fname);
275 return 1;
276 }
277 i++;
278 }
279 if (i) {
280 td->o.continue_on_error |= 1 << etype;
281 td->o.ignore_error_nr[etype] = i;
282 td->o.ignore_error[etype] = error;
283 }
284 return 0;
285
286}
287
288static int str_ignore_error_cb(void *data, const char *input)
289{
290 struct thread_data *td = data;
291 char *str, *p, *n;
292 int type = 0, ret = 1;
293 p = str = strdup(input);
294
295 strip_blank_front(&str);
296 strip_blank_end(str);
297
298 while (p) {
299 n = strchr(p, ',');
300 if (n)
301 *n++ = '\0';
302 ret = ignore_error_type(td, type, p);
303 if (ret)
304 break;
305 p = n;
306 type++;
307 }
308 free(str);
309 return ret;
310}
311
Jens Axboe211097b2007-03-22 18:56:45 +0100312static int str_rw_cb(void *data, const char *str)
313{
314 struct thread_data *td = data;
315 char *nr = get_opt_postfix(str);
316
Jens Axboe5736c102010-07-20 12:03:25 -0600317 td->o.ddir_seq_nr = 1;
Jens Axboe059b0802011-08-25 09:09:37 +0200318 td->o.ddir_seq_add = 0;
319
320 if (!nr)
321 return 0;
322
323 if (td_random(td))
Jens Axboe5736c102010-07-20 12:03:25 -0600324 td->o.ddir_seq_nr = atoi(nr);
Jens Axboe059b0802011-08-25 09:09:37 +0200325 else {
326 long long val;
327
Jens Axboe6925dd32011-09-07 22:10:11 +0200328 if (str_to_decimal(nr, &val, 1, td)) {
Jens Axboe059b0802011-08-25 09:09:37 +0200329 log_err("fio: rw postfix parsing failed\n");
330 free(nr);
331 return 1;
332 }
333
334 td->o.ddir_seq_add = val;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100335 }
Jens Axboe211097b2007-03-22 18:56:45 +0100336
Jens Axboe059b0802011-08-25 09:09:37 +0200337 free(nr);
Jens Axboe211097b2007-03-22 18:56:45 +0100338 return 0;
339}
340
Jens Axboe214e1ec2007-03-15 10:48:13 +0100341static int str_mem_cb(void *data, const char *mem)
342{
343 struct thread_data *td = data;
344
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100345 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100346 td->mmapfile = get_opt_postfix(mem);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100347 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100348 log_err("fio: mmaphuge:/path/to/file\n");
349 return 1;
350 }
351 }
352
353 return 0;
354}
355
Jens Axboe5d7c5d32010-06-21 15:08:17 +0200356static int str_verify_cb(void *data, const char *mem)
357{
358 struct thread_data *td = data;
359
Jens Axboee3aaafc2012-02-22 20:28:17 +0100360 if (td->o.verify == VERIFY_CRC32C_INTEL ||
361 td->o.verify == VERIFY_CRC32C) {
362 crc32c_intel_probe();
Jens Axboe5d7c5d32010-06-21 15:08:17 +0200363 }
364
365 return 0;
366}
367
Jens Axboec223da82010-03-24 13:23:53 +0100368static int fio_clock_source_cb(void *data, const char *str)
369{
370 struct thread_data *td = data;
371
372 fio_clock_source = td->o.clocksource;
373 fio_time_init();
374 return 0;
375}
376
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400377static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100378{
379 mlock_size = *val;
380 return 0;
381}
382
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400383static int str_rwmix_read_cb(void *data, unsigned long long *val)
Jens Axboecb499fc2008-05-28 10:33:32 +0200384{
385 struct thread_data *td = data;
386
387 td->o.rwmix[DDIR_READ] = *val;
388 td->o.rwmix[DDIR_WRITE] = 100 - *val;
389 return 0;
390}
391
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400392static int str_rwmix_write_cb(void *data, unsigned long long *val)
Jens Axboecb499fc2008-05-28 10:33:32 +0200393{
394 struct thread_data *td = data;
395
396 td->o.rwmix[DDIR_WRITE] = *val;
397 td->o.rwmix[DDIR_READ] = 100 - *val;
398 return 0;
399}
400
Jens Axboe214e1ec2007-03-15 10:48:13 +0100401#ifdef FIO_HAVE_IOPRIO
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400402static int str_prioclass_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100403{
404 struct thread_data *td = data;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200405 unsigned short mask;
406
407 /*
408 * mask off old class bits, str_prio_cb() may have set a default class
409 */
410 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
411 td->ioprio &= mask;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100412
413 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
Jens Axboeac684782007-11-08 08:29:07 +0100414 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100415 return 0;
416}
417
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400418static int str_prio_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100419{
420 struct thread_data *td = data;
421
422 td->ioprio |= *val;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200423
424 /*
425 * If no class is set, assume BE
426 */
427 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
428 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
429
Jens Axboeac684782007-11-08 08:29:07 +0100430 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100431 return 0;
432}
433#endif
434
435static int str_exitall_cb(void)
436{
437 exitall_on_terminate = 1;
438 return 0;
439}
440
Jens Axboe214e1ec2007-03-15 10:48:13 +0100441#ifdef FIO_HAVE_CPU_AFFINITY
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400442static int str_cpumask_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100443{
444 struct thread_data *td = data;
Jens Axboed2e268b2007-06-15 10:33:49 +0200445 unsigned int i;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100446 long max_cpu;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100447 int ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100448
Jens Axboed2ce18b2008-12-12 20:51:40 +0100449 ret = fio_cpuset_init(&td->o.cpumask);
450 if (ret < 0) {
451 log_err("fio: cpuset_init failed\n");
452 td_verror(td, ret, "fio_cpuset_init");
453 return 1;
454 }
455
Jens Axboec00a2282011-07-08 20:56:06 +0200456 max_cpu = cpus_online();
Jens Axboed2e268b2007-06-15 10:33:49 +0200457
Jens Axboe62a72732008-12-08 11:37:01 +0100458 for (i = 0; i < sizeof(int) * 8; i++) {
459 if ((1 << i) & *val) {
Jens Axboeb03daaf2008-12-08 20:31:43 +0100460 if (i > max_cpu) {
461 log_err("fio: CPU %d too large (max=%ld)\n", i,
462 max_cpu);
463 return 1;
464 }
Jens Axboe62a72732008-12-08 11:37:01 +0100465 dprint(FD_PARSE, "set cpu allowed %d\n", i);
Jens Axboe6d459ee2008-12-12 20:02:58 +0100466 fio_cpu_set(&td->o.cpumask, i);
Jens Axboe62a72732008-12-08 11:37:01 +0100467 }
468 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200469
Jens Axboe375b2692007-05-22 09:13:02 +0200470 td->o.cpumask_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100471 return 0;
472}
473
Jens Axboee8462bd2009-07-06 12:59:04 +0200474static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
475 const char *input)
Jens Axboed2e268b2007-06-15 10:33:49 +0200476{
Jens Axboed2e268b2007-06-15 10:33:49 +0200477 char *cpu, *str, *p;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100478 long max_cpu;
Jens Axboe19608d62008-12-08 15:03:12 +0100479 int ret = 0;
Jens Axboed2e268b2007-06-15 10:33:49 +0200480
Jens Axboee8462bd2009-07-06 12:59:04 +0200481 ret = fio_cpuset_init(mask);
Jens Axboed2ce18b2008-12-12 20:51:40 +0100482 if (ret < 0) {
483 log_err("fio: cpuset_init failed\n");
484 td_verror(td, ret, "fio_cpuset_init");
485 return 1;
486 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200487
488 p = str = strdup(input);
489
490 strip_blank_front(&str);
491 strip_blank_end(str);
492
Jens Axboec00a2282011-07-08 20:56:06 +0200493 max_cpu = cpus_online();
Jens Axboeb03daaf2008-12-08 20:31:43 +0100494
Jens Axboed2e268b2007-06-15 10:33:49 +0200495 while ((cpu = strsep(&str, ",")) != NULL) {
Jens Axboe62a72732008-12-08 11:37:01 +0100496 char *str2, *cpu2;
497 int icpu, icpu2;
498
Jens Axboed2e268b2007-06-15 10:33:49 +0200499 if (!strlen(cpu))
500 break;
Jens Axboe62a72732008-12-08 11:37:01 +0100501
502 str2 = cpu;
503 icpu2 = -1;
504 while ((cpu2 = strsep(&str2, "-")) != NULL) {
505 if (!strlen(cpu2))
506 break;
507
508 icpu2 = atoi(cpu2);
509 }
510
511 icpu = atoi(cpu);
512 if (icpu2 == -1)
513 icpu2 = icpu;
514 while (icpu <= icpu2) {
Jens Axboe6d459ee2008-12-12 20:02:58 +0100515 if (icpu >= FIO_MAX_CPUS) {
Jens Axboe19608d62008-12-08 15:03:12 +0100516 log_err("fio: your OS only supports up to"
Jens Axboe6d459ee2008-12-12 20:02:58 +0100517 " %d CPUs\n", (int) FIO_MAX_CPUS);
Jens Axboe19608d62008-12-08 15:03:12 +0100518 ret = 1;
519 break;
520 }
Jens Axboeb03daaf2008-12-08 20:31:43 +0100521 if (icpu > max_cpu) {
522 log_err("fio: CPU %d too large (max=%ld)\n",
523 icpu, max_cpu);
524 ret = 1;
525 break;
526 }
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200527
Jens Axboe62a72732008-12-08 11:37:01 +0100528 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
Jens Axboee8462bd2009-07-06 12:59:04 +0200529 fio_cpu_set(mask, icpu);
Jens Axboe62a72732008-12-08 11:37:01 +0100530 icpu++;
531 }
Jens Axboe19608d62008-12-08 15:03:12 +0100532 if (ret)
533 break;
Jens Axboed2e268b2007-06-15 10:33:49 +0200534 }
535
536 free(p);
Jens Axboe19608d62008-12-08 15:03:12 +0100537 if (!ret)
538 td->o.cpumask_set = 1;
539 return ret;
Jens Axboed2e268b2007-06-15 10:33:49 +0200540}
Jens Axboee8462bd2009-07-06 12:59:04 +0200541
542static int str_cpus_allowed_cb(void *data, const char *input)
543{
544 struct thread_data *td = data;
545 int ret;
546
547 ret = set_cpus_allowed(td, &td->o.cpumask, input);
548 if (!ret)
549 td->o.cpumask_set = 1;
550
551 return ret;
552}
553
554static int str_verify_cpus_allowed_cb(void *data, const char *input)
555{
556 struct thread_data *td = data;
557 int ret;
558
559 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
560 if (!ret)
561 td->o.verify_cpumask_set = 1;
562
563 return ret;
564}
Jens Axboed2e268b2007-06-15 10:33:49 +0200565#endif
566
Yufei Rend0b937e2012-10-19 23:11:52 -0400567#ifdef FIO_HAVE_LIBNUMA
568static int str_numa_cpunodes_cb(void *data, char *input)
569{
570 struct thread_data *td = data;
571
572 /* numa_parse_nodestring() parses a character string list
573 * of nodes into a bit mask. The bit mask is allocated by
574 * numa_allocate_nodemask(), so it should be freed by
575 * numa_free_nodemask().
576 */
577 td->o.numa_cpunodesmask = numa_parse_nodestring(input);
578 if (td->o.numa_cpunodesmask == NULL) {
579 log_err("fio: numa_parse_nodestring failed\n");
580 td_verror(td, 1, "str_numa_cpunodes_cb");
581 return 1;
582 }
583
584 td->o.numa_cpumask_set = 1;
585 return 0;
586}
587
588static int str_numa_mpol_cb(void *data, char *input)
589{
590 struct thread_data *td = data;
591 const char * const policy_types[] =
592 { "default", "prefer", "bind", "interleave", "local" };
593 int i;
594
595 char *nodelist = strchr(input, ':');
596 if (nodelist) {
597 /* NUL-terminate mode */
598 *nodelist++ = '\0';
599 }
600
601 for (i = 0; i <= MPOL_LOCAL; i++) {
602 if (!strcmp(input, policy_types[i])) {
603 td->o.numa_mem_mode = i;
604 break;
605 }
606 }
607 if (i > MPOL_LOCAL) {
608 log_err("fio: memory policy should be: default, prefer, bind, interleave, local\n");
609 goto out;
610 }
611
612 switch (td->o.numa_mem_mode) {
613 case MPOL_PREFERRED:
614 /*
615 * Insist on a nodelist of one node only
616 */
617 if (nodelist) {
618 char *rest = nodelist;
619 while (isdigit(*rest))
620 rest++;
621 if (*rest) {
622 log_err("fio: one node only for \'prefer\'\n");
623 goto out;
624 }
625 } else {
626 log_err("fio: one node is needed for \'prefer\'\n");
627 goto out;
628 }
629 break;
630 case MPOL_INTERLEAVE:
631 /*
632 * Default to online nodes with memory if no nodelist
633 */
634 if (!nodelist)
635 nodelist = strdup("all");
636 break;
637 case MPOL_LOCAL:
638 case MPOL_DEFAULT:
639 /*
640 * Don't allow a nodelist
641 */
642 if (nodelist) {
643 log_err("fio: NO nodelist for \'local\'\n");
644 goto out;
645 }
646 break;
647 case MPOL_BIND:
648 /*
649 * Insist on a nodelist
650 */
651 if (!nodelist) {
652 log_err("fio: a nodelist is needed for \'bind\'\n");
653 goto out;
654 }
655 break;
656 }
657
658
659 /* numa_parse_nodestring() parses a character string list
660 * of nodes into a bit mask. The bit mask is allocated by
661 * numa_allocate_nodemask(), so it should be freed by
662 * numa_free_nodemask().
663 */
664 switch (td->o.numa_mem_mode) {
665 case MPOL_PREFERRED:
666 td->o.numa_mem_prefer_node = atoi(nodelist);
667 break;
668 case MPOL_INTERLEAVE:
669 case MPOL_BIND:
670 td->o.numa_memnodesmask = numa_parse_nodestring(nodelist);
671 if (td->o.numa_memnodesmask == NULL) {
672 log_err("fio: numa_parse_nodestring failed\n");
673 td_verror(td, 1, "str_numa_memnodes_cb");
674 return 1;
675 }
676 break;
677 case MPOL_LOCAL:
678 case MPOL_DEFAULT:
679 default:
680 break;
681 }
682
683 td->o.numa_memmask_set = 1;
684 return 0;
685
686out:
687 return 1;
688}
689#endif
690
Jens Axboe0d29de82010-09-01 13:54:15 +0200691#ifdef FIO_HAVE_TRIM
692static int str_verify_trim_cb(void *data, unsigned long long *val)
693{
694 struct thread_data *td = data;
695
696 td->o.trim_percentage = *val;
697 return 0;
698}
699#endif
700
Jens Axboe214e1ec2007-03-15 10:48:13 +0100701static int str_fst_cb(void *data, const char *str)
702{
703 struct thread_data *td = data;
704 char *nr = get_opt_postfix(str);
705
706 td->file_service_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100707 if (nr) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100708 td->file_service_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100709 free(nr);
710 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100711
712 return 0;
713}
714
Jens Axboe3ae06372010-03-19 19:17:15 +0100715#ifdef FIO_HAVE_SYNC_FILE_RANGE
Jens Axboe44f29692010-03-09 20:09:44 +0100716static int str_sfr_cb(void *data, const char *str)
717{
718 struct thread_data *td = data;
719 char *nr = get_opt_postfix(str);
720
721 td->sync_file_range_nr = 1;
722 if (nr) {
723 td->sync_file_range_nr = atoi(nr);
724 free(nr);
725 }
726
727 return 0;
728}
Jens Axboe3ae06372010-03-19 19:17:15 +0100729#endif
Jens Axboe44f29692010-03-09 20:09:44 +0100730
Jens Axboee25839d2012-11-06 10:49:42 +0100731static int str_random_distribution_cb(void *data, const char *str)
732{
733 struct thread_data *td = data;
734 double val;
735 char *nr;
736
737 if (td->o.random_distribution == FIO_RAND_DIST_RANDOM)
738 return 0;
739
740 nr = get_opt_postfix(str);
741 if (!nr)
742 val = 0.6;
743 else if (!str_to_float(nr, &val)) {
744 log_err("fio: random postfix parsing failed\n");
745 free(nr);
746 return 1;
747 }
748
749 td->o.zipf_theta = val;
750 free(nr);
751 return 0;
752}
753
Jens Axboe921c7662008-03-26 09:17:55 +0100754static int check_dir(struct thread_data *td, char *fname)
755{
Jens Axboe3f0ca9b2011-05-24 21:36:24 +0200756#if 0
Jens Axboe921c7662008-03-26 09:17:55 +0100757 char file[PATH_MAX], *dir;
Jens Axboebc838912008-04-07 09:00:54 +0200758 int elen = 0;
Jens Axboe921c7662008-03-26 09:17:55 +0100759
Jens Axboebc838912008-04-07 09:00:54 +0200760 if (td->o.directory) {
761 strcpy(file, td->o.directory);
Jens Axboefcef0b32008-05-26 14:53:24 +0200762 strcat(file, "/");
Jens Axboebc838912008-04-07 09:00:54 +0200763 elen = strlen(file);
764 }
765
Jens Axboefcef0b32008-05-26 14:53:24 +0200766 sprintf(file + elen, "%s", fname);
Jens Axboe921c7662008-03-26 09:17:55 +0100767 dir = dirname(file);
768
Jens Axboefcef0b32008-05-26 14:53:24 +0200769 {
770 struct stat sb;
771 /*
772 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
773 * yet, so we can't do this check right here...
774 */
Jens Axboe921c7662008-03-26 09:17:55 +0100775 if (lstat(dir, &sb) < 0) {
776 int ret = errno;
777
778 log_err("fio: %s is not a directory\n", dir);
779 td_verror(td, ret, "lstat");
780 return 1;
781 }
782
783 if (!S_ISDIR(sb.st_mode)) {
784 log_err("fio: %s is not a directory\n", dir);
785 return 1;
786 }
Jens Axboefcef0b32008-05-26 14:53:24 +0200787 }
788#endif
Jens Axboe921c7662008-03-26 09:17:55 +0100789
790 return 0;
791}
792
Jens Axboe8e827d32009-08-04 09:51:48 +0200793/*
794 * Return next file in the string. Files are separated with ':'. If the ':'
795 * is escaped with a '\', then that ':' is part of the filename and does not
796 * indicate a new file.
797 */
798static char *get_next_file_name(char **ptr)
799{
800 char *str = *ptr;
801 char *p, *start;
802
803 if (!str || !strlen(str))
804 return NULL;
805
806 start = str;
807 do {
808 /*
809 * No colon, we are done
810 */
811 p = strchr(str, ':');
812 if (!p) {
813 *ptr = NULL;
814 break;
815 }
816
817 /*
818 * We got a colon, but it's the first character. Skip and
819 * continue
820 */
821 if (p == start) {
822 str = ++start;
823 continue;
824 }
825
826 if (*(p - 1) != '\\') {
827 *p = '\0';
828 *ptr = p + 1;
829 break;
830 }
831
832 memmove(p - 1, p, strlen(p) + 1);
833 str = p;
834 } while (1);
835
836 return start;
837}
838
Jens Axboe214e1ec2007-03-15 10:48:13 +0100839static int str_filename_cb(void *data, const char *input)
840{
841 struct thread_data *td = data;
842 char *fname, *str, *p;
843
844 p = str = strdup(input);
845
846 strip_blank_front(&str);
847 strip_blank_end(str);
848
849 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100850 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100851
Jens Axboe8e827d32009-08-04 09:51:48 +0200852 while ((fname = get_next_file_name(&str)) != NULL) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100853 if (!strlen(fname))
854 break;
Jens Axboe921c7662008-03-26 09:17:55 +0100855 if (check_dir(td, fname)) {
856 free(p);
857 return 1;
858 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100859 add_file(td, fname);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100860 td->o.nr_files++;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100861 }
862
863 free(p);
864 return 0;
865}
866
867static int str_directory_cb(void *data, const char fio_unused *str)
868{
869 struct thread_data *td = data;
870 struct stat sb;
871
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100872 if (lstat(td->o.directory, &sb) < 0) {
Jens Axboe921c7662008-03-26 09:17:55 +0100873 int ret = errno;
874
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100875 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe921c7662008-03-26 09:17:55 +0100876 td_verror(td, ret, "lstat");
Jens Axboe214e1ec2007-03-15 10:48:13 +0100877 return 1;
878 }
879 if (!S_ISDIR(sb.st_mode)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100880 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100881 return 1;
882 }
883
884 return 0;
885}
886
887static int str_opendir_cb(void *data, const char fio_unused *str)
888{
889 struct thread_data *td = data;
890
891 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100892 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100893
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100894 return add_dir_files(td, td->o.opendir);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100895}
896
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400897static int str_verify_offset_cb(void *data, unsigned long long *off)
Shawn Lewis546a9142007-07-28 21:11:37 +0200898{
899 struct thread_data *td = data;
Jens Axboea59e1702007-07-30 08:53:27 +0200900
Shawn Lewis546a9142007-07-28 21:11:37 +0200901 if (*off && *off < sizeof(struct verify_header)) {
Jens Axboea59e1702007-07-30 08:53:27 +0200902 log_err("fio: verify_offset too small\n");
Shawn Lewis546a9142007-07-28 21:11:37 +0200903 return 1;
904 }
Jens Axboea59e1702007-07-30 08:53:27 +0200905
906 td->o.verify_offset = *off;
Shawn Lewis546a9142007-07-28 21:11:37 +0200907 return 0;
908}
909
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100910static int str_verify_pattern_cb(void *data, const char *input)
Jens Axboe90059d62007-07-30 09:33:12 +0200911{
912 struct thread_data *td = data;
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100913 long off;
914 int i = 0, j = 0, len, k, base = 10;
915 char* loc1, * loc2;
Jens Axboe90059d62007-07-30 09:33:12 +0200916
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100917 loc1 = strstr(input, "0x");
918 loc2 = strstr(input, "0X");
919 if (loc1 || loc2)
920 base = 16;
921 off = strtol(input, NULL, base);
922 if (off != LONG_MAX || errno != ERANGE) {
923 while (off) {
924 td->o.verify_pattern[i] = off & 0xff;
925 off >>= 8;
926 i++;
927 }
928 } else {
929 len = strlen(input);
930 k = len - 1;
931 if (base == 16) {
932 if (loc1)
933 j = loc1 - input + 2;
934 else
935 j = loc2 - input + 2;
936 } else
937 return 1;
938 if (len - j < MAX_PATTERN_SIZE * 2) {
939 while (k >= j) {
940 off = converthexchartoint(input[k--]);
941 if (k >= j)
942 off += (converthexchartoint(input[k--])
943 * 16);
944 td->o.verify_pattern[i++] = (char) off;
945 }
946 }
947 }
Steven Langefcd9dc2012-02-02 20:22:04 +0100948
949 /*
950 * Fill the pattern all the way to the end. This greatly reduces
951 * the number of memcpy's we have to do when verifying the IO.
952 */
953 while (i > 1 && i * 2 <= MAX_PATTERN_SIZE) {
954 memcpy(&td->o.verify_pattern[i], &td->o.verify_pattern[0], i);
955 i *= 2;
956 }
Steven Lang9a2a86d2012-02-07 09:42:59 +0100957 if (i == 1) {
958 /*
959 * The code in verify_io_u_pattern assumes a single byte pattern
960 * fills the whole verify pattern buffer.
961 */
962 memset(td->o.verify_pattern, td->o.verify_pattern[0],
963 MAX_PATTERN_SIZE);
964 }
Steven Langefcd9dc2012-02-02 20:22:04 +0100965
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100966 td->o.verify_pattern_bytes = i;
Steven Langefcd9dc2012-02-02 20:22:04 +0100967
Jens Axboe92bf48d2011-01-14 21:20:42 +0100968 /*
969 * VERIFY_META could already be set
970 */
971 if (td->o.verify == VERIFY_NONE)
972 td->o.verify = VERIFY_PATTERN;
Steven Langefcd9dc2012-02-02 20:22:04 +0100973
Jens Axboe90059d62007-07-30 09:33:12 +0200974 return 0;
975}
Jens Axboe214e1ec2007-03-15 10:48:13 +0100976
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100977static int str_lockfile_cb(void *data, const char *str)
978{
979 struct thread_data *td = data;
980 char *nr = get_opt_postfix(str);
981
982 td->o.lockfile_batch = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100983 if (nr) {
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100984 td->o.lockfile_batch = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100985 free(nr);
986 }
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100987
988 return 0;
989}
990
Jens Axboee3cedca2008-11-19 19:57:52 +0100991static int str_write_bw_log_cb(void *data, const char *str)
992{
993 struct thread_data *td = data;
994
995 if (str)
996 td->o.bw_log_file = strdup(str);
997
998 td->o.write_bw_log = 1;
999 return 0;
1000}
1001
1002static int str_write_lat_log_cb(void *data, const char *str)
1003{
1004 struct thread_data *td = data;
1005
1006 if (str)
1007 td->o.lat_log_file = strdup(str);
1008
1009 td->o.write_lat_log = 1;
1010 return 0;
1011}
1012
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001013static int str_write_iops_log_cb(void *data, const char *str)
1014{
1015 struct thread_data *td = data;
1016
1017 if (str)
1018 td->o.iops_log_file = strdup(str);
1019
1020 td->o.write_iops_log = 1;
1021 return 0;
1022}
1023
Jens Axboe993bf482008-11-14 13:04:53 +01001024static int str_gtod_reduce_cb(void *data, int *il)
1025{
1026 struct thread_data *td = data;
1027 int val = *il;
1028
Jens Axboe02af0982010-06-24 09:59:34 +02001029 td->o.disable_lat = !!val;
Jens Axboe993bf482008-11-14 13:04:53 +01001030 td->o.disable_clat = !!val;
1031 td->o.disable_slat = !!val;
1032 td->o.disable_bw = !!val;
Jens Axboe0dc1bc02011-10-13 08:55:29 +02001033 td->o.clat_percentiles = !val;
Jens Axboe993bf482008-11-14 13:04:53 +01001034 if (val)
1035 td->tv_cache_mask = 63;
1036
1037 return 0;
1038}
1039
Cigy Cyriac85bc8332010-08-10 19:21:09 -04001040static int str_gtod_cpu_cb(void *data, long long *il)
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001041{
1042 struct thread_data *td = data;
1043 int val = *il;
1044
1045 td->o.gtod_cpu = val;
1046 td->o.gtod_offload = 1;
1047 return 0;
1048}
1049
Jens Axboe7bb59102011-07-12 19:47:03 +02001050static int str_size_cb(void *data, unsigned long long *__val)
1051{
1052 struct thread_data *td = data;
1053 unsigned long long v = *__val;
1054
1055 if (parse_is_percent(v)) {
1056 td->o.size = 0;
1057 td->o.size_percent = -1ULL - v;
1058 } else
1059 td->o.size = v;
1060
1061 return 0;
1062}
1063
Jens Axboe896cac22009-07-01 10:38:35 +02001064static int rw_verify(struct fio_option *o, void *data)
1065{
1066 struct thread_data *td = data;
1067
1068 if (read_only && td_write(td)) {
1069 log_err("fio: job <%s> has write bit set, but fio is in"
1070 " read-only mode\n", td->o.name);
1071 return 1;
1072 }
1073
1074 return 0;
1075}
1076
Jens Axboe276ca4f2009-07-01 10:43:05 +02001077static int gtod_cpu_verify(struct fio_option *o, void *data)
Jens Axboe29d43ff2009-07-01 10:42:18 +02001078{
Jens Axboe276ca4f2009-07-01 10:43:05 +02001079#ifndef FIO_HAVE_CPU_AFFINITY
Jens Axboe29d43ff2009-07-01 10:42:18 +02001080 struct thread_data *td = data;
1081
Jens Axboe29d43ff2009-07-01 10:42:18 +02001082 if (td->o.gtod_cpu) {
1083 log_err("fio: platform must support CPU affinity for"
1084 "gettimeofday() offloading\n");
1085 return 1;
1086 }
1087#endif
1088
1089 return 0;
1090}
1091
Jens Axboe90fef2d2009-07-17 22:33:32 +02001092static int kb_base_verify(struct fio_option *o, void *data)
1093{
1094 struct thread_data *td = data;
1095
1096 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
1097 log_err("fio: kb_base set to nonsensical value: %u\n",
1098 td->o.kb_base);
1099 return 1;
1100 }
1101
1102 return 0;
1103}
1104
Jens Axboe214e1ec2007-03-15 10:48:13 +01001105/*
1106 * Map of job/command line options
1107 */
Jens Axboe07b32322010-03-05 09:48:44 +01001108static struct fio_option options[FIO_MAX_OPTS] = {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001109 {
1110 .name = "description",
1111 .type = FIO_OPT_STR_STORE,
1112 .off1 = td_var_offset(description),
1113 .help = "Text job description",
1114 },
1115 {
1116 .name = "name",
1117 .type = FIO_OPT_STR_STORE,
1118 .off1 = td_var_offset(name),
1119 .help = "Name of this job",
1120 },
1121 {
1122 .name = "directory",
1123 .type = FIO_OPT_STR_STORE,
1124 .off1 = td_var_offset(directory),
1125 .cb = str_directory_cb,
1126 .help = "Directory to store files in",
1127 },
1128 {
1129 .name = "filename",
1130 .type = FIO_OPT_STR_STORE,
1131 .off1 = td_var_offset(filename),
1132 .cb = str_filename_cb,
Jens Axboef0d524b2009-04-27 08:00:48 +02001133 .prio = -1, /* must come after "directory" */
Jens Axboe214e1ec2007-03-15 10:48:13 +01001134 .help = "File(s) to use for the workload",
1135 },
1136 {
Jens Axboe90fef2d2009-07-17 22:33:32 +02001137 .name = "kb_base",
1138 .type = FIO_OPT_INT,
1139 .off1 = td_var_offset(kb_base),
Jens Axboe90fef2d2009-07-17 22:33:32 +02001140 .verify = kb_base_verify,
Jens Axboea639f0b2009-07-18 08:25:35 +02001141 .prio = 1,
Jens Axboe90fef2d2009-07-17 22:33:32 +02001142 .def = "1024",
Jens Axboea639f0b2009-07-18 08:25:35 +02001143 .help = "How many bytes per KB for reporting (1000 or 1024)",
Jens Axboe90fef2d2009-07-17 22:33:32 +02001144 },
1145 {
Jens Axboe29c13492008-03-01 19:25:20 +01001146 .name = "lockfile",
Jens Axboe4d4e80f2008-03-04 10:18:56 +01001147 .type = FIO_OPT_STR,
1148 .cb = str_lockfile_cb,
1149 .off1 = td_var_offset(file_lock_mode),
Jens Axboe29c13492008-03-01 19:25:20 +01001150 .help = "Lock file when doing IO to it",
1151 .parent = "filename",
Jens Axboe4d4e80f2008-03-04 10:18:56 +01001152 .def = "none",
1153 .posval = {
1154 { .ival = "none",
1155 .oval = FILE_LOCK_NONE,
1156 .help = "No file locking",
1157 },
1158 { .ival = "exclusive",
1159 .oval = FILE_LOCK_EXCLUSIVE,
1160 .help = "Exclusive file lock",
1161 },
1162 {
1163 .ival = "readwrite",
1164 .oval = FILE_LOCK_READWRITE,
1165 .help = "Read vs write lock",
1166 },
1167 },
Jens Axboe29c13492008-03-01 19:25:20 +01001168 },
1169 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001170 .name = "opendir",
1171 .type = FIO_OPT_STR_STORE,
1172 .off1 = td_var_offset(opendir),
1173 .cb = str_opendir_cb,
1174 .help = "Recursively add files from this directory and down",
1175 },
1176 {
1177 .name = "rw",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001178 .alias = "readwrite",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001179 .type = FIO_OPT_STR,
Jens Axboe211097b2007-03-22 18:56:45 +01001180 .cb = str_rw_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001181 .off1 = td_var_offset(td_ddir),
1182 .help = "IO direction",
1183 .def = "read",
Jens Axboe896cac22009-07-01 10:38:35 +02001184 .verify = rw_verify,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001185 .posval = {
1186 { .ival = "read",
1187 .oval = TD_DDIR_READ,
1188 .help = "Sequential read",
1189 },
1190 { .ival = "write",
1191 .oval = TD_DDIR_WRITE,
1192 .help = "Sequential write",
1193 },
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001194 { .ival = "trim",
1195 .oval = TD_DDIR_TRIM,
1196 .help = "Sequential trim",
1197 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001198 { .ival = "randread",
1199 .oval = TD_DDIR_RANDREAD,
1200 .help = "Random read",
1201 },
1202 { .ival = "randwrite",
1203 .oval = TD_DDIR_RANDWRITE,
1204 .help = "Random write",
1205 },
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001206 { .ival = "randtrim",
1207 .oval = TD_DDIR_RANDTRIM,
1208 .help = "Random trim",
1209 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001210 { .ival = "rw",
1211 .oval = TD_DDIR_RW,
1212 .help = "Sequential read and write mix",
1213 },
Jens Axboe10b023d2012-03-23 13:40:06 +01001214 { .ival = "readwrite",
1215 .oval = TD_DDIR_RW,
1216 .help = "Sequential read and write mix",
1217 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001218 { .ival = "randrw",
1219 .oval = TD_DDIR_RANDRW,
1220 .help = "Random read and write mix"
1221 },
1222 },
1223 },
1224 {
Jens Axboe38dad622010-07-20 14:46:00 -06001225 .name = "rw_sequencer",
1226 .type = FIO_OPT_STR,
1227 .off1 = td_var_offset(rw_seq),
1228 .help = "IO offset generator modifier",
1229 .def = "sequential",
1230 .posval = {
1231 { .ival = "sequential",
1232 .oval = RW_SEQ_SEQ,
1233 .help = "Generate sequential offsets",
1234 },
1235 { .ival = "identical",
1236 .oval = RW_SEQ_IDENT,
1237 .help = "Generate identical offsets",
1238 },
1239 },
1240 },
1241
1242 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001243 .name = "ioengine",
1244 .type = FIO_OPT_STR_STORE,
1245 .off1 = td_var_offset(ioengine),
1246 .help = "IO engine to use",
Jens Axboe58483fa2011-01-19 11:09:58 -07001247 .def = FIO_PREFERRED_ENGINE,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001248 .posval = {
1249 { .ival = "sync",
1250 .help = "Use read/write",
1251 },
gurudas paia31041e2007-10-23 15:12:30 +02001252 { .ival = "psync",
1253 .help = "Use pread/pwrite",
1254 },
Jens Axboe1d2af022008-02-04 10:59:07 +01001255 { .ival = "vsync",
Bruce Cran03e20d62011-01-02 20:14:54 +01001256 .help = "Use readv/writev",
Jens Axboe1d2af022008-02-04 10:59:07 +01001257 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001258#ifdef FIO_HAVE_LIBAIO
1259 { .ival = "libaio",
1260 .help = "Linux native asynchronous IO",
1261 },
1262#endif
1263#ifdef FIO_HAVE_POSIXAIO
1264 { .ival = "posixaio",
1265 .help = "POSIX asynchronous IO",
1266 },
1267#endif
Jens Axboe417f0062008-06-02 11:59:30 +02001268#ifdef FIO_HAVE_SOLARISAIO
1269 { .ival = "solarisaio",
1270 .help = "Solaris native asynchronous IO",
1271 },
1272#endif
Bruce Cran03e20d62011-01-02 20:14:54 +01001273#ifdef FIO_HAVE_WINDOWSAIO
1274 { .ival = "windowsaio",
Jens Axboe3be80072011-01-19 11:07:28 -07001275 .help = "Windows native asynchronous IO"
Steven Langde890a12011-11-09 14:03:34 +01001276 },
Jens Axboe3be80072011-01-19 11:07:28 -07001277#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001278 { .ival = "mmap",
Bruce Cran03e20d62011-01-02 20:14:54 +01001279 .help = "Memory mapped IO"
Jens Axboe214e1ec2007-03-15 10:48:13 +01001280 },
1281#ifdef FIO_HAVE_SPLICE
1282 { .ival = "splice",
1283 .help = "splice/vmsplice based IO",
1284 },
Jens Axboe9cce02e2007-06-22 15:42:21 +02001285 { .ival = "netsplice",
1286 .help = "splice/vmsplice to/from the network",
1287 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001288#endif
1289#ifdef FIO_HAVE_SGIO
1290 { .ival = "sg",
1291 .help = "SCSI generic v3 IO",
1292 },
1293#endif
1294 { .ival = "null",
1295 .help = "Testing engine (no data transfer)",
1296 },
1297 { .ival = "net",
1298 .help = "Network IO",
1299 },
1300#ifdef FIO_HAVE_SYSLET
1301 { .ival = "syslet-rw",
1302 .help = "syslet enabled async pread/pwrite IO",
1303 },
1304#endif
1305 { .ival = "cpuio",
Bruce Cran03e20d62011-01-02 20:14:54 +01001306 .help = "CPU cycle burner engine",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001307 },
Jens Axboeb8c82a42007-03-21 08:48:26 +01001308#ifdef FIO_HAVE_GUASI
1309 { .ival = "guasi",
1310 .help = "GUASI IO engine",
1311 },
1312#endif
Jens Axboe79a43182010-09-07 13:28:58 +02001313#ifdef FIO_HAVE_BINJECT
1314 { .ival = "binject",
1315 .help = "binject direct inject block engine",
1316 },
1317#endif
ren yufei21b8aee2011-08-01 10:01:57 +02001318#ifdef FIO_HAVE_RDMA
1319 { .ival = "rdma",
1320 .help = "RDMA IO engine",
1321 },
1322#endif
Jens Axboe8200b8c2012-09-18 23:55:43 +02001323#ifdef FIO_HAVE_FUSION_AW
1324 { .ival = "fusion-aw-sync",
1325 .help = "Fusion-io atomic write engine",
1326 },
1327#endif
Jens Axboe1ecc95c2012-09-20 13:46:34 +02001328#ifdef FIO_HAVE_E4_ENG
1329 { .ival = "e4defrag",
1330 .help = "ext4 defrag engine",
1331 },
1332#endif
1333#ifdef FIO_HAVE_FALLOC_ENG
1334 { .ival = "falloc",
1335 .help = "fallocate() file based engine",
1336 },
1337#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001338 { .ival = "external",
1339 .help = "Load external engine (append name)",
1340 },
1341 },
1342 },
1343 {
1344 .name = "iodepth",
1345 .type = FIO_OPT_INT,
1346 .off1 = td_var_offset(iodepth),
Bruce Cran03e20d62011-01-02 20:14:54 +01001347 .help = "Number of IO buffers to keep in flight",
Jens Axboe757aff42007-12-12 19:42:13 +01001348 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001349 .def = "1",
1350 },
1351 {
1352 .name = "iodepth_batch",
Jens Axboe49504212008-06-05 09:03:30 +02001353 .alias = "iodepth_batch_submit",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001354 .type = FIO_OPT_INT,
1355 .off1 = td_var_offset(iodepth_batch),
Jens Axboed65db442009-01-16 19:15:33 +01001356 .help = "Number of IO buffers to submit in one go",
Jens Axboeafdf9352007-07-31 16:14:34 +02001357 .parent = "iodepth",
Jens Axboea2e6f8a2008-01-18 10:28:11 +01001358 .minval = 1,
1359 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001360 },
1361 {
Jens Axboe49504212008-06-05 09:03:30 +02001362 .name = "iodepth_batch_complete",
1363 .type = FIO_OPT_INT,
1364 .off1 = td_var_offset(iodepth_batch_complete),
Jens Axboed65db442009-01-16 19:15:33 +01001365 .help = "Number of IO buffers to retrieve in one go",
Jens Axboe49504212008-06-05 09:03:30 +02001366 .parent = "iodepth",
1367 .minval = 0,
1368 .def = "1",
1369 },
1370 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001371 .name = "iodepth_low",
1372 .type = FIO_OPT_INT,
1373 .off1 = td_var_offset(iodepth_low),
1374 .help = "Low water mark for queuing depth",
Jens Axboeafdf9352007-07-31 16:14:34 +02001375 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001376 },
1377 {
1378 .name = "size",
1379 .type = FIO_OPT_STR_VAL,
Jens Axboe7bb59102011-07-12 19:47:03 +02001380 .cb = str_size_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001381 .help = "Total size of device or files",
1382 },
1383 {
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001384 .name = "fill_device",
Jens Axboe74586c12011-01-20 10:16:03 -07001385 .alias = "fill_fs",
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001386 .type = FIO_OPT_BOOL,
1387 .off1 = td_var_offset(fill_device),
1388 .help = "Write until an ENOSPC error occurs",
1389 .def = "0",
1390 },
1391 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001392 .name = "filesize",
1393 .type = FIO_OPT_STR_VAL,
1394 .off1 = td_var_offset(file_size_low),
1395 .off2 = td_var_offset(file_size_high),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001396 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001397 .help = "Size of individual files",
1398 },
1399 {
Jens Axboe67a10002007-07-31 23:12:16 +02001400 .name = "offset",
1401 .alias = "fileoffset",
1402 .type = FIO_OPT_STR_VAL,
1403 .off1 = td_var_offset(start_offset),
1404 .help = "Start IO from this offset",
1405 .def = "0",
1406 },
1407 {
Jens Axboe2d7cd862012-03-15 14:53:38 +01001408 .name = "offset_increment",
1409 .type = FIO_OPT_STR_VAL,
1410 .off1 = td_var_offset(offset_increment),
1411 .help = "What is the increment from one offset to the next",
1412 .parent = "offset",
1413 .def = "0",
1414 },
1415 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001416 .name = "bs",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001417 .alias = "blocksize",
Jens Axboee01b22b2009-06-09 15:43:25 +02001418 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001419 .off1 = td_var_offset(bs[DDIR_READ]),
1420 .off2 = td_var_offset(bs[DDIR_WRITE]),
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001421 .off3 = td_var_offset(bs[DDIR_TRIM]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001422 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001423 .help = "Block size unit",
1424 .def = "4k",
Jens Axboe67a10002007-07-31 23:12:16 +02001425 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001426 },
1427 {
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001428 .name = "ba",
1429 .alias = "blockalign",
Jens Axboee01b22b2009-06-09 15:43:25 +02001430 .type = FIO_OPT_INT,
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001431 .off1 = td_var_offset(ba[DDIR_READ]),
1432 .off2 = td_var_offset(ba[DDIR_WRITE]),
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001433 .off3 = td_var_offset(ba[DDIR_TRIM]),
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001434 .minval = 1,
1435 .help = "IO block offset alignment",
1436 .parent = "rw",
1437 },
1438 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001439 .name = "bsrange",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001440 .alias = "blocksize_range",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001441 .type = FIO_OPT_RANGE,
1442 .off1 = td_var_offset(min_bs[DDIR_READ]),
1443 .off2 = td_var_offset(max_bs[DDIR_READ]),
1444 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1445 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001446 .off5 = td_var_offset(min_bs[DDIR_TRIM]),
1447 .off6 = td_var_offset(max_bs[DDIR_TRIM]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001448 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001449 .help = "Set block size range (in more detail than bs)",
Jens Axboe67a10002007-07-31 23:12:16 +02001450 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001451 },
1452 {
Jens Axboe564ca972007-12-14 12:21:19 +01001453 .name = "bssplit",
1454 .type = FIO_OPT_STR,
1455 .cb = str_bssplit_cb,
1456 .help = "Set a specific mix of block sizes",
1457 .parent = "rw",
1458 },
1459 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001460 .name = "bs_unaligned",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001461 .alias = "blocksize_unaligned",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001462 .type = FIO_OPT_STR_SET,
1463 .off1 = td_var_offset(bs_unaligned),
1464 .help = "Don't sector align IO buffer sizes",
Jens Axboe67a10002007-07-31 23:12:16 +02001465 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001466 },
1467 {
1468 .name = "randrepeat",
1469 .type = FIO_OPT_BOOL,
1470 .off1 = td_var_offset(rand_repeatable),
1471 .help = "Use repeatable random IO pattern",
1472 .def = "1",
Jens Axboe67a10002007-07-31 23:12:16 +02001473 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001474 },
1475 {
Jens Axboe2615cc42011-03-28 09:35:09 +02001476 .name = "use_os_rand",
1477 .type = FIO_OPT_BOOL,
1478 .off1 = td_var_offset(use_os_rand),
1479 .help = "Set to use OS random generator",
1480 .def = "0",
1481 .parent = "rw",
1482 },
1483 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001484 .name = "norandommap",
1485 .type = FIO_OPT_STR_SET,
1486 .off1 = td_var_offset(norandommap),
1487 .help = "Accept potential duplicate random blocks",
Jens Axboe67a10002007-07-31 23:12:16 +02001488 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001489 },
1490 {
Jens Axboe2b386d22008-03-26 10:32:57 +01001491 .name = "softrandommap",
1492 .type = FIO_OPT_BOOL,
1493 .off1 = td_var_offset(softrandommap),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001494 .help = "Set norandommap if randommap allocation fails",
Jens Axboe2b386d22008-03-26 10:32:57 +01001495 .parent = "norandommap",
1496 .def = "0",
1497 },
1498 {
Jens Axboee25839d2012-11-06 10:49:42 +01001499 .name = "random_distribution",
1500 .type = FIO_OPT_STR,
1501 .off1 = td_var_offset(random_distribution),
1502 .cb = str_random_distribution_cb,
1503 .help = "Random offset distribution generator",
1504 .def = "random",
1505 .posval = {
1506 { .ival = "random",
1507 .oval = FIO_RAND_DIST_RANDOM,
1508 .help = "Completely random",
1509 },
1510 { .ival = "zipf",
1511 .oval = FIO_RAND_DIST_ZIPF,
1512 .help = "Zipf distribution",
1513 },
1514 },
1515 },
1516 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001517 .name = "nrfiles",
Jens Axboed7c8be02010-11-25 08:21:39 +01001518 .alias = "nr_files",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001519 .type = FIO_OPT_INT,
1520 .off1 = td_var_offset(nr_files),
1521 .help = "Split job workload between this number of files",
1522 .def = "1",
1523 },
1524 {
1525 .name = "openfiles",
1526 .type = FIO_OPT_INT,
1527 .off1 = td_var_offset(open_files),
1528 .help = "Number of files to keep open at the same time",
1529 },
1530 {
1531 .name = "file_service_type",
1532 .type = FIO_OPT_STR,
1533 .cb = str_fst_cb,
1534 .off1 = td_var_offset(file_service_type),
1535 .help = "How to select which file to service next",
1536 .def = "roundrobin",
1537 .posval = {
1538 { .ival = "random",
1539 .oval = FIO_FSERVICE_RANDOM,
1540 .help = "Choose a file at random",
1541 },
1542 { .ival = "roundrobin",
1543 .oval = FIO_FSERVICE_RR,
1544 .help = "Round robin select files",
1545 },
Jens Axboea086c252009-03-04 08:27:37 +01001546 { .ival = "sequential",
1547 .oval = FIO_FSERVICE_SEQ,
1548 .help = "Finish one file before moving to the next",
1549 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001550 },
Jens Axboe67a10002007-07-31 23:12:16 +02001551 .parent = "nrfiles",
1552 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001553#ifdef FIO_HAVE_FALLOCATE
1554 {
1555 .name = "fallocate",
Eric Gourioua596f042011-06-17 09:11:45 +02001556 .type = FIO_OPT_STR,
1557 .off1 = td_var_offset(fallocate_mode),
1558 .help = "Whether pre-allocation is performed when laying out files",
1559 .def = "posix",
1560 .posval = {
1561 { .ival = "none",
1562 .oval = FIO_FALLOCATE_NONE,
1563 .help = "Do not pre-allocate space",
1564 },
1565 { .ival = "posix",
1566 .oval = FIO_FALLOCATE_POSIX,
1567 .help = "Use posix_fallocate()",
1568 },
1569#ifdef FIO_HAVE_LINUX_FALLOCATE
1570 { .ival = "keep",
1571 .oval = FIO_FALLOCATE_KEEP_SIZE,
1572 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1573 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001574#endif
Eric Gourioua596f042011-06-17 09:11:45 +02001575 /* Compatibility with former boolean values */
1576 { .ival = "0",
1577 .oval = FIO_FALLOCATE_NONE,
1578 .help = "Alias for 'none'",
1579 },
1580 { .ival = "1",
1581 .oval = FIO_FALLOCATE_POSIX,
1582 .help = "Alias for 'posix'",
1583 },
1584 },
1585 },
1586#endif /* FIO_HAVE_FALLOCATE */
Jens Axboe67a10002007-07-31 23:12:16 +02001587 {
1588 .name = "fadvise_hint",
1589 .type = FIO_OPT_BOOL,
1590 .off1 = td_var_offset(fadvise_hint),
1591 .help = "Use fadvise() to advise the kernel on IO pattern",
1592 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001593 },
1594 {
1595 .name = "fsync",
1596 .type = FIO_OPT_INT,
1597 .off1 = td_var_offset(fsync_blocks),
1598 .help = "Issue fsync for writes every given number of blocks",
1599 .def = "0",
1600 },
1601 {
Jens Axboe5f9099e2009-06-16 22:40:26 +02001602 .name = "fdatasync",
1603 .type = FIO_OPT_INT,
1604 .off1 = td_var_offset(fdatasync_blocks),
1605 .help = "Issue fdatasync for writes every given number of blocks",
1606 .def = "0",
1607 },
Jens Axboe1ef2b6b2010-10-08 15:07:01 +02001608 {
1609 .name = "write_barrier",
1610 .type = FIO_OPT_INT,
1611 .off1 = td_var_offset(barrier_blocks),
1612 .help = "Make every Nth write a barrier write",
1613 .def = "0",
1614 },
Jens Axboe44f29692010-03-09 20:09:44 +01001615#ifdef FIO_HAVE_SYNC_FILE_RANGE
1616 {
1617 .name = "sync_file_range",
1618 .posval = {
1619 { .ival = "wait_before",
1620 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1621 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001622 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001623 },
1624 { .ival = "write",
1625 .oval = SYNC_FILE_RANGE_WRITE,
1626 .help = "SYNC_FILE_RANGE_WRITE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001627 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001628 },
1629 {
1630 .ival = "wait_after",
1631 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1632 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
Jens Axboe3843deb2010-03-09 20:41:15 +01001633 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001634 },
1635 },
Jens Axboe3843deb2010-03-09 20:41:15 +01001636 .type = FIO_OPT_STR_MULTI,
Jens Axboe44f29692010-03-09 20:09:44 +01001637 .cb = str_sfr_cb,
1638 .off1 = td_var_offset(sync_file_range),
1639 .help = "Use sync_file_range()",
1640 },
1641#endif
Jens Axboe5f9099e2009-06-16 22:40:26 +02001642 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001643 .name = "direct",
1644 .type = FIO_OPT_BOOL,
1645 .off1 = td_var_offset(odirect),
1646 .help = "Use O_DIRECT IO (negates buffered)",
1647 .def = "0",
1648 },
1649 {
1650 .name = "buffered",
1651 .type = FIO_OPT_BOOL,
1652 .off1 = td_var_offset(odirect),
1653 .neg = 1,
1654 .help = "Use buffered IO (negates direct)",
1655 .def = "1",
1656 },
1657 {
1658 .name = "overwrite",
1659 .type = FIO_OPT_BOOL,
1660 .off1 = td_var_offset(overwrite),
1661 .help = "When writing, set whether to overwrite current data",
1662 .def = "0",
1663 },
1664 {
1665 .name = "loops",
1666 .type = FIO_OPT_INT,
1667 .off1 = td_var_offset(loops),
1668 .help = "Number of times to run the job",
1669 .def = "1",
1670 },
1671 {
1672 .name = "numjobs",
1673 .type = FIO_OPT_INT,
1674 .off1 = td_var_offset(numjobs),
1675 .help = "Duplicate this job this many times",
1676 .def = "1",
1677 },
1678 {
1679 .name = "startdelay",
Jens Axboea5737c92010-06-29 10:40:30 +02001680 .type = FIO_OPT_STR_VAL_TIME,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001681 .off1 = td_var_offset(start_delay),
1682 .help = "Only start job when this period has passed",
1683 .def = "0",
1684 },
1685 {
1686 .name = "runtime",
1687 .alias = "timeout",
1688 .type = FIO_OPT_STR_VAL_TIME,
1689 .off1 = td_var_offset(timeout),
1690 .help = "Stop workload when this amount of time has passed",
1691 .def = "0",
1692 },
1693 {
Jens Axboecf4464c2007-04-17 20:14:42 +02001694 .name = "time_based",
1695 .type = FIO_OPT_STR_SET,
1696 .off1 = td_var_offset(time_based),
1697 .help = "Keep running until runtime/timeout is met",
1698 },
1699 {
Jens Axboe721938a2008-09-10 09:46:16 +02001700 .name = "ramp_time",
1701 .type = FIO_OPT_STR_VAL_TIME,
1702 .off1 = td_var_offset(ramp_time),
1703 .help = "Ramp up time before measuring performance",
1704 },
1705 {
Jens Axboec223da82010-03-24 13:23:53 +01001706 .name = "clocksource",
1707 .type = FIO_OPT_STR,
1708 .cb = fio_clock_source_cb,
1709 .off1 = td_var_offset(clocksource),
1710 .help = "What type of timing source to use",
Jens Axboec223da82010-03-24 13:23:53 +01001711 .posval = {
1712 { .ival = "gettimeofday",
1713 .oval = CS_GTOD,
1714 .help = "Use gettimeofday(2) for timing",
1715 },
1716 { .ival = "clock_gettime",
1717 .oval = CS_CGETTIME,
1718 .help = "Use clock_gettime(2) for timing",
1719 },
1720#ifdef ARCH_HAVE_CPU_CLOCK
1721 { .ival = "cpu",
1722 .oval = CS_CPUCLOCK,
1723 .help = "Use CPU private clock",
1724 },
1725#endif
1726 },
1727 },
1728 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001729 .name = "mem",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001730 .alias = "iomem",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001731 .type = FIO_OPT_STR,
1732 .cb = str_mem_cb,
1733 .off1 = td_var_offset(mem_type),
1734 .help = "Backing type for IO buffers",
1735 .def = "malloc",
1736 .posval = {
1737 { .ival = "malloc",
1738 .oval = MEM_MALLOC,
1739 .help = "Use malloc(3) for IO buffers",
1740 },
Jens Axboeb370e462007-03-19 10:51:49 +01001741 { .ival = "shm",
1742 .oval = MEM_SHM,
1743 .help = "Use shared memory segments for IO buffers",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001744 },
1745#ifdef FIO_HAVE_HUGETLB
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001746 { .ival = "shmhuge",
1747 .oval = MEM_SHMHUGE,
1748 .help = "Like shm, but use huge pages",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001749 },
1750#endif
Jens Axboeb370e462007-03-19 10:51:49 +01001751 { .ival = "mmap",
1752 .oval = MEM_MMAP,
1753 .help = "Use mmap(2) (file or anon) for IO buffers",
1754 },
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001755#ifdef FIO_HAVE_HUGETLB
1756 { .ival = "mmaphuge",
1757 .oval = MEM_MMAPHUGE,
1758 .help = "Like mmap, but use huge pages",
1759 },
1760#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001761 },
1762 },
1763 {
Jens Axboed529ee12009-07-01 10:33:03 +02001764 .name = "iomem_align",
1765 .alias = "mem_align",
1766 .type = FIO_OPT_INT,
1767 .off1 = td_var_offset(mem_align),
1768 .minval = 0,
1769 .help = "IO memory buffer offset alignment",
1770 .def = "0",
1771 .parent = "iomem",
1772 },
1773 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001774 .name = "verify",
1775 .type = FIO_OPT_STR,
1776 .off1 = td_var_offset(verify),
1777 .help = "Verify data written",
Jens Axboe5d7c5d32010-06-21 15:08:17 +02001778 .cb = str_verify_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001779 .def = "0",
1780 .posval = {
1781 { .ival = "0",
1782 .oval = VERIFY_NONE,
1783 .help = "Don't do IO verification",
1784 },
Jens Axboefcca4b52007-07-27 15:42:00 +02001785 { .ival = "md5",
1786 .oval = VERIFY_MD5,
1787 .help = "Use md5 checksums for verification",
1788 },
Jens Axboed77a7af2007-07-27 15:35:06 +02001789 { .ival = "crc64",
1790 .oval = VERIFY_CRC64,
1791 .help = "Use crc64 checksums for verification",
1792 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001793 { .ival = "crc32",
1794 .oval = VERIFY_CRC32,
1795 .help = "Use crc32 checksums for verification",
1796 },
Jens Axboeaf497e62008-08-04 15:40:35 +02001797 { .ival = "crc32c-intel",
Jens Axboee3aaafc2012-02-22 20:28:17 +01001798 .oval = VERIFY_CRC32C,
1799 .help = "Use crc32c checksums for verification (hw assisted, if available)",
Jens Axboeaf497e62008-08-04 15:40:35 +02001800 },
Jens Axboebac39e02008-06-11 20:46:19 +02001801 { .ival = "crc32c",
1802 .oval = VERIFY_CRC32C,
Jens Axboee3aaafc2012-02-22 20:28:17 +01001803 .help = "Use crc32c checksums for verification (hw assisted, if available)",
Jens Axboebac39e02008-06-11 20:46:19 +02001804 },
Jens Axboe969f7ed2007-07-27 09:07:17 +02001805 { .ival = "crc16",
1806 .oval = VERIFY_CRC16,
1807 .help = "Use crc16 checksums for verification",
1808 },
Jens Axboe1e154bd2007-07-27 09:52:40 +02001809 { .ival = "crc7",
1810 .oval = VERIFY_CRC7,
1811 .help = "Use crc7 checksums for verification",
1812 },
Jens Axboe7c353ce2009-08-09 22:40:33 +02001813 { .ival = "sha1",
1814 .oval = VERIFY_SHA1,
1815 .help = "Use sha1 checksums for verification",
1816 },
Jens Axboecd14cc12007-07-30 10:59:33 +02001817 { .ival = "sha256",
1818 .oval = VERIFY_SHA256,
1819 .help = "Use sha256 checksums for verification",
1820 },
1821 { .ival = "sha512",
1822 .oval = VERIFY_SHA512,
1823 .help = "Use sha512 checksums for verification",
1824 },
Shawn Lewis7437ee82007-08-02 21:05:58 +02001825 { .ival = "meta",
1826 .oval = VERIFY_META,
1827 .help = "Use io information",
1828 },
Jens Axboe36690c92007-03-26 10:23:34 +02001829 {
1830 .ival = "null",
1831 .oval = VERIFY_NULL,
1832 .help = "Pretend to verify",
1833 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001834 },
1835 },
1836 {
Jens Axboe005c5652007-08-02 22:21:36 +02001837 .name = "do_verify",
Jens Axboe68e1f292007-08-10 10:32:14 +02001838 .type = FIO_OPT_BOOL,
Jens Axboe005c5652007-08-02 22:21:36 +02001839 .off1 = td_var_offset(do_verify),
1840 .help = "Run verification stage after write",
1841 .def = "1",
1842 .parent = "verify",
1843 },
1844 {
Jens Axboe160b9662007-03-27 10:59:49 +02001845 .name = "verifysort",
1846 .type = FIO_OPT_BOOL,
1847 .off1 = td_var_offset(verifysort),
1848 .help = "Sort written verify blocks for read back",
1849 .def = "1",
Jens Axboec83f2df2007-07-31 22:51:47 +02001850 .parent = "verify",
Jens Axboe160b9662007-03-27 10:59:49 +02001851 },
1852 {
Jens Axboea59e1702007-07-30 08:53:27 +02001853 .name = "verify_interval",
Jens Axboee01b22b2009-06-09 15:43:25 +02001854 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001855 .off1 = td_var_offset(verify_interval),
Jens Axboe819a9682007-07-28 21:30:31 +02001856 .minval = 2 * sizeof(struct verify_header),
Jens Axboea59e1702007-07-30 08:53:27 +02001857 .help = "Store verify buffer header every N bytes",
Jens Axboeafdf9352007-07-31 16:14:34 +02001858 .parent = "verify",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +02001859 },
1860 {
Jens Axboea59e1702007-07-30 08:53:27 +02001861 .name = "verify_offset",
Jens Axboee01b22b2009-06-09 15:43:25 +02001862 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001863 .help = "Offset verify header location by N bytes",
Shawn Lewis546a9142007-07-28 21:11:37 +02001864 .def = "0",
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001865 .cb = str_verify_offset_cb,
Jens Axboeafdf9352007-07-31 16:14:34 +02001866 .parent = "verify",
Shawn Lewis546a9142007-07-28 21:11:37 +02001867 },
1868 {
Shawn Lewise28218f2008-01-16 11:01:33 +01001869 .name = "verify_pattern",
Radha Ramachandran0e92f872009-10-27 20:14:27 +01001870 .type = FIO_OPT_STR,
Shawn Lewise28218f2008-01-16 11:01:33 +01001871 .cb = str_verify_pattern_cb,
1872 .help = "Fill pattern for IO buffers",
1873 .parent = "verify",
1874 },
1875 {
Jens Axboea12a3b42007-08-09 10:20:54 +02001876 .name = "verify_fatal",
Jens Axboe68e1f292007-08-10 10:32:14 +02001877 .type = FIO_OPT_BOOL,
Jens Axboea12a3b42007-08-09 10:20:54 +02001878 .off1 = td_var_offset(verify_fatal),
1879 .def = "0",
1880 .help = "Exit on a single verify failure, don't continue",
1881 .parent = "verify",
1882 },
1883 {
Jens Axboeb463e932011-01-12 09:03:23 +01001884 .name = "verify_dump",
1885 .type = FIO_OPT_BOOL,
1886 .off1 = td_var_offset(verify_dump),
Jens Axboeef71e312011-10-25 22:43:36 +02001887 .def = "0",
Jens Axboeb463e932011-01-12 09:03:23 +01001888 .help = "Dump contents of good and bad blocks on failure",
1889 .parent = "verify",
1890 },
1891 {
Jens Axboee8462bd2009-07-06 12:59:04 +02001892 .name = "verify_async",
1893 .type = FIO_OPT_INT,
1894 .off1 = td_var_offset(verify_async),
1895 .def = "0",
1896 .help = "Number of async verifier threads to use",
1897 .parent = "verify",
1898 },
Jens Axboe9e144182010-06-15 14:25:36 +02001899 {
1900 .name = "verify_backlog",
1901 .type = FIO_OPT_STR_VAL,
1902 .off1 = td_var_offset(verify_backlog),
1903 .help = "Verify after this number of blocks are written",
1904 .parent = "verify",
1905 },
1906 {
1907 .name = "verify_backlog_batch",
1908 .type = FIO_OPT_INT,
1909 .off1 = td_var_offset(verify_batch),
1910 .help = "Verify this number of IO blocks",
Jens Axboe0d29de82010-09-01 13:54:15 +02001911 .parent = "verify",
Jens Axboe9e144182010-06-15 14:25:36 +02001912 },
Jens Axboee8462bd2009-07-06 12:59:04 +02001913#ifdef FIO_HAVE_CPU_AFFINITY
1914 {
1915 .name = "verify_async_cpus",
1916 .type = FIO_OPT_STR,
1917 .cb = str_verify_cpus_allowed_cb,
1918 .help = "Set CPUs allowed for async verify threads",
1919 .parent = "verify_async",
1920 },
1921#endif
Jens Axboe0d29de82010-09-01 13:54:15 +02001922#ifdef FIO_HAVE_TRIM
1923 {
1924 .name = "trim_percentage",
1925 .type = FIO_OPT_INT,
1926 .cb = str_verify_trim_cb,
1927 .maxval = 100,
1928 .help = "Number of verify blocks to discard/trim",
1929 .parent = "verify",
1930 .def = "0",
1931 },
1932 {
1933 .name = "trim_verify_zero",
1934 .type = FIO_OPT_INT,
1935 .help = "Verify that trim/discarded blocks are returned as zeroes",
1936 .off1 = td_var_offset(trim_zero),
1937 .parent = "trim_percentage",
1938 .def = "1",
1939 },
1940 {
1941 .name = "trim_backlog",
1942 .type = FIO_OPT_STR_VAL,
1943 .off1 = td_var_offset(trim_backlog),
1944 .help = "Trim after this number of blocks are written",
1945 .parent = "trim_percentage",
1946 },
1947 {
1948 .name = "trim_backlog_batch",
1949 .type = FIO_OPT_INT,
1950 .off1 = td_var_offset(trim_batch),
1951 .help = "Trim this number of IO blocks",
1952 .parent = "trim_percentage",
1953 },
1954#endif
Jens Axboee8462bd2009-07-06 12:59:04 +02001955 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001956 .name = "write_iolog",
1957 .type = FIO_OPT_STR_STORE,
1958 .off1 = td_var_offset(write_iolog_file),
1959 .help = "Store IO pattern to file",
1960 },
1961 {
1962 .name = "read_iolog",
1963 .type = FIO_OPT_STR_STORE,
1964 .off1 = td_var_offset(read_iolog_file),
1965 .help = "Playback IO pattern from file",
1966 },
1967 {
David Nellans64bbb862010-08-24 22:13:30 +02001968 .name = "replay_no_stall",
1969 .type = FIO_OPT_INT,
1970 .off1 = td_var_offset(no_stall),
1971 .def = "0",
Jens Axboe87e7a972010-08-25 09:01:25 +02001972 .parent = "read_iolog",
David Nellans64bbb862010-08-24 22:13:30 +02001973 .help = "Playback IO pattern file as fast as possible without stalls",
1974 },
1975 {
David Nellansd1c46c02010-08-31 21:20:47 +02001976 .name = "replay_redirect",
1977 .type = FIO_OPT_STR_STORE,
1978 .off1 = td_var_offset(replay_redirect),
1979 .parent = "read_iolog",
1980 .help = "Replay all I/O onto this device, regardless of trace device",
1981 },
1982 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001983 .name = "exec_prerun",
1984 .type = FIO_OPT_STR_STORE,
1985 .off1 = td_var_offset(exec_prerun),
1986 .help = "Execute this file prior to running job",
1987 },
1988 {
1989 .name = "exec_postrun",
1990 .type = FIO_OPT_STR_STORE,
1991 .off1 = td_var_offset(exec_postrun),
1992 .help = "Execute this file after running job",
1993 },
1994#ifdef FIO_HAVE_IOSCHED_SWITCH
1995 {
1996 .name = "ioscheduler",
1997 .type = FIO_OPT_STR_STORE,
1998 .off1 = td_var_offset(ioscheduler),
1999 .help = "Use this IO scheduler on the backing device",
2000 },
2001#endif
2002 {
2003 .name = "zonesize",
2004 .type = FIO_OPT_STR_VAL,
2005 .off1 = td_var_offset(zone_size),
Steven Noonaned335852012-01-31 13:58:00 +01002006 .help = "Amount of data to read per zone",
2007 .def = "0",
2008 },
2009 {
2010 .name = "zonerange",
2011 .type = FIO_OPT_STR_VAL,
2012 .off1 = td_var_offset(zone_range),
Jens Axboe214e1ec2007-03-15 10:48:13 +01002013 .help = "Give size of an IO zone",
2014 .def = "0",
2015 },
2016 {
2017 .name = "zoneskip",
2018 .type = FIO_OPT_STR_VAL,
2019 .off1 = td_var_offset(zone_skip),
2020 .help = "Space between IO zones",
2021 .def = "0",
2022 },
2023 {
2024 .name = "lockmem",
2025 .type = FIO_OPT_STR_VAL,
2026 .cb = str_lockmem_cb,
2027 .help = "Lock down this amount of memory",
2028 .def = "0",
2029 },
2030 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002031 .name = "rwmixread",
2032 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02002033 .cb = str_rwmix_read_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002034 .maxval = 100,
2035 .help = "Percentage of mixed workload that is reads",
2036 .def = "50",
2037 },
2038 {
2039 .name = "rwmixwrite",
2040 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02002041 .cb = str_rwmix_write_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002042 .maxval = 100,
2043 .help = "Percentage of mixed workload that is writes",
2044 .def = "50",
2045 },
2046 {
Jens Axboeafdf9352007-07-31 16:14:34 +02002047 .name = "rwmixcycle",
Jens Axboe15ca1502008-04-07 09:26:02 +02002048 .type = FIO_OPT_DEPRECATED,
Jens Axboeafdf9352007-07-31 16:14:34 +02002049 },
2050 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002051 .name = "nice",
2052 .type = FIO_OPT_INT,
2053 .off1 = td_var_offset(nice),
2054 .help = "Set job CPU nice value",
2055 .minval = -19,
2056 .maxval = 20,
2057 .def = "0",
2058 },
2059#ifdef FIO_HAVE_IOPRIO
2060 {
2061 .name = "prio",
2062 .type = FIO_OPT_INT,
2063 .cb = str_prio_cb,
2064 .help = "Set job IO priority value",
2065 .minval = 0,
2066 .maxval = 7,
2067 },
2068 {
2069 .name = "prioclass",
2070 .type = FIO_OPT_INT,
2071 .cb = str_prioclass_cb,
2072 .help = "Set job IO priority class",
2073 .minval = 0,
2074 .maxval = 3,
2075 },
2076#endif
2077 {
2078 .name = "thinktime",
2079 .type = FIO_OPT_INT,
2080 .off1 = td_var_offset(thinktime),
2081 .help = "Idle time between IO buffers (usec)",
2082 .def = "0",
2083 },
2084 {
2085 .name = "thinktime_spin",
2086 .type = FIO_OPT_INT,
2087 .off1 = td_var_offset(thinktime_spin),
2088 .help = "Start think time by spinning this amount (usec)",
2089 .def = "0",
Jens Axboeafdf9352007-07-31 16:14:34 +02002090 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002091 },
2092 {
2093 .name = "thinktime_blocks",
2094 .type = FIO_OPT_INT,
2095 .off1 = td_var_offset(thinktime_blocks),
2096 .help = "IO buffer period between 'thinktime'",
2097 .def = "1",
Jens Axboeafdf9352007-07-31 16:14:34 +02002098 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002099 },
2100 {
2101 .name = "rate",
Jens Axboee01b22b2009-06-09 15:43:25 +02002102 .type = FIO_OPT_INT,
Shaohua Li6eaf09d2012-09-14 08:49:43 +02002103 .off1 = td_var_offset(rate[DDIR_READ]),
2104 .off2 = td_var_offset(rate[DDIR_WRITE]),
2105 .off3 = td_var_offset(rate[DDIR_TRIM]),
Jens Axboe214e1ec2007-03-15 10:48:13 +01002106 .help = "Set bandwidth rate",
2107 },
2108 {
2109 .name = "ratemin",
Jens Axboee01b22b2009-06-09 15:43:25 +02002110 .type = FIO_OPT_INT,
Shaohua Li6eaf09d2012-09-14 08:49:43 +02002111 .off1 = td_var_offset(ratemin[DDIR_READ]),
2112 .off2 = td_var_offset(ratemin[DDIR_WRITE]),
2113 .off3 = td_var_offset(ratemin[DDIR_TRIM]),
Jens Axboe4e991c22007-03-15 11:41:11 +01002114 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02002115 .parent = "rate",
Jens Axboe4e991c22007-03-15 11:41:11 +01002116 },
2117 {
2118 .name = "rate_iops",
Jens Axboee01b22b2009-06-09 15:43:25 +02002119 .type = FIO_OPT_INT,
Shaohua Li6eaf09d2012-09-14 08:49:43 +02002120 .off1 = td_var_offset(rate_iops[DDIR_READ]),
2121 .off2 = td_var_offset(rate_iops[DDIR_WRITE]),
2122 .off3 = td_var_offset(rate_iops[DDIR_TRIM]),
Jens Axboe4e991c22007-03-15 11:41:11 +01002123 .help = "Limit IO used to this number of IO operations/sec",
2124 },
2125 {
2126 .name = "rate_iops_min",
Jens Axboee01b22b2009-06-09 15:43:25 +02002127 .type = FIO_OPT_INT,
Shaohua Li6eaf09d2012-09-14 08:49:43 +02002128 .off1 = td_var_offset(rate_iops_min[DDIR_READ]),
2129 .off2 = td_var_offset(rate_iops_min[DDIR_WRITE]),
2130 .off3 = td_var_offset(rate_iops_min[DDIR_TRIM]),
Bruce Cran03e20d62011-01-02 20:14:54 +01002131 .help = "Job must meet this rate or it will be shut down",
Jens Axboeafdf9352007-07-31 16:14:34 +02002132 .parent = "rate_iops",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002133 },
2134 {
2135 .name = "ratecycle",
2136 .type = FIO_OPT_INT,
2137 .off1 = td_var_offset(ratecycle),
2138 .help = "Window average for rate limits (msec)",
2139 .def = "1000",
Jens Axboeafdf9352007-07-31 16:14:34 +02002140 .parent = "rate",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002141 },
2142 {
Jens Axboe15501532012-10-24 16:37:45 +02002143 .name = "max_latency",
2144 .type = FIO_OPT_INT,
2145 .off1 = td_var_offset(max_latency),
2146 .help = "Maximum tolerated IO latency (usec)",
2147 },
2148 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002149 .name = "invalidate",
2150 .type = FIO_OPT_BOOL,
2151 .off1 = td_var_offset(invalidate_cache),
2152 .help = "Invalidate buffer/page cache prior to running job",
2153 .def = "1",
2154 },
2155 {
2156 .name = "sync",
2157 .type = FIO_OPT_BOOL,
2158 .off1 = td_var_offset(sync_io),
2159 .help = "Use O_SYNC for buffered writes",
2160 .def = "0",
Jens Axboe67a10002007-07-31 23:12:16 +02002161 .parent = "buffered",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002162 },
2163 {
2164 .name = "bwavgtime",
2165 .type = FIO_OPT_INT,
2166 .off1 = td_var_offset(bw_avg_time),
Jens Axboe5ec10ea2008-03-06 15:42:00 +01002167 .help = "Time window over which to calculate bandwidth"
2168 " (msec)",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002169 .def = "500",
Jens Axboec8eeb9d2011-10-05 14:02:22 +02002170 .parent = "write_bw_log",
2171 },
2172 {
2173 .name = "iopsavgtime",
2174 .type = FIO_OPT_INT,
2175 .off1 = td_var_offset(iops_avg_time),
2176 .help = "Time window over which to calculate IOPS (msec)",
2177 .def = "500",
2178 .parent = "write_iops_log",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002179 },
2180 {
2181 .name = "create_serialize",
2182 .type = FIO_OPT_BOOL,
2183 .off1 = td_var_offset(create_serialize),
2184 .help = "Serialize creating of job files",
2185 .def = "1",
2186 },
2187 {
2188 .name = "create_fsync",
2189 .type = FIO_OPT_BOOL,
2190 .off1 = td_var_offset(create_fsync),
Bruce Cran03e20d62011-01-02 20:14:54 +01002191 .help = "fsync file after creation",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002192 .def = "1",
2193 },
2194 {
Jens Axboe814452b2009-03-04 12:53:13 +01002195 .name = "create_on_open",
2196 .type = FIO_OPT_BOOL,
2197 .off1 = td_var_offset(create_on_open),
2198 .help = "Create files when they are opened for IO",
2199 .def = "0",
2200 },
Jens Axboe0b9d69e2009-09-11 22:29:54 +02002201 {
Jens Axboe25460cf2012-05-02 13:58:02 +02002202 .name = "create_only",
2203 .type = FIO_OPT_BOOL,
2204 .off1 = td_var_offset(create_only),
2205 .help = "Only perform file creation phase",
2206 .def = "0",
2207 },
2208 {
Zhang, Yanminafad68f2009-05-20 11:30:55 +02002209 .name = "pre_read",
2210 .type = FIO_OPT_BOOL,
2211 .off1 = td_var_offset(pre_read),
Bruce Cran03e20d62011-01-02 20:14:54 +01002212 .help = "Pre-read files before starting official testing",
Zhang, Yanminafad68f2009-05-20 11:30:55 +02002213 .def = "0",
2214 },
Jens Axboe814452b2009-03-04 12:53:13 +01002215 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002216 .name = "cpuload",
2217 .type = FIO_OPT_INT,
2218 .off1 = td_var_offset(cpuload),
2219 .help = "Use this percentage of CPU",
2220 },
2221 {
2222 .name = "cpuchunks",
2223 .type = FIO_OPT_INT,
2224 .off1 = td_var_offset(cpucycle),
2225 .help = "Length of the CPU burn cycles (usecs)",
2226 .def = "50000",
Jens Axboe67a10002007-07-31 23:12:16 +02002227 .parent = "cpuload",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002228 },
2229#ifdef FIO_HAVE_CPU_AFFINITY
2230 {
2231 .name = "cpumask",
2232 .type = FIO_OPT_INT,
2233 .cb = str_cpumask_cb,
2234 .help = "CPU affinity mask",
2235 },
Jens Axboed2e268b2007-06-15 10:33:49 +02002236 {
2237 .name = "cpus_allowed",
2238 .type = FIO_OPT_STR,
2239 .cb = str_cpus_allowed_cb,
2240 .help = "Set CPUs allowed",
2241 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01002242#endif
Yufei Rend0b937e2012-10-19 23:11:52 -04002243#ifdef FIO_HAVE_LIBNUMA
2244 {
2245 .name = "numa_cpu_nodes",
2246 .type = FIO_OPT_STR,
2247 .cb = str_numa_cpunodes_cb,
2248 .help = "NUMA CPU nodes bind",
2249 },
2250 {
2251 .name = "numa_mem_policy",
2252 .type = FIO_OPT_STR,
2253 .cb = str_numa_mpol_cb,
2254 .help = "NUMA memory policy setup",
2255 },
2256#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01002257 {
2258 .name = "end_fsync",
2259 .type = FIO_OPT_BOOL,
2260 .off1 = td_var_offset(end_fsync),
2261 .help = "Include fsync at the end of job",
2262 .def = "0",
2263 },
2264 {
2265 .name = "fsync_on_close",
2266 .type = FIO_OPT_BOOL,
2267 .off1 = td_var_offset(fsync_on_close),
2268 .help = "fsync files on close",
2269 .def = "0",
2270 },
2271 {
2272 .name = "unlink",
2273 .type = FIO_OPT_BOOL,
2274 .off1 = td_var_offset(unlink),
2275 .help = "Unlink created files after job has completed",
2276 .def = "0",
2277 },
2278 {
2279 .name = "exitall",
2280 .type = FIO_OPT_STR_SET,
2281 .cb = str_exitall_cb,
2282 .help = "Terminate all jobs when one exits",
2283 },
2284 {
2285 .name = "stonewall",
Jens Axboed3923652011-08-03 12:38:39 +02002286 .alias = "wait_for_previous",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002287 .type = FIO_OPT_STR_SET,
2288 .off1 = td_var_offset(stonewall),
2289 .help = "Insert a hard barrier between this job and previous",
2290 },
2291 {
Jens Axboeb3d62a72007-03-20 14:23:26 +01002292 .name = "new_group",
2293 .type = FIO_OPT_STR_SET,
2294 .off1 = td_var_offset(new_group),
2295 .help = "Mark the start of a new group (for reporting)",
2296 },
2297 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002298 .name = "thread",
2299 .type = FIO_OPT_STR_SET,
2300 .off1 = td_var_offset(use_thread),
2301 .help = "Use threads instead of forks",
2302 },
2303 {
2304 .name = "write_bw_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01002305 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002306 .off1 = td_var_offset(write_bw_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01002307 .cb = str_write_bw_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002308 .help = "Write log of bandwidth during run",
2309 },
2310 {
2311 .name = "write_lat_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01002312 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002313 .off1 = td_var_offset(write_lat_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01002314 .cb = str_write_lat_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002315 .help = "Write log of latency during run",
2316 },
2317 {
Jens Axboec8eeb9d2011-10-05 14:02:22 +02002318 .name = "write_iops_log",
2319 .type = FIO_OPT_STR,
2320 .off1 = td_var_offset(write_iops_log),
2321 .cb = str_write_iops_log_cb,
2322 .help = "Write log of IOPS during run",
2323 },
2324 {
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01002325 .name = "log_avg_msec",
2326 .type = FIO_OPT_INT,
2327 .off1 = td_var_offset(log_avg_msec),
2328 .help = "Average bw/iops/lat logs over this period of time",
2329 .def = "0",
2330 },
2331 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002332 .name = "hugepage-size",
Jens Axboee01b22b2009-06-09 15:43:25 +02002333 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002334 .off1 = td_var_offset(hugepage_size),
2335 .help = "When using hugepages, specify size of each page",
Jens Axboe81179ee2011-10-04 12:42:06 +02002336 .def = __fio_stringify(FIO_HUGE_PAGE),
Jens Axboe214e1ec2007-03-15 10:48:13 +01002337 },
2338 {
2339 .name = "group_reporting",
2340 .type = FIO_OPT_STR_SET,
2341 .off1 = td_var_offset(group_reporting),
2342 .help = "Do reporting on a per-group basis",
2343 },
2344 {
Jens Axboee9459e52007-04-17 15:46:32 +02002345 .name = "zero_buffers",
2346 .type = FIO_OPT_STR_SET,
2347 .off1 = td_var_offset(zero_buffers),
2348 .help = "Init IO buffers to all zeroes",
2349 },
Jens Axboe5973caf2008-05-21 19:52:35 +02002350 {
2351 .name = "refill_buffers",
2352 .type = FIO_OPT_STR_SET,
2353 .off1 = td_var_offset(refill_buffers),
2354 .help = "Refill IO buffers on every IO submit",
2355 },
Yu-ju Hong83349192011-08-13 00:53:44 +02002356 {
Jens Axboefd684182011-09-19 09:24:44 +02002357 .name = "scramble_buffers",
2358 .type = FIO_OPT_BOOL,
2359 .off1 = td_var_offset(scramble_buffers),
2360 .help = "Slightly scramble buffers on every IO submit",
2361 .def = "1",
2362 },
2363 {
Jens Axboe9c426842012-03-02 21:02:12 +01002364 .name = "buffer_compress_percentage",
2365 .type = FIO_OPT_INT,
2366 .off1 = td_var_offset(compress_percentage),
2367 .maxval = 100,
2368 .minval = 1,
2369 .help = "How compressible the buffer is (approximately)",
2370 },
2371 {
Jens Axboef97a43a2012-03-09 19:06:24 +01002372 .name = "buffer_compress_chunk",
2373 .type = FIO_OPT_INT,
2374 .off1 = td_var_offset(compress_chunk),
Jens Axboe207b18e2012-03-09 19:11:25 +01002375 .parent = "buffer_compress_percentage",
Jens Axboef97a43a2012-03-09 19:06:24 +01002376 .help = "Size of compressible region in buffer",
2377 },
2378 {
Yu-ju Hong83349192011-08-13 00:53:44 +02002379 .name = "clat_percentiles",
2380 .type = FIO_OPT_BOOL,
2381 .off1 = td_var_offset(clat_percentiles),
2382 .help = "Enable the reporting of completion latency percentiles",
Jens Axboe467b35e2011-10-13 08:53:24 +02002383 .def = "1",
Yu-ju Hong83349192011-08-13 00:53:44 +02002384 },
2385 {
2386 .name = "percentile_list",
2387 .type = FIO_OPT_FLOAT_LIST,
2388 .off1 = td_var_offset(percentile_list),
2389 .off2 = td_var_offset(overwrite_plist),
2390 .help = "Specify a custom list of percentiles to report",
2391 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2392 .minfp = 0.0,
2393 .maxfp = 100.0,
2394 },
2395
Jens Axboe0a839f32007-04-26 09:02:34 +02002396#ifdef FIO_HAVE_DISK_UTIL
2397 {
2398 .name = "disk_util",
2399 .type = FIO_OPT_BOOL,
2400 .off1 = td_var_offset(do_disk_util),
Jens Axboef66ab3c2008-06-05 11:48:22 +02002401 .help = "Log disk utilization statistics",
Jens Axboe0a839f32007-04-26 09:02:34 +02002402 .def = "1",
2403 },
2404#endif
Jens Axboee9459e52007-04-17 15:46:32 +02002405 {
Jens Axboe993bf482008-11-14 13:04:53 +01002406 .name = "gtod_reduce",
2407 .type = FIO_OPT_BOOL,
2408 .help = "Greatly reduce number of gettimeofday() calls",
2409 .cb = str_gtod_reduce_cb,
2410 .def = "0",
2411 },
2412 {
Jens Axboe02af0982010-06-24 09:59:34 +02002413 .name = "disable_lat",
2414 .type = FIO_OPT_BOOL,
2415 .off1 = td_var_offset(disable_lat),
2416 .help = "Disable latency numbers",
2417 .parent = "gtod_reduce",
2418 .def = "0",
2419 },
2420 {
Jens Axboe9520ebb2008-10-16 21:03:27 +02002421 .name = "disable_clat",
2422 .type = FIO_OPT_BOOL,
2423 .off1 = td_var_offset(disable_clat),
2424 .help = "Disable completion latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01002425 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002426 .def = "0",
2427 },
2428 {
2429 .name = "disable_slat",
2430 .type = FIO_OPT_BOOL,
2431 .off1 = td_var_offset(disable_slat),
Bruce Cran03e20d62011-01-02 20:14:54 +01002432 .help = "Disable submission latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01002433 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002434 .def = "0",
2435 },
2436 {
2437 .name = "disable_bw_measurement",
2438 .type = FIO_OPT_BOOL,
2439 .off1 = td_var_offset(disable_bw),
2440 .help = "Disable bandwidth logging",
Jens Axboe993bf482008-11-14 13:04:53 +01002441 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002442 .def = "0",
2443 },
2444 {
Jens Axboebe4ecfd2008-12-08 14:10:52 +01002445 .name = "gtod_cpu",
2446 .type = FIO_OPT_INT,
2447 .cb = str_gtod_cpu_cb,
Bruce Cran03e20d62011-01-02 20:14:54 +01002448 .help = "Set up dedicated gettimeofday() thread on this CPU",
Jens Axboe29d43ff2009-07-01 10:42:18 +02002449 .verify = gtod_cpu_verify,
Jens Axboebe4ecfd2008-12-08 14:10:52 +01002450 },
2451 {
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002452 .name = "continue_on_error",
Steven Lang06842022011-11-17 09:45:17 +01002453 .type = FIO_OPT_STR,
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002454 .off1 = td_var_offset(continue_on_error),
Bruce Cran03e20d62011-01-02 20:14:54 +01002455 .help = "Continue on non-fatal errors during IO",
Steven Lang06842022011-11-17 09:45:17 +01002456 .def = "none",
2457 .posval = {
2458 { .ival = "none",
2459 .oval = ERROR_TYPE_NONE,
2460 .help = "Exit when an error is encountered",
2461 },
2462 { .ival = "read",
2463 .oval = ERROR_TYPE_READ,
2464 .help = "Continue on read errors only",
2465 },
2466 { .ival = "write",
2467 .oval = ERROR_TYPE_WRITE,
2468 .help = "Continue on write errors only",
2469 },
2470 { .ival = "io",
2471 .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2472 .help = "Continue on any IO errors",
2473 },
2474 { .ival = "verify",
2475 .oval = ERROR_TYPE_VERIFY,
2476 .help = "Continue on verify errors only",
2477 },
2478 { .ival = "all",
2479 .oval = ERROR_TYPE_ANY,
2480 .help = "Continue on all io and verify errors",
2481 },
2482 { .ival = "0",
2483 .oval = ERROR_TYPE_NONE,
2484 .help = "Alias for 'none'",
2485 },
2486 { .ival = "1",
2487 .oval = ERROR_TYPE_ANY,
2488 .help = "Alias for 'all'",
2489 },
2490 },
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002491 },
2492 {
Dmitry Monakhov8b28bd42012-09-23 15:46:09 +04002493 .name = "ignore_error",
2494 .type = FIO_OPT_STR,
2495 .cb = str_ignore_error_cb,
2496 .help = "Set a specific list of errors to ignore",
2497 .parent = "rw",
2498 },
2499 {
2500 .name = "error_dump",
2501 .type = FIO_OPT_BOOL,
2502 .off1 = td_var_offset(error_dump),
2503 .def = "0",
2504 .help = "Dump info on each error",
2505 },
2506
2507 {
Jens Axboe9ac8a792009-11-13 21:23:07 +01002508 .name = "profile",
Jens Axboe79d16312010-03-04 12:43:20 +01002509 .type = FIO_OPT_STR_STORE,
Jens Axboe9ac8a792009-11-13 21:23:07 +01002510 .off1 = td_var_offset(profile),
Jens Axboe9ac8a792009-11-13 21:23:07 +01002511 .help = "Select a specific builtin performance test",
2512 },
2513 {
Jens Axboea696fa22009-12-04 10:05:02 +01002514 .name = "cgroup",
2515 .type = FIO_OPT_STR_STORE,
2516 .off1 = td_var_offset(cgroup),
2517 .help = "Add job to cgroup of this name",
2518 },
2519 {
2520 .name = "cgroup_weight",
2521 .type = FIO_OPT_INT,
2522 .off1 = td_var_offset(cgroup_weight),
2523 .help = "Use given weight for cgroup",
2524 .minval = 100,
2525 .maxval = 1000,
Jens Axboea696fa22009-12-04 10:05:02 +01002526 },
2527 {
Vivek Goyal7de87092010-03-31 22:55:15 +02002528 .name = "cgroup_nodelete",
2529 .type = FIO_OPT_BOOL,
2530 .off1 = td_var_offset(cgroup_nodelete),
2531 .help = "Do not delete cgroups after job completion",
2532 .def = "0",
2533 },
2534 {
Jens Axboee0b0d892009-12-08 10:10:14 +01002535 .name = "uid",
2536 .type = FIO_OPT_INT,
2537 .off1 = td_var_offset(uid),
2538 .help = "Run job with this user ID",
2539 },
2540 {
2541 .name = "gid",
2542 .type = FIO_OPT_INT,
2543 .off1 = td_var_offset(gid),
2544 .help = "Run job with this group ID",
2545 },
2546 {
Dan Ehrenberg9e684a42012-02-20 11:05:14 +01002547 .name = "flow_id",
2548 .type = FIO_OPT_INT,
2549 .off1 = td_var_offset(flow_id),
2550 .help = "The flow index ID to use",
2551 .def = "0",
2552 },
2553 {
2554 .name = "flow",
2555 .type = FIO_OPT_INT,
2556 .off1 = td_var_offset(flow),
2557 .help = "Weight for flow control of this job",
2558 .parent = "flow_id",
2559 .def = "0",
2560 },
2561 {
2562 .name = "flow_watermark",
2563 .type = FIO_OPT_INT,
2564 .off1 = td_var_offset(flow_watermark),
2565 .help = "High watermark for flow control. This option"
2566 " should be set to the same value for all threads"
2567 " with non-zero flow.",
2568 .parent = "flow_id",
2569 .def = "1024",
2570 },
2571 {
2572 .name = "flow_sleep",
2573 .type = FIO_OPT_INT,
2574 .off1 = td_var_offset(flow_sleep),
2575 .help = "How many microseconds to sleep after being held"
2576 " back by the flow control mechanism",
2577 .parent = "flow_id",
2578 .def = "0",
2579 },
2580 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002581 .name = NULL,
2582 },
2583};
2584
Jens Axboe17af15d2010-04-13 10:38:16 +02002585static void add_to_lopt(struct option *lopt, struct fio_option *o,
Steven Langde890a12011-11-09 14:03:34 +01002586 const char *name, int val)
Jens Axboe9f817362010-03-04 14:38:10 +01002587{
Jens Axboe17af15d2010-04-13 10:38:16 +02002588 lopt->name = (char *) name;
Steven Langde890a12011-11-09 14:03:34 +01002589 lopt->val = val;
Jens Axboe9f817362010-03-04 14:38:10 +01002590 if (o->type == FIO_OPT_STR_SET)
2591 lopt->has_arg = no_argument;
2592 else
2593 lopt->has_arg = required_argument;
2594}
2595
Steven Langde890a12011-11-09 14:03:34 +01002596static void options_to_lopts(struct fio_option *opts,
2597 struct option *long_options,
2598 int i, int option_type)
2599{
2600 struct fio_option *o = &opts[0];
2601 while (o->name) {
2602 add_to_lopt(&long_options[i], o, o->name, option_type);
2603 if (o->alias) {
2604 i++;
2605 add_to_lopt(&long_options[i], o, o->alias, option_type);
2606 }
2607
2608 i++;
2609 o++;
2610 assert(i < FIO_NR_OPTIONS);
2611 }
2612}
2613
2614void fio_options_set_ioengine_opts(struct option *long_options,
2615 struct thread_data *td)
2616{
2617 unsigned int i;
2618
2619 i = 0;
2620 while (long_options[i].name) {
2621 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2622 memset(&long_options[i], 0, sizeof(*long_options));
2623 break;
2624 }
2625 i++;
2626 }
2627
2628 /*
2629 * Just clear out the prior ioengine options.
2630 */
2631 if (!td || !td->eo)
2632 return;
2633
2634 options_to_lopts(td->io_ops->options, long_options, i,
2635 FIO_GETOPT_IOENGINE);
2636}
2637
Jens Axboe214e1ec2007-03-15 10:48:13 +01002638void fio_options_dup_and_init(struct option *long_options)
2639{
Jens Axboe214e1ec2007-03-15 10:48:13 +01002640 unsigned int i;
2641
2642 options_init(options);
2643
2644 i = 0;
2645 while (long_options[i].name)
2646 i++;
2647
Steven Langde890a12011-11-09 14:03:34 +01002648 options_to_lopts(options, long_options, i, FIO_GETOPT_JOB);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002649}
2650
Jens Axboe74929ac2009-08-05 11:42:37 +02002651struct fio_keyword {
2652 const char *word;
2653 const char *desc;
2654 char *replace;
2655};
2656
2657static struct fio_keyword fio_keywords[] = {
2658 {
2659 .word = "$pagesize",
2660 .desc = "Page size in the system",
2661 },
2662 {
2663 .word = "$mb_memory",
2664 .desc = "Megabytes of memory online",
2665 },
2666 {
2667 .word = "$ncpus",
2668 .desc = "Number of CPUs online in the system",
2669 },
2670 {
2671 .word = NULL,
2672 },
2673};
2674
2675void fio_keywords_init(void)
2676{
Jens Axboe3b2e1462009-12-15 08:58:10 +01002677 unsigned long long mb_memory;
Jens Axboe74929ac2009-08-05 11:42:37 +02002678 char buf[128];
2679 long l;
2680
Jens Axboea4cfc472012-10-09 10:30:48 -06002681 sprintf(buf, "%lu", (unsigned long) page_size);
Jens Axboe74929ac2009-08-05 11:42:37 +02002682 fio_keywords[0].replace = strdup(buf);
2683
Jens Axboe8eb016d2011-07-11 10:24:20 +02002684 mb_memory = os_phys_mem() / (1024 * 1024);
Jens Axboe3b2e1462009-12-15 08:58:10 +01002685 sprintf(buf, "%llu", mb_memory);
Jens Axboe74929ac2009-08-05 11:42:37 +02002686 fio_keywords[1].replace = strdup(buf);
2687
Jens Axboec00a2282011-07-08 20:56:06 +02002688 l = cpus_online();
Jens Axboe74929ac2009-08-05 11:42:37 +02002689 sprintf(buf, "%lu", l);
2690 fio_keywords[2].replace = strdup(buf);
2691}
2692
Jens Axboe892a6ff2009-11-13 12:19:49 +01002693#define BC_APP "bc"
2694
2695static char *bc_calc(char *str)
2696{
Steven Langd0c814e2011-10-28 08:37:13 +02002697 char buf[128], *tmp;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002698 FILE *f;
2699 int ret;
2700
2701 /*
2702 * No math, just return string
2703 */
Steven Langd0c814e2011-10-28 08:37:13 +02002704 if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2705 !strchr(str, '/')) || strchr(str, '\''))
Jens Axboe892a6ff2009-11-13 12:19:49 +01002706 return str;
2707
2708 /*
2709 * Split option from value, we only need to calculate the value
2710 */
2711 tmp = strchr(str, '=');
2712 if (!tmp)
2713 return str;
2714
2715 tmp++;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002716
Steven Langd0c814e2011-10-28 08:37:13 +02002717 /*
2718 * Prevent buffer overflows; such a case isn't reasonable anyway
2719 */
2720 if (strlen(str) >= 128 || strlen(tmp) > 100)
2721 return str;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002722
2723 sprintf(buf, "which %s > /dev/null", BC_APP);
2724 if (system(buf)) {
2725 log_err("fio: bc is needed for performing math\n");
Jens Axboe892a6ff2009-11-13 12:19:49 +01002726 return NULL;
2727 }
2728
Steven Langd0c814e2011-10-28 08:37:13 +02002729 sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002730 f = popen(buf, "r");
2731 if (!f) {
Jens Axboe892a6ff2009-11-13 12:19:49 +01002732 return NULL;
2733 }
2734
Steven Langd0c814e2011-10-28 08:37:13 +02002735 ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002736 if (ret <= 0) {
Jens Axboe892a6ff2009-11-13 12:19:49 +01002737 return NULL;
2738 }
2739
Jens Axboe892a6ff2009-11-13 12:19:49 +01002740 pclose(f);
Steven Langd0c814e2011-10-28 08:37:13 +02002741 buf[(tmp - str) + ret - 1] = '\0';
2742 memcpy(buf, str, tmp - str);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002743 free(str);
Steven Langd0c814e2011-10-28 08:37:13 +02002744 return strdup(buf);
2745}
2746
2747/*
2748 * Return a copy of the input string with substrings of the form ${VARNAME}
2749 * substituted with the value of the environment variable VARNAME. The
2750 * substitution always occurs, even if VARNAME is empty or the corresponding
2751 * environment variable undefined.
2752 */
2753static char *option_dup_subs(const char *opt)
2754{
2755 char out[OPT_LEN_MAX+1];
2756 char in[OPT_LEN_MAX+1];
2757 char *outptr = out;
2758 char *inptr = in;
2759 char *ch1, *ch2, *env;
2760 ssize_t nchr = OPT_LEN_MAX;
2761 size_t envlen;
2762
2763 if (strlen(opt) + 1 > OPT_LEN_MAX) {
2764 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2765 return NULL;
2766 }
2767
2768 in[OPT_LEN_MAX] = '\0';
2769 strncpy(in, opt, OPT_LEN_MAX);
2770
2771 while (*inptr && nchr > 0) {
2772 if (inptr[0] == '$' && inptr[1] == '{') {
2773 ch2 = strchr(inptr, '}');
2774 if (ch2 && inptr+1 < ch2) {
2775 ch1 = inptr+2;
2776 inptr = ch2+1;
2777 *ch2 = '\0';
2778
2779 env = getenv(ch1);
2780 if (env) {
2781 envlen = strlen(env);
2782 if (envlen <= nchr) {
2783 memcpy(outptr, env, envlen);
2784 outptr += envlen;
2785 nchr -= envlen;
2786 }
2787 }
2788
2789 continue;
2790 }
2791 }
2792
2793 *outptr++ = *inptr++;
2794 --nchr;
2795 }
2796
2797 *outptr = '\0';
2798 return strdup(out);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002799}
2800
Jens Axboe74929ac2009-08-05 11:42:37 +02002801/*
2802 * Look for reserved variable names and replace them with real values
2803 */
2804static char *fio_keyword_replace(char *opt)
2805{
2806 char *s;
2807 int i;
Steven Langd0c814e2011-10-28 08:37:13 +02002808 int docalc = 0;
Jens Axboe74929ac2009-08-05 11:42:37 +02002809
2810 for (i = 0; fio_keywords[i].word != NULL; i++) {
2811 struct fio_keyword *kw = &fio_keywords[i];
2812
2813 while ((s = strstr(opt, kw->word)) != NULL) {
2814 char *new = malloc(strlen(opt) + 1);
2815 char *o_org = opt;
2816 int olen = s - opt;
2817 int len;
2818
2819 /*
2820 * Copy part of the string before the keyword and
2821 * sprintf() the replacement after it.
2822 */
2823 memcpy(new, opt, olen);
2824 len = sprintf(new + olen, "%s", kw->replace);
2825
2826 /*
2827 * If there's more in the original string, copy that
2828 * in too
2829 */
2830 opt += strlen(kw->word) + olen;
2831 if (strlen(opt))
2832 memcpy(new + olen + len, opt, opt - o_org - 1);
2833
2834 /*
2835 * replace opt and free the old opt
2836 */
2837 opt = new;
Steven Langd0c814e2011-10-28 08:37:13 +02002838 free(o_org);
Jens Axboe7a958bd2009-11-13 12:33:54 +01002839
Steven Langd0c814e2011-10-28 08:37:13 +02002840 docalc = 1;
Jens Axboe74929ac2009-08-05 11:42:37 +02002841 }
2842 }
2843
Steven Langd0c814e2011-10-28 08:37:13 +02002844 /*
2845 * Check for potential math and invoke bc, if possible
2846 */
2847 if (docalc)
2848 opt = bc_calc(opt);
2849
Jens Axboe7a958bd2009-11-13 12:33:54 +01002850 return opt;
Jens Axboe74929ac2009-08-05 11:42:37 +02002851}
2852
Steven Langd0c814e2011-10-28 08:37:13 +02002853static char **dup_and_sub_options(char **opts, int num_opts)
2854{
2855 int i;
2856 char **opts_copy = malloc(num_opts * sizeof(*opts));
2857 for (i = 0; i < num_opts; i++) {
2858 opts_copy[i] = option_dup_subs(opts[i]);
2859 if (!opts_copy[i])
2860 continue;
2861 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2862 }
2863 return opts_copy;
2864}
2865
Jens Axboe3b8b7132008-06-10 19:46:23 +02002866int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
Jens Axboe214e1ec2007-03-15 10:48:13 +01002867{
Steven Langde890a12011-11-09 14:03:34 +01002868 int i, ret, unknown;
Steven Langd0c814e2011-10-28 08:37:13 +02002869 char **opts_copy;
Jens Axboe3b8b7132008-06-10 19:46:23 +02002870
2871 sort_options(opts, options, num_opts);
Steven Langd0c814e2011-10-28 08:37:13 +02002872 opts_copy = dup_and_sub_options(opts, num_opts);
Jens Axboe3b8b7132008-06-10 19:46:23 +02002873
Steven Langde890a12011-11-09 14:03:34 +01002874 for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
2875 struct fio_option *o;
2876 int newret = parse_option(opts_copy[i], opts[i], options, &o,
2877 td);
Steven Langd0c814e2011-10-28 08:37:13 +02002878
Steven Langde890a12011-11-09 14:03:34 +01002879 if (opts_copy[i]) {
2880 if (newret && !o) {
2881 unknown++;
2882 continue;
2883 }
Steven Langd0c814e2011-10-28 08:37:13 +02002884 free(opts_copy[i]);
Steven Langde890a12011-11-09 14:03:34 +01002885 opts_copy[i] = NULL;
2886 }
2887
2888 ret |= newret;
2889 }
2890
2891 if (unknown) {
2892 ret |= ioengine_load(td);
2893 if (td->eo) {
2894 sort_options(opts_copy, td->io_ops->options, num_opts);
2895 opts = opts_copy;
2896 }
2897 for (i = 0; i < num_opts; i++) {
2898 struct fio_option *o = NULL;
2899 int newret = 1;
2900 if (!opts_copy[i])
2901 continue;
2902
2903 if (td->eo)
2904 newret = parse_option(opts_copy[i], opts[i],
2905 td->io_ops->options, &o,
2906 td->eo);
2907
2908 ret |= newret;
2909 if (!o)
2910 log_err("Bad option <%s>\n", opts[i]);
2911
2912 free(opts_copy[i]);
2913 opts_copy[i] = NULL;
2914 }
Jens Axboe74929ac2009-08-05 11:42:37 +02002915 }
Jens Axboe3b8b7132008-06-10 19:46:23 +02002916
Steven Langd0c814e2011-10-28 08:37:13 +02002917 free(opts_copy);
Jens Axboe3b8b7132008-06-10 19:46:23 +02002918 return ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +01002919}
2920
2921int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2922{
Jens Axboe07b32322010-03-05 09:48:44 +01002923 return parse_cmd_option(opt, val, options, td);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002924}
2925
Steven Langde890a12011-11-09 14:03:34 +01002926int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
2927 char *val)
2928{
2929 return parse_cmd_option(opt, val, td->io_ops->options, td);
2930}
2931
Jens Axboe214e1ec2007-03-15 10:48:13 +01002932void fio_fill_default_options(struct thread_data *td)
2933{
2934 fill_default_options(td, options);
2935}
2936
2937int fio_show_option_help(const char *opt)
2938{
Jens Axboe07b32322010-03-05 09:48:44 +01002939 return show_cmd_help(options, opt);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002940}
Jens Axboed23bb322007-03-23 15:57:56 +01002941
Steven Langde890a12011-11-09 14:03:34 +01002942void options_mem_dupe(void *data, struct fio_option *options)
2943{
2944 struct fio_option *o;
2945 char **ptr;
2946
2947 for (o = &options[0]; o->name; o++) {
2948 if (o->type != FIO_OPT_STR_STORE)
2949 continue;
2950
2951 ptr = td_var(data, o->off1);
2952 if (*ptr)
2953 *ptr = strdup(*ptr);
2954 }
2955}
2956
Jens Axboe7e356b22011-10-14 10:55:16 +02002957/*
2958 * dupe FIO_OPT_STR_STORE options
2959 */
Steven Langde890a12011-11-09 14:03:34 +01002960void fio_options_mem_dupe(struct thread_data *td)
Jens Axboed23bb322007-03-23 15:57:56 +01002961{
Steven Langde890a12011-11-09 14:03:34 +01002962 options_mem_dupe(&td->o, options);
Jens Axboe1647f592011-11-09 20:25:21 +01002963
2964 if (td->eo && td->io_ops) {
Steven Langde890a12011-11-09 14:03:34 +01002965 void *oldeo = td->eo;
Jens Axboe1647f592011-11-09 20:25:21 +01002966
Steven Langde890a12011-11-09 14:03:34 +01002967 td->eo = malloc(td->io_ops->option_struct_size);
2968 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
2969 options_mem_dupe(td->eo, td->io_ops->options);
Jens Axboed23bb322007-03-23 15:57:56 +01002970 }
2971}
2972
Jens Axboed6978a32009-07-18 21:04:09 +02002973unsigned int fio_get_kb_base(void *data)
2974{
2975 struct thread_data *td = data;
2976 unsigned int kb_base = 0;
2977
2978 if (td)
2979 kb_base = td->o.kb_base;
2980 if (!kb_base)
2981 kb_base = 1024;
2982
2983 return kb_base;
2984}
Jens Axboe9f988e22010-03-04 10:42:38 +01002985
Jens Axboe07b32322010-03-05 09:48:44 +01002986int add_option(struct fio_option *o)
Jens Axboe9f988e22010-03-04 10:42:38 +01002987{
Jens Axboe07b32322010-03-05 09:48:44 +01002988 struct fio_option *__o;
2989 int opt_index = 0;
2990
2991 __o = options;
2992 while (__o->name) {
2993 opt_index++;
2994 __o++;
2995 }
2996
2997 memcpy(&options[opt_index], o, sizeof(*o));
2998 return 0;
Jens Axboe9f988e22010-03-04 10:42:38 +01002999}
Jens Axboee2de69d2010-03-04 14:05:48 +01003000
Jens Axboe07b32322010-03-05 09:48:44 +01003001void invalidate_profile_options(const char *prof_name)
Jens Axboee2de69d2010-03-04 14:05:48 +01003002{
Jens Axboe07b32322010-03-05 09:48:44 +01003003 struct fio_option *o;
Jens Axboee2de69d2010-03-04 14:05:48 +01003004
Jens Axboe07b32322010-03-05 09:48:44 +01003005 o = options;
3006 while (o->name) {
3007 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
3008 o->type = FIO_OPT_INVALID;
3009 o->prof_name = NULL;
3010 }
3011 o++;
Jens Axboee2de69d2010-03-04 14:05:48 +01003012 }
3013}
Jens Axboef5b6bb82010-03-05 10:09:59 +01003014
3015void add_opt_posval(const char *optname, const char *ival, const char *help)
3016{
3017 struct fio_option *o;
3018 unsigned int i;
3019
3020 o = find_option(options, optname);
3021 if (!o)
3022 return;
3023
3024 for (i = 0; i < PARSE_MAX_VP; i++) {
3025 if (o->posval[i].ival)
3026 continue;
3027
3028 o->posval[i].ival = ival;
3029 o->posval[i].help = help;
3030 break;
3031 }
3032}
3033
3034void del_opt_posval(const char *optname, const char *ival)
3035{
3036 struct fio_option *o;
3037 unsigned int i;
3038
3039 o = find_option(options, optname);
3040 if (!o)
3041 return;
3042
3043 for (i = 0; i < PARSE_MAX_VP; i++) {
3044 if (!o->posval[i].ival)
3045 continue;
3046 if (strcmp(o->posval[i].ival, ival))
3047 continue;
3048
3049 o->posval[i].ival = NULL;
3050 o->posval[i].help = NULL;
3051 }
3052}
Jens Axboe7e356b22011-10-14 10:55:16 +02003053
3054void fio_options_free(struct thread_data *td)
3055{
3056 options_free(options, td);
Steven Langde890a12011-11-09 14:03:34 +01003057 if (td->eo && td->io_ops && td->io_ops->options) {
3058 options_free(td->io_ops->options, td->eo);
3059 free(td->eo);
3060 td->eo = NULL;
3061 }
Jens Axboe7e356b22011-10-14 10:55:16 +02003062}