blob: 1760762040c65fb83d0eb10a0466738c514551ec [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;
Jens Axboefa80fea2012-12-09 20:29:00 +0100373 fio_clock_source_set = 1;
Jens Axboe01423ea2012-12-14 20:37:06 +0100374 fio_clock_init();
Jens Axboec223da82010-03-24 13:23:53 +0100375 return 0;
376}
377
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400378static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100379{
380 mlock_size = *val;
381 return 0;
382}
383
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400384static int str_rwmix_read_cb(void *data, unsigned long long *val)
Jens Axboecb499fc2008-05-28 10:33:32 +0200385{
386 struct thread_data *td = data;
387
388 td->o.rwmix[DDIR_READ] = *val;
389 td->o.rwmix[DDIR_WRITE] = 100 - *val;
390 return 0;
391}
392
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400393static int str_rwmix_write_cb(void *data, unsigned long long *val)
Jens Axboecb499fc2008-05-28 10:33:32 +0200394{
395 struct thread_data *td = data;
396
397 td->o.rwmix[DDIR_WRITE] = *val;
398 td->o.rwmix[DDIR_READ] = 100 - *val;
399 return 0;
400}
401
Jens Axboe214e1ec2007-03-15 10:48:13 +0100402#ifdef FIO_HAVE_IOPRIO
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400403static int str_prioclass_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100404{
405 struct thread_data *td = data;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200406 unsigned short mask;
407
408 /*
409 * mask off old class bits, str_prio_cb() may have set a default class
410 */
411 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
412 td->ioprio &= mask;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100413
414 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
Jens Axboeac684782007-11-08 08:29:07 +0100415 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100416 return 0;
417}
418
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400419static int str_prio_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100420{
421 struct thread_data *td = data;
422
423 td->ioprio |= *val;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200424
425 /*
426 * If no class is set, assume BE
427 */
428 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
429 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
430
Jens Axboeac684782007-11-08 08:29:07 +0100431 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100432 return 0;
433}
434#endif
435
436static int str_exitall_cb(void)
437{
438 exitall_on_terminate = 1;
439 return 0;
440}
441
Jens Axboe214e1ec2007-03-15 10:48:13 +0100442#ifdef FIO_HAVE_CPU_AFFINITY
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400443static int str_cpumask_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100444{
445 struct thread_data *td = data;
Jens Axboed2e268b2007-06-15 10:33:49 +0200446 unsigned int i;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100447 long max_cpu;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100448 int ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100449
Jens Axboed2ce18b2008-12-12 20:51:40 +0100450 ret = fio_cpuset_init(&td->o.cpumask);
451 if (ret < 0) {
452 log_err("fio: cpuset_init failed\n");
453 td_verror(td, ret, "fio_cpuset_init");
454 return 1;
455 }
456
Jens Axboec00a2282011-07-08 20:56:06 +0200457 max_cpu = cpus_online();
Jens Axboed2e268b2007-06-15 10:33:49 +0200458
Jens Axboe62a72732008-12-08 11:37:01 +0100459 for (i = 0; i < sizeof(int) * 8; i++) {
460 if ((1 << i) & *val) {
Jens Axboeb03daaf2008-12-08 20:31:43 +0100461 if (i > max_cpu) {
462 log_err("fio: CPU %d too large (max=%ld)\n", i,
463 max_cpu);
464 return 1;
465 }
Jens Axboe62a72732008-12-08 11:37:01 +0100466 dprint(FD_PARSE, "set cpu allowed %d\n", i);
Jens Axboe6d459ee2008-12-12 20:02:58 +0100467 fio_cpu_set(&td->o.cpumask, i);
Jens Axboe62a72732008-12-08 11:37:01 +0100468 }
469 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200470
Jens Axboe375b2692007-05-22 09:13:02 +0200471 td->o.cpumask_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100472 return 0;
473}
474
Jens Axboee8462bd2009-07-06 12:59:04 +0200475static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
476 const char *input)
Jens Axboed2e268b2007-06-15 10:33:49 +0200477{
Jens Axboed2e268b2007-06-15 10:33:49 +0200478 char *cpu, *str, *p;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100479 long max_cpu;
Jens Axboe19608d62008-12-08 15:03:12 +0100480 int ret = 0;
Jens Axboed2e268b2007-06-15 10:33:49 +0200481
Jens Axboee8462bd2009-07-06 12:59:04 +0200482 ret = fio_cpuset_init(mask);
Jens Axboed2ce18b2008-12-12 20:51:40 +0100483 if (ret < 0) {
484 log_err("fio: cpuset_init failed\n");
485 td_verror(td, ret, "fio_cpuset_init");
486 return 1;
487 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200488
489 p = str = strdup(input);
490
491 strip_blank_front(&str);
492 strip_blank_end(str);
493
Jens Axboec00a2282011-07-08 20:56:06 +0200494 max_cpu = cpus_online();
Jens Axboeb03daaf2008-12-08 20:31:43 +0100495
Jens Axboed2e268b2007-06-15 10:33:49 +0200496 while ((cpu = strsep(&str, ",")) != NULL) {
Jens Axboe62a72732008-12-08 11:37:01 +0100497 char *str2, *cpu2;
498 int icpu, icpu2;
499
Jens Axboed2e268b2007-06-15 10:33:49 +0200500 if (!strlen(cpu))
501 break;
Jens Axboe62a72732008-12-08 11:37:01 +0100502
503 str2 = cpu;
504 icpu2 = -1;
505 while ((cpu2 = strsep(&str2, "-")) != NULL) {
506 if (!strlen(cpu2))
507 break;
508
509 icpu2 = atoi(cpu2);
510 }
511
512 icpu = atoi(cpu);
513 if (icpu2 == -1)
514 icpu2 = icpu;
515 while (icpu <= icpu2) {
Jens Axboe6d459ee2008-12-12 20:02:58 +0100516 if (icpu >= FIO_MAX_CPUS) {
Jens Axboe19608d62008-12-08 15:03:12 +0100517 log_err("fio: your OS only supports up to"
Jens Axboe6d459ee2008-12-12 20:02:58 +0100518 " %d CPUs\n", (int) FIO_MAX_CPUS);
Jens Axboe19608d62008-12-08 15:03:12 +0100519 ret = 1;
520 break;
521 }
Jens Axboeb03daaf2008-12-08 20:31:43 +0100522 if (icpu > max_cpu) {
523 log_err("fio: CPU %d too large (max=%ld)\n",
524 icpu, max_cpu);
525 ret = 1;
526 break;
527 }
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200528
Jens Axboe62a72732008-12-08 11:37:01 +0100529 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
Jens Axboee8462bd2009-07-06 12:59:04 +0200530 fio_cpu_set(mask, icpu);
Jens Axboe62a72732008-12-08 11:37:01 +0100531 icpu++;
532 }
Jens Axboe19608d62008-12-08 15:03:12 +0100533 if (ret)
534 break;
Jens Axboed2e268b2007-06-15 10:33:49 +0200535 }
536
537 free(p);
Jens Axboe19608d62008-12-08 15:03:12 +0100538 if (!ret)
539 td->o.cpumask_set = 1;
540 return ret;
Jens Axboed2e268b2007-06-15 10:33:49 +0200541}
Jens Axboee8462bd2009-07-06 12:59:04 +0200542
543static int str_cpus_allowed_cb(void *data, const char *input)
544{
545 struct thread_data *td = data;
546 int ret;
547
548 ret = set_cpus_allowed(td, &td->o.cpumask, input);
549 if (!ret)
550 td->o.cpumask_set = 1;
551
552 return ret;
553}
554
555static int str_verify_cpus_allowed_cb(void *data, const char *input)
556{
557 struct thread_data *td = data;
558 int ret;
559
560 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
561 if (!ret)
562 td->o.verify_cpumask_set = 1;
563
564 return ret;
565}
Jens Axboed2e268b2007-06-15 10:33:49 +0200566#endif
567
Jens Axboe67bf9822013-01-10 11:23:19 +0100568#ifdef CONFIG_LIBNUMA
Yufei Rend0b937e2012-10-19 23:11:52 -0400569static int str_numa_cpunodes_cb(void *data, char *input)
570{
571 struct thread_data *td = data;
572
573 /* numa_parse_nodestring() parses a character string list
574 * of nodes into a bit mask. The bit mask is allocated by
575 * numa_allocate_nodemask(), so it should be freed by
576 * numa_free_nodemask().
577 */
578 td->o.numa_cpunodesmask = numa_parse_nodestring(input);
579 if (td->o.numa_cpunodesmask == NULL) {
580 log_err("fio: numa_parse_nodestring failed\n");
581 td_verror(td, 1, "str_numa_cpunodes_cb");
582 return 1;
583 }
584
585 td->o.numa_cpumask_set = 1;
586 return 0;
587}
588
589static int str_numa_mpol_cb(void *data, char *input)
590{
591 struct thread_data *td = data;
592 const char * const policy_types[] =
593 { "default", "prefer", "bind", "interleave", "local" };
594 int i;
595
596 char *nodelist = strchr(input, ':');
597 if (nodelist) {
598 /* NUL-terminate mode */
599 *nodelist++ = '\0';
600 }
601
602 for (i = 0; i <= MPOL_LOCAL; i++) {
603 if (!strcmp(input, policy_types[i])) {
604 td->o.numa_mem_mode = i;
605 break;
606 }
607 }
608 if (i > MPOL_LOCAL) {
609 log_err("fio: memory policy should be: default, prefer, bind, interleave, local\n");
610 goto out;
611 }
612
613 switch (td->o.numa_mem_mode) {
614 case MPOL_PREFERRED:
615 /*
616 * Insist on a nodelist of one node only
617 */
618 if (nodelist) {
619 char *rest = nodelist;
620 while (isdigit(*rest))
621 rest++;
622 if (*rest) {
623 log_err("fio: one node only for \'prefer\'\n");
624 goto out;
625 }
626 } else {
627 log_err("fio: one node is needed for \'prefer\'\n");
628 goto out;
629 }
630 break;
631 case MPOL_INTERLEAVE:
632 /*
633 * Default to online nodes with memory if no nodelist
634 */
635 if (!nodelist)
636 nodelist = strdup("all");
637 break;
638 case MPOL_LOCAL:
639 case MPOL_DEFAULT:
640 /*
641 * Don't allow a nodelist
642 */
643 if (nodelist) {
644 log_err("fio: NO nodelist for \'local\'\n");
645 goto out;
646 }
647 break;
648 case MPOL_BIND:
649 /*
650 * Insist on a nodelist
651 */
652 if (!nodelist) {
653 log_err("fio: a nodelist is needed for \'bind\'\n");
654 goto out;
655 }
656 break;
657 }
658
659
660 /* numa_parse_nodestring() parses a character string list
661 * of nodes into a bit mask. The bit mask is allocated by
662 * numa_allocate_nodemask(), so it should be freed by
663 * numa_free_nodemask().
664 */
665 switch (td->o.numa_mem_mode) {
666 case MPOL_PREFERRED:
667 td->o.numa_mem_prefer_node = atoi(nodelist);
668 break;
669 case MPOL_INTERLEAVE:
670 case MPOL_BIND:
671 td->o.numa_memnodesmask = numa_parse_nodestring(nodelist);
672 if (td->o.numa_memnodesmask == NULL) {
673 log_err("fio: numa_parse_nodestring failed\n");
674 td_verror(td, 1, "str_numa_memnodes_cb");
675 return 1;
676 }
677 break;
678 case MPOL_LOCAL:
679 case MPOL_DEFAULT:
680 default:
681 break;
682 }
683
684 td->o.numa_memmask_set = 1;
685 return 0;
686
687out:
688 return 1;
689}
690#endif
691
Jens Axboe0d29de82010-09-01 13:54:15 +0200692#ifdef FIO_HAVE_TRIM
693static int str_verify_trim_cb(void *data, unsigned long long *val)
694{
695 struct thread_data *td = data;
696
697 td->o.trim_percentage = *val;
698 return 0;
699}
700#endif
701
Jens Axboe214e1ec2007-03-15 10:48:13 +0100702static int str_fst_cb(void *data, const char *str)
703{
704 struct thread_data *td = data;
705 char *nr = get_opt_postfix(str);
706
707 td->file_service_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100708 if (nr) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100709 td->file_service_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100710 free(nr);
711 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100712
713 return 0;
714}
715
Jens Axboe67bf9822013-01-10 11:23:19 +0100716#ifdef CONFIG_SYNC_FILE_RANGE
Jens Axboe44f29692010-03-09 20:09:44 +0100717static int str_sfr_cb(void *data, const char *str)
718{
719 struct thread_data *td = data;
720 char *nr = get_opt_postfix(str);
721
722 td->sync_file_range_nr = 1;
723 if (nr) {
724 td->sync_file_range_nr = atoi(nr);
725 free(nr);
726 }
727
728 return 0;
729}
Jens Axboe3ae06372010-03-19 19:17:15 +0100730#endif
Jens Axboe44f29692010-03-09 20:09:44 +0100731
Jens Axboee25839d2012-11-06 10:49:42 +0100732static int str_random_distribution_cb(void *data, const char *str)
733{
734 struct thread_data *td = data;
735 double val;
736 char *nr;
737
Jens Axboe925fee32012-11-06 13:50:32 +0100738 if (td->o.random_distribution == FIO_RAND_DIST_ZIPF)
739 val = 1.1;
740 else if (td->o.random_distribution == FIO_RAND_DIST_PARETO)
741 val = 0.2;
742 else
Jens Axboee25839d2012-11-06 10:49:42 +0100743 return 0;
744
745 nr = get_opt_postfix(str);
Jens Axboe925fee32012-11-06 13:50:32 +0100746 if (nr && !str_to_float(nr, &val)) {
Jens Axboee25839d2012-11-06 10:49:42 +0100747 log_err("fio: random postfix parsing failed\n");
748 free(nr);
749 return 1;
750 }
751
Jens Axboe078189c2012-11-07 13:47:22 +0100752 free(nr);
753
Jens Axboe18ded912012-11-08 08:36:00 +0100754 if (td->o.random_distribution == FIO_RAND_DIST_ZIPF) {
755 if (val == 1.00) {
756 log_err("fio: zipf theta must different than 1.0\n");
757 return 1;
758 }
Jens Axboe925fee32012-11-06 13:50:32 +0100759 td->o.zipf_theta = val;
Jens Axboe18ded912012-11-08 08:36:00 +0100760 } else {
Jens Axboe078189c2012-11-07 13:47:22 +0100761 if (val <= 0.00 || val >= 1.00) {
762 log_err("fio: pareto input out of range (0 < input < 1.0)\n");
763 return 1;
764 }
Jens Axboe925fee32012-11-06 13:50:32 +0100765 td->o.pareto_h = val;
Jens Axboe078189c2012-11-07 13:47:22 +0100766 }
Jens Axboe925fee32012-11-06 13:50:32 +0100767
Jens Axboee25839d2012-11-06 10:49:42 +0100768 return 0;
769}
770
Jens Axboe921c7662008-03-26 09:17:55 +0100771static int check_dir(struct thread_data *td, char *fname)
772{
Jens Axboe3f0ca9b2011-05-24 21:36:24 +0200773#if 0
Jens Axboe921c7662008-03-26 09:17:55 +0100774 char file[PATH_MAX], *dir;
Jens Axboebc838912008-04-07 09:00:54 +0200775 int elen = 0;
Jens Axboe921c7662008-03-26 09:17:55 +0100776
Jens Axboebc838912008-04-07 09:00:54 +0200777 if (td->o.directory) {
778 strcpy(file, td->o.directory);
Jens Axboefcef0b32008-05-26 14:53:24 +0200779 strcat(file, "/");
Jens Axboebc838912008-04-07 09:00:54 +0200780 elen = strlen(file);
781 }
782
Jens Axboefcef0b32008-05-26 14:53:24 +0200783 sprintf(file + elen, "%s", fname);
Jens Axboe921c7662008-03-26 09:17:55 +0100784 dir = dirname(file);
785
Jens Axboefcef0b32008-05-26 14:53:24 +0200786 {
787 struct stat sb;
788 /*
789 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
790 * yet, so we can't do this check right here...
791 */
Jens Axboe921c7662008-03-26 09:17:55 +0100792 if (lstat(dir, &sb) < 0) {
793 int ret = errno;
794
795 log_err("fio: %s is not a directory\n", dir);
796 td_verror(td, ret, "lstat");
797 return 1;
798 }
799
800 if (!S_ISDIR(sb.st_mode)) {
801 log_err("fio: %s is not a directory\n", dir);
802 return 1;
803 }
Jens Axboefcef0b32008-05-26 14:53:24 +0200804 }
805#endif
Jens Axboe921c7662008-03-26 09:17:55 +0100806
807 return 0;
808}
809
Jens Axboe8e827d32009-08-04 09:51:48 +0200810/*
811 * Return next file in the string. Files are separated with ':'. If the ':'
812 * is escaped with a '\', then that ':' is part of the filename and does not
813 * indicate a new file.
814 */
815static char *get_next_file_name(char **ptr)
816{
817 char *str = *ptr;
818 char *p, *start;
819
820 if (!str || !strlen(str))
821 return NULL;
822
823 start = str;
824 do {
825 /*
826 * No colon, we are done
827 */
828 p = strchr(str, ':');
829 if (!p) {
830 *ptr = NULL;
831 break;
832 }
833
834 /*
835 * We got a colon, but it's the first character. Skip and
836 * continue
837 */
838 if (p == start) {
839 str = ++start;
840 continue;
841 }
842
843 if (*(p - 1) != '\\') {
844 *p = '\0';
845 *ptr = p + 1;
846 break;
847 }
848
849 memmove(p - 1, p, strlen(p) + 1);
850 str = p;
851 } while (1);
852
853 return start;
854}
855
Jens Axboe214e1ec2007-03-15 10:48:13 +0100856static int str_filename_cb(void *data, const char *input)
857{
858 struct thread_data *td = data;
859 char *fname, *str, *p;
860
861 p = str = strdup(input);
862
863 strip_blank_front(&str);
864 strip_blank_end(str);
865
866 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100867 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100868
Jens Axboe8e827d32009-08-04 09:51:48 +0200869 while ((fname = get_next_file_name(&str)) != NULL) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100870 if (!strlen(fname))
871 break;
Jens Axboe921c7662008-03-26 09:17:55 +0100872 if (check_dir(td, fname)) {
873 free(p);
874 return 1;
875 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100876 add_file(td, fname);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100877 td->o.nr_files++;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100878 }
879
880 free(p);
881 return 0;
882}
883
884static int str_directory_cb(void *data, const char fio_unused *str)
885{
886 struct thread_data *td = data;
887 struct stat sb;
888
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100889 if (lstat(td->o.directory, &sb) < 0) {
Jens Axboe921c7662008-03-26 09:17:55 +0100890 int ret = errno;
891
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100892 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe921c7662008-03-26 09:17:55 +0100893 td_verror(td, ret, "lstat");
Jens Axboe214e1ec2007-03-15 10:48:13 +0100894 return 1;
895 }
896 if (!S_ISDIR(sb.st_mode)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100897 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100898 return 1;
899 }
900
901 return 0;
902}
903
904static int str_opendir_cb(void *data, const char fio_unused *str)
905{
906 struct thread_data *td = data;
907
908 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100909 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100910
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100911 return add_dir_files(td, td->o.opendir);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100912}
913
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400914static int str_verify_offset_cb(void *data, unsigned long long *off)
Shawn Lewis546a9142007-07-28 21:11:37 +0200915{
916 struct thread_data *td = data;
Jens Axboea59e1702007-07-30 08:53:27 +0200917
Shawn Lewis546a9142007-07-28 21:11:37 +0200918 if (*off && *off < sizeof(struct verify_header)) {
Jens Axboea59e1702007-07-30 08:53:27 +0200919 log_err("fio: verify_offset too small\n");
Shawn Lewis546a9142007-07-28 21:11:37 +0200920 return 1;
921 }
Jens Axboea59e1702007-07-30 08:53:27 +0200922
923 td->o.verify_offset = *off;
Shawn Lewis546a9142007-07-28 21:11:37 +0200924 return 0;
925}
926
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100927static int str_verify_pattern_cb(void *data, const char *input)
Jens Axboe90059d62007-07-30 09:33:12 +0200928{
929 struct thread_data *td = data;
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100930 long off;
931 int i = 0, j = 0, len, k, base = 10;
932 char* loc1, * loc2;
Jens Axboe90059d62007-07-30 09:33:12 +0200933
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100934 loc1 = strstr(input, "0x");
935 loc2 = strstr(input, "0X");
936 if (loc1 || loc2)
937 base = 16;
938 off = strtol(input, NULL, base);
939 if (off != LONG_MAX || errno != ERANGE) {
940 while (off) {
941 td->o.verify_pattern[i] = off & 0xff;
942 off >>= 8;
943 i++;
944 }
945 } else {
946 len = strlen(input);
947 k = len - 1;
948 if (base == 16) {
949 if (loc1)
950 j = loc1 - input + 2;
951 else
952 j = loc2 - input + 2;
953 } else
954 return 1;
955 if (len - j < MAX_PATTERN_SIZE * 2) {
956 while (k >= j) {
957 off = converthexchartoint(input[k--]);
958 if (k >= j)
959 off += (converthexchartoint(input[k--])
960 * 16);
961 td->o.verify_pattern[i++] = (char) off;
962 }
963 }
964 }
Steven Langefcd9dc2012-02-02 20:22:04 +0100965
966 /*
967 * Fill the pattern all the way to the end. This greatly reduces
968 * the number of memcpy's we have to do when verifying the IO.
969 */
970 while (i > 1 && i * 2 <= MAX_PATTERN_SIZE) {
971 memcpy(&td->o.verify_pattern[i], &td->o.verify_pattern[0], i);
972 i *= 2;
973 }
Steven Lang9a2a86d2012-02-07 09:42:59 +0100974 if (i == 1) {
975 /*
976 * The code in verify_io_u_pattern assumes a single byte pattern
977 * fills the whole verify pattern buffer.
978 */
979 memset(td->o.verify_pattern, td->o.verify_pattern[0],
980 MAX_PATTERN_SIZE);
981 }
Steven Langefcd9dc2012-02-02 20:22:04 +0100982
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100983 td->o.verify_pattern_bytes = i;
Steven Langefcd9dc2012-02-02 20:22:04 +0100984
Jens Axboe92bf48d2011-01-14 21:20:42 +0100985 /*
986 * VERIFY_META could already be set
987 */
988 if (td->o.verify == VERIFY_NONE)
989 td->o.verify = VERIFY_PATTERN;
Steven Langefcd9dc2012-02-02 20:22:04 +0100990
Jens Axboe90059d62007-07-30 09:33:12 +0200991 return 0;
992}
Jens Axboe214e1ec2007-03-15 10:48:13 +0100993
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100994static int str_lockfile_cb(void *data, const char *str)
995{
996 struct thread_data *td = data;
997 char *nr = get_opt_postfix(str);
998
999 td->o.lockfile_batch = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +01001000 if (nr) {
Jens Axboe4d4e80f2008-03-04 10:18:56 +01001001 td->o.lockfile_batch = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +01001002 free(nr);
1003 }
Jens Axboe4d4e80f2008-03-04 10:18:56 +01001004
1005 return 0;
1006}
1007
Jens Axboee3cedca2008-11-19 19:57:52 +01001008static int str_write_bw_log_cb(void *data, const char *str)
1009{
1010 struct thread_data *td = data;
1011
1012 if (str)
1013 td->o.bw_log_file = strdup(str);
1014
1015 td->o.write_bw_log = 1;
1016 return 0;
1017}
1018
1019static int str_write_lat_log_cb(void *data, const char *str)
1020{
1021 struct thread_data *td = data;
1022
1023 if (str)
1024 td->o.lat_log_file = strdup(str);
1025
1026 td->o.write_lat_log = 1;
1027 return 0;
1028}
1029
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001030static int str_write_iops_log_cb(void *data, const char *str)
1031{
1032 struct thread_data *td = data;
1033
1034 if (str)
1035 td->o.iops_log_file = strdup(str);
1036
1037 td->o.write_iops_log = 1;
1038 return 0;
1039}
1040
Jens Axboe993bf482008-11-14 13:04:53 +01001041static int str_gtod_reduce_cb(void *data, int *il)
1042{
1043 struct thread_data *td = data;
1044 int val = *il;
1045
Jens Axboe02af0982010-06-24 09:59:34 +02001046 td->o.disable_lat = !!val;
Jens Axboe993bf482008-11-14 13:04:53 +01001047 td->o.disable_clat = !!val;
1048 td->o.disable_slat = !!val;
1049 td->o.disable_bw = !!val;
Jens Axboe0dc1bc02011-10-13 08:55:29 +02001050 td->o.clat_percentiles = !val;
Jens Axboe993bf482008-11-14 13:04:53 +01001051 if (val)
1052 td->tv_cache_mask = 63;
1053
1054 return 0;
1055}
1056
Cigy Cyriac85bc8332010-08-10 19:21:09 -04001057static int str_gtod_cpu_cb(void *data, long long *il)
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001058{
1059 struct thread_data *td = data;
1060 int val = *il;
1061
1062 td->o.gtod_cpu = val;
1063 td->o.gtod_offload = 1;
1064 return 0;
1065}
1066
Jens Axboe7bb59102011-07-12 19:47:03 +02001067static int str_size_cb(void *data, unsigned long long *__val)
1068{
1069 struct thread_data *td = data;
1070 unsigned long long v = *__val;
1071
1072 if (parse_is_percent(v)) {
1073 td->o.size = 0;
1074 td->o.size_percent = -1ULL - v;
1075 } else
1076 td->o.size = v;
1077
1078 return 0;
1079}
1080
Jens Axboe896cac22009-07-01 10:38:35 +02001081static int rw_verify(struct fio_option *o, void *data)
1082{
1083 struct thread_data *td = data;
1084
1085 if (read_only && td_write(td)) {
1086 log_err("fio: job <%s> has write bit set, but fio is in"
1087 " read-only mode\n", td->o.name);
1088 return 1;
1089 }
1090
1091 return 0;
1092}
1093
Jens Axboe276ca4f2009-07-01 10:43:05 +02001094static int gtod_cpu_verify(struct fio_option *o, void *data)
Jens Axboe29d43ff2009-07-01 10:42:18 +02001095{
Jens Axboe276ca4f2009-07-01 10:43:05 +02001096#ifndef FIO_HAVE_CPU_AFFINITY
Jens Axboe29d43ff2009-07-01 10:42:18 +02001097 struct thread_data *td = data;
1098
Jens Axboe29d43ff2009-07-01 10:42:18 +02001099 if (td->o.gtod_cpu) {
1100 log_err("fio: platform must support CPU affinity for"
1101 "gettimeofday() offloading\n");
1102 return 1;
1103 }
1104#endif
1105
1106 return 0;
1107}
1108
Jens Axboe90fef2d2009-07-17 22:33:32 +02001109static int kb_base_verify(struct fio_option *o, void *data)
1110{
1111 struct thread_data *td = data;
1112
1113 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
1114 log_err("fio: kb_base set to nonsensical value: %u\n",
1115 td->o.kb_base);
1116 return 1;
1117 }
1118
1119 return 0;
1120}
1121
Jens Axboe214e1ec2007-03-15 10:48:13 +01001122/*
1123 * Map of job/command line options
1124 */
Jens Axboe07b32322010-03-05 09:48:44 +01001125static struct fio_option options[FIO_MAX_OPTS] = {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001126 {
1127 .name = "description",
1128 .type = FIO_OPT_STR_STORE,
1129 .off1 = td_var_offset(description),
1130 .help = "Text job description",
1131 },
1132 {
1133 .name = "name",
1134 .type = FIO_OPT_STR_STORE,
1135 .off1 = td_var_offset(name),
1136 .help = "Name of this job",
1137 },
1138 {
1139 .name = "directory",
1140 .type = FIO_OPT_STR_STORE,
1141 .off1 = td_var_offset(directory),
1142 .cb = str_directory_cb,
1143 .help = "Directory to store files in",
1144 },
1145 {
1146 .name = "filename",
1147 .type = FIO_OPT_STR_STORE,
1148 .off1 = td_var_offset(filename),
1149 .cb = str_filename_cb,
Jens Axboef0d524b2009-04-27 08:00:48 +02001150 .prio = -1, /* must come after "directory" */
Jens Axboe214e1ec2007-03-15 10:48:13 +01001151 .help = "File(s) to use for the workload",
1152 },
1153 {
Jens Axboe90fef2d2009-07-17 22:33:32 +02001154 .name = "kb_base",
1155 .type = FIO_OPT_INT,
1156 .off1 = td_var_offset(kb_base),
Jens Axboe90fef2d2009-07-17 22:33:32 +02001157 .verify = kb_base_verify,
Jens Axboea639f0b2009-07-18 08:25:35 +02001158 .prio = 1,
Jens Axboe90fef2d2009-07-17 22:33:32 +02001159 .def = "1024",
Jens Axboea639f0b2009-07-18 08:25:35 +02001160 .help = "How many bytes per KB for reporting (1000 or 1024)",
Jens Axboe90fef2d2009-07-17 22:33:32 +02001161 },
1162 {
Jens Axboe29c13492008-03-01 19:25:20 +01001163 .name = "lockfile",
Jens Axboe4d4e80f2008-03-04 10:18:56 +01001164 .type = FIO_OPT_STR,
1165 .cb = str_lockfile_cb,
1166 .off1 = td_var_offset(file_lock_mode),
Jens Axboe29c13492008-03-01 19:25:20 +01001167 .help = "Lock file when doing IO to it",
1168 .parent = "filename",
Jens Axboe4d4e80f2008-03-04 10:18:56 +01001169 .def = "none",
1170 .posval = {
1171 { .ival = "none",
1172 .oval = FILE_LOCK_NONE,
1173 .help = "No file locking",
1174 },
1175 { .ival = "exclusive",
1176 .oval = FILE_LOCK_EXCLUSIVE,
1177 .help = "Exclusive file lock",
1178 },
1179 {
1180 .ival = "readwrite",
1181 .oval = FILE_LOCK_READWRITE,
1182 .help = "Read vs write lock",
1183 },
1184 },
Jens Axboe29c13492008-03-01 19:25:20 +01001185 },
1186 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001187 .name = "opendir",
1188 .type = FIO_OPT_STR_STORE,
1189 .off1 = td_var_offset(opendir),
1190 .cb = str_opendir_cb,
1191 .help = "Recursively add files from this directory and down",
1192 },
1193 {
1194 .name = "rw",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001195 .alias = "readwrite",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001196 .type = FIO_OPT_STR,
Jens Axboe211097b2007-03-22 18:56:45 +01001197 .cb = str_rw_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001198 .off1 = td_var_offset(td_ddir),
1199 .help = "IO direction",
1200 .def = "read",
Jens Axboe896cac22009-07-01 10:38:35 +02001201 .verify = rw_verify,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001202 .posval = {
1203 { .ival = "read",
1204 .oval = TD_DDIR_READ,
1205 .help = "Sequential read",
1206 },
1207 { .ival = "write",
1208 .oval = TD_DDIR_WRITE,
1209 .help = "Sequential write",
1210 },
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001211 { .ival = "trim",
1212 .oval = TD_DDIR_TRIM,
1213 .help = "Sequential trim",
1214 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001215 { .ival = "randread",
1216 .oval = TD_DDIR_RANDREAD,
1217 .help = "Random read",
1218 },
1219 { .ival = "randwrite",
1220 .oval = TD_DDIR_RANDWRITE,
1221 .help = "Random write",
1222 },
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001223 { .ival = "randtrim",
1224 .oval = TD_DDIR_RANDTRIM,
1225 .help = "Random trim",
1226 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001227 { .ival = "rw",
1228 .oval = TD_DDIR_RW,
1229 .help = "Sequential read and write mix",
1230 },
Jens Axboe10b023d2012-03-23 13:40:06 +01001231 { .ival = "readwrite",
1232 .oval = TD_DDIR_RW,
1233 .help = "Sequential read and write mix",
1234 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001235 { .ival = "randrw",
1236 .oval = TD_DDIR_RANDRW,
1237 .help = "Random read and write mix"
1238 },
1239 },
1240 },
1241 {
Jens Axboe38dad622010-07-20 14:46:00 -06001242 .name = "rw_sequencer",
1243 .type = FIO_OPT_STR,
1244 .off1 = td_var_offset(rw_seq),
1245 .help = "IO offset generator modifier",
1246 .def = "sequential",
1247 .posval = {
1248 { .ival = "sequential",
1249 .oval = RW_SEQ_SEQ,
1250 .help = "Generate sequential offsets",
1251 },
1252 { .ival = "identical",
1253 .oval = RW_SEQ_IDENT,
1254 .help = "Generate identical offsets",
1255 },
1256 },
1257 },
1258
1259 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001260 .name = "ioengine",
1261 .type = FIO_OPT_STR_STORE,
1262 .off1 = td_var_offset(ioengine),
1263 .help = "IO engine to use",
Jens Axboe58483fa2011-01-19 11:09:58 -07001264 .def = FIO_PREFERRED_ENGINE,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001265 .posval = {
1266 { .ival = "sync",
1267 .help = "Use read/write",
1268 },
gurudas paia31041e2007-10-23 15:12:30 +02001269 { .ival = "psync",
1270 .help = "Use pread/pwrite",
1271 },
Jens Axboe1d2af022008-02-04 10:59:07 +01001272 { .ival = "vsync",
Bruce Cran03e20d62011-01-02 20:14:54 +01001273 .help = "Use readv/writev",
Jens Axboe1d2af022008-02-04 10:59:07 +01001274 },
Jens Axboe67bf9822013-01-10 11:23:19 +01001275#ifdef CONFIG_LIBAIO
Jens Axboe214e1ec2007-03-15 10:48:13 +01001276 { .ival = "libaio",
1277 .help = "Linux native asynchronous IO",
1278 },
1279#endif
Jens Axboe67bf9822013-01-10 11:23:19 +01001280#ifdef CONFIG_POSIXAIO
Jens Axboe214e1ec2007-03-15 10:48:13 +01001281 { .ival = "posixaio",
1282 .help = "POSIX asynchronous IO",
1283 },
1284#endif
Jens Axboe417f0062008-06-02 11:59:30 +02001285#ifdef FIO_HAVE_SOLARISAIO
1286 { .ival = "solarisaio",
1287 .help = "Solaris native asynchronous IO",
1288 },
1289#endif
Bruce Cran03e20d62011-01-02 20:14:54 +01001290#ifdef FIO_HAVE_WINDOWSAIO
1291 { .ival = "windowsaio",
Jens Axboe3be80072011-01-19 11:07:28 -07001292 .help = "Windows native asynchronous IO"
Steven Langde890a12011-11-09 14:03:34 +01001293 },
Jens Axboe3be80072011-01-19 11:07:28 -07001294#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001295 { .ival = "mmap",
Bruce Cran03e20d62011-01-02 20:14:54 +01001296 .help = "Memory mapped IO"
Jens Axboe214e1ec2007-03-15 10:48:13 +01001297 },
Jens Axboe67bf9822013-01-10 11:23:19 +01001298#ifdef CONFIG_LINUX_SPLICE
Jens Axboe214e1ec2007-03-15 10:48:13 +01001299 { .ival = "splice",
1300 .help = "splice/vmsplice based IO",
1301 },
Jens Axboe9cce02e2007-06-22 15:42:21 +02001302 { .ival = "netsplice",
1303 .help = "splice/vmsplice to/from the network",
1304 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001305#endif
1306#ifdef FIO_HAVE_SGIO
1307 { .ival = "sg",
1308 .help = "SCSI generic v3 IO",
1309 },
1310#endif
1311 { .ival = "null",
1312 .help = "Testing engine (no data transfer)",
1313 },
1314 { .ival = "net",
1315 .help = "Network IO",
1316 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001317 { .ival = "cpuio",
Bruce Cran03e20d62011-01-02 20:14:54 +01001318 .help = "CPU cycle burner engine",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001319 },
Jens Axboe67bf9822013-01-10 11:23:19 +01001320#ifdef CONFIG_GUASI
Jens Axboeb8c82a42007-03-21 08:48:26 +01001321 { .ival = "guasi",
1322 .help = "GUASI IO engine",
1323 },
1324#endif
Jens Axboe79a43182010-09-07 13:28:58 +02001325#ifdef FIO_HAVE_BINJECT
1326 { .ival = "binject",
1327 .help = "binject direct inject block engine",
1328 },
1329#endif
Jens Axboe67bf9822013-01-10 11:23:19 +01001330#ifdef CONFIG_RDMA
ren yufei21b8aee2011-08-01 10:01:57 +02001331 { .ival = "rdma",
1332 .help = "RDMA IO engine",
1333 },
1334#endif
Jens Axboe67bf9822013-01-10 11:23:19 +01001335#ifdef CONFIG_FUSION_AW
Jens Axboe8200b8c2012-09-18 23:55:43 +02001336 { .ival = "fusion-aw-sync",
1337 .help = "Fusion-io atomic write engine",
1338 },
1339#endif
Jens Axboe1ecc95c2012-09-20 13:46:34 +02001340#ifdef FIO_HAVE_E4_ENG
1341 { .ival = "e4defrag",
1342 .help = "ext4 defrag engine",
1343 },
1344#endif
1345#ifdef FIO_HAVE_FALLOC_ENG
1346 { .ival = "falloc",
1347 .help = "fallocate() file based engine",
1348 },
1349#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001350 { .ival = "external",
1351 .help = "Load external engine (append name)",
1352 },
1353 },
1354 },
1355 {
1356 .name = "iodepth",
1357 .type = FIO_OPT_INT,
1358 .off1 = td_var_offset(iodepth),
Bruce Cran03e20d62011-01-02 20:14:54 +01001359 .help = "Number of IO buffers to keep in flight",
Jens Axboe757aff42007-12-12 19:42:13 +01001360 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001361 .def = "1",
1362 },
1363 {
1364 .name = "iodepth_batch",
Jens Axboe49504212008-06-05 09:03:30 +02001365 .alias = "iodepth_batch_submit",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001366 .type = FIO_OPT_INT,
1367 .off1 = td_var_offset(iodepth_batch),
Jens Axboed65db442009-01-16 19:15:33 +01001368 .help = "Number of IO buffers to submit in one go",
Jens Axboeafdf9352007-07-31 16:14:34 +02001369 .parent = "iodepth",
Jens Axboea2e6f8a2008-01-18 10:28:11 +01001370 .minval = 1,
1371 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001372 },
1373 {
Jens Axboe49504212008-06-05 09:03:30 +02001374 .name = "iodepth_batch_complete",
1375 .type = FIO_OPT_INT,
1376 .off1 = td_var_offset(iodepth_batch_complete),
Jens Axboed65db442009-01-16 19:15:33 +01001377 .help = "Number of IO buffers to retrieve in one go",
Jens Axboe49504212008-06-05 09:03:30 +02001378 .parent = "iodepth",
1379 .minval = 0,
1380 .def = "1",
1381 },
1382 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001383 .name = "iodepth_low",
1384 .type = FIO_OPT_INT,
1385 .off1 = td_var_offset(iodepth_low),
1386 .help = "Low water mark for queuing depth",
Jens Axboeafdf9352007-07-31 16:14:34 +02001387 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001388 },
1389 {
1390 .name = "size",
1391 .type = FIO_OPT_STR_VAL,
Jens Axboe7bb59102011-07-12 19:47:03 +02001392 .cb = str_size_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001393 .help = "Total size of device or files",
1394 },
1395 {
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001396 .name = "fill_device",
Jens Axboe74586c12011-01-20 10:16:03 -07001397 .alias = "fill_fs",
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001398 .type = FIO_OPT_BOOL,
1399 .off1 = td_var_offset(fill_device),
1400 .help = "Write until an ENOSPC error occurs",
1401 .def = "0",
1402 },
1403 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001404 .name = "filesize",
1405 .type = FIO_OPT_STR_VAL,
1406 .off1 = td_var_offset(file_size_low),
1407 .off2 = td_var_offset(file_size_high),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001408 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001409 .help = "Size of individual files",
1410 },
1411 {
Jens Axboe67a10002007-07-31 23:12:16 +02001412 .name = "offset",
1413 .alias = "fileoffset",
1414 .type = FIO_OPT_STR_VAL,
1415 .off1 = td_var_offset(start_offset),
1416 .help = "Start IO from this offset",
1417 .def = "0",
1418 },
1419 {
Jens Axboe2d7cd862012-03-15 14:53:38 +01001420 .name = "offset_increment",
1421 .type = FIO_OPT_STR_VAL,
1422 .off1 = td_var_offset(offset_increment),
1423 .help = "What is the increment from one offset to the next",
1424 .parent = "offset",
1425 .def = "0",
1426 },
1427 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001428 .name = "bs",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001429 .alias = "blocksize",
Jens Axboee01b22b2009-06-09 15:43:25 +02001430 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001431 .off1 = td_var_offset(bs[DDIR_READ]),
1432 .off2 = td_var_offset(bs[DDIR_WRITE]),
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001433 .off3 = td_var_offset(bs[DDIR_TRIM]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001434 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001435 .help = "Block size unit",
1436 .def = "4k",
Jens Axboe67a10002007-07-31 23:12:16 +02001437 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001438 },
1439 {
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001440 .name = "ba",
1441 .alias = "blockalign",
Jens Axboee01b22b2009-06-09 15:43:25 +02001442 .type = FIO_OPT_INT,
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001443 .off1 = td_var_offset(ba[DDIR_READ]),
1444 .off2 = td_var_offset(ba[DDIR_WRITE]),
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001445 .off3 = td_var_offset(ba[DDIR_TRIM]),
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001446 .minval = 1,
1447 .help = "IO block offset alignment",
1448 .parent = "rw",
1449 },
1450 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001451 .name = "bsrange",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001452 .alias = "blocksize_range",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001453 .type = FIO_OPT_RANGE,
1454 .off1 = td_var_offset(min_bs[DDIR_READ]),
1455 .off2 = td_var_offset(max_bs[DDIR_READ]),
1456 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1457 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001458 .off5 = td_var_offset(min_bs[DDIR_TRIM]),
1459 .off6 = td_var_offset(max_bs[DDIR_TRIM]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001460 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001461 .help = "Set block size range (in more detail than bs)",
Jens Axboe67a10002007-07-31 23:12:16 +02001462 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001463 },
1464 {
Jens Axboe564ca972007-12-14 12:21:19 +01001465 .name = "bssplit",
1466 .type = FIO_OPT_STR,
1467 .cb = str_bssplit_cb,
1468 .help = "Set a specific mix of block sizes",
1469 .parent = "rw",
1470 },
1471 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001472 .name = "bs_unaligned",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001473 .alias = "blocksize_unaligned",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001474 .type = FIO_OPT_STR_SET,
1475 .off1 = td_var_offset(bs_unaligned),
1476 .help = "Don't sector align IO buffer sizes",
Jens Axboe67a10002007-07-31 23:12:16 +02001477 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001478 },
1479 {
1480 .name = "randrepeat",
1481 .type = FIO_OPT_BOOL,
1482 .off1 = td_var_offset(rand_repeatable),
1483 .help = "Use repeatable random IO pattern",
1484 .def = "1",
Jens Axboe67a10002007-07-31 23:12:16 +02001485 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001486 },
1487 {
Jens Axboe2615cc42011-03-28 09:35:09 +02001488 .name = "use_os_rand",
1489 .type = FIO_OPT_BOOL,
1490 .off1 = td_var_offset(use_os_rand),
1491 .help = "Set to use OS random generator",
1492 .def = "0",
1493 .parent = "rw",
1494 },
1495 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001496 .name = "norandommap",
1497 .type = FIO_OPT_STR_SET,
1498 .off1 = td_var_offset(norandommap),
1499 .help = "Accept potential duplicate random blocks",
Jens Axboe67a10002007-07-31 23:12:16 +02001500 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001501 },
1502 {
Jens Axboe2b386d22008-03-26 10:32:57 +01001503 .name = "softrandommap",
1504 .type = FIO_OPT_BOOL,
1505 .off1 = td_var_offset(softrandommap),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001506 .help = "Set norandommap if randommap allocation fails",
Jens Axboe2b386d22008-03-26 10:32:57 +01001507 .parent = "norandommap",
1508 .def = "0",
1509 },
1510 {
Jens Axboe8055e412012-11-26 08:43:47 +01001511 .name = "random_generator",
1512 .type = FIO_OPT_STR,
1513 .off1 = td_var_offset(random_generator),
1514 .help = "Type of random number generator to use",
1515 .def = "tausworthe",
1516 .posval = {
1517 { .ival = "tausworthe",
1518 .oval = FIO_RAND_GEN_TAUSWORTHE,
1519 .help = "Strong Tausworthe generator",
1520 },
1521 { .ival = "lfsr",
1522 .oval = FIO_RAND_GEN_LFSR,
1523 .help = "Variable length LFSR",
1524 },
1525 },
1526 },
1527 {
Jens Axboee25839d2012-11-06 10:49:42 +01001528 .name = "random_distribution",
1529 .type = FIO_OPT_STR,
1530 .off1 = td_var_offset(random_distribution),
1531 .cb = str_random_distribution_cb,
1532 .help = "Random offset distribution generator",
1533 .def = "random",
1534 .posval = {
1535 { .ival = "random",
1536 .oval = FIO_RAND_DIST_RANDOM,
1537 .help = "Completely random",
1538 },
1539 { .ival = "zipf",
1540 .oval = FIO_RAND_DIST_ZIPF,
1541 .help = "Zipf distribution",
1542 },
Jens Axboe925fee32012-11-06 13:50:32 +01001543 { .ival = "pareto",
1544 .oval = FIO_RAND_DIST_PARETO,
1545 .help = "Pareto distribution",
1546 },
Jens Axboee25839d2012-11-06 10:49:42 +01001547 },
1548 },
1549 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001550 .name = "nrfiles",
Jens Axboed7c8be02010-11-25 08:21:39 +01001551 .alias = "nr_files",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001552 .type = FIO_OPT_INT,
1553 .off1 = td_var_offset(nr_files),
1554 .help = "Split job workload between this number of files",
1555 .def = "1",
1556 },
1557 {
1558 .name = "openfiles",
1559 .type = FIO_OPT_INT,
1560 .off1 = td_var_offset(open_files),
1561 .help = "Number of files to keep open at the same time",
1562 },
1563 {
1564 .name = "file_service_type",
1565 .type = FIO_OPT_STR,
1566 .cb = str_fst_cb,
1567 .off1 = td_var_offset(file_service_type),
1568 .help = "How to select which file to service next",
1569 .def = "roundrobin",
1570 .posval = {
1571 { .ival = "random",
1572 .oval = FIO_FSERVICE_RANDOM,
1573 .help = "Choose a file at random",
1574 },
1575 { .ival = "roundrobin",
1576 .oval = FIO_FSERVICE_RR,
1577 .help = "Round robin select files",
1578 },
Jens Axboea086c252009-03-04 08:27:37 +01001579 { .ival = "sequential",
1580 .oval = FIO_FSERVICE_SEQ,
1581 .help = "Finish one file before moving to the next",
1582 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001583 },
Jens Axboe67a10002007-07-31 23:12:16 +02001584 .parent = "nrfiles",
1585 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001586#ifdef FIO_HAVE_FALLOCATE
1587 {
1588 .name = "fallocate",
Eric Gourioua596f042011-06-17 09:11:45 +02001589 .type = FIO_OPT_STR,
1590 .off1 = td_var_offset(fallocate_mode),
1591 .help = "Whether pre-allocation is performed when laying out files",
1592 .def = "posix",
1593 .posval = {
1594 { .ival = "none",
1595 .oval = FIO_FALLOCATE_NONE,
1596 .help = "Do not pre-allocate space",
1597 },
1598 { .ival = "posix",
1599 .oval = FIO_FALLOCATE_POSIX,
1600 .help = "Use posix_fallocate()",
1601 },
1602#ifdef FIO_HAVE_LINUX_FALLOCATE
1603 { .ival = "keep",
1604 .oval = FIO_FALLOCATE_KEEP_SIZE,
1605 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1606 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001607#endif
Eric Gourioua596f042011-06-17 09:11:45 +02001608 /* Compatibility with former boolean values */
1609 { .ival = "0",
1610 .oval = FIO_FALLOCATE_NONE,
1611 .help = "Alias for 'none'",
1612 },
1613 { .ival = "1",
1614 .oval = FIO_FALLOCATE_POSIX,
1615 .help = "Alias for 'posix'",
1616 },
1617 },
1618 },
1619#endif /* FIO_HAVE_FALLOCATE */
Jens Axboe67a10002007-07-31 23:12:16 +02001620 {
1621 .name = "fadvise_hint",
1622 .type = FIO_OPT_BOOL,
1623 .off1 = td_var_offset(fadvise_hint),
1624 .help = "Use fadvise() to advise the kernel on IO pattern",
1625 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001626 },
1627 {
1628 .name = "fsync",
1629 .type = FIO_OPT_INT,
1630 .off1 = td_var_offset(fsync_blocks),
1631 .help = "Issue fsync for writes every given number of blocks",
1632 .def = "0",
1633 },
1634 {
Jens Axboe5f9099e2009-06-16 22:40:26 +02001635 .name = "fdatasync",
1636 .type = FIO_OPT_INT,
1637 .off1 = td_var_offset(fdatasync_blocks),
1638 .help = "Issue fdatasync for writes every given number of blocks",
1639 .def = "0",
1640 },
Jens Axboe1ef2b6b2010-10-08 15:07:01 +02001641 {
1642 .name = "write_barrier",
1643 .type = FIO_OPT_INT,
1644 .off1 = td_var_offset(barrier_blocks),
1645 .help = "Make every Nth write a barrier write",
1646 .def = "0",
1647 },
Jens Axboe67bf9822013-01-10 11:23:19 +01001648#ifdef CONFIG_SYNC_FILE_RANGE
Jens Axboe44f29692010-03-09 20:09:44 +01001649 {
1650 .name = "sync_file_range",
1651 .posval = {
1652 { .ival = "wait_before",
1653 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1654 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001655 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001656 },
1657 { .ival = "write",
1658 .oval = SYNC_FILE_RANGE_WRITE,
1659 .help = "SYNC_FILE_RANGE_WRITE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001660 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001661 },
1662 {
1663 .ival = "wait_after",
1664 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1665 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
Jens Axboe3843deb2010-03-09 20:41:15 +01001666 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001667 },
1668 },
Jens Axboe3843deb2010-03-09 20:41:15 +01001669 .type = FIO_OPT_STR_MULTI,
Jens Axboe44f29692010-03-09 20:09:44 +01001670 .cb = str_sfr_cb,
1671 .off1 = td_var_offset(sync_file_range),
1672 .help = "Use sync_file_range()",
1673 },
1674#endif
Jens Axboe5f9099e2009-06-16 22:40:26 +02001675 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001676 .name = "direct",
1677 .type = FIO_OPT_BOOL,
1678 .off1 = td_var_offset(odirect),
1679 .help = "Use O_DIRECT IO (negates buffered)",
1680 .def = "0",
1681 },
1682 {
1683 .name = "buffered",
1684 .type = FIO_OPT_BOOL,
1685 .off1 = td_var_offset(odirect),
1686 .neg = 1,
1687 .help = "Use buffered IO (negates direct)",
1688 .def = "1",
1689 },
1690 {
1691 .name = "overwrite",
1692 .type = FIO_OPT_BOOL,
1693 .off1 = td_var_offset(overwrite),
1694 .help = "When writing, set whether to overwrite current data",
1695 .def = "0",
1696 },
1697 {
1698 .name = "loops",
1699 .type = FIO_OPT_INT,
1700 .off1 = td_var_offset(loops),
1701 .help = "Number of times to run the job",
1702 .def = "1",
1703 },
1704 {
1705 .name = "numjobs",
1706 .type = FIO_OPT_INT,
1707 .off1 = td_var_offset(numjobs),
1708 .help = "Duplicate this job this many times",
1709 .def = "1",
1710 },
1711 {
1712 .name = "startdelay",
Jens Axboea5737c92010-06-29 10:40:30 +02001713 .type = FIO_OPT_STR_VAL_TIME,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001714 .off1 = td_var_offset(start_delay),
1715 .help = "Only start job when this period has passed",
1716 .def = "0",
1717 },
1718 {
1719 .name = "runtime",
1720 .alias = "timeout",
1721 .type = FIO_OPT_STR_VAL_TIME,
1722 .off1 = td_var_offset(timeout),
1723 .help = "Stop workload when this amount of time has passed",
1724 .def = "0",
1725 },
1726 {
Jens Axboecf4464c2007-04-17 20:14:42 +02001727 .name = "time_based",
1728 .type = FIO_OPT_STR_SET,
1729 .off1 = td_var_offset(time_based),
1730 .help = "Keep running until runtime/timeout is met",
1731 },
1732 {
Jens Axboe721938a2008-09-10 09:46:16 +02001733 .name = "ramp_time",
1734 .type = FIO_OPT_STR_VAL_TIME,
1735 .off1 = td_var_offset(ramp_time),
1736 .help = "Ramp up time before measuring performance",
1737 },
1738 {
Jens Axboec223da82010-03-24 13:23:53 +01001739 .name = "clocksource",
1740 .type = FIO_OPT_STR,
1741 .cb = fio_clock_source_cb,
1742 .off1 = td_var_offset(clocksource),
1743 .help = "What type of timing source to use",
Jens Axboec223da82010-03-24 13:23:53 +01001744 .posval = {
Jens Axboe67bf9822013-01-10 11:23:19 +01001745#ifdef CONFIG_GETTIMEOFDAY
Jens Axboec223da82010-03-24 13:23:53 +01001746 { .ival = "gettimeofday",
1747 .oval = CS_GTOD,
1748 .help = "Use gettimeofday(2) for timing",
1749 },
Jens Axboe67bf9822013-01-10 11:23:19 +01001750#endif
1751#ifdef CONFIG_CLOCK_GETTIME
Jens Axboec223da82010-03-24 13:23:53 +01001752 { .ival = "clock_gettime",
1753 .oval = CS_CGETTIME,
1754 .help = "Use clock_gettime(2) for timing",
1755 },
Jens Axboe67bf9822013-01-10 11:23:19 +01001756#endif
Jens Axboec223da82010-03-24 13:23:53 +01001757#ifdef ARCH_HAVE_CPU_CLOCK
1758 { .ival = "cpu",
1759 .oval = CS_CPUCLOCK,
1760 .help = "Use CPU private clock",
1761 },
1762#endif
1763 },
1764 },
1765 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001766 .name = "mem",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001767 .alias = "iomem",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001768 .type = FIO_OPT_STR,
1769 .cb = str_mem_cb,
1770 .off1 = td_var_offset(mem_type),
1771 .help = "Backing type for IO buffers",
1772 .def = "malloc",
1773 .posval = {
1774 { .ival = "malloc",
1775 .oval = MEM_MALLOC,
1776 .help = "Use malloc(3) for IO buffers",
1777 },
Jens Axboeb370e462007-03-19 10:51:49 +01001778 { .ival = "shm",
1779 .oval = MEM_SHM,
1780 .help = "Use shared memory segments for IO buffers",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001781 },
1782#ifdef FIO_HAVE_HUGETLB
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001783 { .ival = "shmhuge",
1784 .oval = MEM_SHMHUGE,
1785 .help = "Like shm, but use huge pages",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001786 },
1787#endif
Jens Axboeb370e462007-03-19 10:51:49 +01001788 { .ival = "mmap",
1789 .oval = MEM_MMAP,
1790 .help = "Use mmap(2) (file or anon) for IO buffers",
1791 },
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001792#ifdef FIO_HAVE_HUGETLB
1793 { .ival = "mmaphuge",
1794 .oval = MEM_MMAPHUGE,
1795 .help = "Like mmap, but use huge pages",
1796 },
1797#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001798 },
1799 },
1800 {
Jens Axboed529ee12009-07-01 10:33:03 +02001801 .name = "iomem_align",
1802 .alias = "mem_align",
1803 .type = FIO_OPT_INT,
1804 .off1 = td_var_offset(mem_align),
1805 .minval = 0,
1806 .help = "IO memory buffer offset alignment",
1807 .def = "0",
1808 .parent = "iomem",
1809 },
1810 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001811 .name = "verify",
1812 .type = FIO_OPT_STR,
1813 .off1 = td_var_offset(verify),
1814 .help = "Verify data written",
Jens Axboe5d7c5d32010-06-21 15:08:17 +02001815 .cb = str_verify_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001816 .def = "0",
1817 .posval = {
1818 { .ival = "0",
1819 .oval = VERIFY_NONE,
1820 .help = "Don't do IO verification",
1821 },
Jens Axboefcca4b52007-07-27 15:42:00 +02001822 { .ival = "md5",
1823 .oval = VERIFY_MD5,
1824 .help = "Use md5 checksums for verification",
1825 },
Jens Axboed77a7af2007-07-27 15:35:06 +02001826 { .ival = "crc64",
1827 .oval = VERIFY_CRC64,
1828 .help = "Use crc64 checksums for verification",
1829 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001830 { .ival = "crc32",
1831 .oval = VERIFY_CRC32,
1832 .help = "Use crc32 checksums for verification",
1833 },
Jens Axboeaf497e62008-08-04 15:40:35 +02001834 { .ival = "crc32c-intel",
Jens Axboee3aaafc2012-02-22 20:28:17 +01001835 .oval = VERIFY_CRC32C,
1836 .help = "Use crc32c checksums for verification (hw assisted, if available)",
Jens Axboeaf497e62008-08-04 15:40:35 +02001837 },
Jens Axboebac39e02008-06-11 20:46:19 +02001838 { .ival = "crc32c",
1839 .oval = VERIFY_CRC32C,
Jens Axboee3aaafc2012-02-22 20:28:17 +01001840 .help = "Use crc32c checksums for verification (hw assisted, if available)",
Jens Axboebac39e02008-06-11 20:46:19 +02001841 },
Jens Axboe969f7ed2007-07-27 09:07:17 +02001842 { .ival = "crc16",
1843 .oval = VERIFY_CRC16,
1844 .help = "Use crc16 checksums for verification",
1845 },
Jens Axboe1e154bd2007-07-27 09:52:40 +02001846 { .ival = "crc7",
1847 .oval = VERIFY_CRC7,
1848 .help = "Use crc7 checksums for verification",
1849 },
Jens Axboe7c353ce2009-08-09 22:40:33 +02001850 { .ival = "sha1",
1851 .oval = VERIFY_SHA1,
1852 .help = "Use sha1 checksums for verification",
1853 },
Jens Axboecd14cc12007-07-30 10:59:33 +02001854 { .ival = "sha256",
1855 .oval = VERIFY_SHA256,
1856 .help = "Use sha256 checksums for verification",
1857 },
1858 { .ival = "sha512",
1859 .oval = VERIFY_SHA512,
1860 .help = "Use sha512 checksums for verification",
1861 },
Shawn Lewis7437ee82007-08-02 21:05:58 +02001862 { .ival = "meta",
1863 .oval = VERIFY_META,
1864 .help = "Use io information",
1865 },
Jens Axboe36690c92007-03-26 10:23:34 +02001866 {
1867 .ival = "null",
1868 .oval = VERIFY_NULL,
1869 .help = "Pretend to verify",
1870 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001871 },
1872 },
1873 {
Jens Axboe005c5652007-08-02 22:21:36 +02001874 .name = "do_verify",
Jens Axboe68e1f292007-08-10 10:32:14 +02001875 .type = FIO_OPT_BOOL,
Jens Axboe005c5652007-08-02 22:21:36 +02001876 .off1 = td_var_offset(do_verify),
1877 .help = "Run verification stage after write",
1878 .def = "1",
1879 .parent = "verify",
1880 },
1881 {
Jens Axboe160b9662007-03-27 10:59:49 +02001882 .name = "verifysort",
1883 .type = FIO_OPT_BOOL,
1884 .off1 = td_var_offset(verifysort),
1885 .help = "Sort written verify blocks for read back",
1886 .def = "1",
Jens Axboec83f2df2007-07-31 22:51:47 +02001887 .parent = "verify",
Jens Axboe160b9662007-03-27 10:59:49 +02001888 },
1889 {
Jens Axboe1ae83d42013-01-12 01:44:15 -07001890 .name = "verifysort_nr",
1891 .type = FIO_OPT_INT,
1892 .off1 = td_var_offset(verifysort_nr),
1893 .help = "Pre-load and sort verify blocks for a read workload",
1894 .minval = 0,
1895 .maxval = 131072,
1896 .def = "1024",
1897 .parent = "verify",
1898 },
1899 {
Jens Axboea59e1702007-07-30 08:53:27 +02001900 .name = "verify_interval",
Jens Axboee01b22b2009-06-09 15:43:25 +02001901 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001902 .off1 = td_var_offset(verify_interval),
Jens Axboe819a9682007-07-28 21:30:31 +02001903 .minval = 2 * sizeof(struct verify_header),
Jens Axboea59e1702007-07-30 08:53:27 +02001904 .help = "Store verify buffer header every N bytes",
Jens Axboeafdf9352007-07-31 16:14:34 +02001905 .parent = "verify",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +02001906 },
1907 {
Jens Axboea59e1702007-07-30 08:53:27 +02001908 .name = "verify_offset",
Jens Axboee01b22b2009-06-09 15:43:25 +02001909 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001910 .help = "Offset verify header location by N bytes",
Shawn Lewis546a9142007-07-28 21:11:37 +02001911 .def = "0",
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001912 .cb = str_verify_offset_cb,
Jens Axboeafdf9352007-07-31 16:14:34 +02001913 .parent = "verify",
Shawn Lewis546a9142007-07-28 21:11:37 +02001914 },
1915 {
Shawn Lewise28218f2008-01-16 11:01:33 +01001916 .name = "verify_pattern",
Radha Ramachandran0e92f872009-10-27 20:14:27 +01001917 .type = FIO_OPT_STR,
Shawn Lewise28218f2008-01-16 11:01:33 +01001918 .cb = str_verify_pattern_cb,
1919 .help = "Fill pattern for IO buffers",
1920 .parent = "verify",
1921 },
1922 {
Jens Axboea12a3b42007-08-09 10:20:54 +02001923 .name = "verify_fatal",
Jens Axboe68e1f292007-08-10 10:32:14 +02001924 .type = FIO_OPT_BOOL,
Jens Axboea12a3b42007-08-09 10:20:54 +02001925 .off1 = td_var_offset(verify_fatal),
1926 .def = "0",
1927 .help = "Exit on a single verify failure, don't continue",
1928 .parent = "verify",
1929 },
1930 {
Jens Axboeb463e932011-01-12 09:03:23 +01001931 .name = "verify_dump",
1932 .type = FIO_OPT_BOOL,
1933 .off1 = td_var_offset(verify_dump),
Jens Axboeef71e312011-10-25 22:43:36 +02001934 .def = "0",
Jens Axboeb463e932011-01-12 09:03:23 +01001935 .help = "Dump contents of good and bad blocks on failure",
1936 .parent = "verify",
1937 },
1938 {
Jens Axboee8462bd2009-07-06 12:59:04 +02001939 .name = "verify_async",
1940 .type = FIO_OPT_INT,
1941 .off1 = td_var_offset(verify_async),
1942 .def = "0",
1943 .help = "Number of async verifier threads to use",
1944 .parent = "verify",
1945 },
Jens Axboe9e144182010-06-15 14:25:36 +02001946 {
1947 .name = "verify_backlog",
1948 .type = FIO_OPT_STR_VAL,
1949 .off1 = td_var_offset(verify_backlog),
1950 .help = "Verify after this number of blocks are written",
1951 .parent = "verify",
1952 },
1953 {
1954 .name = "verify_backlog_batch",
1955 .type = FIO_OPT_INT,
1956 .off1 = td_var_offset(verify_batch),
1957 .help = "Verify this number of IO blocks",
Jens Axboe0d29de82010-09-01 13:54:15 +02001958 .parent = "verify",
Jens Axboe9e144182010-06-15 14:25:36 +02001959 },
Jens Axboee8462bd2009-07-06 12:59:04 +02001960#ifdef FIO_HAVE_CPU_AFFINITY
1961 {
1962 .name = "verify_async_cpus",
1963 .type = FIO_OPT_STR,
1964 .cb = str_verify_cpus_allowed_cb,
1965 .help = "Set CPUs allowed for async verify threads",
1966 .parent = "verify_async",
1967 },
1968#endif
Jens Axboe0d29de82010-09-01 13:54:15 +02001969#ifdef FIO_HAVE_TRIM
1970 {
1971 .name = "trim_percentage",
1972 .type = FIO_OPT_INT,
1973 .cb = str_verify_trim_cb,
1974 .maxval = 100,
1975 .help = "Number of verify blocks to discard/trim",
1976 .parent = "verify",
1977 .def = "0",
1978 },
1979 {
1980 .name = "trim_verify_zero",
1981 .type = FIO_OPT_INT,
1982 .help = "Verify that trim/discarded blocks are returned as zeroes",
1983 .off1 = td_var_offset(trim_zero),
1984 .parent = "trim_percentage",
1985 .def = "1",
1986 },
1987 {
1988 .name = "trim_backlog",
1989 .type = FIO_OPT_STR_VAL,
1990 .off1 = td_var_offset(trim_backlog),
1991 .help = "Trim after this number of blocks are written",
1992 .parent = "trim_percentage",
1993 },
1994 {
1995 .name = "trim_backlog_batch",
1996 .type = FIO_OPT_INT,
1997 .off1 = td_var_offset(trim_batch),
1998 .help = "Trim this number of IO blocks",
1999 .parent = "trim_percentage",
2000 },
2001#endif
Jens Axboee8462bd2009-07-06 12:59:04 +02002002 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002003 .name = "write_iolog",
2004 .type = FIO_OPT_STR_STORE,
2005 .off1 = td_var_offset(write_iolog_file),
2006 .help = "Store IO pattern to file",
2007 },
2008 {
2009 .name = "read_iolog",
2010 .type = FIO_OPT_STR_STORE,
2011 .off1 = td_var_offset(read_iolog_file),
2012 .help = "Playback IO pattern from file",
2013 },
2014 {
David Nellans64bbb862010-08-24 22:13:30 +02002015 .name = "replay_no_stall",
2016 .type = FIO_OPT_INT,
2017 .off1 = td_var_offset(no_stall),
2018 .def = "0",
Jens Axboe87e7a972010-08-25 09:01:25 +02002019 .parent = "read_iolog",
David Nellans64bbb862010-08-24 22:13:30 +02002020 .help = "Playback IO pattern file as fast as possible without stalls",
2021 },
2022 {
David Nellansd1c46c02010-08-31 21:20:47 +02002023 .name = "replay_redirect",
2024 .type = FIO_OPT_STR_STORE,
2025 .off1 = td_var_offset(replay_redirect),
2026 .parent = "read_iolog",
2027 .help = "Replay all I/O onto this device, regardless of trace device",
2028 },
2029 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002030 .name = "exec_prerun",
2031 .type = FIO_OPT_STR_STORE,
2032 .off1 = td_var_offset(exec_prerun),
2033 .help = "Execute this file prior to running job",
2034 },
2035 {
2036 .name = "exec_postrun",
2037 .type = FIO_OPT_STR_STORE,
2038 .off1 = td_var_offset(exec_postrun),
2039 .help = "Execute this file after running job",
2040 },
2041#ifdef FIO_HAVE_IOSCHED_SWITCH
2042 {
2043 .name = "ioscheduler",
2044 .type = FIO_OPT_STR_STORE,
2045 .off1 = td_var_offset(ioscheduler),
2046 .help = "Use this IO scheduler on the backing device",
2047 },
2048#endif
2049 {
2050 .name = "zonesize",
2051 .type = FIO_OPT_STR_VAL,
2052 .off1 = td_var_offset(zone_size),
Steven Noonaned335852012-01-31 13:58:00 +01002053 .help = "Amount of data to read per zone",
2054 .def = "0",
2055 },
2056 {
2057 .name = "zonerange",
2058 .type = FIO_OPT_STR_VAL,
2059 .off1 = td_var_offset(zone_range),
Jens Axboe214e1ec2007-03-15 10:48:13 +01002060 .help = "Give size of an IO zone",
2061 .def = "0",
2062 },
2063 {
2064 .name = "zoneskip",
2065 .type = FIO_OPT_STR_VAL,
2066 .off1 = td_var_offset(zone_skip),
2067 .help = "Space between IO zones",
2068 .def = "0",
2069 },
2070 {
2071 .name = "lockmem",
2072 .type = FIO_OPT_STR_VAL,
2073 .cb = str_lockmem_cb,
2074 .help = "Lock down this amount of memory",
2075 .def = "0",
2076 },
2077 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002078 .name = "rwmixread",
2079 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02002080 .cb = str_rwmix_read_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002081 .maxval = 100,
2082 .help = "Percentage of mixed workload that is reads",
2083 .def = "50",
2084 },
2085 {
2086 .name = "rwmixwrite",
2087 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02002088 .cb = str_rwmix_write_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002089 .maxval = 100,
2090 .help = "Percentage of mixed workload that is writes",
2091 .def = "50",
2092 },
2093 {
Jens Axboeafdf9352007-07-31 16:14:34 +02002094 .name = "rwmixcycle",
Jens Axboe15ca1502008-04-07 09:26:02 +02002095 .type = FIO_OPT_DEPRECATED,
Jens Axboeafdf9352007-07-31 16:14:34 +02002096 },
2097 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002098 .name = "nice",
2099 .type = FIO_OPT_INT,
2100 .off1 = td_var_offset(nice),
2101 .help = "Set job CPU nice value",
2102 .minval = -19,
2103 .maxval = 20,
2104 .def = "0",
2105 },
2106#ifdef FIO_HAVE_IOPRIO
2107 {
2108 .name = "prio",
2109 .type = FIO_OPT_INT,
2110 .cb = str_prio_cb,
2111 .help = "Set job IO priority value",
2112 .minval = 0,
2113 .maxval = 7,
2114 },
2115 {
2116 .name = "prioclass",
2117 .type = FIO_OPT_INT,
2118 .cb = str_prioclass_cb,
2119 .help = "Set job IO priority class",
2120 .minval = 0,
2121 .maxval = 3,
2122 },
2123#endif
2124 {
2125 .name = "thinktime",
2126 .type = FIO_OPT_INT,
2127 .off1 = td_var_offset(thinktime),
2128 .help = "Idle time between IO buffers (usec)",
2129 .def = "0",
2130 },
2131 {
2132 .name = "thinktime_spin",
2133 .type = FIO_OPT_INT,
2134 .off1 = td_var_offset(thinktime_spin),
2135 .help = "Start think time by spinning this amount (usec)",
2136 .def = "0",
Jens Axboeafdf9352007-07-31 16:14:34 +02002137 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002138 },
2139 {
2140 .name = "thinktime_blocks",
2141 .type = FIO_OPT_INT,
2142 .off1 = td_var_offset(thinktime_blocks),
2143 .help = "IO buffer period between 'thinktime'",
2144 .def = "1",
Jens Axboeafdf9352007-07-31 16:14:34 +02002145 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002146 },
2147 {
2148 .name = "rate",
Jens Axboee01b22b2009-06-09 15:43:25 +02002149 .type = FIO_OPT_INT,
Shaohua Li6eaf09d2012-09-14 08:49:43 +02002150 .off1 = td_var_offset(rate[DDIR_READ]),
2151 .off2 = td_var_offset(rate[DDIR_WRITE]),
2152 .off3 = td_var_offset(rate[DDIR_TRIM]),
Jens Axboe214e1ec2007-03-15 10:48:13 +01002153 .help = "Set bandwidth rate",
2154 },
2155 {
2156 .name = "ratemin",
Jens Axboee01b22b2009-06-09 15:43:25 +02002157 .type = FIO_OPT_INT,
Shaohua Li6eaf09d2012-09-14 08:49:43 +02002158 .off1 = td_var_offset(ratemin[DDIR_READ]),
2159 .off2 = td_var_offset(ratemin[DDIR_WRITE]),
2160 .off3 = td_var_offset(ratemin[DDIR_TRIM]),
Jens Axboe4e991c22007-03-15 11:41:11 +01002161 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02002162 .parent = "rate",
Jens Axboe4e991c22007-03-15 11:41:11 +01002163 },
2164 {
2165 .name = "rate_iops",
Jens Axboee01b22b2009-06-09 15:43:25 +02002166 .type = FIO_OPT_INT,
Shaohua Li6eaf09d2012-09-14 08:49:43 +02002167 .off1 = td_var_offset(rate_iops[DDIR_READ]),
2168 .off2 = td_var_offset(rate_iops[DDIR_WRITE]),
2169 .off3 = td_var_offset(rate_iops[DDIR_TRIM]),
Jens Axboe4e991c22007-03-15 11:41:11 +01002170 .help = "Limit IO used to this number of IO operations/sec",
2171 },
2172 {
2173 .name = "rate_iops_min",
Jens Axboee01b22b2009-06-09 15:43:25 +02002174 .type = FIO_OPT_INT,
Shaohua Li6eaf09d2012-09-14 08:49:43 +02002175 .off1 = td_var_offset(rate_iops_min[DDIR_READ]),
2176 .off2 = td_var_offset(rate_iops_min[DDIR_WRITE]),
2177 .off3 = td_var_offset(rate_iops_min[DDIR_TRIM]),
Bruce Cran03e20d62011-01-02 20:14:54 +01002178 .help = "Job must meet this rate or it will be shut down",
Jens Axboeafdf9352007-07-31 16:14:34 +02002179 .parent = "rate_iops",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002180 },
2181 {
2182 .name = "ratecycle",
2183 .type = FIO_OPT_INT,
2184 .off1 = td_var_offset(ratecycle),
2185 .help = "Window average for rate limits (msec)",
2186 .def = "1000",
Jens Axboeafdf9352007-07-31 16:14:34 +02002187 .parent = "rate",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002188 },
2189 {
Jens Axboe15501532012-10-24 16:37:45 +02002190 .name = "max_latency",
2191 .type = FIO_OPT_INT,
2192 .off1 = td_var_offset(max_latency),
2193 .help = "Maximum tolerated IO latency (usec)",
2194 },
2195 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002196 .name = "invalidate",
2197 .type = FIO_OPT_BOOL,
2198 .off1 = td_var_offset(invalidate_cache),
2199 .help = "Invalidate buffer/page cache prior to running job",
2200 .def = "1",
2201 },
2202 {
2203 .name = "sync",
2204 .type = FIO_OPT_BOOL,
2205 .off1 = td_var_offset(sync_io),
2206 .help = "Use O_SYNC for buffered writes",
2207 .def = "0",
Jens Axboe67a10002007-07-31 23:12:16 +02002208 .parent = "buffered",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002209 },
2210 {
2211 .name = "bwavgtime",
2212 .type = FIO_OPT_INT,
2213 .off1 = td_var_offset(bw_avg_time),
Jens Axboe5ec10ea2008-03-06 15:42:00 +01002214 .help = "Time window over which to calculate bandwidth"
2215 " (msec)",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002216 .def = "500",
Jens Axboec8eeb9d2011-10-05 14:02:22 +02002217 .parent = "write_bw_log",
2218 },
2219 {
2220 .name = "iopsavgtime",
2221 .type = FIO_OPT_INT,
2222 .off1 = td_var_offset(iops_avg_time),
2223 .help = "Time window over which to calculate IOPS (msec)",
2224 .def = "500",
2225 .parent = "write_iops_log",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002226 },
2227 {
2228 .name = "create_serialize",
2229 .type = FIO_OPT_BOOL,
2230 .off1 = td_var_offset(create_serialize),
2231 .help = "Serialize creating of job files",
2232 .def = "1",
2233 },
2234 {
2235 .name = "create_fsync",
2236 .type = FIO_OPT_BOOL,
2237 .off1 = td_var_offset(create_fsync),
Bruce Cran03e20d62011-01-02 20:14:54 +01002238 .help = "fsync file after creation",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002239 .def = "1",
2240 },
2241 {
Jens Axboe814452b2009-03-04 12:53:13 +01002242 .name = "create_on_open",
2243 .type = FIO_OPT_BOOL,
2244 .off1 = td_var_offset(create_on_open),
2245 .help = "Create files when they are opened for IO",
2246 .def = "0",
2247 },
Jens Axboe0b9d69e2009-09-11 22:29:54 +02002248 {
Jens Axboe25460cf2012-05-02 13:58:02 +02002249 .name = "create_only",
2250 .type = FIO_OPT_BOOL,
2251 .off1 = td_var_offset(create_only),
2252 .help = "Only perform file creation phase",
2253 .def = "0",
2254 },
2255 {
Zhang, Yanminafad68f2009-05-20 11:30:55 +02002256 .name = "pre_read",
2257 .type = FIO_OPT_BOOL,
2258 .off1 = td_var_offset(pre_read),
Bruce Cran03e20d62011-01-02 20:14:54 +01002259 .help = "Pre-read files before starting official testing",
Zhang, Yanminafad68f2009-05-20 11:30:55 +02002260 .def = "0",
2261 },
Jens Axboe814452b2009-03-04 12:53:13 +01002262 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002263 .name = "cpuload",
2264 .type = FIO_OPT_INT,
2265 .off1 = td_var_offset(cpuload),
2266 .help = "Use this percentage of CPU",
2267 },
2268 {
2269 .name = "cpuchunks",
2270 .type = FIO_OPT_INT,
2271 .off1 = td_var_offset(cpucycle),
2272 .help = "Length of the CPU burn cycles (usecs)",
2273 .def = "50000",
Jens Axboe67a10002007-07-31 23:12:16 +02002274 .parent = "cpuload",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002275 },
2276#ifdef FIO_HAVE_CPU_AFFINITY
2277 {
2278 .name = "cpumask",
2279 .type = FIO_OPT_INT,
2280 .cb = str_cpumask_cb,
2281 .help = "CPU affinity mask",
2282 },
Jens Axboed2e268b2007-06-15 10:33:49 +02002283 {
2284 .name = "cpus_allowed",
2285 .type = FIO_OPT_STR,
2286 .cb = str_cpus_allowed_cb,
2287 .help = "Set CPUs allowed",
2288 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01002289#endif
Jens Axboe67bf9822013-01-10 11:23:19 +01002290#ifdef CONFIG_LIBNUMA
Yufei Rend0b937e2012-10-19 23:11:52 -04002291 {
2292 .name = "numa_cpu_nodes",
2293 .type = FIO_OPT_STR,
2294 .cb = str_numa_cpunodes_cb,
2295 .help = "NUMA CPU nodes bind",
2296 },
2297 {
2298 .name = "numa_mem_policy",
2299 .type = FIO_OPT_STR,
2300 .cb = str_numa_mpol_cb,
2301 .help = "NUMA memory policy setup",
2302 },
2303#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01002304 {
2305 .name = "end_fsync",
2306 .type = FIO_OPT_BOOL,
2307 .off1 = td_var_offset(end_fsync),
2308 .help = "Include fsync at the end of job",
2309 .def = "0",
2310 },
2311 {
2312 .name = "fsync_on_close",
2313 .type = FIO_OPT_BOOL,
2314 .off1 = td_var_offset(fsync_on_close),
2315 .help = "fsync files on close",
2316 .def = "0",
2317 },
2318 {
2319 .name = "unlink",
2320 .type = FIO_OPT_BOOL,
2321 .off1 = td_var_offset(unlink),
2322 .help = "Unlink created files after job has completed",
2323 .def = "0",
2324 },
2325 {
2326 .name = "exitall",
2327 .type = FIO_OPT_STR_SET,
2328 .cb = str_exitall_cb,
2329 .help = "Terminate all jobs when one exits",
2330 },
2331 {
2332 .name = "stonewall",
Jens Axboed3923652011-08-03 12:38:39 +02002333 .alias = "wait_for_previous",
Jens Axboe214e1ec2007-03-15 10:48:13 +01002334 .type = FIO_OPT_STR_SET,
2335 .off1 = td_var_offset(stonewall),
2336 .help = "Insert a hard barrier between this job and previous",
2337 },
2338 {
Jens Axboeb3d62a72007-03-20 14:23:26 +01002339 .name = "new_group",
2340 .type = FIO_OPT_STR_SET,
2341 .off1 = td_var_offset(new_group),
2342 .help = "Mark the start of a new group (for reporting)",
2343 },
2344 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002345 .name = "thread",
2346 .type = FIO_OPT_STR_SET,
2347 .off1 = td_var_offset(use_thread),
2348 .help = "Use threads instead of forks",
2349 },
2350 {
2351 .name = "write_bw_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01002352 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002353 .off1 = td_var_offset(write_bw_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01002354 .cb = str_write_bw_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002355 .help = "Write log of bandwidth during run",
2356 },
2357 {
2358 .name = "write_lat_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01002359 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002360 .off1 = td_var_offset(write_lat_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01002361 .cb = str_write_lat_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002362 .help = "Write log of latency during run",
2363 },
2364 {
Jens Axboec8eeb9d2011-10-05 14:02:22 +02002365 .name = "write_iops_log",
2366 .type = FIO_OPT_STR,
2367 .off1 = td_var_offset(write_iops_log),
2368 .cb = str_write_iops_log_cb,
2369 .help = "Write log of IOPS during run",
2370 },
2371 {
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01002372 .name = "log_avg_msec",
2373 .type = FIO_OPT_INT,
2374 .off1 = td_var_offset(log_avg_msec),
2375 .help = "Average bw/iops/lat logs over this period of time",
2376 .def = "0",
2377 },
2378 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002379 .name = "hugepage-size",
Jens Axboee01b22b2009-06-09 15:43:25 +02002380 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01002381 .off1 = td_var_offset(hugepage_size),
2382 .help = "When using hugepages, specify size of each page",
Jens Axboe81179ee2011-10-04 12:42:06 +02002383 .def = __fio_stringify(FIO_HUGE_PAGE),
Jens Axboe214e1ec2007-03-15 10:48:13 +01002384 },
2385 {
2386 .name = "group_reporting",
2387 .type = FIO_OPT_STR_SET,
2388 .off1 = td_var_offset(group_reporting),
2389 .help = "Do reporting on a per-group basis",
2390 },
2391 {
Jens Axboee9459e52007-04-17 15:46:32 +02002392 .name = "zero_buffers",
2393 .type = FIO_OPT_STR_SET,
2394 .off1 = td_var_offset(zero_buffers),
2395 .help = "Init IO buffers to all zeroes",
2396 },
Jens Axboe5973caf2008-05-21 19:52:35 +02002397 {
2398 .name = "refill_buffers",
2399 .type = FIO_OPT_STR_SET,
2400 .off1 = td_var_offset(refill_buffers),
2401 .help = "Refill IO buffers on every IO submit",
2402 },
Yu-ju Hong83349192011-08-13 00:53:44 +02002403 {
Jens Axboefd684182011-09-19 09:24:44 +02002404 .name = "scramble_buffers",
2405 .type = FIO_OPT_BOOL,
2406 .off1 = td_var_offset(scramble_buffers),
2407 .help = "Slightly scramble buffers on every IO submit",
2408 .def = "1",
2409 },
2410 {
Jens Axboe9c426842012-03-02 21:02:12 +01002411 .name = "buffer_compress_percentage",
2412 .type = FIO_OPT_INT,
2413 .off1 = td_var_offset(compress_percentage),
2414 .maxval = 100,
2415 .minval = 1,
2416 .help = "How compressible the buffer is (approximately)",
2417 },
2418 {
Jens Axboef97a43a2012-03-09 19:06:24 +01002419 .name = "buffer_compress_chunk",
2420 .type = FIO_OPT_INT,
2421 .off1 = td_var_offset(compress_chunk),
Jens Axboe207b18e2012-03-09 19:11:25 +01002422 .parent = "buffer_compress_percentage",
Jens Axboef97a43a2012-03-09 19:06:24 +01002423 .help = "Size of compressible region in buffer",
2424 },
2425 {
Yu-ju Hong83349192011-08-13 00:53:44 +02002426 .name = "clat_percentiles",
2427 .type = FIO_OPT_BOOL,
2428 .off1 = td_var_offset(clat_percentiles),
2429 .help = "Enable the reporting of completion latency percentiles",
Jens Axboe467b35e2011-10-13 08:53:24 +02002430 .def = "1",
Yu-ju Hong83349192011-08-13 00:53:44 +02002431 },
2432 {
2433 .name = "percentile_list",
2434 .type = FIO_OPT_FLOAT_LIST,
2435 .off1 = td_var_offset(percentile_list),
2436 .off2 = td_var_offset(overwrite_plist),
2437 .help = "Specify a custom list of percentiles to report",
2438 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2439 .minfp = 0.0,
2440 .maxfp = 100.0,
2441 },
2442
Jens Axboe0a839f32007-04-26 09:02:34 +02002443#ifdef FIO_HAVE_DISK_UTIL
2444 {
2445 .name = "disk_util",
2446 .type = FIO_OPT_BOOL,
2447 .off1 = td_var_offset(do_disk_util),
Jens Axboef66ab3c2008-06-05 11:48:22 +02002448 .help = "Log disk utilization statistics",
Jens Axboe0a839f32007-04-26 09:02:34 +02002449 .def = "1",
2450 },
2451#endif
Jens Axboee9459e52007-04-17 15:46:32 +02002452 {
Jens Axboe993bf482008-11-14 13:04:53 +01002453 .name = "gtod_reduce",
2454 .type = FIO_OPT_BOOL,
2455 .help = "Greatly reduce number of gettimeofday() calls",
2456 .cb = str_gtod_reduce_cb,
2457 .def = "0",
2458 },
2459 {
Jens Axboe02af0982010-06-24 09:59:34 +02002460 .name = "disable_lat",
2461 .type = FIO_OPT_BOOL,
2462 .off1 = td_var_offset(disable_lat),
2463 .help = "Disable latency numbers",
2464 .parent = "gtod_reduce",
2465 .def = "0",
2466 },
2467 {
Jens Axboe9520ebb2008-10-16 21:03:27 +02002468 .name = "disable_clat",
2469 .type = FIO_OPT_BOOL,
2470 .off1 = td_var_offset(disable_clat),
2471 .help = "Disable completion latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01002472 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002473 .def = "0",
2474 },
2475 {
2476 .name = "disable_slat",
2477 .type = FIO_OPT_BOOL,
2478 .off1 = td_var_offset(disable_slat),
Bruce Cran03e20d62011-01-02 20:14:54 +01002479 .help = "Disable submission latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01002480 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002481 .def = "0",
2482 },
2483 {
2484 .name = "disable_bw_measurement",
2485 .type = FIO_OPT_BOOL,
2486 .off1 = td_var_offset(disable_bw),
2487 .help = "Disable bandwidth logging",
Jens Axboe993bf482008-11-14 13:04:53 +01002488 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002489 .def = "0",
2490 },
2491 {
Jens Axboebe4ecfd2008-12-08 14:10:52 +01002492 .name = "gtod_cpu",
2493 .type = FIO_OPT_INT,
2494 .cb = str_gtod_cpu_cb,
Bruce Cran03e20d62011-01-02 20:14:54 +01002495 .help = "Set up dedicated gettimeofday() thread on this CPU",
Jens Axboe29d43ff2009-07-01 10:42:18 +02002496 .verify = gtod_cpu_verify,
Jens Axboebe4ecfd2008-12-08 14:10:52 +01002497 },
2498 {
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002499 .name = "continue_on_error",
Steven Lang06842022011-11-17 09:45:17 +01002500 .type = FIO_OPT_STR,
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002501 .off1 = td_var_offset(continue_on_error),
Bruce Cran03e20d62011-01-02 20:14:54 +01002502 .help = "Continue on non-fatal errors during IO",
Steven Lang06842022011-11-17 09:45:17 +01002503 .def = "none",
2504 .posval = {
2505 { .ival = "none",
2506 .oval = ERROR_TYPE_NONE,
2507 .help = "Exit when an error is encountered",
2508 },
2509 { .ival = "read",
2510 .oval = ERROR_TYPE_READ,
2511 .help = "Continue on read errors only",
2512 },
2513 { .ival = "write",
2514 .oval = ERROR_TYPE_WRITE,
2515 .help = "Continue on write errors only",
2516 },
2517 { .ival = "io",
2518 .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2519 .help = "Continue on any IO errors",
2520 },
2521 { .ival = "verify",
2522 .oval = ERROR_TYPE_VERIFY,
2523 .help = "Continue on verify errors only",
2524 },
2525 { .ival = "all",
2526 .oval = ERROR_TYPE_ANY,
2527 .help = "Continue on all io and verify errors",
2528 },
2529 { .ival = "0",
2530 .oval = ERROR_TYPE_NONE,
2531 .help = "Alias for 'none'",
2532 },
2533 { .ival = "1",
2534 .oval = ERROR_TYPE_ANY,
2535 .help = "Alias for 'all'",
2536 },
2537 },
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002538 },
2539 {
Dmitry Monakhov8b28bd42012-09-23 15:46:09 +04002540 .name = "ignore_error",
2541 .type = FIO_OPT_STR,
2542 .cb = str_ignore_error_cb,
2543 .help = "Set a specific list of errors to ignore",
2544 .parent = "rw",
2545 },
2546 {
2547 .name = "error_dump",
2548 .type = FIO_OPT_BOOL,
2549 .off1 = td_var_offset(error_dump),
2550 .def = "0",
2551 .help = "Dump info on each error",
2552 },
2553
2554 {
Jens Axboe9ac8a792009-11-13 21:23:07 +01002555 .name = "profile",
Jens Axboe79d16312010-03-04 12:43:20 +01002556 .type = FIO_OPT_STR_STORE,
Jens Axboe9ac8a792009-11-13 21:23:07 +01002557 .off1 = td_var_offset(profile),
Jens Axboe9ac8a792009-11-13 21:23:07 +01002558 .help = "Select a specific builtin performance test",
2559 },
2560 {
Jens Axboea696fa22009-12-04 10:05:02 +01002561 .name = "cgroup",
2562 .type = FIO_OPT_STR_STORE,
2563 .off1 = td_var_offset(cgroup),
2564 .help = "Add job to cgroup of this name",
2565 },
2566 {
2567 .name = "cgroup_weight",
2568 .type = FIO_OPT_INT,
2569 .off1 = td_var_offset(cgroup_weight),
2570 .help = "Use given weight for cgroup",
2571 .minval = 100,
2572 .maxval = 1000,
Jens Axboea696fa22009-12-04 10:05:02 +01002573 },
2574 {
Vivek Goyal7de87092010-03-31 22:55:15 +02002575 .name = "cgroup_nodelete",
2576 .type = FIO_OPT_BOOL,
2577 .off1 = td_var_offset(cgroup_nodelete),
2578 .help = "Do not delete cgroups after job completion",
2579 .def = "0",
2580 },
2581 {
Jens Axboee0b0d892009-12-08 10:10:14 +01002582 .name = "uid",
2583 .type = FIO_OPT_INT,
2584 .off1 = td_var_offset(uid),
2585 .help = "Run job with this user ID",
2586 },
2587 {
2588 .name = "gid",
2589 .type = FIO_OPT_INT,
2590 .off1 = td_var_offset(gid),
2591 .help = "Run job with this group ID",
2592 },
2593 {
Dan Ehrenberg9e684a42012-02-20 11:05:14 +01002594 .name = "flow_id",
2595 .type = FIO_OPT_INT,
2596 .off1 = td_var_offset(flow_id),
2597 .help = "The flow index ID to use",
2598 .def = "0",
2599 },
2600 {
2601 .name = "flow",
2602 .type = FIO_OPT_INT,
2603 .off1 = td_var_offset(flow),
2604 .help = "Weight for flow control of this job",
2605 .parent = "flow_id",
2606 .def = "0",
2607 },
2608 {
2609 .name = "flow_watermark",
2610 .type = FIO_OPT_INT,
2611 .off1 = td_var_offset(flow_watermark),
2612 .help = "High watermark for flow control. This option"
2613 " should be set to the same value for all threads"
2614 " with non-zero flow.",
2615 .parent = "flow_id",
2616 .def = "1024",
2617 },
2618 {
2619 .name = "flow_sleep",
2620 .type = FIO_OPT_INT,
2621 .off1 = td_var_offset(flow_sleep),
2622 .help = "How many microseconds to sleep after being held"
2623 " back by the flow control mechanism",
2624 .parent = "flow_id",
2625 .def = "0",
2626 },
2627 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002628 .name = NULL,
2629 },
2630};
2631
Jens Axboe17af15d2010-04-13 10:38:16 +02002632static void add_to_lopt(struct option *lopt, struct fio_option *o,
Steven Langde890a12011-11-09 14:03:34 +01002633 const char *name, int val)
Jens Axboe9f817362010-03-04 14:38:10 +01002634{
Jens Axboe17af15d2010-04-13 10:38:16 +02002635 lopt->name = (char *) name;
Steven Langde890a12011-11-09 14:03:34 +01002636 lopt->val = val;
Jens Axboe9f817362010-03-04 14:38:10 +01002637 if (o->type == FIO_OPT_STR_SET)
2638 lopt->has_arg = no_argument;
2639 else
2640 lopt->has_arg = required_argument;
2641}
2642
Steven Langde890a12011-11-09 14:03:34 +01002643static void options_to_lopts(struct fio_option *opts,
2644 struct option *long_options,
2645 int i, int option_type)
2646{
2647 struct fio_option *o = &opts[0];
2648 while (o->name) {
2649 add_to_lopt(&long_options[i], o, o->name, option_type);
2650 if (o->alias) {
2651 i++;
2652 add_to_lopt(&long_options[i], o, o->alias, option_type);
2653 }
2654
2655 i++;
2656 o++;
2657 assert(i < FIO_NR_OPTIONS);
2658 }
2659}
2660
2661void fio_options_set_ioengine_opts(struct option *long_options,
2662 struct thread_data *td)
2663{
2664 unsigned int i;
2665
2666 i = 0;
2667 while (long_options[i].name) {
2668 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2669 memset(&long_options[i], 0, sizeof(*long_options));
2670 break;
2671 }
2672 i++;
2673 }
2674
2675 /*
2676 * Just clear out the prior ioengine options.
2677 */
2678 if (!td || !td->eo)
2679 return;
2680
2681 options_to_lopts(td->io_ops->options, long_options, i,
2682 FIO_GETOPT_IOENGINE);
2683}
2684
Jens Axboe214e1ec2007-03-15 10:48:13 +01002685void fio_options_dup_and_init(struct option *long_options)
2686{
Jens Axboe214e1ec2007-03-15 10:48:13 +01002687 unsigned int i;
2688
2689 options_init(options);
2690
2691 i = 0;
2692 while (long_options[i].name)
2693 i++;
2694
Steven Langde890a12011-11-09 14:03:34 +01002695 options_to_lopts(options, long_options, i, FIO_GETOPT_JOB);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002696}
2697
Jens Axboe74929ac2009-08-05 11:42:37 +02002698struct fio_keyword {
2699 const char *word;
2700 const char *desc;
2701 char *replace;
2702};
2703
2704static struct fio_keyword fio_keywords[] = {
2705 {
2706 .word = "$pagesize",
2707 .desc = "Page size in the system",
2708 },
2709 {
2710 .word = "$mb_memory",
2711 .desc = "Megabytes of memory online",
2712 },
2713 {
2714 .word = "$ncpus",
2715 .desc = "Number of CPUs online in the system",
2716 },
2717 {
2718 .word = NULL,
2719 },
2720};
2721
2722void fio_keywords_init(void)
2723{
Jens Axboe3b2e1462009-12-15 08:58:10 +01002724 unsigned long long mb_memory;
Jens Axboe74929ac2009-08-05 11:42:37 +02002725 char buf[128];
2726 long l;
2727
Jens Axboea4cfc472012-10-09 10:30:48 -06002728 sprintf(buf, "%lu", (unsigned long) page_size);
Jens Axboe74929ac2009-08-05 11:42:37 +02002729 fio_keywords[0].replace = strdup(buf);
2730
Jens Axboe8eb016d2011-07-11 10:24:20 +02002731 mb_memory = os_phys_mem() / (1024 * 1024);
Jens Axboe3b2e1462009-12-15 08:58:10 +01002732 sprintf(buf, "%llu", mb_memory);
Jens Axboe74929ac2009-08-05 11:42:37 +02002733 fio_keywords[1].replace = strdup(buf);
2734
Jens Axboec00a2282011-07-08 20:56:06 +02002735 l = cpus_online();
Jens Axboe74929ac2009-08-05 11:42:37 +02002736 sprintf(buf, "%lu", l);
2737 fio_keywords[2].replace = strdup(buf);
2738}
2739
Jens Axboe892a6ff2009-11-13 12:19:49 +01002740#define BC_APP "bc"
2741
2742static char *bc_calc(char *str)
2743{
Steven Langd0c814e2011-10-28 08:37:13 +02002744 char buf[128], *tmp;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002745 FILE *f;
2746 int ret;
2747
2748 /*
2749 * No math, just return string
2750 */
Steven Langd0c814e2011-10-28 08:37:13 +02002751 if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2752 !strchr(str, '/')) || strchr(str, '\''))
Jens Axboe892a6ff2009-11-13 12:19:49 +01002753 return str;
2754
2755 /*
2756 * Split option from value, we only need to calculate the value
2757 */
2758 tmp = strchr(str, '=');
2759 if (!tmp)
2760 return str;
2761
2762 tmp++;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002763
Steven Langd0c814e2011-10-28 08:37:13 +02002764 /*
2765 * Prevent buffer overflows; such a case isn't reasonable anyway
2766 */
2767 if (strlen(str) >= 128 || strlen(tmp) > 100)
2768 return str;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002769
2770 sprintf(buf, "which %s > /dev/null", BC_APP);
2771 if (system(buf)) {
2772 log_err("fio: bc is needed for performing math\n");
Jens Axboe892a6ff2009-11-13 12:19:49 +01002773 return NULL;
2774 }
2775
Steven Langd0c814e2011-10-28 08:37:13 +02002776 sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002777 f = popen(buf, "r");
2778 if (!f) {
Jens Axboe892a6ff2009-11-13 12:19:49 +01002779 return NULL;
2780 }
2781
Steven Langd0c814e2011-10-28 08:37:13 +02002782 ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002783 if (ret <= 0) {
Jens Axboe892a6ff2009-11-13 12:19:49 +01002784 return NULL;
2785 }
2786
Jens Axboe892a6ff2009-11-13 12:19:49 +01002787 pclose(f);
Steven Langd0c814e2011-10-28 08:37:13 +02002788 buf[(tmp - str) + ret - 1] = '\0';
2789 memcpy(buf, str, tmp - str);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002790 free(str);
Steven Langd0c814e2011-10-28 08:37:13 +02002791 return strdup(buf);
2792}
2793
2794/*
2795 * Return a copy of the input string with substrings of the form ${VARNAME}
2796 * substituted with the value of the environment variable VARNAME. The
2797 * substitution always occurs, even if VARNAME is empty or the corresponding
2798 * environment variable undefined.
2799 */
2800static char *option_dup_subs(const char *opt)
2801{
2802 char out[OPT_LEN_MAX+1];
2803 char in[OPT_LEN_MAX+1];
2804 char *outptr = out;
2805 char *inptr = in;
2806 char *ch1, *ch2, *env;
2807 ssize_t nchr = OPT_LEN_MAX;
2808 size_t envlen;
2809
2810 if (strlen(opt) + 1 > OPT_LEN_MAX) {
2811 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2812 return NULL;
2813 }
2814
2815 in[OPT_LEN_MAX] = '\0';
2816 strncpy(in, opt, OPT_LEN_MAX);
2817
2818 while (*inptr && nchr > 0) {
2819 if (inptr[0] == '$' && inptr[1] == '{') {
2820 ch2 = strchr(inptr, '}');
2821 if (ch2 && inptr+1 < ch2) {
2822 ch1 = inptr+2;
2823 inptr = ch2+1;
2824 *ch2 = '\0';
2825
2826 env = getenv(ch1);
2827 if (env) {
2828 envlen = strlen(env);
2829 if (envlen <= nchr) {
2830 memcpy(outptr, env, envlen);
2831 outptr += envlen;
2832 nchr -= envlen;
2833 }
2834 }
2835
2836 continue;
2837 }
2838 }
2839
2840 *outptr++ = *inptr++;
2841 --nchr;
2842 }
2843
2844 *outptr = '\0';
2845 return strdup(out);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002846}
2847
Jens Axboe74929ac2009-08-05 11:42:37 +02002848/*
2849 * Look for reserved variable names and replace them with real values
2850 */
2851static char *fio_keyword_replace(char *opt)
2852{
2853 char *s;
2854 int i;
Steven Langd0c814e2011-10-28 08:37:13 +02002855 int docalc = 0;
Jens Axboe74929ac2009-08-05 11:42:37 +02002856
2857 for (i = 0; fio_keywords[i].word != NULL; i++) {
2858 struct fio_keyword *kw = &fio_keywords[i];
2859
2860 while ((s = strstr(opt, kw->word)) != NULL) {
2861 char *new = malloc(strlen(opt) + 1);
2862 char *o_org = opt;
2863 int olen = s - opt;
2864 int len;
2865
2866 /*
2867 * Copy part of the string before the keyword and
2868 * sprintf() the replacement after it.
2869 */
2870 memcpy(new, opt, olen);
2871 len = sprintf(new + olen, "%s", kw->replace);
2872
2873 /*
2874 * If there's more in the original string, copy that
2875 * in too
2876 */
2877 opt += strlen(kw->word) + olen;
2878 if (strlen(opt))
2879 memcpy(new + olen + len, opt, opt - o_org - 1);
2880
2881 /*
2882 * replace opt and free the old opt
2883 */
2884 opt = new;
Steven Langd0c814e2011-10-28 08:37:13 +02002885 free(o_org);
Jens Axboe7a958bd2009-11-13 12:33:54 +01002886
Steven Langd0c814e2011-10-28 08:37:13 +02002887 docalc = 1;
Jens Axboe74929ac2009-08-05 11:42:37 +02002888 }
2889 }
2890
Steven Langd0c814e2011-10-28 08:37:13 +02002891 /*
2892 * Check for potential math and invoke bc, if possible
2893 */
2894 if (docalc)
2895 opt = bc_calc(opt);
2896
Jens Axboe7a958bd2009-11-13 12:33:54 +01002897 return opt;
Jens Axboe74929ac2009-08-05 11:42:37 +02002898}
2899
Steven Langd0c814e2011-10-28 08:37:13 +02002900static char **dup_and_sub_options(char **opts, int num_opts)
2901{
2902 int i;
2903 char **opts_copy = malloc(num_opts * sizeof(*opts));
2904 for (i = 0; i < num_opts; i++) {
2905 opts_copy[i] = option_dup_subs(opts[i]);
2906 if (!opts_copy[i])
2907 continue;
2908 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2909 }
2910 return opts_copy;
2911}
2912
Jens Axboe3b8b7132008-06-10 19:46:23 +02002913int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
Jens Axboe214e1ec2007-03-15 10:48:13 +01002914{
Steven Langde890a12011-11-09 14:03:34 +01002915 int i, ret, unknown;
Steven Langd0c814e2011-10-28 08:37:13 +02002916 char **opts_copy;
Jens Axboe3b8b7132008-06-10 19:46:23 +02002917
2918 sort_options(opts, options, num_opts);
Steven Langd0c814e2011-10-28 08:37:13 +02002919 opts_copy = dup_and_sub_options(opts, num_opts);
Jens Axboe3b8b7132008-06-10 19:46:23 +02002920
Steven Langde890a12011-11-09 14:03:34 +01002921 for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
2922 struct fio_option *o;
2923 int newret = parse_option(opts_copy[i], opts[i], options, &o,
2924 td);
Steven Langd0c814e2011-10-28 08:37:13 +02002925
Steven Langde890a12011-11-09 14:03:34 +01002926 if (opts_copy[i]) {
2927 if (newret && !o) {
2928 unknown++;
2929 continue;
2930 }
Steven Langd0c814e2011-10-28 08:37:13 +02002931 free(opts_copy[i]);
Steven Langde890a12011-11-09 14:03:34 +01002932 opts_copy[i] = NULL;
2933 }
2934
2935 ret |= newret;
2936 }
2937
2938 if (unknown) {
2939 ret |= ioengine_load(td);
2940 if (td->eo) {
2941 sort_options(opts_copy, td->io_ops->options, num_opts);
2942 opts = opts_copy;
2943 }
2944 for (i = 0; i < num_opts; i++) {
2945 struct fio_option *o = NULL;
2946 int newret = 1;
2947 if (!opts_copy[i])
2948 continue;
2949
2950 if (td->eo)
2951 newret = parse_option(opts_copy[i], opts[i],
2952 td->io_ops->options, &o,
2953 td->eo);
2954
2955 ret |= newret;
2956 if (!o)
2957 log_err("Bad option <%s>\n", opts[i]);
2958
2959 free(opts_copy[i]);
2960 opts_copy[i] = NULL;
2961 }
Jens Axboe74929ac2009-08-05 11:42:37 +02002962 }
Jens Axboe3b8b7132008-06-10 19:46:23 +02002963
Steven Langd0c814e2011-10-28 08:37:13 +02002964 free(opts_copy);
Jens Axboe3b8b7132008-06-10 19:46:23 +02002965 return ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +01002966}
2967
2968int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2969{
Jens Axboe07b32322010-03-05 09:48:44 +01002970 return parse_cmd_option(opt, val, options, td);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002971}
2972
Steven Langde890a12011-11-09 14:03:34 +01002973int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
2974 char *val)
2975{
2976 return parse_cmd_option(opt, val, td->io_ops->options, td);
2977}
2978
Jens Axboe214e1ec2007-03-15 10:48:13 +01002979void fio_fill_default_options(struct thread_data *td)
2980{
2981 fill_default_options(td, options);
2982}
2983
2984int fio_show_option_help(const char *opt)
2985{
Jens Axboe07b32322010-03-05 09:48:44 +01002986 return show_cmd_help(options, opt);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002987}
Jens Axboed23bb322007-03-23 15:57:56 +01002988
Steven Langde890a12011-11-09 14:03:34 +01002989void options_mem_dupe(void *data, struct fio_option *options)
2990{
2991 struct fio_option *o;
2992 char **ptr;
2993
2994 for (o = &options[0]; o->name; o++) {
2995 if (o->type != FIO_OPT_STR_STORE)
2996 continue;
2997
2998 ptr = td_var(data, o->off1);
2999 if (*ptr)
3000 *ptr = strdup(*ptr);
3001 }
3002}
3003
Jens Axboe7e356b22011-10-14 10:55:16 +02003004/*
3005 * dupe FIO_OPT_STR_STORE options
3006 */
Steven Langde890a12011-11-09 14:03:34 +01003007void fio_options_mem_dupe(struct thread_data *td)
Jens Axboed23bb322007-03-23 15:57:56 +01003008{
Steven Langde890a12011-11-09 14:03:34 +01003009 options_mem_dupe(&td->o, options);
Jens Axboe1647f592011-11-09 20:25:21 +01003010
3011 if (td->eo && td->io_ops) {
Steven Langde890a12011-11-09 14:03:34 +01003012 void *oldeo = td->eo;
Jens Axboe1647f592011-11-09 20:25:21 +01003013
Steven Langde890a12011-11-09 14:03:34 +01003014 td->eo = malloc(td->io_ops->option_struct_size);
3015 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
3016 options_mem_dupe(td->eo, td->io_ops->options);
Jens Axboed23bb322007-03-23 15:57:56 +01003017 }
3018}
3019
Jens Axboed6978a32009-07-18 21:04:09 +02003020unsigned int fio_get_kb_base(void *data)
3021{
3022 struct thread_data *td = data;
3023 unsigned int kb_base = 0;
3024
3025 if (td)
3026 kb_base = td->o.kb_base;
3027 if (!kb_base)
3028 kb_base = 1024;
3029
3030 return kb_base;
3031}
Jens Axboe9f988e22010-03-04 10:42:38 +01003032
Jens Axboe07b32322010-03-05 09:48:44 +01003033int add_option(struct fio_option *o)
Jens Axboe9f988e22010-03-04 10:42:38 +01003034{
Jens Axboe07b32322010-03-05 09:48:44 +01003035 struct fio_option *__o;
3036 int opt_index = 0;
3037
3038 __o = options;
3039 while (__o->name) {
3040 opt_index++;
3041 __o++;
3042 }
3043
3044 memcpy(&options[opt_index], o, sizeof(*o));
3045 return 0;
Jens Axboe9f988e22010-03-04 10:42:38 +01003046}
Jens Axboee2de69d2010-03-04 14:05:48 +01003047
Jens Axboe07b32322010-03-05 09:48:44 +01003048void invalidate_profile_options(const char *prof_name)
Jens Axboee2de69d2010-03-04 14:05:48 +01003049{
Jens Axboe07b32322010-03-05 09:48:44 +01003050 struct fio_option *o;
Jens Axboee2de69d2010-03-04 14:05:48 +01003051
Jens Axboe07b32322010-03-05 09:48:44 +01003052 o = options;
3053 while (o->name) {
3054 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
3055 o->type = FIO_OPT_INVALID;
3056 o->prof_name = NULL;
3057 }
3058 o++;
Jens Axboee2de69d2010-03-04 14:05:48 +01003059 }
3060}
Jens Axboef5b6bb82010-03-05 10:09:59 +01003061
3062void add_opt_posval(const char *optname, const char *ival, const char *help)
3063{
3064 struct fio_option *o;
3065 unsigned int i;
3066
3067 o = find_option(options, optname);
3068 if (!o)
3069 return;
3070
3071 for (i = 0; i < PARSE_MAX_VP; i++) {
3072 if (o->posval[i].ival)
3073 continue;
3074
3075 o->posval[i].ival = ival;
3076 o->posval[i].help = help;
3077 break;
3078 }
3079}
3080
3081void del_opt_posval(const char *optname, const char *ival)
3082{
3083 struct fio_option *o;
3084 unsigned int i;
3085
3086 o = find_option(options, optname);
3087 if (!o)
3088 return;
3089
3090 for (i = 0; i < PARSE_MAX_VP; i++) {
3091 if (!o->posval[i].ival)
3092 continue;
3093 if (strcmp(o->posval[i].ival, ival))
3094 continue;
3095
3096 o->posval[i].ival = NULL;
3097 o->posval[i].help = NULL;
3098 }
3099}
Jens Axboe7e356b22011-10-14 10:55:16 +02003100
3101void fio_options_free(struct thread_data *td)
3102{
3103 options_free(options, td);
Steven Langde890a12011-11-09 14:03:34 +01003104 if (td->eo && td->io_ops && td->io_ops->options) {
3105 options_free(td->io_ops->options, td->eo);
3106 free(td->eo);
3107 td->eo = NULL;
3108 }
Jens Axboe7e356b22011-10-14 10:55:16 +02003109}