Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 1 | /* |
| 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 Carroll | 88b5a39 | 2008-10-07 11:25:20 +0200 | [diff] [blame] | 11 | #include <stdlib.h> |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 12 | |
| 13 | #include "parse.h" |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 14 | #include "debug.h" |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 15 | #include "options.h" |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 16 | |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 17 | static struct fio_option *fio_options; |
Jens Axboe | d6978a3 | 2009-07-18 21:04:09 +0200 | [diff] [blame] | 18 | extern unsigned int fio_get_kb_base(void *); |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 19 | |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 20 | static 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 | |
| 28 | static 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 Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 46 | static void show_option_range(struct fio_option *o, FILE *out) |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 47 | { |
| 48 | if (!o->minval && !o->maxval) |
| 49 | return; |
| 50 | |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 51 | fprintf(out, "%20s: min=%d", "range", o->minval); |
Jens Axboe | 3980127 | 2009-07-01 09:06:12 +0200 | [diff] [blame] | 52 | if (o->maxval) |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 53 | fprintf(out, ", max=%d", o->maxval); |
| 54 | fprintf(out, "\n"); |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static void show_option_values(struct fio_option *o) |
| 58 | { |
Jens Axboe | a3073f4 | 2010-03-05 10:06:15 +0100 | [diff] [blame] | 59 | int i; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 60 | |
Jens Axboe | a3073f4 | 2010-03-05 10:06:15 +0100 | [diff] [blame] | 61 | for (i = 0; i < PARSE_MAX_VP; i++) { |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 62 | const struct value_pair *vp = &o->posval[i]; |
| 63 | |
| 64 | if (!vp->ival) |
Jens Axboe | a3073f4 | 2010-03-05 10:06:15 +0100 | [diff] [blame] | 65 | continue; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 66 | |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 67 | printf("%20s: %-10s", i == 0 ? "valid values" : "", vp->ival); |
| 68 | if (vp->help) |
| 69 | printf(" %s", vp->help); |
| 70 | printf("\n"); |
Jens Axboe | a3073f4 | 2010-03-05 10:06:15 +0100 | [diff] [blame] | 71 | } |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 72 | |
| 73 | if (i) |
| 74 | printf("\n"); |
| 75 | } |
| 76 | |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 77 | static void show_option_help(struct fio_option *o, FILE *out) |
| 78 | { |
| 79 | const char *typehelp[] = { |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 80 | "invalid", |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 81 | "string (opt=bla)", |
Jens Axboe | ae3fb6f | 2010-09-14 13:10:35 +0200 | [diff] [blame] | 82 | "string (opt=bla)", |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 83 | "string with possible k/m/g postfix (opt=4k)", |
| 84 | "string with time postfix (opt=10s)", |
| 85 | "string (opt=bla)", |
| 86 | "string with dual range (opt=1k-4k,4k-8k)", |
| 87 | "integer value (opt=100)", |
| 88 | "boolean value (opt=1)", |
| 89 | "no argument (opt)", |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 90 | "deprecated", |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | if (o->alias) |
| 94 | fprintf(out, "%20s: %s\n", "alias", o->alias); |
| 95 | |
| 96 | fprintf(out, "%20s: %s\n", "type", typehelp[o->type]); |
| 97 | fprintf(out, "%20s: %s\n", "default", o->def ? o->def : "no default"); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 98 | if (o->prof_name) |
| 99 | fprintf(out, "%20s: only for profile '%s'\n", "valid", o->prof_name); |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 100 | show_option_range(o, stdout); |
| 101 | show_option_values(o); |
| 102 | } |
| 103 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 104 | static unsigned long get_mult_time(char c) |
| 105 | { |
| 106 | switch (c) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 107 | case 'm': |
| 108 | case 'M': |
| 109 | return 60; |
| 110 | case 'h': |
| 111 | case 'H': |
| 112 | return 60 * 60; |
| 113 | case 'd': |
| 114 | case 'D': |
| 115 | return 24 * 60 * 60; |
| 116 | default: |
| 117 | return 1; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 121 | static unsigned long long __get_mult_bytes(const char *p, void *data) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 122 | { |
Jens Axboe | d6978a3 | 2009-07-18 21:04:09 +0200 | [diff] [blame] | 123 | unsigned int kb_base = fio_get_kb_base(data); |
Jens Axboe | a639f0b | 2009-07-18 08:25:35 +0200 | [diff] [blame] | 124 | unsigned long long ret = 1; |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 125 | unsigned int i, pow = 0, mult = kb_base; |
| 126 | char *c; |
Jens Axboe | a639f0b | 2009-07-18 08:25:35 +0200 | [diff] [blame] | 127 | |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 128 | if (!p) |
| 129 | return 1; |
Jens Axboe | a639f0b | 2009-07-18 08:25:35 +0200 | [diff] [blame] | 130 | |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 131 | c = strdup(p); |
| 132 | |
| 133 | for (i = 0; i < strlen(c); i++) |
| 134 | c[i] = tolower(c[i]); |
| 135 | |
| 136 | if (!strcmp("pib", c)) { |
| 137 | pow = 5; |
| 138 | mult = 1000; |
| 139 | } else if (!strcmp("tib", c)) { |
| 140 | pow = 4; |
| 141 | mult = 1000; |
| 142 | } else if (!strcmp("gib", c)) { |
| 143 | pow = 3; |
| 144 | mult = 1000; |
| 145 | } else if (!strcmp("mib", c)) { |
| 146 | pow = 2; |
| 147 | mult = 1000; |
| 148 | } else if (!strcmp("kib", c)) { |
| 149 | pow = 1; |
| 150 | mult = 1000; |
| 151 | } else if (!strcmp("p", c) || !strcmp("pb", c)) |
| 152 | pow = 5; |
| 153 | else if (!strcmp("t", c) || !strcmp("tb", c)) |
| 154 | pow = 4; |
| 155 | else if (!strcmp("g", c) || !strcmp("gb", c)) |
| 156 | pow = 3; |
| 157 | else if (!strcmp("m", c) || !strcmp("mb", c)) |
| 158 | pow = 2; |
| 159 | else if (!strcmp("k", c) || !strcmp("kb", c)) |
| 160 | pow = 1; |
| 161 | |
| 162 | while (pow--) |
| 163 | ret *= (unsigned long long) mult; |
| 164 | |
| 165 | free(c); |
Jens Axboe | a639f0b | 2009-07-18 08:25:35 +0200 | [diff] [blame] | 166 | return ret; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 169 | static unsigned long long get_mult_bytes(const char *str, int len, void *data) |
| 170 | { |
| 171 | const char *p; |
| 172 | |
Jens Axboe | 1d1c187 | 2010-07-29 10:50:05 +0200 | [diff] [blame] | 173 | if (len < 2) |
| 174 | return __get_mult_bytes(str, data); |
| 175 | |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 176 | /* |
| 177 | * if the last char is 'b' or 'B', the user likely used |
| 178 | * "1gb" instead of just "1g". If the second to last is also |
| 179 | * a letter, adjust. |
| 180 | */ |
| 181 | p = str + len - 1; |
| 182 | while (isalpha(*(p - 1))) |
| 183 | p--; |
| 184 | if (!isalpha(*p)) |
| 185 | p = NULL; |
| 186 | |
| 187 | return __get_mult_bytes(p, data); |
| 188 | } |
| 189 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 190 | /* |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 191 | * convert string into decimal value, noting any size suffix |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 192 | */ |
Jens Axboe | d6978a3 | 2009-07-18 21:04:09 +0200 | [diff] [blame] | 193 | int str_to_decimal(const char *str, long long *val, int kilo, void *data) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 194 | { |
Jens Axboe | b347f9d | 2009-03-09 14:15:21 +0100 | [diff] [blame] | 195 | int len, base; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 196 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 197 | len = strlen(str); |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 198 | if (!len) |
| 199 | return 1; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 200 | |
Jens Axboe | b347f9d | 2009-03-09 14:15:21 +0100 | [diff] [blame] | 201 | if (strstr(str, "0x") || strstr(str, "0X")) |
| 202 | base = 16; |
| 203 | else |
| 204 | base = 10; |
| 205 | |
| 206 | *val = strtoll(str, NULL, base); |
Jens Axboe | cda866c | 2007-01-10 16:02:32 +0100 | [diff] [blame] | 207 | if (*val == LONG_MAX && errno == ERANGE) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 208 | return 1; |
| 209 | |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 210 | if (kilo) |
| 211 | *val *= get_mult_bytes(str, len, data); |
| 212 | else |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 213 | *val *= get_mult_time(str[len - 1]); |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 214 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 215 | return 0; |
| 216 | } |
| 217 | |
Jens Axboe | d6978a3 | 2009-07-18 21:04:09 +0200 | [diff] [blame] | 218 | static int check_str_bytes(const char *p, long long *val, void *data) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 219 | { |
Jens Axboe | d6978a3 | 2009-07-18 21:04:09 +0200 | [diff] [blame] | 220 | return str_to_decimal(p, val, 1, data); |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 221 | } |
| 222 | |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 223 | static int check_str_time(const char *p, long long *val) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 224 | { |
Jens Axboe | d6978a3 | 2009-07-18 21:04:09 +0200 | [diff] [blame] | 225 | return str_to_decimal(p, val, 0, NULL); |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | void strip_blank_front(char **p) |
| 229 | { |
| 230 | char *s = *p; |
| 231 | |
| 232 | while (isspace(*s)) |
| 233 | s++; |
Jens Axboe | 4d651da | 2007-03-28 19:34:53 +0200 | [diff] [blame] | 234 | |
| 235 | *p = s; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | void strip_blank_end(char *p) |
| 239 | { |
Jens Axboe | 853ee7f | 2009-03-06 20:29:29 +0100 | [diff] [blame] | 240 | char *start = p, *s; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 241 | |
Jens Axboe | 523bfad | 2007-04-04 11:04:06 +0200 | [diff] [blame] | 242 | s = strchr(p, ';'); |
| 243 | if (s) |
| 244 | *s = '\0'; |
| 245 | s = strchr(p, '#'); |
| 246 | if (s) |
| 247 | *s = '\0'; |
| 248 | if (s) |
| 249 | p = s; |
| 250 | |
Jens Axboe | 7f7e6e5 | 2007-07-19 14:50:05 +0200 | [diff] [blame] | 251 | s = p + strlen(p); |
Jens Axboe | 853ee7f | 2009-03-06 20:29:29 +0100 | [diff] [blame] | 252 | while ((isspace(*s) || iscntrl(*s)) && (s > start)) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 253 | s--; |
| 254 | |
| 255 | *(s + 1) = '\0'; |
| 256 | } |
| 257 | |
Jens Axboe | d6978a3 | 2009-07-18 21:04:09 +0200 | [diff] [blame] | 258 | static int check_range_bytes(const char *str, long *val, void *data) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 259 | { |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 260 | long long __val; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 261 | |
Jens Axboe | 57fc29f | 2010-06-23 22:24:07 +0200 | [diff] [blame] | 262 | if (!str_to_decimal(str, &__val, 1, data)) { |
| 263 | *val = __val; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 264 | return 0; |
| 265 | } |
| 266 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 267 | return 1; |
| 268 | } |
| 269 | |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 270 | static int check_int(const char *p, int *val) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 271 | { |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 272 | if (!strlen(p)) |
| 273 | return 1; |
Jens Axboe | d78ee46 | 2007-08-10 14:03:20 +0200 | [diff] [blame] | 274 | if (strstr(p, "0x") || strstr(p, "0X")) { |
Jens Axboe | a61bdfd | 2007-07-30 09:07:04 +0200 | [diff] [blame] | 275 | if (sscanf(p, "%x", val) == 1) |
| 276 | return 0; |
| 277 | } else { |
| 278 | if (sscanf(p, "%u", val) == 1) |
| 279 | return 0; |
| 280 | } |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 281 | |
| 282 | return 1; |
| 283 | } |
| 284 | |
Jens Axboe | 808def7 | 2010-07-14 16:27:02 -0600 | [diff] [blame] | 285 | static int opt_len(const char *str) |
| 286 | { |
| 287 | char *postfix; |
| 288 | |
| 289 | postfix = strchr(str, ':'); |
| 290 | if (!postfix) |
| 291 | return strlen(str); |
| 292 | |
| 293 | return (int)(postfix - str); |
| 294 | } |
| 295 | |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 296 | #define val_store(ptr, val, off, or, data) \ |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 297 | do { \ |
| 298 | ptr = td_var((data), (off)); \ |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 299 | if ((or)) \ |
| 300 | *ptr |= (val); \ |
| 301 | else \ |
| 302 | *ptr = (val); \ |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 303 | } while (0) |
| 304 | |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 305 | static int __handle_option(struct fio_option *o, const char *ptr, void *data, |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 306 | int first, int more) |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 307 | { |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 308 | int il, *ilp; |
| 309 | long long ull, *ullp; |
| 310 | long ul1, ul2; |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 311 | char **cp; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 312 | int ret = 0, is_time = 0; |
| 313 | |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 314 | dprint(FD_PARSE, "__handle_option=%s, type=%d, ptr=%s\n", o->name, |
| 315 | o->type, ptr); |
| 316 | |
Jens Axboe | e3cedca | 2008-11-19 19:57:52 +0100 | [diff] [blame] | 317 | if (!ptr && o->type != FIO_OPT_STR_SET && o->type != FIO_OPT_STR) { |
Jens Axboe | 08e26e3 | 2006-11-21 13:15:10 +0100 | [diff] [blame] | 318 | fprintf(stderr, "Option %s requires an argument\n", o->name); |
| 319 | return 1; |
| 320 | } |
| 321 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 322 | switch (o->type) { |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 323 | case FIO_OPT_STR: |
| 324 | case FIO_OPT_STR_MULTI: { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 325 | fio_opt_str_fn *fn = o->cb; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 326 | const struct value_pair *vp; |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 327 | struct value_pair posval[PARSE_MAX_VP]; |
Jens Axboe | ae2ddba | 2010-03-10 12:49:03 +0100 | [diff] [blame] | 328 | int i, all_skipped = 1; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 329 | |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 330 | posval_sort(o, posval); |
| 331 | |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 332 | ret = 1; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 333 | for (i = 0; i < PARSE_MAX_VP; i++) { |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 334 | vp = &posval[i]; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 335 | if (!vp->ival || vp->ival[0] == '\0') |
Jens Axboe | a3073f4 | 2010-03-05 10:06:15 +0100 | [diff] [blame] | 336 | continue; |
Jens Axboe | ae2ddba | 2010-03-10 12:49:03 +0100 | [diff] [blame] | 337 | all_skipped = 0; |
Jens Axboe | 808def7 | 2010-07-14 16:27:02 -0600 | [diff] [blame] | 338 | if (!strncmp(vp->ival, ptr, opt_len(ptr))) { |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 339 | ret = 0; |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 340 | if (o->roff1) { |
| 341 | if (vp->or) |
| 342 | *(unsigned int *) o->roff1 |= vp->oval; |
| 343 | else |
| 344 | *(unsigned int *) o->roff1 = vp->oval; |
| 345 | } else { |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 346 | if (!o->off1) |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 347 | continue; |
| 348 | val_store(ilp, vp->oval, o->off1, vp->or, data); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 349 | } |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 350 | continue; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Jens Axboe | ae2ddba | 2010-03-10 12:49:03 +0100 | [diff] [blame] | 354 | if (ret && !all_skipped) |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 355 | show_option_values(o); |
| 356 | else if (fn) |
| 357 | ret = fn(data, ptr); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 358 | break; |
| 359 | } |
| 360 | case FIO_OPT_STR_VAL_TIME: |
| 361 | is_time = 1; |
Jens Axboe | f7fa265 | 2009-03-09 14:20:20 +0100 | [diff] [blame] | 362 | case FIO_OPT_INT: |
Jens Axboe | e01b22b | 2009-06-09 15:43:25 +0200 | [diff] [blame] | 363 | case FIO_OPT_STR_VAL: { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 364 | fio_opt_str_val_fn *fn = o->cb; |
| 365 | |
| 366 | if (is_time) |
| 367 | ret = check_str_time(ptr, &ull); |
| 368 | else |
Jens Axboe | d6978a3 | 2009-07-18 21:04:09 +0200 | [diff] [blame] | 369 | ret = check_str_bytes(ptr, &ull, data); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 370 | |
| 371 | if (ret) |
| 372 | break; |
| 373 | |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 374 | if (o->maxval && ull > o->maxval) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 375 | fprintf(stderr, "max value out of range: %lld" |
| 376 | " (%d max)\n", ull, o->maxval); |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 377 | return 1; |
| 378 | } |
| 379 | if (o->minval && ull < o->minval) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 380 | fprintf(stderr, "min value out of range: %lld" |
| 381 | " (%d min)\n", ull, o->minval); |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 382 | return 1; |
| 383 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 384 | |
| 385 | if (fn) |
| 386 | ret = fn(data, &ull); |
| 387 | else { |
Jens Axboe | e01b22b | 2009-06-09 15:43:25 +0200 | [diff] [blame] | 388 | if (o->type == FIO_OPT_INT) { |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 389 | if (first) { |
| 390 | if (o->roff1) |
Jens Axboe | 7758d4f | 2010-03-18 16:50:31 +0100 | [diff] [blame] | 391 | *(unsigned int *) o->roff1 = ull; |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 392 | else |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 393 | val_store(ilp, ull, o->off1, 0, data); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 394 | } |
| 395 | if (!more) { |
| 396 | if (o->roff2) |
Jens Axboe | 7758d4f | 2010-03-18 16:50:31 +0100 | [diff] [blame] | 397 | *(unsigned int *) o->roff2 = ull; |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 398 | else if (o->off2) |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 399 | val_store(ilp, ull, o->off2, 0, data); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 400 | } |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 401 | } else { |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 402 | if (first) { |
| 403 | if (o->roff1) |
| 404 | *(unsigned long long *) o->roff1 = ull; |
| 405 | else |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 406 | val_store(ullp, ull, o->off1, 0, data); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 407 | } |
| 408 | if (!more) { |
| 409 | if (o->roff2) |
| 410 | *(unsigned long long *) o->roff2 = ull; |
| 411 | else if (o->off2) |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 412 | val_store(ullp, ull, o->off2, 0, data); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 413 | } |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 414 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 415 | } |
| 416 | break; |
| 417 | } |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 418 | case FIO_OPT_STR_STORE: { |
| 419 | fio_opt_str_fn *fn = o->cb; |
| 420 | |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 421 | if (o->roff1) |
| 422 | cp = (char **) o->roff1; |
| 423 | else |
| 424 | cp = td_var(data, o->off1); |
| 425 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 426 | *cp = strdup(ptr); |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 427 | if (fn) { |
| 428 | ret = fn(data, ptr); |
| 429 | if (ret) { |
| 430 | free(*cp); |
| 431 | *cp = NULL; |
| 432 | } |
| 433 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 434 | break; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 435 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 436 | case FIO_OPT_RANGE: { |
Jens Axboe | b765a37 | 2006-10-27 15:00:16 +0200 | [diff] [blame] | 437 | char tmp[128]; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 438 | char *p1, *p2; |
| 439 | |
Jens Axboe | 0bbab0e | 2006-11-02 09:18:36 +0100 | [diff] [blame] | 440 | strncpy(tmp, ptr, sizeof(tmp) - 1); |
Jens Axboe | b765a37 | 2006-10-27 15:00:16 +0200 | [diff] [blame] | 441 | |
| 442 | p1 = strchr(tmp, '-'); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 443 | if (!p1) { |
Jens Axboe | 0c9baf9 | 2007-01-11 15:59:26 +0100 | [diff] [blame] | 444 | p1 = strchr(tmp, ':'); |
| 445 | if (!p1) { |
| 446 | ret = 1; |
| 447 | break; |
| 448 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | p2 = p1 + 1; |
| 452 | *p1 = '\0'; |
Jens Axboe | b765a37 | 2006-10-27 15:00:16 +0200 | [diff] [blame] | 453 | p1 = tmp; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 454 | |
| 455 | ret = 1; |
Jens Axboe | d6978a3 | 2009-07-18 21:04:09 +0200 | [diff] [blame] | 456 | if (!check_range_bytes(p1, &ul1, data) && |
| 457 | !check_range_bytes(p2, &ul2, data)) { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 458 | ret = 0; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 459 | if (ul1 > ul2) { |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 460 | unsigned long foo = ul1; |
| 461 | |
| 462 | ul1 = ul2; |
| 463 | ul2 = foo; |
| 464 | } |
| 465 | |
| 466 | if (first) { |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 467 | if (o->roff1) |
Jens Axboe | 7758d4f | 2010-03-18 16:50:31 +0100 | [diff] [blame] | 468 | *(unsigned int *) o->roff1 = ul1; |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 469 | else |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 470 | val_store(ilp, ul1, o->off1, 0, data); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 471 | if (o->roff2) |
Jens Axboe | 7758d4f | 2010-03-18 16:50:31 +0100 | [diff] [blame] | 472 | *(unsigned int *) o->roff2 = ul2; |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 473 | else |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 474 | val_store(ilp, ul2, o->off2, 0, data); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 475 | } |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 476 | if (o->roff3 && o->roff4) { |
Jens Axboe | 7758d4f | 2010-03-18 16:50:31 +0100 | [diff] [blame] | 477 | *(unsigned int *) o->roff3 = ul1; |
| 478 | *(unsigned int *) o->roff4 = ul2; |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 479 | } else if (o->off3 && o->off4) { |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 480 | val_store(ilp, ul1, o->off3, 0, data); |
| 481 | val_store(ilp, ul2, o->off4, 0, data); |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 485 | break; |
| 486 | } |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 487 | case FIO_OPT_BOOL: { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 488 | fio_opt_int_fn *fn = o->cb; |
| 489 | |
| 490 | ret = check_int(ptr, &il); |
| 491 | if (ret) |
| 492 | break; |
| 493 | |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 494 | if (o->maxval && il > (int) o->maxval) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 495 | fprintf(stderr, "max value out of range: %d (%d max)\n", |
| 496 | il, o->maxval); |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 497 | return 1; |
| 498 | } |
| 499 | if (o->minval && il < o->minval) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 500 | fprintf(stderr, "min value out of range: %d (%d min)\n", |
| 501 | il, o->minval); |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 502 | return 1; |
| 503 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 504 | |
Jens Axboe | 76a43db | 2007-01-11 13:24:44 +0100 | [diff] [blame] | 505 | if (o->neg) |
| 506 | il = !il; |
| 507 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 508 | if (fn) |
| 509 | ret = fn(data, &il); |
| 510 | else { |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 511 | if (first) { |
| 512 | if (o->roff1) |
| 513 | *(unsigned int *)o->roff1 = il; |
| 514 | else |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 515 | val_store(ilp, il, o->off1, 0, data); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 516 | } |
| 517 | if (!more) { |
| 518 | if (o->roff2) |
| 519 | *(unsigned int *) o->roff2 = il; |
| 520 | else if (o->off2) |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 521 | val_store(ilp, il, o->off2, 0, data); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 522 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 523 | } |
| 524 | break; |
| 525 | } |
| 526 | case FIO_OPT_STR_SET: { |
| 527 | fio_opt_str_set_fn *fn = o->cb; |
| 528 | |
| 529 | if (fn) |
| 530 | ret = fn(data); |
| 531 | else { |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 532 | if (first) { |
| 533 | if (o->roff1) |
| 534 | *(unsigned int *) o->roff1 = 1; |
| 535 | else |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 536 | val_store(ilp, 1, o->off1, 0, data); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 537 | } |
| 538 | if (!more) { |
| 539 | if (o->roff2) |
| 540 | *(unsigned int *) o->roff2 = 1; |
| 541 | else if (o->off2) |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 542 | val_store(ilp, 1, o->off2, 0, data); |
Jens Axboe | 02c6aad | 2010-03-04 13:49:11 +0100 | [diff] [blame] | 543 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 544 | } |
| 545 | break; |
| 546 | } |
Jens Axboe | 15ca150 | 2008-04-07 09:26:02 +0200 | [diff] [blame] | 547 | case FIO_OPT_DEPRECATED: |
| 548 | fprintf(stdout, "Option %s is deprecated\n", o->name); |
| 549 | break; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 550 | default: |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 551 | fprintf(stderr, "Bad option type %u\n", o->type); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 552 | ret = 1; |
| 553 | } |
| 554 | |
Jens Axboe | 70a4c0c | 2009-07-01 09:24:05 +0200 | [diff] [blame] | 555 | if (ret) |
| 556 | return ret; |
| 557 | |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 558 | if (o->verify) { |
Jens Axboe | 70a4c0c | 2009-07-01 09:24:05 +0200 | [diff] [blame] | 559 | ret = o->verify(o, data); |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 560 | if (ret) { |
| 561 | fprintf(stderr,"Correct format for offending option\n"); |
| 562 | fprintf(stderr, "%20s: %s\n", o->name, o->help); |
| 563 | show_option_help(o, stderr); |
| 564 | } |
| 565 | } |
Jens Axboe | 70a4c0c | 2009-07-01 09:24:05 +0200 | [diff] [blame] | 566 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 567 | return ret; |
| 568 | } |
| 569 | |
Jens Axboe | 7c8f1a5 | 2009-06-09 12:28:57 +0200 | [diff] [blame] | 570 | static int handle_option(struct fio_option *o, const char *__ptr, void *data) |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 571 | { |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 572 | char *o_ptr, *ptr, *ptr2; |
| 573 | int ret, done; |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 574 | |
Jens Axboe | 7c8f1a5 | 2009-06-09 12:28:57 +0200 | [diff] [blame] | 575 | dprint(FD_PARSE, "handle_option=%s, ptr=%s\n", o->name, __ptr); |
| 576 | |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 577 | o_ptr = ptr = NULL; |
Jens Axboe | 7c8f1a5 | 2009-06-09 12:28:57 +0200 | [diff] [blame] | 578 | if (__ptr) |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 579 | o_ptr = ptr = strdup(__ptr); |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 580 | |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 581 | /* |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 582 | * See if we have another set of parameters, hidden after a comma. |
| 583 | * Do this before parsing this round, to check if we should |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 584 | * copy set 1 options to set 2. |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 585 | */ |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 586 | done = 0; |
| 587 | ret = 1; |
| 588 | do { |
| 589 | int __ret; |
| 590 | |
| 591 | ptr2 = NULL; |
| 592 | if (ptr && |
| 593 | (o->type != FIO_OPT_STR_STORE) && |
| 594 | (o->type != FIO_OPT_STR)) { |
| 595 | ptr2 = strchr(ptr, ','); |
| 596 | if (ptr2 && *(ptr2 + 1) == '\0') |
| 597 | *ptr2 = '\0'; |
| 598 | if (o->type != FIO_OPT_STR_MULTI) { |
| 599 | if (!ptr2) |
| 600 | ptr2 = strchr(ptr, ':'); |
| 601 | if (!ptr2) |
| 602 | ptr2 = strchr(ptr, '-'); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | /* |
| 607 | * Don't return early if parsing the first option fails - if |
| 608 | * we are doing multiple arguments, we can allow the first one |
| 609 | * being empty. |
| 610 | */ |
| 611 | __ret = __handle_option(o, ptr, data, !done, !!ptr2); |
| 612 | if (ret) |
| 613 | ret = __ret; |
| 614 | |
Jens Axboe | 0c9baf9 | 2007-01-11 15:59:26 +0100 | [diff] [blame] | 615 | if (!ptr2) |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 616 | break; |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 617 | |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 618 | ptr = ptr2 + 1; |
| 619 | done++; |
| 620 | } while (1); |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 621 | |
Jens Axboe | b62bdf2 | 2010-03-10 12:36:17 +0100 | [diff] [blame] | 622 | if (o_ptr) |
| 623 | free(o_ptr); |
| 624 | return ret; |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 625 | } |
| 626 | |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 627 | static struct fio_option *get_option(const char *opt, |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 628 | struct fio_option *options, char **post) |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 629 | { |
| 630 | struct fio_option *o; |
| 631 | char *ret; |
| 632 | |
| 633 | ret = strchr(opt, '='); |
| 634 | if (ret) { |
| 635 | *post = ret; |
| 636 | *ret = '\0'; |
| 637 | ret = (char *) opt; |
| 638 | (*post)++; |
Jens Axboe | 43c129b | 2008-12-08 14:06:42 +0100 | [diff] [blame] | 639 | strip_blank_end(ret); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 640 | o = find_option(options, ret); |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 641 | } else { |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 642 | o = find_option(options, opt); |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 643 | *post = NULL; |
| 644 | } |
| 645 | |
| 646 | return o; |
| 647 | } |
| 648 | |
| 649 | static int opt_cmp(const void *p1, const void *p2) |
| 650 | { |
| 651 | struct fio_option *o1, *o2; |
| 652 | char *s1, *s2, *foo; |
Jens Axboe | 8cdabc1 | 2008-11-19 12:31:43 +0100 | [diff] [blame] | 653 | int prio1, prio2; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 654 | |
| 655 | s1 = strdup(*((char **) p1)); |
| 656 | s2 = strdup(*((char **) p2)); |
| 657 | |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 658 | o1 = get_option(s1, fio_options, &foo); |
| 659 | o2 = get_option(s2, fio_options, &foo); |
Jens Axboe | 0b9d69e | 2009-09-11 22:29:54 +0200 | [diff] [blame] | 660 | |
Jens Axboe | 8cdabc1 | 2008-11-19 12:31:43 +0100 | [diff] [blame] | 661 | prio1 = prio2 = 0; |
| 662 | if (o1) |
| 663 | prio1 = o1->prio; |
| 664 | if (o2) |
| 665 | prio2 = o2->prio; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 666 | |
| 667 | free(s1); |
| 668 | free(s2); |
Jens Axboe | 8cdabc1 | 2008-11-19 12:31:43 +0100 | [diff] [blame] | 669 | return prio2 - prio1; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | void sort_options(char **opts, struct fio_option *options, int num_opts) |
| 673 | { |
| 674 | fio_options = options; |
| 675 | qsort(opts, num_opts, sizeof(char *), opt_cmp); |
| 676 | fio_options = NULL; |
| 677 | } |
| 678 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 679 | int parse_cmd_option(const char *opt, const char *val, |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 680 | struct fio_option *options, void *data) |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 681 | { |
| 682 | struct fio_option *o; |
| 683 | |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 684 | o = find_option(options, opt); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 685 | if (!o) { |
Jens Axboe | 43c129b | 2008-12-08 14:06:42 +0100 | [diff] [blame] | 686 | fprintf(stderr, "Bad option <%s>\n", opt); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 687 | return 1; |
| 688 | } |
| 689 | |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 690 | if (!handle_option(o, val, data)) |
| 691 | return 0; |
| 692 | |
| 693 | fprintf(stderr, "fio: failed parsing %s=%s\n", opt, val); |
| 694 | return 1; |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 695 | } |
| 696 | |
Aaron Carroll | 88b5a39 | 2008-10-07 11:25:20 +0200 | [diff] [blame] | 697 | /* |
| 698 | * Return a copy of the input string with substrings of the form ${VARNAME} |
| 699 | * substituted with the value of the environment variable VARNAME. The |
| 700 | * substitution always occurs, even if VARNAME is empty or the corresponding |
| 701 | * environment variable undefined. |
| 702 | */ |
| 703 | static char *option_dup_subs(const char *opt) |
| 704 | { |
| 705 | char out[OPT_LEN_MAX+1]; |
| 706 | char in[OPT_LEN_MAX+1]; |
| 707 | char *outptr = out; |
| 708 | char *inptr = in; |
| 709 | char *ch1, *ch2, *env; |
| 710 | ssize_t nchr = OPT_LEN_MAX; |
| 711 | size_t envlen; |
| 712 | |
Jens Axboe | a0741cb | 2010-03-05 12:46:37 +0100 | [diff] [blame] | 713 | if (strlen(opt) + 1 > OPT_LEN_MAX) { |
Jens Axboe | 38789b5 | 2010-03-03 09:23:20 +0100 | [diff] [blame] | 714 | fprintf(stderr, "OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX); |
| 715 | return NULL; |
| 716 | } |
| 717 | |
Aaron Carroll | 88b5a39 | 2008-10-07 11:25:20 +0200 | [diff] [blame] | 718 | in[OPT_LEN_MAX] = '\0'; |
| 719 | strncpy(in, opt, OPT_LEN_MAX); |
| 720 | |
| 721 | while (*inptr && nchr > 0) { |
| 722 | if (inptr[0] == '$' && inptr[1] == '{') { |
| 723 | ch2 = strchr(inptr, '}'); |
| 724 | if (ch2 && inptr+1 < ch2) { |
| 725 | ch1 = inptr+2; |
| 726 | inptr = ch2+1; |
| 727 | *ch2 = '\0'; |
| 728 | |
| 729 | env = getenv(ch1); |
| 730 | if (env) { |
| 731 | envlen = strlen(env); |
| 732 | if (envlen <= nchr) { |
| 733 | memcpy(outptr, env, envlen); |
| 734 | outptr += envlen; |
| 735 | nchr -= envlen; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | continue; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | *outptr++ = *inptr++; |
| 744 | --nchr; |
| 745 | } |
| 746 | |
| 747 | *outptr = '\0'; |
| 748 | return strdup(out); |
| 749 | } |
| 750 | |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 751 | int parse_option(const char *opt, struct fio_option *options, void *data) |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 752 | { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 753 | struct fio_option *o; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 754 | char *post, *tmp; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 755 | |
Aaron Carroll | 88b5a39 | 2008-10-07 11:25:20 +0200 | [diff] [blame] | 756 | tmp = option_dup_subs(opt); |
Jens Axboe | 38789b5 | 2010-03-03 09:23:20 +0100 | [diff] [blame] | 757 | if (!tmp) |
| 758 | return 1; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 759 | |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 760 | o = get_option(tmp, options, &post); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 761 | if (!o) { |
Jens Axboe | 43c129b | 2008-12-08 14:06:42 +0100 | [diff] [blame] | 762 | fprintf(stderr, "Bad option <%s>\n", tmp); |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 763 | free(tmp); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 764 | return 1; |
| 765 | } |
| 766 | |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 767 | if (!handle_option(o, post, data)) { |
| 768 | free(tmp); |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 769 | return 0; |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 770 | } |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 771 | |
| 772 | fprintf(stderr, "fio: failed parsing %s\n", opt); |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 773 | free(tmp); |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 774 | return 1; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 775 | } |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 776 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 777 | /* |
| 778 | * Option match, levenshtein distance. Handy for not quite remembering what |
| 779 | * the option name is. |
| 780 | */ |
| 781 | static int string_distance(const char *s1, const char *s2) |
| 782 | { |
| 783 | unsigned int s1_len = strlen(s1); |
| 784 | unsigned int s2_len = strlen(s2); |
| 785 | unsigned int *p, *q, *r; |
| 786 | unsigned int i, j; |
| 787 | |
| 788 | p = malloc(sizeof(unsigned int) * (s2_len + 1)); |
| 789 | q = malloc(sizeof(unsigned int) * (s2_len + 1)); |
| 790 | |
| 791 | p[0] = 0; |
| 792 | for (i = 1; i <= s2_len; i++) |
| 793 | p[i] = p[i - 1] + 1; |
| 794 | |
| 795 | for (i = 1; i <= s1_len; i++) { |
| 796 | q[0] = p[0] + 1; |
| 797 | for (j = 1; j <= s2_len; j++) { |
| 798 | unsigned int sub = p[j - 1]; |
| 799 | |
| 800 | if (s1[i - 1] != s2[j - 1]) |
| 801 | sub++; |
| 802 | |
| 803 | q[j] = min(p[j] + 1, min(q[j - 1] + 1, sub)); |
| 804 | } |
| 805 | r = p; |
| 806 | p = q; |
| 807 | q = r; |
| 808 | } |
| 809 | |
| 810 | i = p[s2_len]; |
| 811 | free(p); |
| 812 | free(q); |
| 813 | return i; |
| 814 | } |
| 815 | |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 816 | static struct fio_option *find_child(struct fio_option *options, |
| 817 | struct fio_option *o) |
| 818 | { |
| 819 | struct fio_option *__o; |
| 820 | |
Jens Axboe | fdf2874 | 2007-07-31 23:06:09 +0200 | [diff] [blame] | 821 | for (__o = options + 1; __o->name; __o++) |
| 822 | if (__o->parent && !strcmp(__o->parent, o->name)) |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 823 | return __o; |
| 824 | |
| 825 | return NULL; |
| 826 | } |
| 827 | |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 828 | static void __print_option(struct fio_option *o, struct fio_option *org, |
| 829 | int level) |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 830 | { |
| 831 | char name[256], *p; |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 832 | int depth; |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 833 | |
| 834 | if (!o) |
| 835 | return; |
Jens Axboe | ef9aff5 | 2007-07-31 22:56:53 +0200 | [diff] [blame] | 836 | if (!org) |
| 837 | org = o; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 838 | |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 839 | p = name; |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 840 | depth = level; |
| 841 | while (depth--) |
| 842 | p += sprintf(p, "%s", " "); |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 843 | |
| 844 | sprintf(p, "%s", o->name); |
| 845 | |
| 846 | printf("%-24s: %s\n", name, o->help); |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | static void print_option(struct fio_option *o) |
| 850 | { |
| 851 | struct fio_option *parent; |
| 852 | struct fio_option *__o; |
| 853 | unsigned int printed; |
| 854 | unsigned int level; |
| 855 | |
| 856 | __print_option(o, NULL, 0); |
| 857 | parent = o; |
| 858 | level = 0; |
| 859 | do { |
| 860 | level++; |
| 861 | printed = 0; |
| 862 | |
| 863 | while ((__o = find_child(o, parent)) != NULL) { |
| 864 | __print_option(__o, o, level); |
| 865 | o = __o; |
| 866 | printed++; |
| 867 | } |
| 868 | |
| 869 | parent = o; |
| 870 | } while (printed); |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 871 | } |
| 872 | |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 873 | int show_cmd_help(struct fio_option *options, const char *name) |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 874 | { |
| 875 | struct fio_option *o, *closest; |
Jens Axboe | d091d09 | 2010-04-01 19:56:23 +0200 | [diff] [blame] | 876 | unsigned int best_dist = -1U; |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 877 | int found = 0; |
Jens Axboe | 320beef | 2007-03-01 10:44:12 +0100 | [diff] [blame] | 878 | int show_all = 0; |
| 879 | |
| 880 | if (!name || !strcmp(name, "all")) |
| 881 | show_all = 1; |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 882 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 883 | closest = NULL; |
| 884 | best_dist = -1; |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 885 | for (o = &options[0]; o->name; o++) { |
Jens Axboe | 320beef | 2007-03-01 10:44:12 +0100 | [diff] [blame] | 886 | int match = 0; |
| 887 | |
Jens Axboe | 15ca150 | 2008-04-07 09:26:02 +0200 | [diff] [blame] | 888 | if (o->type == FIO_OPT_DEPRECATED) |
| 889 | continue; |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 890 | if (!exec_profile && o->prof_name) |
| 891 | continue; |
Jens Axboe | 15ca150 | 2008-04-07 09:26:02 +0200 | [diff] [blame] | 892 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 893 | if (name) { |
Jens Axboe | 7f9348f | 2007-03-15 14:09:28 +0100 | [diff] [blame] | 894 | if (!strcmp(name, o->name) || |
| 895 | (o->alias && !strcmp(name, o->alias))) |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 896 | match = 1; |
| 897 | else { |
| 898 | unsigned int dist; |
| 899 | |
| 900 | dist = string_distance(name, o->name); |
| 901 | if (dist < best_dist) { |
| 902 | best_dist = dist; |
| 903 | closest = o; |
| 904 | } |
| 905 | } |
| 906 | } |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 907 | |
| 908 | if (show_all || match) { |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 909 | found = 1; |
Jens Axboe | c167ded | 2007-03-14 13:02:53 +0100 | [diff] [blame] | 910 | if (match) |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 911 | printf("%20s: %s\n", o->name, o->help); |
Jens Axboe | c167ded | 2007-03-14 13:02:53 +0100 | [diff] [blame] | 912 | if (show_all) { |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 913 | if (!o->parent) |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 914 | print_option(o); |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 915 | continue; |
Jens Axboe | c167ded | 2007-03-14 13:02:53 +0100 | [diff] [blame] | 916 | } |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 917 | } |
| 918 | |
Jens Axboe | 70df2f1 | 2007-01-11 14:04:47 +0100 | [diff] [blame] | 919 | if (!match) |
| 920 | continue; |
| 921 | |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 922 | show_option_help(o, stdout); |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 923 | } |
| 924 | |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 925 | if (found) |
| 926 | return 0; |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 927 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 928 | printf("No such command: %s", name); |
Jens Axboe | d091d09 | 2010-04-01 19:56:23 +0200 | [diff] [blame] | 929 | |
| 930 | /* |
| 931 | * Only print an appropriately close option, one where the edit |
| 932 | * distance isn't too big. Otherwise we get crazy matches. |
| 933 | */ |
| 934 | if (closest && best_dist < 3) { |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 935 | printf(" - showing closest match\n"); |
| 936 | printf("%20s: %s\n", closest->name, closest->help); |
Jens Axboe | d447a8c | 2009-07-17 22:26:15 +0200 | [diff] [blame] | 937 | show_option_help(closest, stdout); |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 938 | } else |
| 939 | printf("\n"); |
| 940 | |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 941 | return 1; |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 942 | } |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 943 | |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 944 | /* |
| 945 | * Handle parsing of default parameters. |
| 946 | */ |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 947 | void fill_default_options(void *data, struct fio_option *options) |
| 948 | { |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 949 | struct fio_option *o; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 950 | |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 951 | dprint(FD_PARSE, "filling default options\n"); |
| 952 | |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 953 | for (o = &options[0]; o->name; o++) |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 954 | if (o->def) |
| 955 | handle_option(o, o->def, data); |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 956 | } |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 957 | |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 958 | void option_init(struct fio_option *o) |
| 959 | { |
| 960 | if (o->type == FIO_OPT_DEPRECATED) |
| 961 | return; |
| 962 | if (o->type == FIO_OPT_BOOL) { |
| 963 | o->minval = 0; |
| 964 | o->maxval = 1; |
| 965 | } |
| 966 | if (o->type == FIO_OPT_STR_SET && o->def) { |
| 967 | fprintf(stderr, "Option %s: string set option with" |
| 968 | " default will always be true\n", o->name); |
| 969 | } |
Jens Axboe | e2de69d | 2010-03-04 14:05:48 +0100 | [diff] [blame] | 970 | if (!o->cb && (!o->off1 && !o->roff1)) { |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 971 | fprintf(stderr, "Option %s: neither cb nor offset given\n", |
| 972 | o->name); |
| 973 | } |
Jens Axboe | 5f6ddf1 | 2010-03-09 20:40:44 +0100 | [diff] [blame] | 974 | if (o->type == FIO_OPT_STR || o->type == FIO_OPT_STR_STORE || |
| 975 | o->type == FIO_OPT_STR_MULTI) |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 976 | return; |
Jens Axboe | e2de69d | 2010-03-04 14:05:48 +0100 | [diff] [blame] | 977 | if (o->cb && ((o->off1 || o->off2 || o->off3 || o->off4) || |
| 978 | (o->roff1 || o->roff2 || o->roff3 || o->roff4))) { |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 979 | fprintf(stderr, "Option %s: both cb and offset given\n", |
| 980 | o->name); |
| 981 | } |
| 982 | } |
| 983 | |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 984 | /* |
| 985 | * Sanitize the options structure. For now it just sets min/max for bool |
Jens Axboe | 5b0a888 | 2007-01-11 14:40:27 +0100 | [diff] [blame] | 986 | * values and whether both callback and offsets are given. |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 987 | */ |
| 988 | void options_init(struct fio_option *options) |
| 989 | { |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 990 | struct fio_option *o; |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 991 | |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 992 | dprint(FD_PARSE, "init options\n"); |
| 993 | |
Jens Axboe | 9f988e2 | 2010-03-04 10:42:38 +0100 | [diff] [blame] | 994 | for (o = &options[0]; o->name; o++) |
| 995 | option_init(o); |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 996 | } |