blob: 8fb93ca7a0c2c6a331a75e5250c86f0d9e37e156 [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;
169 char *str, *p, *odir;
170 int ret = 0;
171
172 p = str = strdup(input);
173
174 strip_blank_front(&str);
175 strip_blank_end(str);
176
177 odir = strchr(str, ',');
178 if (odir) {
179 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
180 if (!ret) {
181 *odir = '\0';
182 ret = bssplit_ddir(td, DDIR_READ, str);
183 }
184 } else {
185 char *op;
186
187 op = strdup(str);
188
189 ret = bssplit_ddir(td, DDIR_READ, str);
190 if (!ret)
191 ret = bssplit_ddir(td, DDIR_WRITE, op);
192
193 free(op);
194 }
Jens Axboe564ca972007-12-14 12:21:19 +0100195
196 free(p);
Jens Axboe720e84a2009-04-21 08:29:55 +0200197 return ret;
Jens Axboe564ca972007-12-14 12:21:19 +0100198}
199
Jens Axboe211097b2007-03-22 18:56:45 +0100200static int str_rw_cb(void *data, const char *str)
201{
202 struct thread_data *td = data;
203 char *nr = get_opt_postfix(str);
204
Jens Axboe5736c102010-07-20 12:03:25 -0600205 td->o.ddir_seq_nr = 1;
Jens Axboe059b0802011-08-25 09:09:37 +0200206 td->o.ddir_seq_add = 0;
207
208 if (!nr)
209 return 0;
210
211 if (td_random(td))
Jens Axboe5736c102010-07-20 12:03:25 -0600212 td->o.ddir_seq_nr = atoi(nr);
Jens Axboe059b0802011-08-25 09:09:37 +0200213 else {
214 long long val;
215
Jens Axboe6925dd32011-09-07 22:10:11 +0200216 if (str_to_decimal(nr, &val, 1, td)) {
Jens Axboe059b0802011-08-25 09:09:37 +0200217 log_err("fio: rw postfix parsing failed\n");
218 free(nr);
219 return 1;
220 }
221
222 td->o.ddir_seq_add = val;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100223 }
Jens Axboe211097b2007-03-22 18:56:45 +0100224
Jens Axboe059b0802011-08-25 09:09:37 +0200225 free(nr);
Jens Axboe211097b2007-03-22 18:56:45 +0100226 return 0;
227}
228
Jens Axboe214e1ec2007-03-15 10:48:13 +0100229static int str_mem_cb(void *data, const char *mem)
230{
231 struct thread_data *td = data;
232
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100233 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100234 td->mmapfile = get_opt_postfix(mem);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100235 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100236 log_err("fio: mmaphuge:/path/to/file\n");
237 return 1;
238 }
239 }
240
241 return 0;
242}
243
Jens Axboe5d7c5d32010-06-21 15:08:17 +0200244static int str_verify_cb(void *data, const char *mem)
245{
246 struct thread_data *td = data;
247
248 if (td->o.verify != VERIFY_CRC32C_INTEL)
249 return 0;
250
251 if (!crc32c_intel_works()) {
252 log_info("fio: System does not support hw accelerated crc32c. Falling back to sw crc32c.\n");
253 td->o.verify = VERIFY_CRC32C;
254 }
255
256 return 0;
257}
258
Jens Axboec223da82010-03-24 13:23:53 +0100259static int fio_clock_source_cb(void *data, const char *str)
260{
261 struct thread_data *td = data;
262
263 fio_clock_source = td->o.clocksource;
264 fio_time_init();
265 return 0;
266}
267
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400268static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100269{
270 mlock_size = *val;
271 return 0;
272}
273
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400274static int str_rwmix_read_cb(void *data, unsigned long long *val)
Jens Axboecb499fc2008-05-28 10:33:32 +0200275{
276 struct thread_data *td = data;
277
278 td->o.rwmix[DDIR_READ] = *val;
279 td->o.rwmix[DDIR_WRITE] = 100 - *val;
280 return 0;
281}
282
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400283static int str_rwmix_write_cb(void *data, unsigned long long *val)
Jens Axboecb499fc2008-05-28 10:33:32 +0200284{
285 struct thread_data *td = data;
286
287 td->o.rwmix[DDIR_WRITE] = *val;
288 td->o.rwmix[DDIR_READ] = 100 - *val;
289 return 0;
290}
291
Jens Axboe214e1ec2007-03-15 10:48:13 +0100292#ifdef FIO_HAVE_IOPRIO
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400293static int str_prioclass_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100294{
295 struct thread_data *td = data;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200296 unsigned short mask;
297
298 /*
299 * mask off old class bits, str_prio_cb() may have set a default class
300 */
301 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
302 td->ioprio &= mask;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100303
304 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
Jens Axboeac684782007-11-08 08:29:07 +0100305 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100306 return 0;
307}
308
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400309static int str_prio_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100310{
311 struct thread_data *td = data;
312
313 td->ioprio |= *val;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200314
315 /*
316 * If no class is set, assume BE
317 */
318 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
319 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
320
Jens Axboeac684782007-11-08 08:29:07 +0100321 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100322 return 0;
323}
324#endif
325
326static int str_exitall_cb(void)
327{
328 exitall_on_terminate = 1;
329 return 0;
330}
331
Jens Axboe214e1ec2007-03-15 10:48:13 +0100332#ifdef FIO_HAVE_CPU_AFFINITY
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400333static int str_cpumask_cb(void *data, unsigned long long *val)
Jens Axboe214e1ec2007-03-15 10:48:13 +0100334{
335 struct thread_data *td = data;
Jens Axboed2e268b2007-06-15 10:33:49 +0200336 unsigned int i;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100337 long max_cpu;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100338 int ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100339
Jens Axboed2ce18b2008-12-12 20:51:40 +0100340 ret = fio_cpuset_init(&td->o.cpumask);
341 if (ret < 0) {
342 log_err("fio: cpuset_init failed\n");
343 td_verror(td, ret, "fio_cpuset_init");
344 return 1;
345 }
346
Jens Axboec00a2282011-07-08 20:56:06 +0200347 max_cpu = cpus_online();
Jens Axboed2e268b2007-06-15 10:33:49 +0200348
Jens Axboe62a72732008-12-08 11:37:01 +0100349 for (i = 0; i < sizeof(int) * 8; i++) {
350 if ((1 << i) & *val) {
Jens Axboeb03daaf2008-12-08 20:31:43 +0100351 if (i > max_cpu) {
352 log_err("fio: CPU %d too large (max=%ld)\n", i,
353 max_cpu);
354 return 1;
355 }
Jens Axboe62a72732008-12-08 11:37:01 +0100356 dprint(FD_PARSE, "set cpu allowed %d\n", i);
Jens Axboe6d459ee2008-12-12 20:02:58 +0100357 fio_cpu_set(&td->o.cpumask, i);
Jens Axboe62a72732008-12-08 11:37:01 +0100358 }
359 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200360
Jens Axboe375b2692007-05-22 09:13:02 +0200361 td->o.cpumask_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100362 return 0;
363}
364
Jens Axboee8462bd2009-07-06 12:59:04 +0200365static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
366 const char *input)
Jens Axboed2e268b2007-06-15 10:33:49 +0200367{
Jens Axboed2e268b2007-06-15 10:33:49 +0200368 char *cpu, *str, *p;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100369 long max_cpu;
Jens Axboe19608d62008-12-08 15:03:12 +0100370 int ret = 0;
Jens Axboed2e268b2007-06-15 10:33:49 +0200371
Jens Axboee8462bd2009-07-06 12:59:04 +0200372 ret = fio_cpuset_init(mask);
Jens Axboed2ce18b2008-12-12 20:51:40 +0100373 if (ret < 0) {
374 log_err("fio: cpuset_init failed\n");
375 td_verror(td, ret, "fio_cpuset_init");
376 return 1;
377 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200378
379 p = str = strdup(input);
380
381 strip_blank_front(&str);
382 strip_blank_end(str);
383
Jens Axboec00a2282011-07-08 20:56:06 +0200384 max_cpu = cpus_online();
Jens Axboeb03daaf2008-12-08 20:31:43 +0100385
Jens Axboed2e268b2007-06-15 10:33:49 +0200386 while ((cpu = strsep(&str, ",")) != NULL) {
Jens Axboe62a72732008-12-08 11:37:01 +0100387 char *str2, *cpu2;
388 int icpu, icpu2;
389
Jens Axboed2e268b2007-06-15 10:33:49 +0200390 if (!strlen(cpu))
391 break;
Jens Axboe62a72732008-12-08 11:37:01 +0100392
393 str2 = cpu;
394 icpu2 = -1;
395 while ((cpu2 = strsep(&str2, "-")) != NULL) {
396 if (!strlen(cpu2))
397 break;
398
399 icpu2 = atoi(cpu2);
400 }
401
402 icpu = atoi(cpu);
403 if (icpu2 == -1)
404 icpu2 = icpu;
405 while (icpu <= icpu2) {
Jens Axboe6d459ee2008-12-12 20:02:58 +0100406 if (icpu >= FIO_MAX_CPUS) {
Jens Axboe19608d62008-12-08 15:03:12 +0100407 log_err("fio: your OS only supports up to"
Jens Axboe6d459ee2008-12-12 20:02:58 +0100408 " %d CPUs\n", (int) FIO_MAX_CPUS);
Jens Axboe19608d62008-12-08 15:03:12 +0100409 ret = 1;
410 break;
411 }
Jens Axboeb03daaf2008-12-08 20:31:43 +0100412 if (icpu > max_cpu) {
413 log_err("fio: CPU %d too large (max=%ld)\n",
414 icpu, max_cpu);
415 ret = 1;
416 break;
417 }
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200418
Jens Axboe62a72732008-12-08 11:37:01 +0100419 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
Jens Axboee8462bd2009-07-06 12:59:04 +0200420 fio_cpu_set(mask, icpu);
Jens Axboe62a72732008-12-08 11:37:01 +0100421 icpu++;
422 }
Jens Axboe19608d62008-12-08 15:03:12 +0100423 if (ret)
424 break;
Jens Axboed2e268b2007-06-15 10:33:49 +0200425 }
426
427 free(p);
Jens Axboe19608d62008-12-08 15:03:12 +0100428 if (!ret)
429 td->o.cpumask_set = 1;
430 return ret;
Jens Axboed2e268b2007-06-15 10:33:49 +0200431}
Jens Axboee8462bd2009-07-06 12:59:04 +0200432
433static int str_cpus_allowed_cb(void *data, const char *input)
434{
435 struct thread_data *td = data;
436 int ret;
437
438 ret = set_cpus_allowed(td, &td->o.cpumask, input);
439 if (!ret)
440 td->o.cpumask_set = 1;
441
442 return ret;
443}
444
445static int str_verify_cpus_allowed_cb(void *data, const char *input)
446{
447 struct thread_data *td = data;
448 int ret;
449
450 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
451 if (!ret)
452 td->o.verify_cpumask_set = 1;
453
454 return ret;
455}
Jens Axboed2e268b2007-06-15 10:33:49 +0200456#endif
457
Jens Axboe0d29de82010-09-01 13:54:15 +0200458#ifdef FIO_HAVE_TRIM
459static int str_verify_trim_cb(void *data, unsigned long long *val)
460{
461 struct thread_data *td = data;
462
463 td->o.trim_percentage = *val;
464 return 0;
465}
466#endif
467
Jens Axboe214e1ec2007-03-15 10:48:13 +0100468static int str_fst_cb(void *data, const char *str)
469{
470 struct thread_data *td = data;
471 char *nr = get_opt_postfix(str);
472
473 td->file_service_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100474 if (nr) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100475 td->file_service_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100476 free(nr);
477 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100478
479 return 0;
480}
481
Jens Axboe3ae06372010-03-19 19:17:15 +0100482#ifdef FIO_HAVE_SYNC_FILE_RANGE
Jens Axboe44f29692010-03-09 20:09:44 +0100483static int str_sfr_cb(void *data, const char *str)
484{
485 struct thread_data *td = data;
486 char *nr = get_opt_postfix(str);
487
488 td->sync_file_range_nr = 1;
489 if (nr) {
490 td->sync_file_range_nr = atoi(nr);
491 free(nr);
492 }
493
494 return 0;
495}
Jens Axboe3ae06372010-03-19 19:17:15 +0100496#endif
Jens Axboe44f29692010-03-09 20:09:44 +0100497
Jens Axboe921c7662008-03-26 09:17:55 +0100498static int check_dir(struct thread_data *td, char *fname)
499{
Jens Axboe3f0ca9b2011-05-24 21:36:24 +0200500#if 0
Jens Axboe921c7662008-03-26 09:17:55 +0100501 char file[PATH_MAX], *dir;
Jens Axboebc838912008-04-07 09:00:54 +0200502 int elen = 0;
Jens Axboe921c7662008-03-26 09:17:55 +0100503
Jens Axboebc838912008-04-07 09:00:54 +0200504 if (td->o.directory) {
505 strcpy(file, td->o.directory);
Jens Axboefcef0b32008-05-26 14:53:24 +0200506 strcat(file, "/");
Jens Axboebc838912008-04-07 09:00:54 +0200507 elen = strlen(file);
508 }
509
Jens Axboefcef0b32008-05-26 14:53:24 +0200510 sprintf(file + elen, "%s", fname);
Jens Axboe921c7662008-03-26 09:17:55 +0100511 dir = dirname(file);
512
Jens Axboefcef0b32008-05-26 14:53:24 +0200513 {
514 struct stat sb;
515 /*
516 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
517 * yet, so we can't do this check right here...
518 */
Jens Axboe921c7662008-03-26 09:17:55 +0100519 if (lstat(dir, &sb) < 0) {
520 int ret = errno;
521
522 log_err("fio: %s is not a directory\n", dir);
523 td_verror(td, ret, "lstat");
524 return 1;
525 }
526
527 if (!S_ISDIR(sb.st_mode)) {
528 log_err("fio: %s is not a directory\n", dir);
529 return 1;
530 }
Jens Axboefcef0b32008-05-26 14:53:24 +0200531 }
532#endif
Jens Axboe921c7662008-03-26 09:17:55 +0100533
534 return 0;
535}
536
Jens Axboe8e827d32009-08-04 09:51:48 +0200537/*
538 * Return next file in the string. Files are separated with ':'. If the ':'
539 * is escaped with a '\', then that ':' is part of the filename and does not
540 * indicate a new file.
541 */
542static char *get_next_file_name(char **ptr)
543{
544 char *str = *ptr;
545 char *p, *start;
546
547 if (!str || !strlen(str))
548 return NULL;
549
550 start = str;
551 do {
552 /*
553 * No colon, we are done
554 */
555 p = strchr(str, ':');
556 if (!p) {
557 *ptr = NULL;
558 break;
559 }
560
561 /*
562 * We got a colon, but it's the first character. Skip and
563 * continue
564 */
565 if (p == start) {
566 str = ++start;
567 continue;
568 }
569
570 if (*(p - 1) != '\\') {
571 *p = '\0';
572 *ptr = p + 1;
573 break;
574 }
575
576 memmove(p - 1, p, strlen(p) + 1);
577 str = p;
578 } while (1);
579
580 return start;
581}
582
Jens Axboe214e1ec2007-03-15 10:48:13 +0100583static int str_filename_cb(void *data, const char *input)
584{
585 struct thread_data *td = data;
586 char *fname, *str, *p;
587
588 p = str = strdup(input);
589
590 strip_blank_front(&str);
591 strip_blank_end(str);
592
593 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100594 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100595
Jens Axboe8e827d32009-08-04 09:51:48 +0200596 while ((fname = get_next_file_name(&str)) != NULL) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100597 if (!strlen(fname))
598 break;
Jens Axboe921c7662008-03-26 09:17:55 +0100599 if (check_dir(td, fname)) {
600 free(p);
601 return 1;
602 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100603 add_file(td, fname);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100604 td->o.nr_files++;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100605 }
606
607 free(p);
608 return 0;
609}
610
611static int str_directory_cb(void *data, const char fio_unused *str)
612{
613 struct thread_data *td = data;
614 struct stat sb;
615
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100616 if (lstat(td->o.directory, &sb) < 0) {
Jens Axboe921c7662008-03-26 09:17:55 +0100617 int ret = errno;
618
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100619 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe921c7662008-03-26 09:17:55 +0100620 td_verror(td, ret, "lstat");
Jens Axboe214e1ec2007-03-15 10:48:13 +0100621 return 1;
622 }
623 if (!S_ISDIR(sb.st_mode)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100624 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100625 return 1;
626 }
627
628 return 0;
629}
630
631static int str_opendir_cb(void *data, const char fio_unused *str)
632{
633 struct thread_data *td = data;
634
635 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100636 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100637
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100638 return add_dir_files(td, td->o.opendir);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100639}
640
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400641static int str_verify_offset_cb(void *data, unsigned long long *off)
Shawn Lewis546a9142007-07-28 21:11:37 +0200642{
643 struct thread_data *td = data;
Jens Axboea59e1702007-07-30 08:53:27 +0200644
Shawn Lewis546a9142007-07-28 21:11:37 +0200645 if (*off && *off < sizeof(struct verify_header)) {
Jens Axboea59e1702007-07-30 08:53:27 +0200646 log_err("fio: verify_offset too small\n");
Shawn Lewis546a9142007-07-28 21:11:37 +0200647 return 1;
648 }
Jens Axboea59e1702007-07-30 08:53:27 +0200649
650 td->o.verify_offset = *off;
Shawn Lewis546a9142007-07-28 21:11:37 +0200651 return 0;
652}
653
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100654static int str_verify_pattern_cb(void *data, const char *input)
Jens Axboe90059d62007-07-30 09:33:12 +0200655{
656 struct thread_data *td = data;
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100657 long off;
658 int i = 0, j = 0, len, k, base = 10;
659 char* loc1, * loc2;
Jens Axboe90059d62007-07-30 09:33:12 +0200660
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100661 loc1 = strstr(input, "0x");
662 loc2 = strstr(input, "0X");
663 if (loc1 || loc2)
664 base = 16;
665 off = strtol(input, NULL, base);
666 if (off != LONG_MAX || errno != ERANGE) {
667 while (off) {
668 td->o.verify_pattern[i] = off & 0xff;
669 off >>= 8;
670 i++;
671 }
672 } else {
673 len = strlen(input);
674 k = len - 1;
675 if (base == 16) {
676 if (loc1)
677 j = loc1 - input + 2;
678 else
679 j = loc2 - input + 2;
680 } else
681 return 1;
682 if (len - j < MAX_PATTERN_SIZE * 2) {
683 while (k >= j) {
684 off = converthexchartoint(input[k--]);
685 if (k >= j)
686 off += (converthexchartoint(input[k--])
687 * 16);
688 td->o.verify_pattern[i++] = (char) off;
689 }
690 }
691 }
Steven Langefcd9dc2012-02-02 20:22:04 +0100692
693 /*
694 * Fill the pattern all the way to the end. This greatly reduces
695 * the number of memcpy's we have to do when verifying the IO.
696 */
697 while (i > 1 && i * 2 <= MAX_PATTERN_SIZE) {
698 memcpy(&td->o.verify_pattern[i], &td->o.verify_pattern[0], i);
699 i *= 2;
700 }
701
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100702 td->o.verify_pattern_bytes = i;
Steven Langefcd9dc2012-02-02 20:22:04 +0100703
Jens Axboe92bf48d2011-01-14 21:20:42 +0100704 /*
705 * VERIFY_META could already be set
706 */
707 if (td->o.verify == VERIFY_NONE)
708 td->o.verify = VERIFY_PATTERN;
Steven Langefcd9dc2012-02-02 20:22:04 +0100709
Jens Axboe90059d62007-07-30 09:33:12 +0200710 return 0;
711}
Jens Axboe214e1ec2007-03-15 10:48:13 +0100712
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100713static int str_lockfile_cb(void *data, const char *str)
714{
715 struct thread_data *td = data;
716 char *nr = get_opt_postfix(str);
717
718 td->o.lockfile_batch = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100719 if (nr) {
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100720 td->o.lockfile_batch = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100721 free(nr);
722 }
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100723
724 return 0;
725}
726
Jens Axboee3cedca2008-11-19 19:57:52 +0100727static int str_write_bw_log_cb(void *data, const char *str)
728{
729 struct thread_data *td = data;
730
731 if (str)
732 td->o.bw_log_file = strdup(str);
733
734 td->o.write_bw_log = 1;
735 return 0;
736}
737
738static int str_write_lat_log_cb(void *data, const char *str)
739{
740 struct thread_data *td = data;
741
742 if (str)
743 td->o.lat_log_file = strdup(str);
744
745 td->o.write_lat_log = 1;
746 return 0;
747}
748
Jens Axboec8eeb9d2011-10-05 14:02:22 +0200749static int str_write_iops_log_cb(void *data, const char *str)
750{
751 struct thread_data *td = data;
752
753 if (str)
754 td->o.iops_log_file = strdup(str);
755
756 td->o.write_iops_log = 1;
757 return 0;
758}
759
Jens Axboe993bf482008-11-14 13:04:53 +0100760static int str_gtod_reduce_cb(void *data, int *il)
761{
762 struct thread_data *td = data;
763 int val = *il;
764
Jens Axboe02af0982010-06-24 09:59:34 +0200765 td->o.disable_lat = !!val;
Jens Axboe993bf482008-11-14 13:04:53 +0100766 td->o.disable_clat = !!val;
767 td->o.disable_slat = !!val;
768 td->o.disable_bw = !!val;
Jens Axboe0dc1bc02011-10-13 08:55:29 +0200769 td->o.clat_percentiles = !val;
Jens Axboe993bf482008-11-14 13:04:53 +0100770 if (val)
771 td->tv_cache_mask = 63;
772
773 return 0;
774}
775
Cigy Cyriac85bc8332010-08-10 19:21:09 -0400776static int str_gtod_cpu_cb(void *data, long long *il)
Jens Axboebe4ecfd2008-12-08 14:10:52 +0100777{
778 struct thread_data *td = data;
779 int val = *il;
780
781 td->o.gtod_cpu = val;
782 td->o.gtod_offload = 1;
783 return 0;
784}
785
Jens Axboe7bb59102011-07-12 19:47:03 +0200786static int str_size_cb(void *data, unsigned long long *__val)
787{
788 struct thread_data *td = data;
789 unsigned long long v = *__val;
790
791 if (parse_is_percent(v)) {
792 td->o.size = 0;
793 td->o.size_percent = -1ULL - v;
794 } else
795 td->o.size = v;
796
797 return 0;
798}
799
Jens Axboe896cac22009-07-01 10:38:35 +0200800static int rw_verify(struct fio_option *o, void *data)
801{
802 struct thread_data *td = data;
803
804 if (read_only && td_write(td)) {
805 log_err("fio: job <%s> has write bit set, but fio is in"
806 " read-only mode\n", td->o.name);
807 return 1;
808 }
809
810 return 0;
811}
812
Jens Axboe276ca4f2009-07-01 10:43:05 +0200813static int gtod_cpu_verify(struct fio_option *o, void *data)
Jens Axboe29d43ff2009-07-01 10:42:18 +0200814{
Jens Axboe276ca4f2009-07-01 10:43:05 +0200815#ifndef FIO_HAVE_CPU_AFFINITY
Jens Axboe29d43ff2009-07-01 10:42:18 +0200816 struct thread_data *td = data;
817
Jens Axboe29d43ff2009-07-01 10:42:18 +0200818 if (td->o.gtod_cpu) {
819 log_err("fio: platform must support CPU affinity for"
820 "gettimeofday() offloading\n");
821 return 1;
822 }
823#endif
824
825 return 0;
826}
827
Jens Axboe90fef2d2009-07-17 22:33:32 +0200828static int kb_base_verify(struct fio_option *o, void *data)
829{
830 struct thread_data *td = data;
831
832 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
833 log_err("fio: kb_base set to nonsensical value: %u\n",
834 td->o.kb_base);
835 return 1;
836 }
837
838 return 0;
839}
840
Jens Axboe214e1ec2007-03-15 10:48:13 +0100841/*
842 * Map of job/command line options
843 */
Jens Axboe07b32322010-03-05 09:48:44 +0100844static struct fio_option options[FIO_MAX_OPTS] = {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100845 {
846 .name = "description",
847 .type = FIO_OPT_STR_STORE,
848 .off1 = td_var_offset(description),
849 .help = "Text job description",
850 },
851 {
852 .name = "name",
853 .type = FIO_OPT_STR_STORE,
854 .off1 = td_var_offset(name),
855 .help = "Name of this job",
856 },
857 {
858 .name = "directory",
859 .type = FIO_OPT_STR_STORE,
860 .off1 = td_var_offset(directory),
861 .cb = str_directory_cb,
862 .help = "Directory to store files in",
863 },
864 {
865 .name = "filename",
866 .type = FIO_OPT_STR_STORE,
867 .off1 = td_var_offset(filename),
868 .cb = str_filename_cb,
Jens Axboef0d524b2009-04-27 08:00:48 +0200869 .prio = -1, /* must come after "directory" */
Jens Axboe214e1ec2007-03-15 10:48:13 +0100870 .help = "File(s) to use for the workload",
871 },
872 {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200873 .name = "kb_base",
874 .type = FIO_OPT_INT,
875 .off1 = td_var_offset(kb_base),
Jens Axboe90fef2d2009-07-17 22:33:32 +0200876 .verify = kb_base_verify,
Jens Axboea639f0b2009-07-18 08:25:35 +0200877 .prio = 1,
Jens Axboe90fef2d2009-07-17 22:33:32 +0200878 .def = "1024",
Jens Axboea639f0b2009-07-18 08:25:35 +0200879 .help = "How many bytes per KB for reporting (1000 or 1024)",
Jens Axboe90fef2d2009-07-17 22:33:32 +0200880 },
881 {
Jens Axboe29c13492008-03-01 19:25:20 +0100882 .name = "lockfile",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100883 .type = FIO_OPT_STR,
884 .cb = str_lockfile_cb,
885 .off1 = td_var_offset(file_lock_mode),
Jens Axboe29c13492008-03-01 19:25:20 +0100886 .help = "Lock file when doing IO to it",
887 .parent = "filename",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100888 .def = "none",
889 .posval = {
890 { .ival = "none",
891 .oval = FILE_LOCK_NONE,
892 .help = "No file locking",
893 },
894 { .ival = "exclusive",
895 .oval = FILE_LOCK_EXCLUSIVE,
896 .help = "Exclusive file lock",
897 },
898 {
899 .ival = "readwrite",
900 .oval = FILE_LOCK_READWRITE,
901 .help = "Read vs write lock",
902 },
903 },
Jens Axboe29c13492008-03-01 19:25:20 +0100904 },
905 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100906 .name = "opendir",
907 .type = FIO_OPT_STR_STORE,
908 .off1 = td_var_offset(opendir),
909 .cb = str_opendir_cb,
910 .help = "Recursively add files from this directory and down",
911 },
912 {
913 .name = "rw",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100914 .alias = "readwrite",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100915 .type = FIO_OPT_STR,
Jens Axboe211097b2007-03-22 18:56:45 +0100916 .cb = str_rw_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100917 .off1 = td_var_offset(td_ddir),
918 .help = "IO direction",
919 .def = "read",
Jens Axboe896cac22009-07-01 10:38:35 +0200920 .verify = rw_verify,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100921 .posval = {
922 { .ival = "read",
923 .oval = TD_DDIR_READ,
924 .help = "Sequential read",
925 },
926 { .ival = "write",
927 .oval = TD_DDIR_WRITE,
928 .help = "Sequential write",
929 },
930 { .ival = "randread",
931 .oval = TD_DDIR_RANDREAD,
932 .help = "Random read",
933 },
934 { .ival = "randwrite",
935 .oval = TD_DDIR_RANDWRITE,
936 .help = "Random write",
937 },
938 { .ival = "rw",
939 .oval = TD_DDIR_RW,
940 .help = "Sequential read and write mix",
941 },
942 { .ival = "randrw",
943 .oval = TD_DDIR_RANDRW,
944 .help = "Random read and write mix"
945 },
946 },
947 },
948 {
Jens Axboe38dad622010-07-20 14:46:00 -0600949 .name = "rw_sequencer",
950 .type = FIO_OPT_STR,
951 .off1 = td_var_offset(rw_seq),
952 .help = "IO offset generator modifier",
953 .def = "sequential",
954 .posval = {
955 { .ival = "sequential",
956 .oval = RW_SEQ_SEQ,
957 .help = "Generate sequential offsets",
958 },
959 { .ival = "identical",
960 .oval = RW_SEQ_IDENT,
961 .help = "Generate identical offsets",
962 },
963 },
964 },
965
966 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100967 .name = "ioengine",
968 .type = FIO_OPT_STR_STORE,
969 .off1 = td_var_offset(ioengine),
970 .help = "IO engine to use",
Jens Axboe58483fa2011-01-19 11:09:58 -0700971 .def = FIO_PREFERRED_ENGINE,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100972 .posval = {
973 { .ival = "sync",
974 .help = "Use read/write",
975 },
gurudas paia31041e2007-10-23 15:12:30 +0200976 { .ival = "psync",
977 .help = "Use pread/pwrite",
978 },
Jens Axboe1d2af022008-02-04 10:59:07 +0100979 { .ival = "vsync",
Bruce Cran03e20d62011-01-02 20:14:54 +0100980 .help = "Use readv/writev",
Jens Axboe1d2af022008-02-04 10:59:07 +0100981 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100982#ifdef FIO_HAVE_LIBAIO
983 { .ival = "libaio",
984 .help = "Linux native asynchronous IO",
985 },
986#endif
987#ifdef FIO_HAVE_POSIXAIO
988 { .ival = "posixaio",
989 .help = "POSIX asynchronous IO",
990 },
991#endif
Jens Axboe417f0062008-06-02 11:59:30 +0200992#ifdef FIO_HAVE_SOLARISAIO
993 { .ival = "solarisaio",
994 .help = "Solaris native asynchronous IO",
995 },
996#endif
Bruce Cran03e20d62011-01-02 20:14:54 +0100997#ifdef FIO_HAVE_WINDOWSAIO
998 { .ival = "windowsaio",
Jens Axboe3be80072011-01-19 11:07:28 -0700999 .help = "Windows native asynchronous IO"
Steven Langde890a12011-11-09 14:03:34 +01001000 },
Jens Axboe3be80072011-01-19 11:07:28 -07001001#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001002 { .ival = "mmap",
Bruce Cran03e20d62011-01-02 20:14:54 +01001003 .help = "Memory mapped IO"
Jens Axboe214e1ec2007-03-15 10:48:13 +01001004 },
1005#ifdef FIO_HAVE_SPLICE
1006 { .ival = "splice",
1007 .help = "splice/vmsplice based IO",
1008 },
Jens Axboe9cce02e2007-06-22 15:42:21 +02001009 { .ival = "netsplice",
1010 .help = "splice/vmsplice to/from the network",
1011 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001012#endif
1013#ifdef FIO_HAVE_SGIO
1014 { .ival = "sg",
1015 .help = "SCSI generic v3 IO",
1016 },
1017#endif
1018 { .ival = "null",
1019 .help = "Testing engine (no data transfer)",
1020 },
1021 { .ival = "net",
1022 .help = "Network IO",
1023 },
1024#ifdef FIO_HAVE_SYSLET
1025 { .ival = "syslet-rw",
1026 .help = "syslet enabled async pread/pwrite IO",
1027 },
1028#endif
1029 { .ival = "cpuio",
Bruce Cran03e20d62011-01-02 20:14:54 +01001030 .help = "CPU cycle burner engine",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001031 },
Jens Axboeb8c82a42007-03-21 08:48:26 +01001032#ifdef FIO_HAVE_GUASI
1033 { .ival = "guasi",
1034 .help = "GUASI IO engine",
1035 },
1036#endif
Jens Axboe79a43182010-09-07 13:28:58 +02001037#ifdef FIO_HAVE_BINJECT
1038 { .ival = "binject",
1039 .help = "binject direct inject block engine",
1040 },
1041#endif
ren yufei21b8aee2011-08-01 10:01:57 +02001042#ifdef FIO_HAVE_RDMA
1043 { .ival = "rdma",
1044 .help = "RDMA IO engine",
1045 },
1046#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001047 { .ival = "external",
1048 .help = "Load external engine (append name)",
1049 },
1050 },
1051 },
1052 {
1053 .name = "iodepth",
1054 .type = FIO_OPT_INT,
1055 .off1 = td_var_offset(iodepth),
Bruce Cran03e20d62011-01-02 20:14:54 +01001056 .help = "Number of IO buffers to keep in flight",
Jens Axboe757aff42007-12-12 19:42:13 +01001057 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001058 .def = "1",
1059 },
1060 {
1061 .name = "iodepth_batch",
Jens Axboe49504212008-06-05 09:03:30 +02001062 .alias = "iodepth_batch_submit",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001063 .type = FIO_OPT_INT,
1064 .off1 = td_var_offset(iodepth_batch),
Jens Axboed65db442009-01-16 19:15:33 +01001065 .help = "Number of IO buffers to submit in one go",
Jens Axboeafdf9352007-07-31 16:14:34 +02001066 .parent = "iodepth",
Jens Axboea2e6f8a2008-01-18 10:28:11 +01001067 .minval = 1,
1068 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001069 },
1070 {
Jens Axboe49504212008-06-05 09:03:30 +02001071 .name = "iodepth_batch_complete",
1072 .type = FIO_OPT_INT,
1073 .off1 = td_var_offset(iodepth_batch_complete),
Jens Axboed65db442009-01-16 19:15:33 +01001074 .help = "Number of IO buffers to retrieve in one go",
Jens Axboe49504212008-06-05 09:03:30 +02001075 .parent = "iodepth",
1076 .minval = 0,
1077 .def = "1",
1078 },
1079 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001080 .name = "iodepth_low",
1081 .type = FIO_OPT_INT,
1082 .off1 = td_var_offset(iodepth_low),
1083 .help = "Low water mark for queuing depth",
Jens Axboeafdf9352007-07-31 16:14:34 +02001084 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001085 },
1086 {
1087 .name = "size",
1088 .type = FIO_OPT_STR_VAL,
Jens Axboe7bb59102011-07-12 19:47:03 +02001089 .cb = str_size_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001090 .help = "Total size of device or files",
1091 },
1092 {
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001093 .name = "fill_device",
Jens Axboe74586c12011-01-20 10:16:03 -07001094 .alias = "fill_fs",
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001095 .type = FIO_OPT_BOOL,
1096 .off1 = td_var_offset(fill_device),
1097 .help = "Write until an ENOSPC error occurs",
1098 .def = "0",
1099 },
1100 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001101 .name = "filesize",
1102 .type = FIO_OPT_STR_VAL,
1103 .off1 = td_var_offset(file_size_low),
1104 .off2 = td_var_offset(file_size_high),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001105 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001106 .help = "Size of individual files",
1107 },
1108 {
Jens Axboe67a10002007-07-31 23:12:16 +02001109 .name = "offset",
1110 .alias = "fileoffset",
1111 .type = FIO_OPT_STR_VAL,
1112 .off1 = td_var_offset(start_offset),
1113 .help = "Start IO from this offset",
1114 .def = "0",
1115 },
1116 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001117 .name = "bs",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001118 .alias = "blocksize",
Jens Axboee01b22b2009-06-09 15:43:25 +02001119 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001120 .off1 = td_var_offset(bs[DDIR_READ]),
1121 .off2 = td_var_offset(bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001122 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001123 .help = "Block size unit",
1124 .def = "4k",
Jens Axboe67a10002007-07-31 23:12:16 +02001125 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001126 },
1127 {
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001128 .name = "ba",
1129 .alias = "blockalign",
Jens Axboee01b22b2009-06-09 15:43:25 +02001130 .type = FIO_OPT_INT,
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001131 .off1 = td_var_offset(ba[DDIR_READ]),
1132 .off2 = td_var_offset(ba[DDIR_WRITE]),
1133 .minval = 1,
1134 .help = "IO block offset alignment",
1135 .parent = "rw",
1136 },
1137 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001138 .name = "bsrange",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001139 .alias = "blocksize_range",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001140 .type = FIO_OPT_RANGE,
1141 .off1 = td_var_offset(min_bs[DDIR_READ]),
1142 .off2 = td_var_offset(max_bs[DDIR_READ]),
1143 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1144 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001145 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001146 .help = "Set block size range (in more detail than bs)",
Jens Axboe67a10002007-07-31 23:12:16 +02001147 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001148 },
1149 {
Jens Axboe564ca972007-12-14 12:21:19 +01001150 .name = "bssplit",
1151 .type = FIO_OPT_STR,
1152 .cb = str_bssplit_cb,
1153 .help = "Set a specific mix of block sizes",
1154 .parent = "rw",
1155 },
1156 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001157 .name = "bs_unaligned",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001158 .alias = "blocksize_unaligned",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001159 .type = FIO_OPT_STR_SET,
1160 .off1 = td_var_offset(bs_unaligned),
1161 .help = "Don't sector align IO buffer sizes",
Jens Axboe67a10002007-07-31 23:12:16 +02001162 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001163 },
1164 {
1165 .name = "randrepeat",
1166 .type = FIO_OPT_BOOL,
1167 .off1 = td_var_offset(rand_repeatable),
1168 .help = "Use repeatable random IO pattern",
1169 .def = "1",
Jens Axboe67a10002007-07-31 23:12:16 +02001170 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001171 },
1172 {
Jens Axboe2615cc42011-03-28 09:35:09 +02001173 .name = "use_os_rand",
1174 .type = FIO_OPT_BOOL,
1175 .off1 = td_var_offset(use_os_rand),
1176 .help = "Set to use OS random generator",
1177 .def = "0",
1178 .parent = "rw",
1179 },
1180 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001181 .name = "norandommap",
1182 .type = FIO_OPT_STR_SET,
1183 .off1 = td_var_offset(norandommap),
1184 .help = "Accept potential duplicate random blocks",
Jens Axboe67a10002007-07-31 23:12:16 +02001185 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001186 },
1187 {
Jens Axboe2b386d22008-03-26 10:32:57 +01001188 .name = "softrandommap",
1189 .type = FIO_OPT_BOOL,
1190 .off1 = td_var_offset(softrandommap),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001191 .help = "Set norandommap if randommap allocation fails",
Jens Axboe2b386d22008-03-26 10:32:57 +01001192 .parent = "norandommap",
1193 .def = "0",
1194 },
1195 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001196 .name = "nrfiles",
Jens Axboed7c8be02010-11-25 08:21:39 +01001197 .alias = "nr_files",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001198 .type = FIO_OPT_INT,
1199 .off1 = td_var_offset(nr_files),
1200 .help = "Split job workload between this number of files",
1201 .def = "1",
1202 },
1203 {
1204 .name = "openfiles",
1205 .type = FIO_OPT_INT,
1206 .off1 = td_var_offset(open_files),
1207 .help = "Number of files to keep open at the same time",
1208 },
1209 {
1210 .name = "file_service_type",
1211 .type = FIO_OPT_STR,
1212 .cb = str_fst_cb,
1213 .off1 = td_var_offset(file_service_type),
1214 .help = "How to select which file to service next",
1215 .def = "roundrobin",
1216 .posval = {
1217 { .ival = "random",
1218 .oval = FIO_FSERVICE_RANDOM,
1219 .help = "Choose a file at random",
1220 },
1221 { .ival = "roundrobin",
1222 .oval = FIO_FSERVICE_RR,
1223 .help = "Round robin select files",
1224 },
Jens Axboea086c252009-03-04 08:27:37 +01001225 { .ival = "sequential",
1226 .oval = FIO_FSERVICE_SEQ,
1227 .help = "Finish one file before moving to the next",
1228 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001229 },
Jens Axboe67a10002007-07-31 23:12:16 +02001230 .parent = "nrfiles",
1231 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001232#ifdef FIO_HAVE_FALLOCATE
1233 {
1234 .name = "fallocate",
Eric Gourioua596f042011-06-17 09:11:45 +02001235 .type = FIO_OPT_STR,
1236 .off1 = td_var_offset(fallocate_mode),
1237 .help = "Whether pre-allocation is performed when laying out files",
1238 .def = "posix",
1239 .posval = {
1240 { .ival = "none",
1241 .oval = FIO_FALLOCATE_NONE,
1242 .help = "Do not pre-allocate space",
1243 },
1244 { .ival = "posix",
1245 .oval = FIO_FALLOCATE_POSIX,
1246 .help = "Use posix_fallocate()",
1247 },
1248#ifdef FIO_HAVE_LINUX_FALLOCATE
1249 { .ival = "keep",
1250 .oval = FIO_FALLOCATE_KEEP_SIZE,
1251 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1252 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001253#endif
Eric Gourioua596f042011-06-17 09:11:45 +02001254 /* Compatibility with former boolean values */
1255 { .ival = "0",
1256 .oval = FIO_FALLOCATE_NONE,
1257 .help = "Alias for 'none'",
1258 },
1259 { .ival = "1",
1260 .oval = FIO_FALLOCATE_POSIX,
1261 .help = "Alias for 'posix'",
1262 },
1263 },
1264 },
1265#endif /* FIO_HAVE_FALLOCATE */
Jens Axboe67a10002007-07-31 23:12:16 +02001266 {
1267 .name = "fadvise_hint",
1268 .type = FIO_OPT_BOOL,
1269 .off1 = td_var_offset(fadvise_hint),
1270 .help = "Use fadvise() to advise the kernel on IO pattern",
1271 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001272 },
1273 {
1274 .name = "fsync",
1275 .type = FIO_OPT_INT,
1276 .off1 = td_var_offset(fsync_blocks),
1277 .help = "Issue fsync for writes every given number of blocks",
1278 .def = "0",
1279 },
1280 {
Jens Axboe5f9099e2009-06-16 22:40:26 +02001281 .name = "fdatasync",
1282 .type = FIO_OPT_INT,
1283 .off1 = td_var_offset(fdatasync_blocks),
1284 .help = "Issue fdatasync for writes every given number of blocks",
1285 .def = "0",
1286 },
Jens Axboe1ef2b6b2010-10-08 15:07:01 +02001287 {
1288 .name = "write_barrier",
1289 .type = FIO_OPT_INT,
1290 .off1 = td_var_offset(barrier_blocks),
1291 .help = "Make every Nth write a barrier write",
1292 .def = "0",
1293 },
Jens Axboe44f29692010-03-09 20:09:44 +01001294#ifdef FIO_HAVE_SYNC_FILE_RANGE
1295 {
1296 .name = "sync_file_range",
1297 .posval = {
1298 { .ival = "wait_before",
1299 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1300 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001301 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001302 },
1303 { .ival = "write",
1304 .oval = SYNC_FILE_RANGE_WRITE,
1305 .help = "SYNC_FILE_RANGE_WRITE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001306 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001307 },
1308 {
1309 .ival = "wait_after",
1310 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1311 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
Jens Axboe3843deb2010-03-09 20:41:15 +01001312 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001313 },
1314 },
Jens Axboe3843deb2010-03-09 20:41:15 +01001315 .type = FIO_OPT_STR_MULTI,
Jens Axboe44f29692010-03-09 20:09:44 +01001316 .cb = str_sfr_cb,
1317 .off1 = td_var_offset(sync_file_range),
1318 .help = "Use sync_file_range()",
1319 },
1320#endif
Jens Axboe5f9099e2009-06-16 22:40:26 +02001321 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001322 .name = "direct",
1323 .type = FIO_OPT_BOOL,
1324 .off1 = td_var_offset(odirect),
1325 .help = "Use O_DIRECT IO (negates buffered)",
1326 .def = "0",
1327 },
1328 {
1329 .name = "buffered",
1330 .type = FIO_OPT_BOOL,
1331 .off1 = td_var_offset(odirect),
1332 .neg = 1,
1333 .help = "Use buffered IO (negates direct)",
1334 .def = "1",
1335 },
1336 {
1337 .name = "overwrite",
1338 .type = FIO_OPT_BOOL,
1339 .off1 = td_var_offset(overwrite),
1340 .help = "When writing, set whether to overwrite current data",
1341 .def = "0",
1342 },
1343 {
1344 .name = "loops",
1345 .type = FIO_OPT_INT,
1346 .off1 = td_var_offset(loops),
1347 .help = "Number of times to run the job",
1348 .def = "1",
1349 },
1350 {
1351 .name = "numjobs",
1352 .type = FIO_OPT_INT,
1353 .off1 = td_var_offset(numjobs),
1354 .help = "Duplicate this job this many times",
1355 .def = "1",
1356 },
1357 {
1358 .name = "startdelay",
Jens Axboea5737c92010-06-29 10:40:30 +02001359 .type = FIO_OPT_STR_VAL_TIME,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001360 .off1 = td_var_offset(start_delay),
1361 .help = "Only start job when this period has passed",
1362 .def = "0",
1363 },
1364 {
1365 .name = "runtime",
1366 .alias = "timeout",
1367 .type = FIO_OPT_STR_VAL_TIME,
1368 .off1 = td_var_offset(timeout),
1369 .help = "Stop workload when this amount of time has passed",
1370 .def = "0",
1371 },
1372 {
Jens Axboecf4464c2007-04-17 20:14:42 +02001373 .name = "time_based",
1374 .type = FIO_OPT_STR_SET,
1375 .off1 = td_var_offset(time_based),
1376 .help = "Keep running until runtime/timeout is met",
1377 },
1378 {
Jens Axboe721938a2008-09-10 09:46:16 +02001379 .name = "ramp_time",
1380 .type = FIO_OPT_STR_VAL_TIME,
1381 .off1 = td_var_offset(ramp_time),
1382 .help = "Ramp up time before measuring performance",
1383 },
1384 {
Jens Axboec223da82010-03-24 13:23:53 +01001385 .name = "clocksource",
1386 .type = FIO_OPT_STR,
1387 .cb = fio_clock_source_cb,
1388 .off1 = td_var_offset(clocksource),
1389 .help = "What type of timing source to use",
Jens Axboec223da82010-03-24 13:23:53 +01001390 .posval = {
1391 { .ival = "gettimeofday",
1392 .oval = CS_GTOD,
1393 .help = "Use gettimeofday(2) for timing",
1394 },
1395 { .ival = "clock_gettime",
1396 .oval = CS_CGETTIME,
1397 .help = "Use clock_gettime(2) for timing",
1398 },
1399#ifdef ARCH_HAVE_CPU_CLOCK
1400 { .ival = "cpu",
1401 .oval = CS_CPUCLOCK,
1402 .help = "Use CPU private clock",
1403 },
1404#endif
1405 },
1406 },
1407 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001408 .name = "mem",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001409 .alias = "iomem",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001410 .type = FIO_OPT_STR,
1411 .cb = str_mem_cb,
1412 .off1 = td_var_offset(mem_type),
1413 .help = "Backing type for IO buffers",
1414 .def = "malloc",
1415 .posval = {
1416 { .ival = "malloc",
1417 .oval = MEM_MALLOC,
1418 .help = "Use malloc(3) for IO buffers",
1419 },
Jens Axboeb370e462007-03-19 10:51:49 +01001420 { .ival = "shm",
1421 .oval = MEM_SHM,
1422 .help = "Use shared memory segments for IO buffers",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001423 },
1424#ifdef FIO_HAVE_HUGETLB
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001425 { .ival = "shmhuge",
1426 .oval = MEM_SHMHUGE,
1427 .help = "Like shm, but use huge pages",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001428 },
1429#endif
Jens Axboeb370e462007-03-19 10:51:49 +01001430 { .ival = "mmap",
1431 .oval = MEM_MMAP,
1432 .help = "Use mmap(2) (file or anon) for IO buffers",
1433 },
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001434#ifdef FIO_HAVE_HUGETLB
1435 { .ival = "mmaphuge",
1436 .oval = MEM_MMAPHUGE,
1437 .help = "Like mmap, but use huge pages",
1438 },
1439#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001440 },
1441 },
1442 {
Jens Axboed529ee12009-07-01 10:33:03 +02001443 .name = "iomem_align",
1444 .alias = "mem_align",
1445 .type = FIO_OPT_INT,
1446 .off1 = td_var_offset(mem_align),
1447 .minval = 0,
1448 .help = "IO memory buffer offset alignment",
1449 .def = "0",
1450 .parent = "iomem",
1451 },
1452 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001453 .name = "verify",
1454 .type = FIO_OPT_STR,
1455 .off1 = td_var_offset(verify),
1456 .help = "Verify data written",
Jens Axboe5d7c5d32010-06-21 15:08:17 +02001457 .cb = str_verify_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001458 .def = "0",
1459 .posval = {
1460 { .ival = "0",
1461 .oval = VERIFY_NONE,
1462 .help = "Don't do IO verification",
1463 },
Jens Axboefcca4b52007-07-27 15:42:00 +02001464 { .ival = "md5",
1465 .oval = VERIFY_MD5,
1466 .help = "Use md5 checksums for verification",
1467 },
Jens Axboed77a7af2007-07-27 15:35:06 +02001468 { .ival = "crc64",
1469 .oval = VERIFY_CRC64,
1470 .help = "Use crc64 checksums for verification",
1471 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001472 { .ival = "crc32",
1473 .oval = VERIFY_CRC32,
1474 .help = "Use crc32 checksums for verification",
1475 },
Jens Axboeaf497e62008-08-04 15:40:35 +02001476 { .ival = "crc32c-intel",
1477 .oval = VERIFY_CRC32C_INTEL,
1478 .help = "Use hw crc32c checksums for verification",
1479 },
Jens Axboebac39e02008-06-11 20:46:19 +02001480 { .ival = "crc32c",
1481 .oval = VERIFY_CRC32C,
1482 .help = "Use crc32c checksums for verification",
1483 },
Jens Axboe969f7ed2007-07-27 09:07:17 +02001484 { .ival = "crc16",
1485 .oval = VERIFY_CRC16,
1486 .help = "Use crc16 checksums for verification",
1487 },
Jens Axboe1e154bd2007-07-27 09:52:40 +02001488 { .ival = "crc7",
1489 .oval = VERIFY_CRC7,
1490 .help = "Use crc7 checksums for verification",
1491 },
Jens Axboe7c353ce2009-08-09 22:40:33 +02001492 { .ival = "sha1",
1493 .oval = VERIFY_SHA1,
1494 .help = "Use sha1 checksums for verification",
1495 },
Jens Axboecd14cc12007-07-30 10:59:33 +02001496 { .ival = "sha256",
1497 .oval = VERIFY_SHA256,
1498 .help = "Use sha256 checksums for verification",
1499 },
1500 { .ival = "sha512",
1501 .oval = VERIFY_SHA512,
1502 .help = "Use sha512 checksums for verification",
1503 },
Shawn Lewis7437ee82007-08-02 21:05:58 +02001504 { .ival = "meta",
1505 .oval = VERIFY_META,
1506 .help = "Use io information",
1507 },
Jens Axboe36690c92007-03-26 10:23:34 +02001508 {
1509 .ival = "null",
1510 .oval = VERIFY_NULL,
1511 .help = "Pretend to verify",
1512 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001513 },
1514 },
1515 {
Jens Axboe005c5652007-08-02 22:21:36 +02001516 .name = "do_verify",
Jens Axboe68e1f292007-08-10 10:32:14 +02001517 .type = FIO_OPT_BOOL,
Jens Axboe005c5652007-08-02 22:21:36 +02001518 .off1 = td_var_offset(do_verify),
1519 .help = "Run verification stage after write",
1520 .def = "1",
1521 .parent = "verify",
1522 },
1523 {
Jens Axboe160b9662007-03-27 10:59:49 +02001524 .name = "verifysort",
1525 .type = FIO_OPT_BOOL,
1526 .off1 = td_var_offset(verifysort),
1527 .help = "Sort written verify blocks for read back",
1528 .def = "1",
Jens Axboec83f2df2007-07-31 22:51:47 +02001529 .parent = "verify",
Jens Axboe160b9662007-03-27 10:59:49 +02001530 },
1531 {
Jens Axboea59e1702007-07-30 08:53:27 +02001532 .name = "verify_interval",
Jens Axboee01b22b2009-06-09 15:43:25 +02001533 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001534 .off1 = td_var_offset(verify_interval),
Jens Axboe819a9682007-07-28 21:30:31 +02001535 .minval = 2 * sizeof(struct verify_header),
Jens Axboea59e1702007-07-30 08:53:27 +02001536 .help = "Store verify buffer header every N bytes",
Jens Axboeafdf9352007-07-31 16:14:34 +02001537 .parent = "verify",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +02001538 },
1539 {
Jens Axboea59e1702007-07-30 08:53:27 +02001540 .name = "verify_offset",
Jens Axboee01b22b2009-06-09 15:43:25 +02001541 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001542 .help = "Offset verify header location by N bytes",
Shawn Lewis546a9142007-07-28 21:11:37 +02001543 .def = "0",
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001544 .cb = str_verify_offset_cb,
Jens Axboeafdf9352007-07-31 16:14:34 +02001545 .parent = "verify",
Shawn Lewis546a9142007-07-28 21:11:37 +02001546 },
1547 {
Shawn Lewise28218f2008-01-16 11:01:33 +01001548 .name = "verify_pattern",
Radha Ramachandran0e92f872009-10-27 20:14:27 +01001549 .type = FIO_OPT_STR,
Shawn Lewise28218f2008-01-16 11:01:33 +01001550 .cb = str_verify_pattern_cb,
1551 .help = "Fill pattern for IO buffers",
1552 .parent = "verify",
1553 },
1554 {
Jens Axboea12a3b42007-08-09 10:20:54 +02001555 .name = "verify_fatal",
Jens Axboe68e1f292007-08-10 10:32:14 +02001556 .type = FIO_OPT_BOOL,
Jens Axboea12a3b42007-08-09 10:20:54 +02001557 .off1 = td_var_offset(verify_fatal),
1558 .def = "0",
1559 .help = "Exit on a single verify failure, don't continue",
1560 .parent = "verify",
1561 },
1562 {
Jens Axboeb463e932011-01-12 09:03:23 +01001563 .name = "verify_dump",
1564 .type = FIO_OPT_BOOL,
1565 .off1 = td_var_offset(verify_dump),
Jens Axboeef71e312011-10-25 22:43:36 +02001566 .def = "0",
Jens Axboeb463e932011-01-12 09:03:23 +01001567 .help = "Dump contents of good and bad blocks on failure",
1568 .parent = "verify",
1569 },
1570 {
Jens Axboee8462bd2009-07-06 12:59:04 +02001571 .name = "verify_async",
1572 .type = FIO_OPT_INT,
1573 .off1 = td_var_offset(verify_async),
1574 .def = "0",
1575 .help = "Number of async verifier threads to use",
1576 .parent = "verify",
1577 },
Jens Axboe9e144182010-06-15 14:25:36 +02001578 {
1579 .name = "verify_backlog",
1580 .type = FIO_OPT_STR_VAL,
1581 .off1 = td_var_offset(verify_backlog),
1582 .help = "Verify after this number of blocks are written",
1583 .parent = "verify",
1584 },
1585 {
1586 .name = "verify_backlog_batch",
1587 .type = FIO_OPT_INT,
1588 .off1 = td_var_offset(verify_batch),
1589 .help = "Verify this number of IO blocks",
Jens Axboe0d29de82010-09-01 13:54:15 +02001590 .parent = "verify",
Jens Axboe9e144182010-06-15 14:25:36 +02001591 },
Jens Axboee8462bd2009-07-06 12:59:04 +02001592#ifdef FIO_HAVE_CPU_AFFINITY
1593 {
1594 .name = "verify_async_cpus",
1595 .type = FIO_OPT_STR,
1596 .cb = str_verify_cpus_allowed_cb,
1597 .help = "Set CPUs allowed for async verify threads",
1598 .parent = "verify_async",
1599 },
1600#endif
Jens Axboe0d29de82010-09-01 13:54:15 +02001601#ifdef FIO_HAVE_TRIM
1602 {
1603 .name = "trim_percentage",
1604 .type = FIO_OPT_INT,
1605 .cb = str_verify_trim_cb,
1606 .maxval = 100,
1607 .help = "Number of verify blocks to discard/trim",
1608 .parent = "verify",
1609 .def = "0",
1610 },
1611 {
1612 .name = "trim_verify_zero",
1613 .type = FIO_OPT_INT,
1614 .help = "Verify that trim/discarded blocks are returned as zeroes",
1615 .off1 = td_var_offset(trim_zero),
1616 .parent = "trim_percentage",
1617 .def = "1",
1618 },
1619 {
1620 .name = "trim_backlog",
1621 .type = FIO_OPT_STR_VAL,
1622 .off1 = td_var_offset(trim_backlog),
1623 .help = "Trim after this number of blocks are written",
1624 .parent = "trim_percentage",
1625 },
1626 {
1627 .name = "trim_backlog_batch",
1628 .type = FIO_OPT_INT,
1629 .off1 = td_var_offset(trim_batch),
1630 .help = "Trim this number of IO blocks",
1631 .parent = "trim_percentage",
1632 },
1633#endif
Jens Axboee8462bd2009-07-06 12:59:04 +02001634 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001635 .name = "write_iolog",
1636 .type = FIO_OPT_STR_STORE,
1637 .off1 = td_var_offset(write_iolog_file),
1638 .help = "Store IO pattern to file",
1639 },
1640 {
1641 .name = "read_iolog",
1642 .type = FIO_OPT_STR_STORE,
1643 .off1 = td_var_offset(read_iolog_file),
1644 .help = "Playback IO pattern from file",
1645 },
1646 {
David Nellans64bbb862010-08-24 22:13:30 +02001647 .name = "replay_no_stall",
1648 .type = FIO_OPT_INT,
1649 .off1 = td_var_offset(no_stall),
1650 .def = "0",
Jens Axboe87e7a972010-08-25 09:01:25 +02001651 .parent = "read_iolog",
David Nellans64bbb862010-08-24 22:13:30 +02001652 .help = "Playback IO pattern file as fast as possible without stalls",
1653 },
1654 {
David Nellansd1c46c02010-08-31 21:20:47 +02001655 .name = "replay_redirect",
1656 .type = FIO_OPT_STR_STORE,
1657 .off1 = td_var_offset(replay_redirect),
1658 .parent = "read_iolog",
1659 .help = "Replay all I/O onto this device, regardless of trace device",
1660 },
1661 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001662 .name = "exec_prerun",
1663 .type = FIO_OPT_STR_STORE,
1664 .off1 = td_var_offset(exec_prerun),
1665 .help = "Execute this file prior to running job",
1666 },
1667 {
1668 .name = "exec_postrun",
1669 .type = FIO_OPT_STR_STORE,
1670 .off1 = td_var_offset(exec_postrun),
1671 .help = "Execute this file after running job",
1672 },
1673#ifdef FIO_HAVE_IOSCHED_SWITCH
1674 {
1675 .name = "ioscheduler",
1676 .type = FIO_OPT_STR_STORE,
1677 .off1 = td_var_offset(ioscheduler),
1678 .help = "Use this IO scheduler on the backing device",
1679 },
1680#endif
1681 {
1682 .name = "zonesize",
1683 .type = FIO_OPT_STR_VAL,
1684 .off1 = td_var_offset(zone_size),
Steven Noonaned335852012-01-31 13:58:00 +01001685 .help = "Amount of data to read per zone",
1686 .def = "0",
1687 },
1688 {
1689 .name = "zonerange",
1690 .type = FIO_OPT_STR_VAL,
1691 .off1 = td_var_offset(zone_range),
Jens Axboe214e1ec2007-03-15 10:48:13 +01001692 .help = "Give size of an IO zone",
1693 .def = "0",
1694 },
1695 {
1696 .name = "zoneskip",
1697 .type = FIO_OPT_STR_VAL,
1698 .off1 = td_var_offset(zone_skip),
1699 .help = "Space between IO zones",
1700 .def = "0",
1701 },
1702 {
1703 .name = "lockmem",
1704 .type = FIO_OPT_STR_VAL,
1705 .cb = str_lockmem_cb,
1706 .help = "Lock down this amount of memory",
1707 .def = "0",
1708 },
1709 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001710 .name = "rwmixread",
1711 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001712 .cb = str_rwmix_read_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001713 .maxval = 100,
1714 .help = "Percentage of mixed workload that is reads",
1715 .def = "50",
1716 },
1717 {
1718 .name = "rwmixwrite",
1719 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001720 .cb = str_rwmix_write_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001721 .maxval = 100,
1722 .help = "Percentage of mixed workload that is writes",
1723 .def = "50",
1724 },
1725 {
Jens Axboeafdf9352007-07-31 16:14:34 +02001726 .name = "rwmixcycle",
Jens Axboe15ca1502008-04-07 09:26:02 +02001727 .type = FIO_OPT_DEPRECATED,
Jens Axboeafdf9352007-07-31 16:14:34 +02001728 },
1729 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001730 .name = "nice",
1731 .type = FIO_OPT_INT,
1732 .off1 = td_var_offset(nice),
1733 .help = "Set job CPU nice value",
1734 .minval = -19,
1735 .maxval = 20,
1736 .def = "0",
1737 },
1738#ifdef FIO_HAVE_IOPRIO
1739 {
1740 .name = "prio",
1741 .type = FIO_OPT_INT,
1742 .cb = str_prio_cb,
1743 .help = "Set job IO priority value",
1744 .minval = 0,
1745 .maxval = 7,
1746 },
1747 {
1748 .name = "prioclass",
1749 .type = FIO_OPT_INT,
1750 .cb = str_prioclass_cb,
1751 .help = "Set job IO priority class",
1752 .minval = 0,
1753 .maxval = 3,
1754 },
1755#endif
1756 {
1757 .name = "thinktime",
1758 .type = FIO_OPT_INT,
1759 .off1 = td_var_offset(thinktime),
1760 .help = "Idle time between IO buffers (usec)",
1761 .def = "0",
1762 },
1763 {
1764 .name = "thinktime_spin",
1765 .type = FIO_OPT_INT,
1766 .off1 = td_var_offset(thinktime_spin),
1767 .help = "Start think time by spinning this amount (usec)",
1768 .def = "0",
Jens Axboeafdf9352007-07-31 16:14:34 +02001769 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001770 },
1771 {
1772 .name = "thinktime_blocks",
1773 .type = FIO_OPT_INT,
1774 .off1 = td_var_offset(thinktime_blocks),
1775 .help = "IO buffer period between 'thinktime'",
1776 .def = "1",
Jens Axboeafdf9352007-07-31 16:14:34 +02001777 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001778 },
1779 {
1780 .name = "rate",
Jens Axboee01b22b2009-06-09 15:43:25 +02001781 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001782 .off1 = td_var_offset(rate[0]),
1783 .off2 = td_var_offset(rate[1]),
Jens Axboe214e1ec2007-03-15 10:48:13 +01001784 .help = "Set bandwidth rate",
1785 },
1786 {
1787 .name = "ratemin",
Jens Axboee01b22b2009-06-09 15:43:25 +02001788 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001789 .off1 = td_var_offset(ratemin[0]),
1790 .off2 = td_var_offset(ratemin[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001791 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001792 .parent = "rate",
Jens Axboe4e991c22007-03-15 11:41:11 +01001793 },
1794 {
1795 .name = "rate_iops",
Jens Axboee01b22b2009-06-09 15:43:25 +02001796 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001797 .off1 = td_var_offset(rate_iops[0]),
1798 .off2 = td_var_offset(rate_iops[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001799 .help = "Limit IO used to this number of IO operations/sec",
1800 },
1801 {
1802 .name = "rate_iops_min",
Jens Axboee01b22b2009-06-09 15:43:25 +02001803 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001804 .off1 = td_var_offset(rate_iops_min[0]),
1805 .off2 = td_var_offset(rate_iops_min[1]),
Bruce Cran03e20d62011-01-02 20:14:54 +01001806 .help = "Job must meet this rate or it will be shut down",
Jens Axboeafdf9352007-07-31 16:14:34 +02001807 .parent = "rate_iops",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001808 },
1809 {
1810 .name = "ratecycle",
1811 .type = FIO_OPT_INT,
1812 .off1 = td_var_offset(ratecycle),
1813 .help = "Window average for rate limits (msec)",
1814 .def = "1000",
Jens Axboeafdf9352007-07-31 16:14:34 +02001815 .parent = "rate",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001816 },
1817 {
1818 .name = "invalidate",
1819 .type = FIO_OPT_BOOL,
1820 .off1 = td_var_offset(invalidate_cache),
1821 .help = "Invalidate buffer/page cache prior to running job",
1822 .def = "1",
1823 },
1824 {
1825 .name = "sync",
1826 .type = FIO_OPT_BOOL,
1827 .off1 = td_var_offset(sync_io),
1828 .help = "Use O_SYNC for buffered writes",
1829 .def = "0",
Jens Axboe67a10002007-07-31 23:12:16 +02001830 .parent = "buffered",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001831 },
1832 {
1833 .name = "bwavgtime",
1834 .type = FIO_OPT_INT,
1835 .off1 = td_var_offset(bw_avg_time),
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001836 .help = "Time window over which to calculate bandwidth"
1837 " (msec)",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001838 .def = "500",
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001839 .parent = "write_bw_log",
1840 },
1841 {
1842 .name = "iopsavgtime",
1843 .type = FIO_OPT_INT,
1844 .off1 = td_var_offset(iops_avg_time),
1845 .help = "Time window over which to calculate IOPS (msec)",
1846 .def = "500",
1847 .parent = "write_iops_log",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001848 },
1849 {
1850 .name = "create_serialize",
1851 .type = FIO_OPT_BOOL,
1852 .off1 = td_var_offset(create_serialize),
1853 .help = "Serialize creating of job files",
1854 .def = "1",
1855 },
1856 {
1857 .name = "create_fsync",
1858 .type = FIO_OPT_BOOL,
1859 .off1 = td_var_offset(create_fsync),
Bruce Cran03e20d62011-01-02 20:14:54 +01001860 .help = "fsync file after creation",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001861 .def = "1",
1862 },
1863 {
Jens Axboe814452b2009-03-04 12:53:13 +01001864 .name = "create_on_open",
1865 .type = FIO_OPT_BOOL,
1866 .off1 = td_var_offset(create_on_open),
1867 .help = "Create files when they are opened for IO",
1868 .def = "0",
1869 },
Jens Axboe0b9d69e2009-09-11 22:29:54 +02001870 {
Zhang, Yanminafad68f2009-05-20 11:30:55 +02001871 .name = "pre_read",
1872 .type = FIO_OPT_BOOL,
1873 .off1 = td_var_offset(pre_read),
Bruce Cran03e20d62011-01-02 20:14:54 +01001874 .help = "Pre-read files before starting official testing",
Zhang, Yanminafad68f2009-05-20 11:30:55 +02001875 .def = "0",
1876 },
Jens Axboe814452b2009-03-04 12:53:13 +01001877 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001878 .name = "cpuload",
1879 .type = FIO_OPT_INT,
1880 .off1 = td_var_offset(cpuload),
1881 .help = "Use this percentage of CPU",
1882 },
1883 {
1884 .name = "cpuchunks",
1885 .type = FIO_OPT_INT,
1886 .off1 = td_var_offset(cpucycle),
1887 .help = "Length of the CPU burn cycles (usecs)",
1888 .def = "50000",
Jens Axboe67a10002007-07-31 23:12:16 +02001889 .parent = "cpuload",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001890 },
1891#ifdef FIO_HAVE_CPU_AFFINITY
1892 {
1893 .name = "cpumask",
1894 .type = FIO_OPT_INT,
1895 .cb = str_cpumask_cb,
1896 .help = "CPU affinity mask",
1897 },
Jens Axboed2e268b2007-06-15 10:33:49 +02001898 {
1899 .name = "cpus_allowed",
1900 .type = FIO_OPT_STR,
1901 .cb = str_cpus_allowed_cb,
1902 .help = "Set CPUs allowed",
1903 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001904#endif
1905 {
1906 .name = "end_fsync",
1907 .type = FIO_OPT_BOOL,
1908 .off1 = td_var_offset(end_fsync),
1909 .help = "Include fsync at the end of job",
1910 .def = "0",
1911 },
1912 {
1913 .name = "fsync_on_close",
1914 .type = FIO_OPT_BOOL,
1915 .off1 = td_var_offset(fsync_on_close),
1916 .help = "fsync files on close",
1917 .def = "0",
1918 },
1919 {
1920 .name = "unlink",
1921 .type = FIO_OPT_BOOL,
1922 .off1 = td_var_offset(unlink),
1923 .help = "Unlink created files after job has completed",
1924 .def = "0",
1925 },
1926 {
1927 .name = "exitall",
1928 .type = FIO_OPT_STR_SET,
1929 .cb = str_exitall_cb,
1930 .help = "Terminate all jobs when one exits",
1931 },
1932 {
1933 .name = "stonewall",
Jens Axboed3923652011-08-03 12:38:39 +02001934 .alias = "wait_for_previous",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001935 .type = FIO_OPT_STR_SET,
1936 .off1 = td_var_offset(stonewall),
1937 .help = "Insert a hard barrier between this job and previous",
1938 },
1939 {
Jens Axboeb3d62a72007-03-20 14:23:26 +01001940 .name = "new_group",
1941 .type = FIO_OPT_STR_SET,
1942 .off1 = td_var_offset(new_group),
1943 .help = "Mark the start of a new group (for reporting)",
1944 },
1945 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001946 .name = "thread",
1947 .type = FIO_OPT_STR_SET,
1948 .off1 = td_var_offset(use_thread),
1949 .help = "Use threads instead of forks",
1950 },
1951 {
1952 .name = "write_bw_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001953 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001954 .off1 = td_var_offset(write_bw_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001955 .cb = str_write_bw_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001956 .help = "Write log of bandwidth during run",
1957 },
1958 {
1959 .name = "write_lat_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001960 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001961 .off1 = td_var_offset(write_lat_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001962 .cb = str_write_lat_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001963 .help = "Write log of latency during run",
1964 },
1965 {
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001966 .name = "write_iops_log",
1967 .type = FIO_OPT_STR,
1968 .off1 = td_var_offset(write_iops_log),
1969 .cb = str_write_iops_log_cb,
1970 .help = "Write log of IOPS during run",
1971 },
1972 {
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001973 .name = "log_avg_msec",
1974 .type = FIO_OPT_INT,
1975 .off1 = td_var_offset(log_avg_msec),
1976 .help = "Average bw/iops/lat logs over this period of time",
1977 .def = "0",
1978 },
1979 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001980 .name = "hugepage-size",
Jens Axboee01b22b2009-06-09 15:43:25 +02001981 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001982 .off1 = td_var_offset(hugepage_size),
1983 .help = "When using hugepages, specify size of each page",
Jens Axboe81179ee2011-10-04 12:42:06 +02001984 .def = __fio_stringify(FIO_HUGE_PAGE),
Jens Axboe214e1ec2007-03-15 10:48:13 +01001985 },
1986 {
1987 .name = "group_reporting",
1988 .type = FIO_OPT_STR_SET,
1989 .off1 = td_var_offset(group_reporting),
1990 .help = "Do reporting on a per-group basis",
1991 },
1992 {
Jens Axboee9459e52007-04-17 15:46:32 +02001993 .name = "zero_buffers",
1994 .type = FIO_OPT_STR_SET,
1995 .off1 = td_var_offset(zero_buffers),
1996 .help = "Init IO buffers to all zeroes",
1997 },
Jens Axboe5973caf2008-05-21 19:52:35 +02001998 {
1999 .name = "refill_buffers",
2000 .type = FIO_OPT_STR_SET,
2001 .off1 = td_var_offset(refill_buffers),
2002 .help = "Refill IO buffers on every IO submit",
2003 },
Yu-ju Hong83349192011-08-13 00:53:44 +02002004 {
Jens Axboefd684182011-09-19 09:24:44 +02002005 .name = "scramble_buffers",
2006 .type = FIO_OPT_BOOL,
2007 .off1 = td_var_offset(scramble_buffers),
2008 .help = "Slightly scramble buffers on every IO submit",
2009 .def = "1",
2010 },
2011 {
Yu-ju Hong83349192011-08-13 00:53:44 +02002012 .name = "clat_percentiles",
2013 .type = FIO_OPT_BOOL,
2014 .off1 = td_var_offset(clat_percentiles),
2015 .help = "Enable the reporting of completion latency percentiles",
Jens Axboe467b35e2011-10-13 08:53:24 +02002016 .def = "1",
Yu-ju Hong83349192011-08-13 00:53:44 +02002017 },
2018 {
2019 .name = "percentile_list",
2020 .type = FIO_OPT_FLOAT_LIST,
2021 .off1 = td_var_offset(percentile_list),
2022 .off2 = td_var_offset(overwrite_plist),
2023 .help = "Specify a custom list of percentiles to report",
2024 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2025 .minfp = 0.0,
2026 .maxfp = 100.0,
2027 },
2028
Jens Axboe0a839f32007-04-26 09:02:34 +02002029#ifdef FIO_HAVE_DISK_UTIL
2030 {
2031 .name = "disk_util",
2032 .type = FIO_OPT_BOOL,
2033 .off1 = td_var_offset(do_disk_util),
Jens Axboef66ab3c2008-06-05 11:48:22 +02002034 .help = "Log disk utilization statistics",
Jens Axboe0a839f32007-04-26 09:02:34 +02002035 .def = "1",
2036 },
2037#endif
Jens Axboee9459e52007-04-17 15:46:32 +02002038 {
Jens Axboe993bf482008-11-14 13:04:53 +01002039 .name = "gtod_reduce",
2040 .type = FIO_OPT_BOOL,
2041 .help = "Greatly reduce number of gettimeofday() calls",
2042 .cb = str_gtod_reduce_cb,
2043 .def = "0",
2044 },
2045 {
Jens Axboe02af0982010-06-24 09:59:34 +02002046 .name = "disable_lat",
2047 .type = FIO_OPT_BOOL,
2048 .off1 = td_var_offset(disable_lat),
2049 .help = "Disable latency numbers",
2050 .parent = "gtod_reduce",
2051 .def = "0",
2052 },
2053 {
Jens Axboe9520ebb2008-10-16 21:03:27 +02002054 .name = "disable_clat",
2055 .type = FIO_OPT_BOOL,
2056 .off1 = td_var_offset(disable_clat),
2057 .help = "Disable completion latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01002058 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002059 .def = "0",
2060 },
2061 {
2062 .name = "disable_slat",
2063 .type = FIO_OPT_BOOL,
2064 .off1 = td_var_offset(disable_slat),
Bruce Cran03e20d62011-01-02 20:14:54 +01002065 .help = "Disable submission latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01002066 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002067 .def = "0",
2068 },
2069 {
2070 .name = "disable_bw_measurement",
2071 .type = FIO_OPT_BOOL,
2072 .off1 = td_var_offset(disable_bw),
2073 .help = "Disable bandwidth logging",
Jens Axboe993bf482008-11-14 13:04:53 +01002074 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02002075 .def = "0",
2076 },
2077 {
Jens Axboebe4ecfd2008-12-08 14:10:52 +01002078 .name = "gtod_cpu",
2079 .type = FIO_OPT_INT,
2080 .cb = str_gtod_cpu_cb,
Bruce Cran03e20d62011-01-02 20:14:54 +01002081 .help = "Set up dedicated gettimeofday() thread on this CPU",
Jens Axboe29d43ff2009-07-01 10:42:18 +02002082 .verify = gtod_cpu_verify,
Jens Axboebe4ecfd2008-12-08 14:10:52 +01002083 },
2084 {
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002085 .name = "continue_on_error",
Steven Lang06842022011-11-17 09:45:17 +01002086 .type = FIO_OPT_STR,
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002087 .off1 = td_var_offset(continue_on_error),
Bruce Cran03e20d62011-01-02 20:14:54 +01002088 .help = "Continue on non-fatal errors during IO",
Steven Lang06842022011-11-17 09:45:17 +01002089 .def = "none",
2090 .posval = {
2091 { .ival = "none",
2092 .oval = ERROR_TYPE_NONE,
2093 .help = "Exit when an error is encountered",
2094 },
2095 { .ival = "read",
2096 .oval = ERROR_TYPE_READ,
2097 .help = "Continue on read errors only",
2098 },
2099 { .ival = "write",
2100 .oval = ERROR_TYPE_WRITE,
2101 .help = "Continue on write errors only",
2102 },
2103 { .ival = "io",
2104 .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2105 .help = "Continue on any IO errors",
2106 },
2107 { .ival = "verify",
2108 .oval = ERROR_TYPE_VERIFY,
2109 .help = "Continue on verify errors only",
2110 },
2111 { .ival = "all",
2112 .oval = ERROR_TYPE_ANY,
2113 .help = "Continue on all io and verify errors",
2114 },
2115 { .ival = "0",
2116 .oval = ERROR_TYPE_NONE,
2117 .help = "Alias for 'none'",
2118 },
2119 { .ival = "1",
2120 .oval = ERROR_TYPE_ANY,
2121 .help = "Alias for 'all'",
2122 },
2123 },
Radha Ramachandranf2bba182009-06-15 08:40:16 +02002124 },
2125 {
Jens Axboe9ac8a792009-11-13 21:23:07 +01002126 .name = "profile",
Jens Axboe79d16312010-03-04 12:43:20 +01002127 .type = FIO_OPT_STR_STORE,
Jens Axboe9ac8a792009-11-13 21:23:07 +01002128 .off1 = td_var_offset(profile),
Jens Axboe9ac8a792009-11-13 21:23:07 +01002129 .help = "Select a specific builtin performance test",
2130 },
2131 {
Jens Axboea696fa22009-12-04 10:05:02 +01002132 .name = "cgroup",
2133 .type = FIO_OPT_STR_STORE,
2134 .off1 = td_var_offset(cgroup),
2135 .help = "Add job to cgroup of this name",
2136 },
2137 {
2138 .name = "cgroup_weight",
2139 .type = FIO_OPT_INT,
2140 .off1 = td_var_offset(cgroup_weight),
2141 .help = "Use given weight for cgroup",
2142 .minval = 100,
2143 .maxval = 1000,
Jens Axboea696fa22009-12-04 10:05:02 +01002144 },
2145 {
Vivek Goyal7de87092010-03-31 22:55:15 +02002146 .name = "cgroup_nodelete",
2147 .type = FIO_OPT_BOOL,
2148 .off1 = td_var_offset(cgroup_nodelete),
2149 .help = "Do not delete cgroups after job completion",
2150 .def = "0",
2151 },
2152 {
Jens Axboee0b0d892009-12-08 10:10:14 +01002153 .name = "uid",
2154 .type = FIO_OPT_INT,
2155 .off1 = td_var_offset(uid),
2156 .help = "Run job with this user ID",
2157 },
2158 {
2159 .name = "gid",
2160 .type = FIO_OPT_INT,
2161 .off1 = td_var_offset(gid),
2162 .help = "Run job with this group ID",
2163 },
2164 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01002165 .name = NULL,
2166 },
2167};
2168
Jens Axboe17af15d2010-04-13 10:38:16 +02002169static void add_to_lopt(struct option *lopt, struct fio_option *o,
Steven Langde890a12011-11-09 14:03:34 +01002170 const char *name, int val)
Jens Axboe9f817362010-03-04 14:38:10 +01002171{
Jens Axboe17af15d2010-04-13 10:38:16 +02002172 lopt->name = (char *) name;
Steven Langde890a12011-11-09 14:03:34 +01002173 lopt->val = val;
Jens Axboe9f817362010-03-04 14:38:10 +01002174 if (o->type == FIO_OPT_STR_SET)
2175 lopt->has_arg = no_argument;
2176 else
2177 lopt->has_arg = required_argument;
2178}
2179
Steven Langde890a12011-11-09 14:03:34 +01002180static void options_to_lopts(struct fio_option *opts,
2181 struct option *long_options,
2182 int i, int option_type)
2183{
2184 struct fio_option *o = &opts[0];
2185 while (o->name) {
2186 add_to_lopt(&long_options[i], o, o->name, option_type);
2187 if (o->alias) {
2188 i++;
2189 add_to_lopt(&long_options[i], o, o->alias, option_type);
2190 }
2191
2192 i++;
2193 o++;
2194 assert(i < FIO_NR_OPTIONS);
2195 }
2196}
2197
2198void fio_options_set_ioengine_opts(struct option *long_options,
2199 struct thread_data *td)
2200{
2201 unsigned int i;
2202
2203 i = 0;
2204 while (long_options[i].name) {
2205 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2206 memset(&long_options[i], 0, sizeof(*long_options));
2207 break;
2208 }
2209 i++;
2210 }
2211
2212 /*
2213 * Just clear out the prior ioengine options.
2214 */
2215 if (!td || !td->eo)
2216 return;
2217
2218 options_to_lopts(td->io_ops->options, long_options, i,
2219 FIO_GETOPT_IOENGINE);
2220}
2221
Jens Axboe214e1ec2007-03-15 10:48:13 +01002222void fio_options_dup_and_init(struct option *long_options)
2223{
Jens Axboe214e1ec2007-03-15 10:48:13 +01002224 unsigned int i;
2225
2226 options_init(options);
2227
2228 i = 0;
2229 while (long_options[i].name)
2230 i++;
2231
Steven Langde890a12011-11-09 14:03:34 +01002232 options_to_lopts(options, long_options, i, FIO_GETOPT_JOB);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002233}
2234
Jens Axboe74929ac2009-08-05 11:42:37 +02002235struct fio_keyword {
2236 const char *word;
2237 const char *desc;
2238 char *replace;
2239};
2240
2241static struct fio_keyword fio_keywords[] = {
2242 {
2243 .word = "$pagesize",
2244 .desc = "Page size in the system",
2245 },
2246 {
2247 .word = "$mb_memory",
2248 .desc = "Megabytes of memory online",
2249 },
2250 {
2251 .word = "$ncpus",
2252 .desc = "Number of CPUs online in the system",
2253 },
2254 {
2255 .word = NULL,
2256 },
2257};
2258
2259void fio_keywords_init(void)
2260{
Jens Axboe3b2e1462009-12-15 08:58:10 +01002261 unsigned long long mb_memory;
Jens Axboe74929ac2009-08-05 11:42:37 +02002262 char buf[128];
2263 long l;
2264
2265 sprintf(buf, "%lu", page_size);
2266 fio_keywords[0].replace = strdup(buf);
2267
Jens Axboe8eb016d2011-07-11 10:24:20 +02002268 mb_memory = os_phys_mem() / (1024 * 1024);
Jens Axboe3b2e1462009-12-15 08:58:10 +01002269 sprintf(buf, "%llu", mb_memory);
Jens Axboe74929ac2009-08-05 11:42:37 +02002270 fio_keywords[1].replace = strdup(buf);
2271
Jens Axboec00a2282011-07-08 20:56:06 +02002272 l = cpus_online();
Jens Axboe74929ac2009-08-05 11:42:37 +02002273 sprintf(buf, "%lu", l);
2274 fio_keywords[2].replace = strdup(buf);
2275}
2276
Jens Axboe892a6ff2009-11-13 12:19:49 +01002277#define BC_APP "bc"
2278
2279static char *bc_calc(char *str)
2280{
Steven Langd0c814e2011-10-28 08:37:13 +02002281 char buf[128], *tmp;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002282 FILE *f;
2283 int ret;
2284
2285 /*
2286 * No math, just return string
2287 */
Steven Langd0c814e2011-10-28 08:37:13 +02002288 if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2289 !strchr(str, '/')) || strchr(str, '\''))
Jens Axboe892a6ff2009-11-13 12:19:49 +01002290 return str;
2291
2292 /*
2293 * Split option from value, we only need to calculate the value
2294 */
2295 tmp = strchr(str, '=');
2296 if (!tmp)
2297 return str;
2298
2299 tmp++;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002300
Steven Langd0c814e2011-10-28 08:37:13 +02002301 /*
2302 * Prevent buffer overflows; such a case isn't reasonable anyway
2303 */
2304 if (strlen(str) >= 128 || strlen(tmp) > 100)
2305 return str;
Jens Axboe892a6ff2009-11-13 12:19:49 +01002306
2307 sprintf(buf, "which %s > /dev/null", BC_APP);
2308 if (system(buf)) {
2309 log_err("fio: bc is needed for performing math\n");
Jens Axboe892a6ff2009-11-13 12:19:49 +01002310 return NULL;
2311 }
2312
Steven Langd0c814e2011-10-28 08:37:13 +02002313 sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002314 f = popen(buf, "r");
2315 if (!f) {
Jens Axboe892a6ff2009-11-13 12:19:49 +01002316 return NULL;
2317 }
2318
Steven Langd0c814e2011-10-28 08:37:13 +02002319 ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002320 if (ret <= 0) {
Jens Axboe892a6ff2009-11-13 12:19:49 +01002321 return NULL;
2322 }
2323
Jens Axboe892a6ff2009-11-13 12:19:49 +01002324 pclose(f);
Steven Langd0c814e2011-10-28 08:37:13 +02002325 buf[(tmp - str) + ret - 1] = '\0';
2326 memcpy(buf, str, tmp - str);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002327 free(str);
Steven Langd0c814e2011-10-28 08:37:13 +02002328 return strdup(buf);
2329}
2330
2331/*
2332 * Return a copy of the input string with substrings of the form ${VARNAME}
2333 * substituted with the value of the environment variable VARNAME. The
2334 * substitution always occurs, even if VARNAME is empty or the corresponding
2335 * environment variable undefined.
2336 */
2337static char *option_dup_subs(const char *opt)
2338{
2339 char out[OPT_LEN_MAX+1];
2340 char in[OPT_LEN_MAX+1];
2341 char *outptr = out;
2342 char *inptr = in;
2343 char *ch1, *ch2, *env;
2344 ssize_t nchr = OPT_LEN_MAX;
2345 size_t envlen;
2346
2347 if (strlen(opt) + 1 > OPT_LEN_MAX) {
2348 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2349 return NULL;
2350 }
2351
2352 in[OPT_LEN_MAX] = '\0';
2353 strncpy(in, opt, OPT_LEN_MAX);
2354
2355 while (*inptr && nchr > 0) {
2356 if (inptr[0] == '$' && inptr[1] == '{') {
2357 ch2 = strchr(inptr, '}');
2358 if (ch2 && inptr+1 < ch2) {
2359 ch1 = inptr+2;
2360 inptr = ch2+1;
2361 *ch2 = '\0';
2362
2363 env = getenv(ch1);
2364 if (env) {
2365 envlen = strlen(env);
2366 if (envlen <= nchr) {
2367 memcpy(outptr, env, envlen);
2368 outptr += envlen;
2369 nchr -= envlen;
2370 }
2371 }
2372
2373 continue;
2374 }
2375 }
2376
2377 *outptr++ = *inptr++;
2378 --nchr;
2379 }
2380
2381 *outptr = '\0';
2382 return strdup(out);
Jens Axboe892a6ff2009-11-13 12:19:49 +01002383}
2384
Jens Axboe74929ac2009-08-05 11:42:37 +02002385/*
2386 * Look for reserved variable names and replace them with real values
2387 */
2388static char *fio_keyword_replace(char *opt)
2389{
2390 char *s;
2391 int i;
Steven Langd0c814e2011-10-28 08:37:13 +02002392 int docalc = 0;
Jens Axboe74929ac2009-08-05 11:42:37 +02002393
2394 for (i = 0; fio_keywords[i].word != NULL; i++) {
2395 struct fio_keyword *kw = &fio_keywords[i];
2396
2397 while ((s = strstr(opt, kw->word)) != NULL) {
2398 char *new = malloc(strlen(opt) + 1);
2399 char *o_org = opt;
2400 int olen = s - opt;
2401 int len;
2402
2403 /*
2404 * Copy part of the string before the keyword and
2405 * sprintf() the replacement after it.
2406 */
2407 memcpy(new, opt, olen);
2408 len = sprintf(new + olen, "%s", kw->replace);
2409
2410 /*
2411 * If there's more in the original string, copy that
2412 * in too
2413 */
2414 opt += strlen(kw->word) + olen;
2415 if (strlen(opt))
2416 memcpy(new + olen + len, opt, opt - o_org - 1);
2417
2418 /*
2419 * replace opt and free the old opt
2420 */
2421 opt = new;
Steven Langd0c814e2011-10-28 08:37:13 +02002422 free(o_org);
Jens Axboe7a958bd2009-11-13 12:33:54 +01002423
Steven Langd0c814e2011-10-28 08:37:13 +02002424 docalc = 1;
Jens Axboe74929ac2009-08-05 11:42:37 +02002425 }
2426 }
2427
Steven Langd0c814e2011-10-28 08:37:13 +02002428 /*
2429 * Check for potential math and invoke bc, if possible
2430 */
2431 if (docalc)
2432 opt = bc_calc(opt);
2433
Jens Axboe7a958bd2009-11-13 12:33:54 +01002434 return opt;
Jens Axboe74929ac2009-08-05 11:42:37 +02002435}
2436
Steven Langd0c814e2011-10-28 08:37:13 +02002437static char **dup_and_sub_options(char **opts, int num_opts)
2438{
2439 int i;
2440 char **opts_copy = malloc(num_opts * sizeof(*opts));
2441 for (i = 0; i < num_opts; i++) {
2442 opts_copy[i] = option_dup_subs(opts[i]);
2443 if (!opts_copy[i])
2444 continue;
2445 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2446 }
2447 return opts_copy;
2448}
2449
Jens Axboe3b8b7132008-06-10 19:46:23 +02002450int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
Jens Axboe214e1ec2007-03-15 10:48:13 +01002451{
Steven Langde890a12011-11-09 14:03:34 +01002452 int i, ret, unknown;
Steven Langd0c814e2011-10-28 08:37:13 +02002453 char **opts_copy;
Jens Axboe3b8b7132008-06-10 19:46:23 +02002454
2455 sort_options(opts, options, num_opts);
Steven Langd0c814e2011-10-28 08:37:13 +02002456 opts_copy = dup_and_sub_options(opts, num_opts);
Jens Axboe3b8b7132008-06-10 19:46:23 +02002457
Steven Langde890a12011-11-09 14:03:34 +01002458 for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
2459 struct fio_option *o;
2460 int newret = parse_option(opts_copy[i], opts[i], options, &o,
2461 td);
Steven Langd0c814e2011-10-28 08:37:13 +02002462
Steven Langde890a12011-11-09 14:03:34 +01002463 if (opts_copy[i]) {
2464 if (newret && !o) {
2465 unknown++;
2466 continue;
2467 }
Steven Langd0c814e2011-10-28 08:37:13 +02002468 free(opts_copy[i]);
Steven Langde890a12011-11-09 14:03:34 +01002469 opts_copy[i] = NULL;
2470 }
2471
2472 ret |= newret;
2473 }
2474
2475 if (unknown) {
2476 ret |= ioengine_load(td);
2477 if (td->eo) {
2478 sort_options(opts_copy, td->io_ops->options, num_opts);
2479 opts = opts_copy;
2480 }
2481 for (i = 0; i < num_opts; i++) {
2482 struct fio_option *o = NULL;
2483 int newret = 1;
2484 if (!opts_copy[i])
2485 continue;
2486
2487 if (td->eo)
2488 newret = parse_option(opts_copy[i], opts[i],
2489 td->io_ops->options, &o,
2490 td->eo);
2491
2492 ret |= newret;
2493 if (!o)
2494 log_err("Bad option <%s>\n", opts[i]);
2495
2496 free(opts_copy[i]);
2497 opts_copy[i] = NULL;
2498 }
Jens Axboe74929ac2009-08-05 11:42:37 +02002499 }
Jens Axboe3b8b7132008-06-10 19:46:23 +02002500
Steven Langd0c814e2011-10-28 08:37:13 +02002501 free(opts_copy);
Jens Axboe3b8b7132008-06-10 19:46:23 +02002502 return ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +01002503}
2504
2505int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2506{
Jens Axboe07b32322010-03-05 09:48:44 +01002507 return parse_cmd_option(opt, val, options, td);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002508}
2509
Steven Langde890a12011-11-09 14:03:34 +01002510int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
2511 char *val)
2512{
2513 return parse_cmd_option(opt, val, td->io_ops->options, td);
2514}
2515
Jens Axboe214e1ec2007-03-15 10:48:13 +01002516void fio_fill_default_options(struct thread_data *td)
2517{
2518 fill_default_options(td, options);
2519}
2520
2521int fio_show_option_help(const char *opt)
2522{
Jens Axboe07b32322010-03-05 09:48:44 +01002523 return show_cmd_help(options, opt);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002524}
Jens Axboed23bb322007-03-23 15:57:56 +01002525
Steven Langde890a12011-11-09 14:03:34 +01002526void options_mem_dupe(void *data, struct fio_option *options)
2527{
2528 struct fio_option *o;
2529 char **ptr;
2530
2531 for (o = &options[0]; o->name; o++) {
2532 if (o->type != FIO_OPT_STR_STORE)
2533 continue;
2534
2535 ptr = td_var(data, o->off1);
2536 if (*ptr)
2537 *ptr = strdup(*ptr);
2538 }
2539}
2540
Jens Axboe7e356b22011-10-14 10:55:16 +02002541/*
2542 * dupe FIO_OPT_STR_STORE options
2543 */
Steven Langde890a12011-11-09 14:03:34 +01002544void fio_options_mem_dupe(struct thread_data *td)
Jens Axboed23bb322007-03-23 15:57:56 +01002545{
Steven Langde890a12011-11-09 14:03:34 +01002546 options_mem_dupe(&td->o, options);
Jens Axboe1647f592011-11-09 20:25:21 +01002547
2548 if (td->eo && td->io_ops) {
Steven Langde890a12011-11-09 14:03:34 +01002549 void *oldeo = td->eo;
Jens Axboe1647f592011-11-09 20:25:21 +01002550
Steven Langde890a12011-11-09 14:03:34 +01002551 td->eo = malloc(td->io_ops->option_struct_size);
2552 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
2553 options_mem_dupe(td->eo, td->io_ops->options);
Jens Axboed23bb322007-03-23 15:57:56 +01002554 }
2555}
2556
Jens Axboed6978a32009-07-18 21:04:09 +02002557unsigned int fio_get_kb_base(void *data)
2558{
2559 struct thread_data *td = data;
2560 unsigned int kb_base = 0;
2561
2562 if (td)
2563 kb_base = td->o.kb_base;
2564 if (!kb_base)
2565 kb_base = 1024;
2566
2567 return kb_base;
2568}
Jens Axboe9f988e22010-03-04 10:42:38 +01002569
Jens Axboe07b32322010-03-05 09:48:44 +01002570int add_option(struct fio_option *o)
Jens Axboe9f988e22010-03-04 10:42:38 +01002571{
Jens Axboe07b32322010-03-05 09:48:44 +01002572 struct fio_option *__o;
2573 int opt_index = 0;
2574
2575 __o = options;
2576 while (__o->name) {
2577 opt_index++;
2578 __o++;
2579 }
2580
2581 memcpy(&options[opt_index], o, sizeof(*o));
2582 return 0;
Jens Axboe9f988e22010-03-04 10:42:38 +01002583}
Jens Axboee2de69d2010-03-04 14:05:48 +01002584
Jens Axboe07b32322010-03-05 09:48:44 +01002585void invalidate_profile_options(const char *prof_name)
Jens Axboee2de69d2010-03-04 14:05:48 +01002586{
Jens Axboe07b32322010-03-05 09:48:44 +01002587 struct fio_option *o;
Jens Axboee2de69d2010-03-04 14:05:48 +01002588
Jens Axboe07b32322010-03-05 09:48:44 +01002589 o = options;
2590 while (o->name) {
2591 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2592 o->type = FIO_OPT_INVALID;
2593 o->prof_name = NULL;
2594 }
2595 o++;
Jens Axboee2de69d2010-03-04 14:05:48 +01002596 }
2597}
Jens Axboef5b6bb82010-03-05 10:09:59 +01002598
2599void add_opt_posval(const char *optname, const char *ival, const char *help)
2600{
2601 struct fio_option *o;
2602 unsigned int i;
2603
2604 o = find_option(options, optname);
2605 if (!o)
2606 return;
2607
2608 for (i = 0; i < PARSE_MAX_VP; i++) {
2609 if (o->posval[i].ival)
2610 continue;
2611
2612 o->posval[i].ival = ival;
2613 o->posval[i].help = help;
2614 break;
2615 }
2616}
2617
2618void del_opt_posval(const char *optname, const char *ival)
2619{
2620 struct fio_option *o;
2621 unsigned int i;
2622
2623 o = find_option(options, optname);
2624 if (!o)
2625 return;
2626
2627 for (i = 0; i < PARSE_MAX_VP; i++) {
2628 if (!o->posval[i].ival)
2629 continue;
2630 if (strcmp(o->posval[i].ival, ival))
2631 continue;
2632
2633 o->posval[i].ival = NULL;
2634 o->posval[i].help = NULL;
2635 }
2636}
Jens Axboe7e356b22011-10-14 10:55:16 +02002637
2638void fio_options_free(struct thread_data *td)
2639{
2640 options_free(options, td);
Steven Langde890a12011-11-09 14:03:34 +01002641 if (td->eo && td->io_ops && td->io_ops->options) {
2642 options_free(td->io_ops->options, td->eo);
2643 free(td->eo);
2644 td->eo = NULL;
2645 }
Jens Axboe7e356b22011-10-14 10:55:16 +02002646}