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> |
| 11 | |
| 12 | #include "parse.h" |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 13 | #include "debug.h" |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 14 | |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 15 | static int vp_cmp(const void *p1, const void *p2) |
| 16 | { |
| 17 | const struct value_pair *vp1 = p1; |
| 18 | const struct value_pair *vp2 = p2; |
| 19 | |
| 20 | return strlen(vp2->ival) - strlen(vp1->ival); |
| 21 | } |
| 22 | |
| 23 | static void posval_sort(struct fio_option *o, struct value_pair *vpmap) |
| 24 | { |
| 25 | const struct value_pair *vp; |
| 26 | int entries; |
| 27 | |
| 28 | memset(vpmap, 0, PARSE_MAX_VP * sizeof(struct value_pair)); |
| 29 | |
| 30 | for (entries = 0; entries < PARSE_MAX_VP; entries++) { |
| 31 | vp = &o->posval[entries]; |
| 32 | if (!vp->ival || vp->ival[0] == '\0') |
| 33 | break; |
| 34 | |
| 35 | memcpy(&vpmap[entries], vp, sizeof(*vp)); |
| 36 | } |
| 37 | |
| 38 | qsort(vpmap, entries, sizeof(struct value_pair), vp_cmp); |
| 39 | } |
| 40 | |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 41 | static void show_option_range(struct fio_option *o) |
| 42 | { |
| 43 | if (!o->minval && !o->maxval) |
| 44 | return; |
| 45 | |
Jens Axboe | ec1aee0 | 2007-02-26 13:18:47 +0100 | [diff] [blame] | 46 | printf("%20s: min=%d, max=%d\n", "range", o->minval, o->maxval); |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static void show_option_values(struct fio_option *o) |
| 50 | { |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 51 | int i = 0; |
| 52 | |
| 53 | do { |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 54 | const struct value_pair *vp = &o->posval[i]; |
| 55 | |
| 56 | if (!vp->ival) |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 57 | break; |
| 58 | |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 59 | printf("%20s: %-10s", i == 0 ? "valid values" : "", vp->ival); |
| 60 | if (vp->help) |
| 61 | printf(" %s", vp->help); |
| 62 | printf("\n"); |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 63 | i++; |
| 64 | } while (i < PARSE_MAX_VP); |
| 65 | |
| 66 | if (i) |
| 67 | printf("\n"); |
| 68 | } |
| 69 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 70 | static unsigned long get_mult_time(char c) |
| 71 | { |
| 72 | switch (c) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 73 | case 'm': |
| 74 | case 'M': |
| 75 | return 60; |
| 76 | case 'h': |
| 77 | case 'H': |
| 78 | return 60 * 60; |
| 79 | case 'd': |
| 80 | case 'D': |
| 81 | return 24 * 60 * 60; |
| 82 | default: |
| 83 | return 1; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
| 87 | static unsigned long get_mult_bytes(char c) |
| 88 | { |
| 89 | switch (c) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 90 | case 'k': |
| 91 | case 'K': |
| 92 | return 1024; |
| 93 | case 'm': |
| 94 | case 'M': |
| 95 | return 1024 * 1024; |
| 96 | case 'g': |
| 97 | case 'G': |
| 98 | return 1024 * 1024 * 1024; |
| 99 | case 'e': |
| 100 | case 'E': |
| 101 | return 1024 * 1024 * 1024 * 1024UL; |
| 102 | default: |
| 103 | return 1; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
| 107 | /* |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 108 | * convert string into decimal value, noting any size suffix |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 109 | */ |
Jens Axboe | 564ca97 | 2007-12-14 12:21:19 +0100 | [diff] [blame] | 110 | int str_to_decimal(const char *str, long long *val, int kilo) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 111 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 112 | int len; |
| 113 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 114 | len = strlen(str); |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 115 | if (!len) |
| 116 | return 1; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 117 | |
Jens Axboe | 675de85 | 2007-02-10 19:01:07 +0100 | [diff] [blame] | 118 | *val = strtoll(str, NULL, 10); |
Jens Axboe | cda866c | 2007-01-10 16:02:32 +0100 | [diff] [blame] | 119 | if (*val == LONG_MAX && errno == ERANGE) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 120 | return 1; |
| 121 | |
| 122 | if (kilo) |
| 123 | *val *= get_mult_bytes(str[len - 1]); |
| 124 | else |
| 125 | *val *= get_mult_time(str[len - 1]); |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 126 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 130 | static int check_str_bytes(const char *p, long long *val) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 131 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 132 | return str_to_decimal(p, val, 1); |
| 133 | } |
| 134 | |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 135 | static int check_str_time(const char *p, long long *val) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 136 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 137 | return str_to_decimal(p, val, 0); |
| 138 | } |
| 139 | |
| 140 | void strip_blank_front(char **p) |
| 141 | { |
| 142 | char *s = *p; |
| 143 | |
| 144 | while (isspace(*s)) |
| 145 | s++; |
Jens Axboe | 4d651da | 2007-03-28 19:34:53 +0200 | [diff] [blame] | 146 | |
| 147 | *p = s; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | void strip_blank_end(char *p) |
| 151 | { |
Jens Axboe | 523bfad | 2007-04-04 11:04:06 +0200 | [diff] [blame] | 152 | char *s; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 153 | |
Jens Axboe | 523bfad | 2007-04-04 11:04:06 +0200 | [diff] [blame] | 154 | s = strchr(p, ';'); |
| 155 | if (s) |
| 156 | *s = '\0'; |
| 157 | s = strchr(p, '#'); |
| 158 | if (s) |
| 159 | *s = '\0'; |
| 160 | if (s) |
| 161 | p = s; |
| 162 | |
Jens Axboe | 7f7e6e5 | 2007-07-19 14:50:05 +0200 | [diff] [blame] | 163 | s = p + strlen(p); |
| 164 | while ((isspace(*s) || iscntrl(*s)) && (s > p)) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 165 | s--; |
| 166 | |
| 167 | *(s + 1) = '\0'; |
| 168 | } |
| 169 | |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 170 | static int check_range_bytes(const char *str, long *val) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 171 | { |
| 172 | char suffix; |
| 173 | |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 174 | if (!strlen(str)) |
| 175 | return 1; |
| 176 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 177 | if (sscanf(str, "%lu%c", val, &suffix) == 2) { |
| 178 | *val *= get_mult_bytes(suffix); |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | if (sscanf(str, "%lu", val) == 1) |
| 183 | return 0; |
| 184 | |
| 185 | return 1; |
| 186 | } |
| 187 | |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 188 | static int check_int(const char *p, int *val) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 189 | { |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 190 | if (!strlen(p)) |
| 191 | return 1; |
Jens Axboe | d78ee46 | 2007-08-10 14:03:20 +0200 | [diff] [blame] | 192 | if (strstr(p, "0x") || strstr(p, "0X")) { |
Jens Axboe | a61bdfd | 2007-07-30 09:07:04 +0200 | [diff] [blame] | 193 | if (sscanf(p, "%x", val) == 1) |
| 194 | return 0; |
| 195 | } else { |
| 196 | if (sscanf(p, "%u", val) == 1) |
| 197 | return 0; |
| 198 | } |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 199 | |
| 200 | return 1; |
| 201 | } |
| 202 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 203 | static struct fio_option *find_option(struct fio_option *options, |
| 204 | const char *opt) |
| 205 | { |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 206 | struct fio_option *o; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 207 | |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 208 | for (o = &options[0]; o->name; o++) { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 209 | if (!strcmp(o->name, opt)) |
| 210 | return o; |
Jens Axboe | 03b74b3 | 2007-01-11 11:04:31 +0100 | [diff] [blame] | 211 | else if (o->alias && !strcmp(o->alias, opt)) |
| 212 | return o; |
Jens Axboe | 33963c6 | 2006-10-27 11:33:01 +0200 | [diff] [blame] | 213 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 214 | |
| 215 | return NULL; |
| 216 | } |
| 217 | |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 218 | #define val_store(ptr, val, off, data) \ |
| 219 | do { \ |
| 220 | ptr = td_var((data), (off)); \ |
| 221 | *ptr = (val); \ |
| 222 | } while (0) |
| 223 | |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 224 | 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] | 225 | int first, int more) |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 226 | { |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 227 | int il, *ilp; |
| 228 | long long ull, *ullp; |
| 229 | long ul1, ul2; |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 230 | char **cp; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 231 | int ret = 0, is_time = 0; |
| 232 | |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 233 | dprint(FD_PARSE, "__handle_option=%s, type=%d, ptr=%s\n", o->name, |
| 234 | o->type, ptr); |
| 235 | |
Jens Axboe | 08e26e3 | 2006-11-21 13:15:10 +0100 | [diff] [blame] | 236 | if (!ptr && o->type != FIO_OPT_STR_SET) { |
| 237 | fprintf(stderr, "Option %s requires an argument\n", o->name); |
| 238 | return 1; |
| 239 | } |
| 240 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 241 | switch (o->type) { |
| 242 | case FIO_OPT_STR: { |
| 243 | fio_opt_str_fn *fn = o->cb; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 244 | const struct value_pair *vp; |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 245 | struct value_pair posval[PARSE_MAX_VP]; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 246 | int i; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 247 | |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 248 | posval_sort(o, posval); |
| 249 | |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 250 | for (i = 0; i < PARSE_MAX_VP; i++) { |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 251 | vp = &posval[i]; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 252 | if (!vp->ival || vp->ival[0] == '\0') |
| 253 | break; |
Jens Axboe | 6612a27 | 2007-03-13 08:54:06 +0100 | [diff] [blame] | 254 | ret = 1; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 255 | if (!strncmp(vp->ival, ptr, strlen(vp->ival))) { |
| 256 | ret = 0; |
| 257 | if (!o->off1) |
| 258 | break; |
| 259 | val_store(ilp, vp->oval, o->off1, data); |
| 260 | break; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | if (ret) |
| 265 | show_option_values(o); |
| 266 | else if (fn) |
| 267 | ret = fn(data, ptr); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 268 | break; |
| 269 | } |
| 270 | case FIO_OPT_STR_VAL_TIME: |
| 271 | is_time = 1; |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 272 | case FIO_OPT_STR_VAL: |
| 273 | case FIO_OPT_STR_VAL_INT: { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 274 | fio_opt_str_val_fn *fn = o->cb; |
| 275 | |
| 276 | if (is_time) |
| 277 | ret = check_str_time(ptr, &ull); |
| 278 | else |
| 279 | ret = check_str_bytes(ptr, &ull); |
| 280 | |
| 281 | if (ret) |
| 282 | break; |
| 283 | |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 284 | if (o->maxval && ull > o->maxval) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 285 | fprintf(stderr, "max value out of range: %lld" |
| 286 | " (%d max)\n", ull, o->maxval); |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 287 | return 1; |
| 288 | } |
| 289 | if (o->minval && ull < o->minval) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 290 | fprintf(stderr, "min value out of range: %lld" |
| 291 | " (%d min)\n", ull, o->minval); |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 292 | return 1; |
| 293 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 294 | |
| 295 | if (fn) |
| 296 | ret = fn(data, &ull); |
| 297 | else { |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 298 | if (o->type == FIO_OPT_STR_VAL_INT) { |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 299 | if (first) |
| 300 | val_store(ilp, ull, o->off1, data); |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 301 | if (!more && o->off2) |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 302 | val_store(ilp, ull, o->off2, data); |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 303 | } else { |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 304 | if (first) |
| 305 | val_store(ullp, ull, o->off1, data); |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 306 | if (!more && o->off2) |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 307 | val_store(ullp, ull, o->off2, data); |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 308 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 309 | } |
| 310 | break; |
| 311 | } |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 312 | case FIO_OPT_STR_STORE: { |
| 313 | fio_opt_str_fn *fn = o->cb; |
| 314 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 315 | cp = td_var(data, o->off1); |
| 316 | *cp = strdup(ptr); |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 317 | if (fn) { |
| 318 | ret = fn(data, ptr); |
| 319 | if (ret) { |
| 320 | free(*cp); |
| 321 | *cp = NULL; |
| 322 | } |
| 323 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 324 | break; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 325 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 326 | case FIO_OPT_RANGE: { |
Jens Axboe | b765a37 | 2006-10-27 15:00:16 +0200 | [diff] [blame] | 327 | char tmp[128]; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 328 | char *p1, *p2; |
| 329 | |
Jens Axboe | 0bbab0e | 2006-11-02 09:18:36 +0100 | [diff] [blame] | 330 | strncpy(tmp, ptr, sizeof(tmp) - 1); |
Jens Axboe | b765a37 | 2006-10-27 15:00:16 +0200 | [diff] [blame] | 331 | |
| 332 | p1 = strchr(tmp, '-'); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 333 | if (!p1) { |
Jens Axboe | 0c9baf9 | 2007-01-11 15:59:26 +0100 | [diff] [blame] | 334 | p1 = strchr(tmp, ':'); |
| 335 | if (!p1) { |
| 336 | ret = 1; |
| 337 | break; |
| 338 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | p2 = p1 + 1; |
| 342 | *p1 = '\0'; |
Jens Axboe | b765a37 | 2006-10-27 15:00:16 +0200 | [diff] [blame] | 343 | p1 = tmp; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 344 | |
| 345 | ret = 1; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 346 | if (!check_range_bytes(p1, &ul1) && |
| 347 | !check_range_bytes(p2, &ul2)) { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 348 | ret = 0; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 349 | if (ul1 > ul2) { |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 350 | unsigned long foo = ul1; |
| 351 | |
| 352 | ul1 = ul2; |
| 353 | ul2 = foo; |
| 354 | } |
| 355 | |
| 356 | if (first) { |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 357 | val_store(ilp, ul1, o->off1, data); |
| 358 | val_store(ilp, ul2, o->off2, data); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 359 | } |
Jens Axboe | 97e8cd4 | 2008-02-05 09:57:39 +0100 | [diff] [blame] | 360 | if (o->off3 && o->off4) { |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 361 | val_store(ilp, ul1, o->off3, data); |
| 362 | val_store(ilp, ul2, o->off4, data); |
| 363 | } |
| 364 | } |
| 365 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 366 | break; |
| 367 | } |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 368 | case FIO_OPT_INT: |
| 369 | case FIO_OPT_BOOL: { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 370 | fio_opt_int_fn *fn = o->cb; |
| 371 | |
| 372 | ret = check_int(ptr, &il); |
| 373 | if (ret) |
| 374 | break; |
| 375 | |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 376 | if (o->maxval && il > (int) o->maxval) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 377 | fprintf(stderr, "max value out of range: %d (%d max)\n", |
| 378 | il, o->maxval); |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 379 | return 1; |
| 380 | } |
| 381 | if (o->minval && il < o->minval) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 382 | fprintf(stderr, "min value out of range: %d (%d min)\n", |
| 383 | il, o->minval); |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 384 | return 1; |
| 385 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 386 | |
Jens Axboe | 76a43db | 2007-01-11 13:24:44 +0100 | [diff] [blame] | 387 | if (o->neg) |
| 388 | il = !il; |
| 389 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 390 | if (fn) |
| 391 | ret = fn(data, &il); |
| 392 | else { |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 393 | if (first) |
| 394 | val_store(ilp, il, o->off1, data); |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 395 | if (!more && o->off2) |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 396 | val_store(ilp, il, o->off2, data); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 397 | } |
| 398 | break; |
| 399 | } |
| 400 | case FIO_OPT_STR_SET: { |
| 401 | fio_opt_str_set_fn *fn = o->cb; |
| 402 | |
| 403 | if (fn) |
| 404 | ret = fn(data); |
| 405 | else { |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 406 | if (first) |
| 407 | val_store(ilp, 1, o->off1, data); |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 408 | if (!more && o->off2) |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 409 | val_store(ilp, 1, o->off2, data); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 410 | } |
| 411 | break; |
| 412 | } |
Jens Axboe | 15ca150 | 2008-04-07 09:26:02 +0200 | [diff] [blame] | 413 | case FIO_OPT_DEPRECATED: |
| 414 | fprintf(stdout, "Option %s is deprecated\n", o->name); |
| 415 | break; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 416 | default: |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 417 | fprintf(stderr, "Bad option type %u\n", o->type); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 418 | ret = 1; |
| 419 | } |
| 420 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 421 | return ret; |
| 422 | } |
| 423 | |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 424 | static int handle_option(struct fio_option *o, const char *ptr, void *data) |
| 425 | { |
Jens Axboe | 92b586f | 2006-11-07 14:29:17 +0100 | [diff] [blame] | 426 | const char *ptr2 = NULL; |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 427 | int r1, r2; |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 428 | |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 429 | dprint(FD_PARSE, "handle_option=%s, ptr=%s\n", o->name, ptr); |
| 430 | |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 431 | /* |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 432 | * See if we have a second set of parameters, hidden after a comma. |
| 433 | * Do this before parsing the first round, to check if we should |
| 434 | * copy set 1 options to set 2. |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 435 | */ |
Joel Becker | ad231bc | 2007-03-01 08:22:42 +0100 | [diff] [blame] | 436 | if (ptr && |
| 437 | (o->type != FIO_OPT_STR_STORE) && |
| 438 | (o->type != FIO_OPT_STR)) { |
Jens Axboe | 92b586f | 2006-11-07 14:29:17 +0100 | [diff] [blame] | 439 | ptr2 = strchr(ptr, ','); |
Jens Axboe | 0c9baf9 | 2007-01-11 15:59:26 +0100 | [diff] [blame] | 440 | if (!ptr2) |
| 441 | ptr2 = strchr(ptr, ':'); |
Jens Axboe | b486f76 | 2007-03-15 09:15:12 +0100 | [diff] [blame] | 442 | if (!ptr2) |
| 443 | ptr2 = strchr(ptr, '-'); |
Jens Axboe | 0c9baf9 | 2007-01-11 15:59:26 +0100 | [diff] [blame] | 444 | } |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 445 | |
| 446 | /* |
| 447 | * Don't return early if parsing the first option fails - if |
| 448 | * we are doing multiple arguments, we can allow the first one |
| 449 | * being empty. |
| 450 | */ |
| 451 | r1 = __handle_option(o, ptr, data, 1, !!ptr2); |
| 452 | |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 453 | if (!ptr2) |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 454 | return r1; |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 455 | |
| 456 | ptr2++; |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 457 | r2 = __handle_option(o, ptr2, data, 0, 0); |
| 458 | |
| 459 | return r1 && r2; |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 460 | } |
| 461 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 462 | int parse_cmd_option(const char *opt, const char *val, |
| 463 | struct fio_option *options, void *data) |
| 464 | { |
| 465 | struct fio_option *o; |
| 466 | |
| 467 | o = find_option(options, opt); |
| 468 | if (!o) { |
| 469 | fprintf(stderr, "Bad option %s\n", opt); |
| 470 | return 1; |
| 471 | } |
| 472 | |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 473 | if (!handle_option(o, val, data)) |
| 474 | return 0; |
| 475 | |
| 476 | fprintf(stderr, "fio: failed parsing %s=%s\n", opt, val); |
| 477 | return 1; |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 478 | } |
| 479 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 480 | int parse_option(const char *opt, struct fio_option *options, void *data) |
| 481 | { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 482 | struct fio_option *o; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 483 | char *pre, *post; |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 484 | char *tmp; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 485 | |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 486 | tmp = strdup(opt); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 487 | |
| 488 | pre = strchr(tmp, '='); |
| 489 | if (pre) { |
| 490 | post = pre; |
| 491 | *pre = '\0'; |
| 492 | pre = tmp; |
| 493 | post++; |
| 494 | o = find_option(options, pre); |
| 495 | } else { |
| 496 | o = find_option(options, tmp); |
| 497 | post = NULL; |
| 498 | } |
| 499 | |
| 500 | if (!o) { |
| 501 | fprintf(stderr, "Bad option %s\n", tmp); |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 502 | free(tmp); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 503 | return 1; |
| 504 | } |
| 505 | |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 506 | if (!handle_option(o, post, data)) { |
| 507 | free(tmp); |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 508 | return 0; |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 509 | } |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 510 | |
| 511 | fprintf(stderr, "fio: failed parsing %s\n", opt); |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 512 | free(tmp); |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 513 | return 1; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 514 | } |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 515 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 516 | /* |
| 517 | * Option match, levenshtein distance. Handy for not quite remembering what |
| 518 | * the option name is. |
| 519 | */ |
| 520 | static int string_distance(const char *s1, const char *s2) |
| 521 | { |
| 522 | unsigned int s1_len = strlen(s1); |
| 523 | unsigned int s2_len = strlen(s2); |
| 524 | unsigned int *p, *q, *r; |
| 525 | unsigned int i, j; |
| 526 | |
| 527 | p = malloc(sizeof(unsigned int) * (s2_len + 1)); |
| 528 | q = malloc(sizeof(unsigned int) * (s2_len + 1)); |
| 529 | |
| 530 | p[0] = 0; |
| 531 | for (i = 1; i <= s2_len; i++) |
| 532 | p[i] = p[i - 1] + 1; |
| 533 | |
| 534 | for (i = 1; i <= s1_len; i++) { |
| 535 | q[0] = p[0] + 1; |
| 536 | for (j = 1; j <= s2_len; j++) { |
| 537 | unsigned int sub = p[j - 1]; |
| 538 | |
| 539 | if (s1[i - 1] != s2[j - 1]) |
| 540 | sub++; |
| 541 | |
| 542 | q[j] = min(p[j] + 1, min(q[j - 1] + 1, sub)); |
| 543 | } |
| 544 | r = p; |
| 545 | p = q; |
| 546 | q = r; |
| 547 | } |
| 548 | |
| 549 | i = p[s2_len]; |
| 550 | free(p); |
| 551 | free(q); |
| 552 | return i; |
| 553 | } |
| 554 | |
| 555 | static void show_option_help(struct fio_option *o) |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 556 | { |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 557 | const char *typehelp[] = { |
| 558 | "string (opt=bla)", |
| 559 | "string with possible k/m/g postfix (opt=4k)", |
| 560 | "string with range and postfix (opt=1k-4k)", |
| 561 | "string with time postfix (opt=10s)", |
| 562 | "string (opt=bla)", |
| 563 | "string with dual range (opt=1k-4k,4k-8k)", |
| 564 | "integer value (opt=100)", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 565 | "boolean value (opt=1)", |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 566 | "no argument (opt)", |
| 567 | }; |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 568 | |
Jens Axboe | d2bb7fe | 2007-03-15 14:11:38 +0100 | [diff] [blame] | 569 | if (o->alias) |
| 570 | printf("%20s: %s\n", "alias", o->alias); |
| 571 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 572 | printf("%20s: %s\n", "type", typehelp[o->type]); |
| 573 | printf("%20s: %s\n", "default", o->def ? o->def : "no default"); |
| 574 | show_option_range(o); |
| 575 | show_option_values(o); |
| 576 | } |
| 577 | |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 578 | static struct fio_option *find_child(struct fio_option *options, |
| 579 | struct fio_option *o) |
| 580 | { |
| 581 | struct fio_option *__o; |
| 582 | |
Jens Axboe | fdf2874 | 2007-07-31 23:06:09 +0200 | [diff] [blame] | 583 | for (__o = options + 1; __o->name; __o++) |
| 584 | if (__o->parent && !strcmp(__o->parent, o->name)) |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 585 | return __o; |
| 586 | |
| 587 | return NULL; |
| 588 | } |
| 589 | |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 590 | static void __print_option(struct fio_option *o, struct fio_option *org, |
| 591 | int level) |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 592 | { |
| 593 | char name[256], *p; |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 594 | int depth; |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 595 | |
| 596 | if (!o) |
| 597 | return; |
Jens Axboe | ef9aff5 | 2007-07-31 22:56:53 +0200 | [diff] [blame] | 598 | if (!org) |
| 599 | org = o; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 600 | |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 601 | p = name; |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 602 | depth = level; |
| 603 | while (depth--) |
| 604 | p += sprintf(p, "%s", " "); |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 605 | |
| 606 | sprintf(p, "%s", o->name); |
| 607 | |
| 608 | printf("%-24s: %s\n", name, o->help); |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | static void print_option(struct fio_option *o) |
| 612 | { |
| 613 | struct fio_option *parent; |
| 614 | struct fio_option *__o; |
| 615 | unsigned int printed; |
| 616 | unsigned int level; |
| 617 | |
| 618 | __print_option(o, NULL, 0); |
| 619 | parent = o; |
| 620 | level = 0; |
| 621 | do { |
| 622 | level++; |
| 623 | printed = 0; |
| 624 | |
| 625 | while ((__o = find_child(o, parent)) != NULL) { |
| 626 | __print_option(__o, o, level); |
| 627 | o = __o; |
| 628 | printed++; |
| 629 | } |
| 630 | |
| 631 | parent = o; |
| 632 | } while (printed); |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 633 | } |
| 634 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 635 | int show_cmd_help(struct fio_option *options, const char *name) |
| 636 | { |
| 637 | struct fio_option *o, *closest; |
| 638 | unsigned int best_dist; |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 639 | int found = 0; |
Jens Axboe | 320beef | 2007-03-01 10:44:12 +0100 | [diff] [blame] | 640 | int show_all = 0; |
| 641 | |
| 642 | if (!name || !strcmp(name, "all")) |
| 643 | show_all = 1; |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 644 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 645 | closest = NULL; |
| 646 | best_dist = -1; |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 647 | for (o = &options[0]; o->name; o++) { |
Jens Axboe | 320beef | 2007-03-01 10:44:12 +0100 | [diff] [blame] | 648 | int match = 0; |
| 649 | |
Jens Axboe | 15ca150 | 2008-04-07 09:26:02 +0200 | [diff] [blame] | 650 | if (o->type == FIO_OPT_DEPRECATED) |
| 651 | continue; |
| 652 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 653 | if (name) { |
Jens Axboe | 7f9348f | 2007-03-15 14:09:28 +0100 | [diff] [blame] | 654 | if (!strcmp(name, o->name) || |
| 655 | (o->alias && !strcmp(name, o->alias))) |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 656 | match = 1; |
| 657 | else { |
| 658 | unsigned int dist; |
| 659 | |
| 660 | dist = string_distance(name, o->name); |
| 661 | if (dist < best_dist) { |
| 662 | best_dist = dist; |
| 663 | closest = o; |
| 664 | } |
| 665 | } |
| 666 | } |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 667 | |
| 668 | if (show_all || match) { |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 669 | found = 1; |
Jens Axboe | c167ded | 2007-03-14 13:02:53 +0100 | [diff] [blame] | 670 | if (match) |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 671 | printf("%24s: %s\n", o->name, o->help); |
Jens Axboe | c167ded | 2007-03-14 13:02:53 +0100 | [diff] [blame] | 672 | if (show_all) { |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 673 | if (!o->parent) |
Jens Axboe | 323d911 | 2008-03-01 15:12:14 +0100 | [diff] [blame] | 674 | print_option(o); |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 675 | continue; |
Jens Axboe | c167ded | 2007-03-14 13:02:53 +0100 | [diff] [blame] | 676 | } |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Jens Axboe | 70df2f1 | 2007-01-11 14:04:47 +0100 | [diff] [blame] | 679 | if (!match) |
| 680 | continue; |
| 681 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 682 | show_option_help(o); |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 683 | } |
| 684 | |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 685 | if (found) |
| 686 | return 0; |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 687 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 688 | printf("No such command: %s", name); |
| 689 | if (closest) { |
| 690 | printf(" - showing closest match\n"); |
| 691 | printf("%20s: %s\n", closest->name, closest->help); |
| 692 | show_option_help(closest); |
| 693 | } else |
| 694 | printf("\n"); |
| 695 | |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 696 | return 1; |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 697 | } |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 698 | |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 699 | /* |
| 700 | * Handle parsing of default parameters. |
| 701 | */ |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 702 | void fill_default_options(void *data, struct fio_option *options) |
| 703 | { |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 704 | struct fio_option *o; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 705 | |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 706 | dprint(FD_PARSE, "filling default options\n"); |
| 707 | |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 708 | for (o = &options[0]; o->name; o++) |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 709 | if (o->def) |
| 710 | handle_option(o, o->def, data); |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 711 | } |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 712 | |
| 713 | /* |
| 714 | * 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] | 715 | * values and whether both callback and offsets are given. |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 716 | */ |
| 717 | void options_init(struct fio_option *options) |
| 718 | { |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 719 | struct fio_option *o; |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 720 | |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 721 | dprint(FD_PARSE, "init options\n"); |
| 722 | |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 723 | for (o = &options[0]; o->name; o++) { |
Jens Axboe | 15ca150 | 2008-04-07 09:26:02 +0200 | [diff] [blame] | 724 | if (o->type == FIO_OPT_DEPRECATED) |
| 725 | continue; |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 726 | if (o->type == FIO_OPT_BOOL) { |
| 727 | o->minval = 0; |
| 728 | o->maxval = 1; |
| 729 | } |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 730 | if (o->type == FIO_OPT_STR_SET && o->def) { |
| 731 | fprintf(stderr, "Option %s: string set option with" |
| 732 | " default will always be true\n", |
| 733 | o->name); |
| 734 | } |
| 735 | if (!o->cb && !o->off1) { |
| 736 | fprintf(stderr, "Option %s: neither cb nor offset" |
| 737 | " given\n", o->name); |
| 738 | } |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 739 | if (o->type == FIO_OPT_STR || o->type == FIO_OPT_STR_STORE) |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 740 | continue; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 741 | if (o->cb && (o->off1 || o->off2 || o->off3 || o->off4)) { |
| 742 | fprintf(stderr, "Option %s: both cb and offset given\n", |
| 743 | o->name); |
| 744 | } |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 745 | } |
| 746 | } |