blob: e03592d8bd4ee0b7850e2067a847f4caae814f70 [file] [log] [blame]
Jens Axboecb2c86f2006-10-26 13:48:34 +02001/*
2 * This file contains the ini and command liner parser main.
3 */
4#include <stdio.h>
5#include <stdlib.h>
6#include <unistd.h>
7#include <ctype.h>
8#include <string.h>
9#include <errno.h>
10#include <limits.h>
Aaron Carroll88b5a392008-10-07 11:25:20 +020011#include <stdlib.h>
Jens Axboecb2c86f2006-10-26 13:48:34 +020012
13#include "parse.h"
Jens Axboea3d741f2008-02-27 18:32:33 +010014#include "debug.h"
Jens Axboe9f988e22010-03-04 10:42:38 +010015#include "options.h"
Jens Axboecb2c86f2006-10-26 13:48:34 +020016
Jens Axboe3b8b7132008-06-10 19:46:23 +020017static struct fio_option *fio_options;
Jens Axboed6978a32009-07-18 21:04:09 +020018extern unsigned int fio_get_kb_base(void *);
Jens Axboe3b8b7132008-06-10 19:46:23 +020019
Jens Axboef0857372007-03-19 13:15:23 +010020static int vp_cmp(const void *p1, const void *p2)
21{
22 const struct value_pair *vp1 = p1;
23 const struct value_pair *vp2 = p2;
24
25 return strlen(vp2->ival) - strlen(vp1->ival);
26}
27
28static void posval_sort(struct fio_option *o, struct value_pair *vpmap)
29{
30 const struct value_pair *vp;
31 int entries;
32
33 memset(vpmap, 0, PARSE_MAX_VP * sizeof(struct value_pair));
34
35 for (entries = 0; entries < PARSE_MAX_VP; entries++) {
36 vp = &o->posval[entries];
37 if (!vp->ival || vp->ival[0] == '\0')
38 break;
39
40 memcpy(&vpmap[entries], vp, sizeof(*vp));
41 }
42
43 qsort(vpmap, entries, sizeof(struct value_pair), vp_cmp);
44}
45
Jens Axboed447a8c2009-07-17 22:26:15 +020046static void show_option_range(struct fio_option *o, FILE *out)
Jens Axboeb1ec1da2007-02-23 10:29:16 +010047{
48 if (!o->minval && !o->maxval)
49 return;
50
Jens Axboed447a8c2009-07-17 22:26:15 +020051 fprintf(out, "%20s: min=%d", "range", o->minval);
Jens Axboe39801272009-07-01 09:06:12 +020052 if (o->maxval)
Jens Axboed447a8c2009-07-17 22:26:15 +020053 fprintf(out, ", max=%d", o->maxval);
54 fprintf(out, "\n");
Jens Axboeb1ec1da2007-02-23 10:29:16 +010055}
56
57static void show_option_values(struct fio_option *o)
58{
Jens Axboea3073f42010-03-05 10:06:15 +010059 int i;
Jens Axboeb1ec1da2007-02-23 10:29:16 +010060
Jens Axboea3073f42010-03-05 10:06:15 +010061 for (i = 0; i < PARSE_MAX_VP; i++) {
Jens Axboe78372132007-03-14 13:24:07 +010062 const struct value_pair *vp = &o->posval[i];
63
64 if (!vp->ival)
Jens Axboea3073f42010-03-05 10:06:15 +010065 continue;
Jens Axboeb1ec1da2007-02-23 10:29:16 +010066
Jens Axboe78372132007-03-14 13:24:07 +010067 printf("%20s: %-10s", i == 0 ? "valid values" : "", vp->ival);
68 if (vp->help)
69 printf(" %s", vp->help);
70 printf("\n");
Jens Axboea3073f42010-03-05 10:06:15 +010071 }
Jens Axboeb1ec1da2007-02-23 10:29:16 +010072
73 if (i)
74 printf("\n");
75}
76
Jens Axboed447a8c2009-07-17 22:26:15 +020077static void show_option_help(struct fio_option *o, FILE *out)
78{
79 const char *typehelp[] = {
Jens Axboe07b32322010-03-05 09:48:44 +010080 "invalid",
Jens Axboed447a8c2009-07-17 22:26:15 +020081 "string (opt=bla)",
82 "string with possible k/m/g postfix (opt=4k)",
83 "string with time postfix (opt=10s)",
84 "string (opt=bla)",
85 "string with dual range (opt=1k-4k,4k-8k)",
86 "integer value (opt=100)",
87 "boolean value (opt=1)",
88 "no argument (opt)",
Jens Axboe07b32322010-03-05 09:48:44 +010089 "deprecated",
Jens Axboed447a8c2009-07-17 22:26:15 +020090 };
91
92 if (o->alias)
93 fprintf(out, "%20s: %s\n", "alias", o->alias);
94
95 fprintf(out, "%20s: %s\n", "type", typehelp[o->type]);
96 fprintf(out, "%20s: %s\n", "default", o->def ? o->def : "no default");
Jens Axboe07b32322010-03-05 09:48:44 +010097 if (o->prof_name)
98 fprintf(out, "%20s: only for profile '%s'\n", "valid", o->prof_name);
Jens Axboed447a8c2009-07-17 22:26:15 +020099 show_option_range(o, stdout);
100 show_option_values(o);
101}
102
Jens Axboecb2c86f2006-10-26 13:48:34 +0200103static unsigned long get_mult_time(char c)
104{
105 switch (c) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100106 case 'm':
107 case 'M':
108 return 60;
109 case 'h':
110 case 'H':
111 return 60 * 60;
112 case 'd':
113 case 'D':
114 return 24 * 60 * 60;
115 default:
116 return 1;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200117 }
118}
119
Jens Axboe57fc29f2010-06-23 22:24:07 +0200120static unsigned long long __get_mult_bytes(const char *p, void *data)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200121{
Jens Axboed6978a32009-07-18 21:04:09 +0200122 unsigned int kb_base = fio_get_kb_base(data);
Jens Axboea639f0b2009-07-18 08:25:35 +0200123 unsigned long long ret = 1;
Jens Axboe57fc29f2010-06-23 22:24:07 +0200124 unsigned int i, pow = 0, mult = kb_base;
125 char *c;
Jens Axboea639f0b2009-07-18 08:25:35 +0200126
Jens Axboe57fc29f2010-06-23 22:24:07 +0200127 if (!p)
128 return 1;
Jens Axboea639f0b2009-07-18 08:25:35 +0200129
Jens Axboe57fc29f2010-06-23 22:24:07 +0200130 c = strdup(p);
131
132 for (i = 0; i < strlen(c); i++)
133 c[i] = tolower(c[i]);
134
135 if (!strcmp("pib", c)) {
136 pow = 5;
137 mult = 1000;
138 } else if (!strcmp("tib", c)) {
139 pow = 4;
140 mult = 1000;
141 } else if (!strcmp("gib", c)) {
142 pow = 3;
143 mult = 1000;
144 } else if (!strcmp("mib", c)) {
145 pow = 2;
146 mult = 1000;
147 } else if (!strcmp("kib", c)) {
148 pow = 1;
149 mult = 1000;
150 } else if (!strcmp("p", c) || !strcmp("pb", c))
151 pow = 5;
152 else if (!strcmp("t", c) || !strcmp("tb", c))
153 pow = 4;
154 else if (!strcmp("g", c) || !strcmp("gb", c))
155 pow = 3;
156 else if (!strcmp("m", c) || !strcmp("mb", c))
157 pow = 2;
158 else if (!strcmp("k", c) || !strcmp("kb", c))
159 pow = 1;
160
161 while (pow--)
162 ret *= (unsigned long long) mult;
163
164 free(c);
Jens Axboea639f0b2009-07-18 08:25:35 +0200165 return ret;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200166}
167
Jens Axboe57fc29f2010-06-23 22:24:07 +0200168static unsigned long long get_mult_bytes(const char *str, int len, void *data)
169{
170 const char *p;
171
172 /*
173 * if the last char is 'b' or 'B', the user likely used
174 * "1gb" instead of just "1g". If the second to last is also
175 * a letter, adjust.
176 */
177 p = str + len - 1;
178 while (isalpha(*(p - 1)))
179 p--;
180 if (!isalpha(*p))
181 p = NULL;
182
183 return __get_mult_bytes(p, data);
184}
185
Jens Axboecb2c86f2006-10-26 13:48:34 +0200186/*
Jens Axboee1f36502006-10-27 10:54:08 +0200187 * convert string into decimal value, noting any size suffix
Jens Axboecb2c86f2006-10-26 13:48:34 +0200188 */
Jens Axboed6978a32009-07-18 21:04:09 +0200189int str_to_decimal(const char *str, long long *val, int kilo, void *data)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200190{
Jens Axboeb347f9d2009-03-09 14:15:21 +0100191 int len, base;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200192
Jens Axboecb2c86f2006-10-26 13:48:34 +0200193 len = strlen(str);
Jens Axboef90eff52006-11-06 11:08:21 +0100194 if (!len)
195 return 1;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200196
Jens Axboeb347f9d2009-03-09 14:15:21 +0100197 if (strstr(str, "0x") || strstr(str, "0X"))
198 base = 16;
199 else
200 base = 10;
201
202 *val = strtoll(str, NULL, base);
Jens Axboecda866c2007-01-10 16:02:32 +0100203 if (*val == LONG_MAX && errno == ERANGE)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200204 return 1;
205
Jens Axboe57fc29f2010-06-23 22:24:07 +0200206 if (kilo)
207 *val *= get_mult_bytes(str, len, data);
208 else
Jens Axboecb2c86f2006-10-26 13:48:34 +0200209 *val *= get_mult_time(str[len - 1]);
Jens Axboe787f7e92006-11-06 13:26:29 +0100210
Jens Axboecb2c86f2006-10-26 13:48:34 +0200211 return 0;
212}
213
Jens Axboed6978a32009-07-18 21:04:09 +0200214static int check_str_bytes(const char *p, long long *val, void *data)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200215{
Jens Axboed6978a32009-07-18 21:04:09 +0200216 return str_to_decimal(p, val, 1, data);
Jens Axboecb2c86f2006-10-26 13:48:34 +0200217}
218
Jens Axboe63f29372007-01-10 13:20:09 +0100219static int check_str_time(const char *p, long long *val)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200220{
Jens Axboed6978a32009-07-18 21:04:09 +0200221 return str_to_decimal(p, val, 0, NULL);
Jens Axboecb2c86f2006-10-26 13:48:34 +0200222}
223
224void strip_blank_front(char **p)
225{
226 char *s = *p;
227
228 while (isspace(*s))
229 s++;
Jens Axboe4d651da2007-03-28 19:34:53 +0200230
231 *p = s;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200232}
233
234void strip_blank_end(char *p)
235{
Jens Axboe853ee7f2009-03-06 20:29:29 +0100236 char *start = p, *s;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200237
Jens Axboe523bfad2007-04-04 11:04:06 +0200238 s = strchr(p, ';');
239 if (s)
240 *s = '\0';
241 s = strchr(p, '#');
242 if (s)
243 *s = '\0';
244 if (s)
245 p = s;
246
Jens Axboe7f7e6e52007-07-19 14:50:05 +0200247 s = p + strlen(p);
Jens Axboe853ee7f2009-03-06 20:29:29 +0100248 while ((isspace(*s) || iscntrl(*s)) && (s > start))
Jens Axboecb2c86f2006-10-26 13:48:34 +0200249 s--;
250
251 *(s + 1) = '\0';
252}
253
Jens Axboed6978a32009-07-18 21:04:09 +0200254static int check_range_bytes(const char *str, long *val, void *data)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200255{
Jens Axboe57fc29f2010-06-23 22:24:07 +0200256 long long __val;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200257
Jens Axboe57fc29f2010-06-23 22:24:07 +0200258 if (!str_to_decimal(str, &__val, 1, data)) {
259 *val = __val;
Jens Axboecb2c86f2006-10-26 13:48:34 +0200260 return 0;
261 }
262
Jens Axboecb2c86f2006-10-26 13:48:34 +0200263 return 1;
264}
265
Jens Axboe63f29372007-01-10 13:20:09 +0100266static int check_int(const char *p, int *val)
Jens Axboecb2c86f2006-10-26 13:48:34 +0200267{
Jens Axboe787f7e92006-11-06 13:26:29 +0100268 if (!strlen(p))
269 return 1;
Jens Axboed78ee462007-08-10 14:03:20 +0200270 if (strstr(p, "0x") || strstr(p, "0X")) {
Jens Axboea61bdfd2007-07-30 09:07:04 +0200271 if (sscanf(p, "%x", val) == 1)
272 return 0;
273 } else {
274 if (sscanf(p, "%u", val) == 1)
275 return 0;
276 }
Jens Axboecb2c86f2006-10-26 13:48:34 +0200277
278 return 1;
279}
280
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100281#define val_store(ptr, val, off, or, data) \
Jens Axboe17abbe82006-11-06 11:23:10 +0100282 do { \
283 ptr = td_var((data), (off)); \
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100284 if ((or)) \
285 *ptr |= (val); \
286 else \
287 *ptr = (val); \
Jens Axboe17abbe82006-11-06 11:23:10 +0100288 } while (0)
289
Jens Axboef90eff52006-11-06 11:08:21 +0100290static int __handle_option(struct fio_option *o, const char *ptr, void *data,
Jens Axboe787f7e92006-11-06 13:26:29 +0100291 int first, int more)
Jens Axboee1f36502006-10-27 10:54:08 +0200292{
Jens Axboe63f29372007-01-10 13:20:09 +0100293 int il, *ilp;
294 long long ull, *ullp;
295 long ul1, ul2;
Jens Axboeb4692822006-10-27 13:43:22 +0200296 char **cp;
Jens Axboee1f36502006-10-27 10:54:08 +0200297 int ret = 0, is_time = 0;
298
Jens Axboea3d741f2008-02-27 18:32:33 +0100299 dprint(FD_PARSE, "__handle_option=%s, type=%d, ptr=%s\n", o->name,
300 o->type, ptr);
301
Jens Axboee3cedca2008-11-19 19:57:52 +0100302 if (!ptr && o->type != FIO_OPT_STR_SET && o->type != FIO_OPT_STR) {
Jens Axboe08e26e32006-11-21 13:15:10 +0100303 fprintf(stderr, "Option %s requires an argument\n", o->name);
304 return 1;
305 }
306
Jens Axboee1f36502006-10-27 10:54:08 +0200307 switch (o->type) {
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100308 case FIO_OPT_STR:
309 case FIO_OPT_STR_MULTI: {
Jens Axboee1f36502006-10-27 10:54:08 +0200310 fio_opt_str_fn *fn = o->cb;
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100311 const struct value_pair *vp;
Jens Axboef0857372007-03-19 13:15:23 +0100312 struct value_pair posval[PARSE_MAX_VP];
Jens Axboeae2ddba2010-03-10 12:49:03 +0100313 int i, all_skipped = 1;
Jens Axboee1f36502006-10-27 10:54:08 +0200314
Jens Axboef0857372007-03-19 13:15:23 +0100315 posval_sort(o, posval);
316
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100317 ret = 1;
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100318 for (i = 0; i < PARSE_MAX_VP; i++) {
Jens Axboef0857372007-03-19 13:15:23 +0100319 vp = &posval[i];
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100320 if (!vp->ival || vp->ival[0] == '\0')
Jens Axboea3073f42010-03-05 10:06:15 +0100321 continue;
Jens Axboeae2ddba2010-03-10 12:49:03 +0100322 all_skipped = 0;
Jens Axboe7b4cb132010-06-18 14:28:53 +0200323 if (!strncmp(vp->ival, ptr, strlen(ptr))) {
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100324 ret = 0;
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100325 if (o->roff1) {
326 if (vp->or)
327 *(unsigned int *) o->roff1 |= vp->oval;
328 else
329 *(unsigned int *) o->roff1 = vp->oval;
330 } else {
Jens Axboe02c6aad2010-03-04 13:49:11 +0100331 if (!o->off1)
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100332 continue;
333 val_store(ilp, vp->oval, o->off1, vp->or, data);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100334 }
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100335 continue;
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100336 }
337 }
338
Jens Axboeae2ddba2010-03-10 12:49:03 +0100339 if (ret && !all_skipped)
Jens Axboeb1ec1da2007-02-23 10:29:16 +0100340 show_option_values(o);
341 else if (fn)
342 ret = fn(data, ptr);
Jens Axboee1f36502006-10-27 10:54:08 +0200343 break;
344 }
345 case FIO_OPT_STR_VAL_TIME:
346 is_time = 1;
Jens Axboef7fa2652009-03-09 14:20:20 +0100347 case FIO_OPT_INT:
Jens Axboee01b22b2009-06-09 15:43:25 +0200348 case FIO_OPT_STR_VAL: {
Jens Axboee1f36502006-10-27 10:54:08 +0200349 fio_opt_str_val_fn *fn = o->cb;
350
351 if (is_time)
352 ret = check_str_time(ptr, &ull);
353 else
Jens Axboed6978a32009-07-18 21:04:09 +0200354 ret = check_str_bytes(ptr, &ull, data);
Jens Axboee1f36502006-10-27 10:54:08 +0200355
356 if (ret)
357 break;
358
Jens Axboedb8e0162007-01-10 13:41:26 +0100359 if (o->maxval && ull > o->maxval) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100360 fprintf(stderr, "max value out of range: %lld"
361 " (%d max)\n", ull, o->maxval);
Jens Axboedb8e0162007-01-10 13:41:26 +0100362 return 1;
363 }
364 if (o->minval && ull < o->minval) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100365 fprintf(stderr, "min value out of range: %lld"
366 " (%d min)\n", ull, o->minval);
Jens Axboedb8e0162007-01-10 13:41:26 +0100367 return 1;
368 }
Jens Axboee1f36502006-10-27 10:54:08 +0200369
370 if (fn)
371 ret = fn(data, &ull);
372 else {
Jens Axboee01b22b2009-06-09 15:43:25 +0200373 if (o->type == FIO_OPT_INT) {
Jens Axboe02c6aad2010-03-04 13:49:11 +0100374 if (first) {
375 if (o->roff1)
Jens Axboe7758d4f2010-03-18 16:50:31 +0100376 *(unsigned int *) o->roff1 = ull;
Jens Axboe02c6aad2010-03-04 13:49:11 +0100377 else
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100378 val_store(ilp, ull, o->off1, 0, data);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100379 }
380 if (!more) {
381 if (o->roff2)
Jens Axboe7758d4f2010-03-18 16:50:31 +0100382 *(unsigned int *) o->roff2 = ull;
Jens Axboe02c6aad2010-03-04 13:49:11 +0100383 else if (o->off2)
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100384 val_store(ilp, ull, o->off2, 0, data);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100385 }
Jens Axboe75e6f362006-11-03 08:17:09 +0100386 } else {
Jens Axboe02c6aad2010-03-04 13:49:11 +0100387 if (first) {
388 if (o->roff1)
389 *(unsigned long long *) o->roff1 = ull;
390 else
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100391 val_store(ullp, ull, o->off1, 0, data);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100392 }
393 if (!more) {
394 if (o->roff2)
395 *(unsigned long long *) o->roff2 = ull;
396 else if (o->off2)
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100397 val_store(ullp, ull, o->off2, 0, data);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100398 }
Jens Axboe75e6f362006-11-03 08:17:09 +0100399 }
Jens Axboee1f36502006-10-27 10:54:08 +0200400 }
401 break;
402 }
Jens Axboeaf52b342007-03-13 10:07:47 +0100403 case FIO_OPT_STR_STORE: {
404 fio_opt_str_fn *fn = o->cb;
405
Jens Axboe02c6aad2010-03-04 13:49:11 +0100406 if (o->roff1)
407 cp = (char **) o->roff1;
408 else
409 cp = td_var(data, o->off1);
410
Jens Axboee1f36502006-10-27 10:54:08 +0200411 *cp = strdup(ptr);
Jens Axboeaf52b342007-03-13 10:07:47 +0100412 if (fn) {
413 ret = fn(data, ptr);
414 if (ret) {
415 free(*cp);
416 *cp = NULL;
417 }
418 }
Jens Axboee1f36502006-10-27 10:54:08 +0200419 break;
Jens Axboeaf52b342007-03-13 10:07:47 +0100420 }
Jens Axboee1f36502006-10-27 10:54:08 +0200421 case FIO_OPT_RANGE: {
Jens Axboeb765a372006-10-27 15:00:16 +0200422 char tmp[128];
Jens Axboee1f36502006-10-27 10:54:08 +0200423 char *p1, *p2;
424
Jens Axboe0bbab0e2006-11-02 09:18:36 +0100425 strncpy(tmp, ptr, sizeof(tmp) - 1);
Jens Axboeb765a372006-10-27 15:00:16 +0200426
427 p1 = strchr(tmp, '-');
Jens Axboee1f36502006-10-27 10:54:08 +0200428 if (!p1) {
Jens Axboe0c9baf92007-01-11 15:59:26 +0100429 p1 = strchr(tmp, ':');
430 if (!p1) {
431 ret = 1;
432 break;
433 }
Jens Axboee1f36502006-10-27 10:54:08 +0200434 }
435
436 p2 = p1 + 1;
437 *p1 = '\0';
Jens Axboeb765a372006-10-27 15:00:16 +0200438 p1 = tmp;
Jens Axboee1f36502006-10-27 10:54:08 +0200439
440 ret = 1;
Jens Axboed6978a32009-07-18 21:04:09 +0200441 if (!check_range_bytes(p1, &ul1, data) &&
442 !check_range_bytes(p2, &ul2, data)) {
Jens Axboee1f36502006-10-27 10:54:08 +0200443 ret = 0;
Jens Axboee1f36502006-10-27 10:54:08 +0200444 if (ul1 > ul2) {
Jens Axboef90eff52006-11-06 11:08:21 +0100445 unsigned long foo = ul1;
446
447 ul1 = ul2;
448 ul2 = foo;
449 }
450
451 if (first) {
Jens Axboe02c6aad2010-03-04 13:49:11 +0100452 if (o->roff1)
Jens Axboe7758d4f2010-03-18 16:50:31 +0100453 *(unsigned int *) o->roff1 = ul1;
Jens Axboe02c6aad2010-03-04 13:49:11 +0100454 else
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100455 val_store(ilp, ul1, o->off1, 0, data);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100456 if (o->roff2)
Jens Axboe7758d4f2010-03-18 16:50:31 +0100457 *(unsigned int *) o->roff2 = ul2;
Jens Axboe02c6aad2010-03-04 13:49:11 +0100458 else
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100459 val_store(ilp, ul2, o->off2, 0, data);
Jens Axboee1f36502006-10-27 10:54:08 +0200460 }
Jens Axboe02c6aad2010-03-04 13:49:11 +0100461 if (o->roff3 && o->roff4) {
Jens Axboe7758d4f2010-03-18 16:50:31 +0100462 *(unsigned int *) o->roff3 = ul1;
463 *(unsigned int *) o->roff4 = ul2;
Jens Axboe02c6aad2010-03-04 13:49:11 +0100464 } else if (o->off3 && o->off4) {
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100465 val_store(ilp, ul1, o->off3, 0, data);
466 val_store(ilp, ul2, o->off4, 0, data);
Jens Axboe17abbe82006-11-06 11:23:10 +0100467 }
468 }
469
Jens Axboee1f36502006-10-27 10:54:08 +0200470 break;
471 }
Jens Axboe13335dd2007-01-10 13:14:02 +0100472 case FIO_OPT_BOOL: {
Jens Axboee1f36502006-10-27 10:54:08 +0200473 fio_opt_int_fn *fn = o->cb;
474
475 ret = check_int(ptr, &il);
476 if (ret)
477 break;
478
Jens Axboedb8e0162007-01-10 13:41:26 +0100479 if (o->maxval && il > (int) o->maxval) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100480 fprintf(stderr, "max value out of range: %d (%d max)\n",
481 il, o->maxval);
Jens Axboedb8e0162007-01-10 13:41:26 +0100482 return 1;
483 }
484 if (o->minval && il < o->minval) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100485 fprintf(stderr, "min value out of range: %d (%d min)\n",
486 il, o->minval);
Jens Axboedb8e0162007-01-10 13:41:26 +0100487 return 1;
488 }
Jens Axboee1f36502006-10-27 10:54:08 +0200489
Jens Axboe76a43db2007-01-11 13:24:44 +0100490 if (o->neg)
491 il = !il;
492
Jens Axboee1f36502006-10-27 10:54:08 +0200493 if (fn)
494 ret = fn(data, &il);
495 else {
Jens Axboe02c6aad2010-03-04 13:49:11 +0100496 if (first) {
497 if (o->roff1)
498 *(unsigned int *)o->roff1 = il;
499 else
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100500 val_store(ilp, il, o->off1, 0, data);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100501 }
502 if (!more) {
503 if (o->roff2)
504 *(unsigned int *) o->roff2 = il;
505 else if (o->off2)
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100506 val_store(ilp, il, o->off2, 0, data);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100507 }
Jens Axboee1f36502006-10-27 10:54:08 +0200508 }
509 break;
510 }
511 case FIO_OPT_STR_SET: {
512 fio_opt_str_set_fn *fn = o->cb;
513
514 if (fn)
515 ret = fn(data);
516 else {
Jens Axboe02c6aad2010-03-04 13:49:11 +0100517 if (first) {
518 if (o->roff1)
519 *(unsigned int *) o->roff1 = 1;
520 else
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100521 val_store(ilp, 1, o->off1, 0, data);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100522 }
523 if (!more) {
524 if (o->roff2)
525 *(unsigned int *) o->roff2 = 1;
526 else if (o->off2)
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100527 val_store(ilp, 1, o->off2, 0, data);
Jens Axboe02c6aad2010-03-04 13:49:11 +0100528 }
Jens Axboee1f36502006-10-27 10:54:08 +0200529 }
530 break;
531 }
Jens Axboe15ca1502008-04-07 09:26:02 +0200532 case FIO_OPT_DEPRECATED:
533 fprintf(stdout, "Option %s is deprecated\n", o->name);
534 break;
Jens Axboee1f36502006-10-27 10:54:08 +0200535 default:
Jens Axboe1e97cce2006-12-05 11:44:16 +0100536 fprintf(stderr, "Bad option type %u\n", o->type);
Jens Axboee1f36502006-10-27 10:54:08 +0200537 ret = 1;
538 }
539
Jens Axboe70a4c0c2009-07-01 09:24:05 +0200540 if (ret)
541 return ret;
542
Jens Axboed447a8c2009-07-17 22:26:15 +0200543 if (o->verify) {
Jens Axboe70a4c0c2009-07-01 09:24:05 +0200544 ret = o->verify(o, data);
Jens Axboed447a8c2009-07-17 22:26:15 +0200545 if (ret) {
546 fprintf(stderr,"Correct format for offending option\n");
547 fprintf(stderr, "%20s: %s\n", o->name, o->help);
548 show_option_help(o, stderr);
549 }
550 }
Jens Axboe70a4c0c2009-07-01 09:24:05 +0200551
Jens Axboee1f36502006-10-27 10:54:08 +0200552 return ret;
553}
554
Jens Axboe7c8f1a52009-06-09 12:28:57 +0200555static int handle_option(struct fio_option *o, const char *__ptr, void *data)
Jens Axboef90eff52006-11-06 11:08:21 +0100556{
Jens Axboeb62bdf22010-03-10 12:36:17 +0100557 char *o_ptr, *ptr, *ptr2;
558 int ret, done;
Jens Axboef90eff52006-11-06 11:08:21 +0100559
Jens Axboe7c8f1a52009-06-09 12:28:57 +0200560 dprint(FD_PARSE, "handle_option=%s, ptr=%s\n", o->name, __ptr);
561
Jens Axboeb62bdf22010-03-10 12:36:17 +0100562 o_ptr = ptr = NULL;
Jens Axboe7c8f1a52009-06-09 12:28:57 +0200563 if (__ptr)
Jens Axboeb62bdf22010-03-10 12:36:17 +0100564 o_ptr = ptr = strdup(__ptr);
Jens Axboea3d741f2008-02-27 18:32:33 +0100565
Jens Axboef90eff52006-11-06 11:08:21 +0100566 /*
Jens Axboeb62bdf22010-03-10 12:36:17 +0100567 * See if we have another set of parameters, hidden after a comma.
568 * Do this before parsing this round, to check if we should
Jens Axboe787f7e92006-11-06 13:26:29 +0100569 * copy set 1 options to set 2.
Jens Axboef90eff52006-11-06 11:08:21 +0100570 */
Jens Axboeb62bdf22010-03-10 12:36:17 +0100571 done = 0;
572 ret = 1;
573 do {
574 int __ret;
575
576 ptr2 = NULL;
577 if (ptr &&
578 (o->type != FIO_OPT_STR_STORE) &&
579 (o->type != FIO_OPT_STR)) {
580 ptr2 = strchr(ptr, ',');
581 if (ptr2 && *(ptr2 + 1) == '\0')
582 *ptr2 = '\0';
583 if (o->type != FIO_OPT_STR_MULTI) {
584 if (!ptr2)
585 ptr2 = strchr(ptr, ':');
586 if (!ptr2)
587 ptr2 = strchr(ptr, '-');
588 }
589 }
590
591 /*
592 * Don't return early if parsing the first option fails - if
593 * we are doing multiple arguments, we can allow the first one
594 * being empty.
595 */
596 __ret = __handle_option(o, ptr, data, !done, !!ptr2);
597 if (ret)
598 ret = __ret;
599
Jens Axboe0c9baf92007-01-11 15:59:26 +0100600 if (!ptr2)
Jens Axboeb62bdf22010-03-10 12:36:17 +0100601 break;
Jens Axboe787f7e92006-11-06 13:26:29 +0100602
Jens Axboeb62bdf22010-03-10 12:36:17 +0100603 ptr = ptr2 + 1;
604 done++;
605 } while (1);
Jens Axboe787f7e92006-11-06 13:26:29 +0100606
Jens Axboeb62bdf22010-03-10 12:36:17 +0100607 if (o_ptr)
608 free(o_ptr);
609 return ret;
Jens Axboef90eff52006-11-06 11:08:21 +0100610}
611
Jens Axboe3b8b7132008-06-10 19:46:23 +0200612static struct fio_option *get_option(const char *opt,
Jens Axboe07b32322010-03-05 09:48:44 +0100613 struct fio_option *options, char **post)
Jens Axboe3b8b7132008-06-10 19:46:23 +0200614{
615 struct fio_option *o;
616 char *ret;
617
618 ret = strchr(opt, '=');
619 if (ret) {
620 *post = ret;
621 *ret = '\0';
622 ret = (char *) opt;
623 (*post)++;
Jens Axboe43c129b2008-12-08 14:06:42 +0100624 strip_blank_end(ret);
Jens Axboe07b32322010-03-05 09:48:44 +0100625 o = find_option(options, ret);
Jens Axboe3b8b7132008-06-10 19:46:23 +0200626 } else {
Jens Axboe07b32322010-03-05 09:48:44 +0100627 o = find_option(options, opt);
Jens Axboe3b8b7132008-06-10 19:46:23 +0200628 *post = NULL;
629 }
630
631 return o;
632}
633
634static int opt_cmp(const void *p1, const void *p2)
635{
636 struct fio_option *o1, *o2;
637 char *s1, *s2, *foo;
Jens Axboe8cdabc12008-11-19 12:31:43 +0100638 int prio1, prio2;
Jens Axboe3b8b7132008-06-10 19:46:23 +0200639
640 s1 = strdup(*((char **) p1));
641 s2 = strdup(*((char **) p2));
642
Jens Axboe07b32322010-03-05 09:48:44 +0100643 o1 = get_option(s1, fio_options, &foo);
644 o2 = get_option(s2, fio_options, &foo);
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200645
Jens Axboe8cdabc12008-11-19 12:31:43 +0100646 prio1 = prio2 = 0;
647 if (o1)
648 prio1 = o1->prio;
649 if (o2)
650 prio2 = o2->prio;
Jens Axboe3b8b7132008-06-10 19:46:23 +0200651
652 free(s1);
653 free(s2);
Jens Axboe8cdabc12008-11-19 12:31:43 +0100654 return prio2 - prio1;
Jens Axboe3b8b7132008-06-10 19:46:23 +0200655}
656
657void sort_options(char **opts, struct fio_option *options, int num_opts)
658{
659 fio_options = options;
660 qsort(opts, num_opts, sizeof(char *), opt_cmp);
661 fio_options = NULL;
662}
663
Jens Axboeb4692822006-10-27 13:43:22 +0200664int parse_cmd_option(const char *opt, const char *val,
Jens Axboe07b32322010-03-05 09:48:44 +0100665 struct fio_option *options, void *data)
Jens Axboeb4692822006-10-27 13:43:22 +0200666{
667 struct fio_option *o;
668
Jens Axboe07b32322010-03-05 09:48:44 +0100669 o = find_option(options, opt);
Jens Axboeb4692822006-10-27 13:43:22 +0200670 if (!o) {
Jens Axboe43c129b2008-12-08 14:06:42 +0100671 fprintf(stderr, "Bad option <%s>\n", opt);
Jens Axboeb4692822006-10-27 13:43:22 +0200672 return 1;
673 }
674
Jens Axboeb1508cf2006-11-02 09:12:40 +0100675 if (!handle_option(o, val, data))
676 return 0;
677
678 fprintf(stderr, "fio: failed parsing %s=%s\n", opt, val);
679 return 1;
Jens Axboeb4692822006-10-27 13:43:22 +0200680}
681
Aaron Carroll88b5a392008-10-07 11:25:20 +0200682/*
683 * Return a copy of the input string with substrings of the form ${VARNAME}
684 * substituted with the value of the environment variable VARNAME. The
685 * substitution always occurs, even if VARNAME is empty or the corresponding
686 * environment variable undefined.
687 */
688static char *option_dup_subs(const char *opt)
689{
690 char out[OPT_LEN_MAX+1];
691 char in[OPT_LEN_MAX+1];
692 char *outptr = out;
693 char *inptr = in;
694 char *ch1, *ch2, *env;
695 ssize_t nchr = OPT_LEN_MAX;
696 size_t envlen;
697
Jens Axboea0741cb2010-03-05 12:46:37 +0100698 if (strlen(opt) + 1 > OPT_LEN_MAX) {
Jens Axboe38789b52010-03-03 09:23:20 +0100699 fprintf(stderr, "OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
700 return NULL;
701 }
702
Aaron Carroll88b5a392008-10-07 11:25:20 +0200703 in[OPT_LEN_MAX] = '\0';
704 strncpy(in, opt, OPT_LEN_MAX);
705
706 while (*inptr && nchr > 0) {
707 if (inptr[0] == '$' && inptr[1] == '{') {
708 ch2 = strchr(inptr, '}');
709 if (ch2 && inptr+1 < ch2) {
710 ch1 = inptr+2;
711 inptr = ch2+1;
712 *ch2 = '\0';
713
714 env = getenv(ch1);
715 if (env) {
716 envlen = strlen(env);
717 if (envlen <= nchr) {
718 memcpy(outptr, env, envlen);
719 outptr += envlen;
720 nchr -= envlen;
721 }
722 }
723
724 continue;
725 }
726 }
727
728 *outptr++ = *inptr++;
729 --nchr;
730 }
731
732 *outptr = '\0';
733 return strdup(out);
734}
735
Jens Axboe07b32322010-03-05 09:48:44 +0100736int parse_option(const char *opt, struct fio_option *options, void *data)
Jens Axboee1f36502006-10-27 10:54:08 +0200737{
Jens Axboeb4692822006-10-27 13:43:22 +0200738 struct fio_option *o;
Jens Axboe3b8b7132008-06-10 19:46:23 +0200739 char *post, *tmp;
Jens Axboee1f36502006-10-27 10:54:08 +0200740
Aaron Carroll88b5a392008-10-07 11:25:20 +0200741 tmp = option_dup_subs(opt);
Jens Axboe38789b52010-03-03 09:23:20 +0100742 if (!tmp)
743 return 1;
Jens Axboee1f36502006-10-27 10:54:08 +0200744
Jens Axboe07b32322010-03-05 09:48:44 +0100745 o = get_option(tmp, options, &post);
Jens Axboee1f36502006-10-27 10:54:08 +0200746 if (!o) {
Jens Axboe43c129b2008-12-08 14:06:42 +0100747 fprintf(stderr, "Bad option <%s>\n", tmp);
Jens Axboe0401bca2007-03-29 11:00:43 +0200748 free(tmp);
Jens Axboee1f36502006-10-27 10:54:08 +0200749 return 1;
750 }
751
Jens Axboe0401bca2007-03-29 11:00:43 +0200752 if (!handle_option(o, post, data)) {
753 free(tmp);
Jens Axboeb1508cf2006-11-02 09:12:40 +0100754 return 0;
Jens Axboe0401bca2007-03-29 11:00:43 +0200755 }
Jens Axboeb1508cf2006-11-02 09:12:40 +0100756
757 fprintf(stderr, "fio: failed parsing %s\n", opt);
Jens Axboe0401bca2007-03-29 11:00:43 +0200758 free(tmp);
Jens Axboeb1508cf2006-11-02 09:12:40 +0100759 return 1;
Jens Axboee1f36502006-10-27 10:54:08 +0200760}
Jens Axboefd28ca42007-01-09 21:20:13 +0100761
Jens Axboe0e9f7fa2007-03-01 14:05:30 +0100762/*
763 * Option match, levenshtein distance. Handy for not quite remembering what
764 * the option name is.
765 */
766static int string_distance(const char *s1, const char *s2)
767{
768 unsigned int s1_len = strlen(s1);
769 unsigned int s2_len = strlen(s2);
770 unsigned int *p, *q, *r;
771 unsigned int i, j;
772
773 p = malloc(sizeof(unsigned int) * (s2_len + 1));
774 q = malloc(sizeof(unsigned int) * (s2_len + 1));
775
776 p[0] = 0;
777 for (i = 1; i <= s2_len; i++)
778 p[i] = p[i - 1] + 1;
779
780 for (i = 1; i <= s1_len; i++) {
781 q[0] = p[0] + 1;
782 for (j = 1; j <= s2_len; j++) {
783 unsigned int sub = p[j - 1];
784
785 if (s1[i - 1] != s2[j - 1])
786 sub++;
787
788 q[j] = min(p[j] + 1, min(q[j - 1] + 1, sub));
789 }
790 r = p;
791 p = q;
792 q = r;
793 }
794
795 i = p[s2_len];
796 free(p);
797 free(q);
798 return i;
799}
800
Jens Axboeafdf9352007-07-31 16:14:34 +0200801static struct fio_option *find_child(struct fio_option *options,
802 struct fio_option *o)
803{
804 struct fio_option *__o;
805
Jens Axboefdf28742007-07-31 23:06:09 +0200806 for (__o = options + 1; __o->name; __o++)
807 if (__o->parent && !strcmp(__o->parent, o->name))
Jens Axboeafdf9352007-07-31 16:14:34 +0200808 return __o;
809
810 return NULL;
811}
812
Jens Axboe323d9112008-03-01 15:12:14 +0100813static void __print_option(struct fio_option *o, struct fio_option *org,
814 int level)
Jens Axboeafdf9352007-07-31 16:14:34 +0200815{
816 char name[256], *p;
Jens Axboe323d9112008-03-01 15:12:14 +0100817 int depth;
Jens Axboeafdf9352007-07-31 16:14:34 +0200818
819 if (!o)
820 return;
Jens Axboeef9aff52007-07-31 22:56:53 +0200821 if (!org)
822 org = o;
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100823
Jens Axboeafdf9352007-07-31 16:14:34 +0200824 p = name;
Jens Axboe323d9112008-03-01 15:12:14 +0100825 depth = level;
826 while (depth--)
827 p += sprintf(p, "%s", " ");
Jens Axboeafdf9352007-07-31 16:14:34 +0200828
829 sprintf(p, "%s", o->name);
830
831 printf("%-24s: %s\n", name, o->help);
Jens Axboe323d9112008-03-01 15:12:14 +0100832}
833
834static void print_option(struct fio_option *o)
835{
836 struct fio_option *parent;
837 struct fio_option *__o;
838 unsigned int printed;
839 unsigned int level;
840
841 __print_option(o, NULL, 0);
842 parent = o;
843 level = 0;
844 do {
845 level++;
846 printed = 0;
847
848 while ((__o = find_child(o, parent)) != NULL) {
849 __print_option(__o, o, level);
850 o = __o;
851 printed++;
852 }
853
854 parent = o;
855 } while (printed);
Jens Axboeafdf9352007-07-31 16:14:34 +0200856}
857
Jens Axboe07b32322010-03-05 09:48:44 +0100858int show_cmd_help(struct fio_option *options, const char *name)
Jens Axboe0e9f7fa2007-03-01 14:05:30 +0100859{
860 struct fio_option *o, *closest;
Jens Axboed091d092010-04-01 19:56:23 +0200861 unsigned int best_dist = -1U;
Jens Axboe29fc6af2007-01-09 21:22:02 +0100862 int found = 0;
Jens Axboe320beef2007-03-01 10:44:12 +0100863 int show_all = 0;
864
865 if (!name || !strcmp(name, "all"))
866 show_all = 1;
Jens Axboefd28ca42007-01-09 21:20:13 +0100867
Jens Axboe0e9f7fa2007-03-01 14:05:30 +0100868 closest = NULL;
869 best_dist = -1;
Jens Axboe4945ba12007-01-11 14:36:56 +0100870 for (o = &options[0]; o->name; o++) {
Jens Axboe320beef2007-03-01 10:44:12 +0100871 int match = 0;
872
Jens Axboe15ca1502008-04-07 09:26:02 +0200873 if (o->type == FIO_OPT_DEPRECATED)
874 continue;
Jens Axboe07b32322010-03-05 09:48:44 +0100875 if (!exec_profile && o->prof_name)
876 continue;
Jens Axboe15ca1502008-04-07 09:26:02 +0200877
Jens Axboe0e9f7fa2007-03-01 14:05:30 +0100878 if (name) {
Jens Axboe7f9348f2007-03-15 14:09:28 +0100879 if (!strcmp(name, o->name) ||
880 (o->alias && !strcmp(name, o->alias)))
Jens Axboe0e9f7fa2007-03-01 14:05:30 +0100881 match = 1;
882 else {
883 unsigned int dist;
884
885 dist = string_distance(name, o->name);
886 if (dist < best_dist) {
887 best_dist = dist;
888 closest = o;
889 }
890 }
891 }
Jens Axboefd28ca42007-01-09 21:20:13 +0100892
893 if (show_all || match) {
Jens Axboe29fc6af2007-01-09 21:22:02 +0100894 found = 1;
Jens Axboec167ded2007-03-14 13:02:53 +0100895 if (match)
Jens Axboe07b32322010-03-05 09:48:44 +0100896 printf("%20s: %s\n", o->name, o->help);
Jens Axboec167ded2007-03-14 13:02:53 +0100897 if (show_all) {
Jens Axboeafdf9352007-07-31 16:14:34 +0200898 if (!o->parent)
Jens Axboe323d9112008-03-01 15:12:14 +0100899 print_option(o);
Jens Axboe4945ba12007-01-11 14:36:56 +0100900 continue;
Jens Axboec167ded2007-03-14 13:02:53 +0100901 }
Jens Axboefd28ca42007-01-09 21:20:13 +0100902 }
903
Jens Axboe70df2f12007-01-11 14:04:47 +0100904 if (!match)
905 continue;
906
Jens Axboed447a8c2009-07-17 22:26:15 +0200907 show_option_help(o, stdout);
Jens Axboefd28ca42007-01-09 21:20:13 +0100908 }
909
Jens Axboe29fc6af2007-01-09 21:22:02 +0100910 if (found)
911 return 0;
Jens Axboefd28ca42007-01-09 21:20:13 +0100912
Jens Axboe0e9f7fa2007-03-01 14:05:30 +0100913 printf("No such command: %s", name);
Jens Axboed091d092010-04-01 19:56:23 +0200914
915 /*
916 * Only print an appropriately close option, one where the edit
917 * distance isn't too big. Otherwise we get crazy matches.
918 */
919 if (closest && best_dist < 3) {
Jens Axboe0e9f7fa2007-03-01 14:05:30 +0100920 printf(" - showing closest match\n");
921 printf("%20s: %s\n", closest->name, closest->help);
Jens Axboed447a8c2009-07-17 22:26:15 +0200922 show_option_help(closest, stdout);
Jens Axboe0e9f7fa2007-03-01 14:05:30 +0100923 } else
924 printf("\n");
925
Jens Axboe29fc6af2007-01-09 21:22:02 +0100926 return 1;
Jens Axboefd28ca42007-01-09 21:20:13 +0100927}
Jens Axboeee738492007-01-10 11:23:16 +0100928
Jens Axboe13335dd2007-01-10 13:14:02 +0100929/*
930 * Handle parsing of default parameters.
931 */
Jens Axboeee738492007-01-10 11:23:16 +0100932void fill_default_options(void *data, struct fio_option *options)
933{
Jens Axboe4945ba12007-01-11 14:36:56 +0100934 struct fio_option *o;
Jens Axboeee738492007-01-10 11:23:16 +0100935
Jens Axboea3d741f2008-02-27 18:32:33 +0100936 dprint(FD_PARSE, "filling default options\n");
937
Jens Axboe4945ba12007-01-11 14:36:56 +0100938 for (o = &options[0]; o->name; o++)
Jens Axboeee738492007-01-10 11:23:16 +0100939 if (o->def)
940 handle_option(o, o->def, data);
Jens Axboeee738492007-01-10 11:23:16 +0100941}
Jens Axboe13335dd2007-01-10 13:14:02 +0100942
Jens Axboe9f988e22010-03-04 10:42:38 +0100943void option_init(struct fio_option *o)
944{
945 if (o->type == FIO_OPT_DEPRECATED)
946 return;
947 if (o->type == FIO_OPT_BOOL) {
948 o->minval = 0;
949 o->maxval = 1;
950 }
951 if (o->type == FIO_OPT_STR_SET && o->def) {
952 fprintf(stderr, "Option %s: string set option with"
953 " default will always be true\n", o->name);
954 }
Jens Axboee2de69d2010-03-04 14:05:48 +0100955 if (!o->cb && (!o->off1 && !o->roff1)) {
Jens Axboe9f988e22010-03-04 10:42:38 +0100956 fprintf(stderr, "Option %s: neither cb nor offset given\n",
957 o->name);
958 }
Jens Axboe5f6ddf12010-03-09 20:40:44 +0100959 if (o->type == FIO_OPT_STR || o->type == FIO_OPT_STR_STORE ||
960 o->type == FIO_OPT_STR_MULTI)
Jens Axboe9f988e22010-03-04 10:42:38 +0100961 return;
Jens Axboee2de69d2010-03-04 14:05:48 +0100962 if (o->cb && ((o->off1 || o->off2 || o->off3 || o->off4) ||
963 (o->roff1 || o->roff2 || o->roff3 || o->roff4))) {
Jens Axboe9f988e22010-03-04 10:42:38 +0100964 fprintf(stderr, "Option %s: both cb and offset given\n",
965 o->name);
966 }
967}
968
Jens Axboe13335dd2007-01-10 13:14:02 +0100969/*
970 * Sanitize the options structure. For now it just sets min/max for bool
Jens Axboe5b0a8882007-01-11 14:40:27 +0100971 * values and whether both callback and offsets are given.
Jens Axboe13335dd2007-01-10 13:14:02 +0100972 */
973void options_init(struct fio_option *options)
974{
Jens Axboe4945ba12007-01-11 14:36:56 +0100975 struct fio_option *o;
Jens Axboe13335dd2007-01-10 13:14:02 +0100976
Jens Axboea3d741f2008-02-27 18:32:33 +0100977 dprint(FD_PARSE, "init options\n");
978
Jens Axboe9f988e22010-03-04 10:42:38 +0100979 for (o = &options[0]; o->name; o++)
980 option_init(o);
Jens Axboe13335dd2007-01-10 13:14:02 +0100981}