2 * This file contains the ini and command liner parser main.
12 #include "compiler/compiler.h"
19 #include "lib/ieee754.h"
22 #ifdef CONFIG_ARITHMETIC
26 static const char *opt_type_names[] = {
41 "OPT_SOFT_DEPRECATED",
45 static const struct fio_option *__fio_options;
47 static int vp_cmp(const void *p1, const void *p2)
49 const struct value_pair *vp1 = p1;
50 const struct value_pair *vp2 = p2;
52 return strlen(vp2->ival) - strlen(vp1->ival);
55 static void posval_sort(const struct fio_option *o, struct value_pair *vpmap)
57 const struct value_pair *vp;
60 memset(vpmap, 0, PARSE_MAX_VP * sizeof(struct value_pair));
62 for (entries = 0; entries < PARSE_MAX_VP; entries++) {
63 vp = &o->posval[entries];
64 if (!vp->ival || vp->ival[0] == '\0')
67 memcpy(&vpmap[entries], vp, sizeof(*vp));
70 qsort(vpmap, entries, sizeof(struct value_pair), vp_cmp);
73 static void show_option_range(const struct fio_option *o,
74 ssize_t (*logger)(const char *format, ...))
76 if (o->type == FIO_OPT_FLOAT_LIST) {
78 if (!o->minfp && !o->maxfp)
81 logger("%20s: ", "range");
82 if (o->minfp != DBL_MIN) {
83 logger("min=%f", o->minfp);
86 if (o->maxfp != DBL_MAX)
87 logger("%smax=%f", sep, o->maxfp);
89 } else if (!o->posval[0].ival) {
90 if (!o->minval && !o->maxval)
93 logger("%20s: min=%d", "range", o->minval);
95 logger(", max=%d", o->maxval);
100 static void show_option_values(const struct fio_option *o)
104 for (i = 0; i < PARSE_MAX_VP; i++) {
105 const struct value_pair *vp = &o->posval[i];
110 log_info("%20s: %-10s", i == 0 ? "valid values" : "", vp->ival);
112 log_info(" %s", vp->help);
120 static void show_option_help(const struct fio_option *o, int is_err)
122 const char *typehelp[] = {
123 [FIO_OPT_INVALID] = "invalid",
124 [FIO_OPT_STR] = "string (opt=bla)",
125 [FIO_OPT_STR_ULL] = "string (opt=bla)",
126 [FIO_OPT_STR_MULTI] = "string with possible k/m/g postfix (opt=4k)",
127 [FIO_OPT_STR_VAL] = "string (opt=bla)",
128 [FIO_OPT_STR_VAL_TIME] = "string with time postfix (opt=10s)",
129 [FIO_OPT_STR_STORE] = "string (opt=bla)",
130 [FIO_OPT_RANGE] = "one to three ranges (opt=1k-4k[,4k-8k[,1k-8k]])",
131 [FIO_OPT_INT] = "integer value (opt=100)",
132 [FIO_OPT_ULL] = "integer value (opt=100)",
133 [FIO_OPT_BOOL] = "boolean value (opt=1)",
134 [FIO_OPT_FLOAT_LIST] = "list of floating point values separated by ':' (opt=5.9:7.8)",
135 [FIO_OPT_STR_SET] = "empty or boolean value ([0|1])",
136 [FIO_OPT_DEPRECATED] = "deprecated",
137 [FIO_OPT_SOFT_DEPRECATED] = "deprecated",
138 [FIO_OPT_UNSUPPORTED] = "unsupported",
140 ssize_t (*logger)(const char *format, ...);
148 logger("%20s: %s\n", "alias", o->alias);
150 logger("%20s: %s\n", "type", typehelp[o->type]);
151 logger("%20s: %s\n", "default", o->def ? o->def : "no default");
153 logger("%20s: only for profile '%s'\n", "valid", o->prof_name);
154 show_option_range(o, logger);
155 show_option_values(o);
158 static unsigned long long get_mult_time(const char *str, int len,
163 unsigned long long mult = 1;
167 * Go forward until we hit a non-digit, or +/- sign
169 while ((p - str) <= len) {
170 if (!isdigit((int) *p) && (*p != '+') && (*p != '-'))
175 if (!isalpha((int) *p)) {
183 for (i = 0; i < strlen(c); i++)
184 c[i] = tolower((unsigned char)c[i]);
186 if (!strncmp("us", c, 2) || !strncmp("usec", c, 4))
188 else if (!strncmp("ms", c, 2) || !strncmp("msec", c, 4))
190 else if (!strcmp("s", c))
192 else if (!strcmp("m", c))
193 mult = 60 * 1000000UL;
194 else if (!strcmp("h", c))
195 mult = 60 * 60 * 1000000UL;
196 else if (!strcmp("d", c))
197 mult = 24 * 60 * 60 * 1000000ULL;
203 static int is_separator(char c)
216 static unsigned long long __get_mult_bytes(const char *p, void *data,
219 unsigned int kb_base = fio_get_kb_base(data);
220 unsigned long long ret = 1;
221 unsigned int i, pow = 0, mult = kb_base;
229 for (i = 0; i < strlen(c); i++) {
230 c[i] = tolower((unsigned char)c[i]);
231 if (is_separator(c[i])) {
237 /* If kb_base is 1000, use true units.
238 * If kb_base is 1024, use opposite units.
240 if (!strncmp("pib", c, 3)) {
244 else if (kb_base == 1024)
246 } else if (!strncmp("tib", c, 3)) {
250 else if (kb_base == 1024)
252 } else if (!strncmp("gib", c, 3)) {
256 else if (kb_base == 1024)
258 } else if (!strncmp("mib", c, 3)) {
262 else if (kb_base == 1024)
264 } else if (!strncmp("kib", c, 3)) {
268 else if (kb_base == 1024)
270 } else if (!strncmp("p", c, 1) || !strncmp("pb", c, 2)) {
272 } else if (!strncmp("t", c, 1) || !strncmp("tb", c, 2)) {
274 } else if (!strncmp("g", c, 1) || !strncmp("gb", c, 2)) {
276 } else if (!strncmp("m", c, 1) || !strncmp("mb", c, 2)) {
278 } else if (!strncmp("k", c, 1) || !strncmp("kb", c, 2)) {
280 } else if (!strncmp("%", c, 1)) {
287 ret *= (unsigned long long) mult;
293 static unsigned long long get_mult_bytes(const char *str, int len, void *data,
300 return __get_mult_bytes(str, data, percent);
303 * Go forward until we hit a non-digit, or +/- sign
305 while ((p - str) <= len) {
306 if (!isdigit((int) *p) &&
307 (((*p != '+') && (*p != '-')) || digit_seen))
309 digit_seen |= isdigit((int) *p);
313 if (!isalpha((int) *p) && (*p != '%'))
316 return __get_mult_bytes(p, data, percent);
319 extern int evaluate_arithmetic_expression(const char *buffer, long long *ival,
320 double *dval, double implied_units,
324 * Convert string into a floating number. Return 1 for success and 0 otherwise.
326 int str_to_float(const char *str, double *val, int is_time)
328 #ifdef CONFIG_ARITHMETIC
334 rc = evaluate_arithmetic_expression(str, &ival, &dval, 1.0, is_time);
341 return 1 == sscanf(str, "%lf", val);
345 * convert string into decimal value, noting any size suffix
347 int str_to_decimal(const char *str, long long *val, int kilo, void *data,
348 int is_seconds, int is_time)
352 #ifdef CONFIG_ARITHMETIC
355 double implied_units = 1.0;
362 #ifdef CONFIG_ARITHMETIC
364 implied_units = 1000000.0;
366 rc = evaluate_arithmetic_expression(str, &ival, &dval, implied_units, is_time);
367 if (str[0] == '(' && !rc) {
368 if (!kilo && is_seconds)
369 *val = ival / 1000000LL;
376 if (strstr(str, "0x") || strstr(str, "0X"))
381 *val = strtoll(str, NULL, base);
382 if (*val == LONG_MAX && errno == ERANGE)
387 unsigned long long mult;
390 mult = get_mult_bytes(str, len, data, &perc);
396 *val *= get_mult_time(str, len, is_seconds);
401 int check_str_bytes(const char *p, long long *val, void *data)
403 return str_to_decimal(p, val, 1, data, 0, 0);
406 int check_str_time(const char *p, long long *val, int is_seconds)
408 return str_to_decimal(p, val, 0, NULL, is_seconds, 1);
411 void strip_blank_front(char **p)
417 while (isspace((int) *s))
423 void strip_blank_end(char *p)
440 while ((isspace((int) *s) || iscntrl((int) *s)) && (s > start))
446 static int check_range_bytes(const char *str, long long *val, void *data)
450 if (!str_to_decimal(str, &__val, 1, data, 0, 0)) {
458 static int check_int(const char *p, int *val)
462 if (strstr(p, "0x") || strstr(p, "0X")) {
463 if (sscanf(p, "%x", val) == 1)
466 if (sscanf(p, "%u", val) == 1)
473 static size_t opt_len(const char *str)
477 postfix = strchr(str, ':');
481 return (int)(postfix - str);
484 static int str_match_len(const struct value_pair *vp, const char *str)
486 return max(strlen(vp->ival), opt_len(str));
489 #define val_store(ptr, val, off, or, data, o) \
491 ptr = td_var((data), (o), (off)); \
498 static const char *opt_type_name(const struct fio_option *o)
500 compiletime_assert(ARRAY_SIZE(opt_type_names) - 1 == FIO_OPT_UNSUPPORTED,
501 "opt_type_names[] index");
503 if (o->type <= FIO_OPT_UNSUPPORTED)
504 return opt_type_names[o->type];
506 return "OPT_UNKNOWN?";
509 static bool val_too_large(const struct fio_option *o, unsigned long long val,
517 return (int) val > (int) o->maxval;
518 return (unsigned int) val > o->maxval;
521 return val > o->maxval;
524 static bool val_too_small(const struct fio_option *o, unsigned long long val,
531 return (int) val < o->minval;
533 return val < o->minval;
536 static int __handle_option(const struct fio_option *o, const char *ptr,
537 void *data, int first, int more, int curr)
541 long long ull, *ullp;
543 long long ull1, ull2;
546 int ret = 0, is_time = 0;
547 const struct value_pair *vp;
548 struct value_pair posval[PARSE_MAX_VP];
549 int i, all_skipped = 1;
551 dprint(FD_PARSE, "__handle_option=%s, type=%s, ptr=%s\n", o->name,
552 opt_type_name(o), ptr);
554 if (!ptr && o->type != FIO_OPT_STR_SET && o->type != FIO_OPT_STR) {
555 log_err("Option %s requires an argument\n", o->name);
561 case FIO_OPT_STR_ULL:
562 case FIO_OPT_STR_MULTI: {
563 fio_opt_str_fn *fn = o->cb;
565 posval_sort(o, posval);
568 for (i = 0; i < PARSE_MAX_VP; i++) {
570 if (!vp->ival || vp->ival[0] == '\0')
575 if (!strncmp(vp->ival, ptr, str_match_len(vp, ptr))) {
579 if (o->type == FIO_OPT_STR_ULL)
580 val_store(ullp, vp->oval, o->off1, vp->orval, data, o);
582 val_store(ilp, vp->oval, o->off1, vp->orval, data, o);
587 if (ret && !all_skipped)
588 show_option_values(o);
593 case FIO_OPT_STR_VAL_TIME:
598 case FIO_OPT_STR_VAL: {
599 fio_opt_str_val_fn *fn = o->cb;
602 if (!is_time && o->is_time)
603 is_time = o->is_time;
605 tmp[sizeof(tmp) - 1] = '\0';
606 strncpy(tmp, ptr, sizeof(tmp) - 1);
607 p = strchr(tmp, ',');
612 ret = check_str_time(tmp, &ull, o->is_seconds);
614 ret = check_str_bytes(tmp, &ull, data);
616 dprint(FD_PARSE, " ret=%d, out=%llu\n", ret, ull);
620 if (o->pow2 && !is_power_of_2(ull)) {
621 log_err("%s: must be a power-of-2\n", o->name);
625 if (val_too_large(o, ull, o->type == FIO_OPT_INT)) {
626 log_err("%s: max value out of range: %llu"
627 " (%llu max)\n", o->name, ull, o->maxval);
630 if (val_too_small(o, ull, o->type == FIO_OPT_INT)) {
631 log_err("%s: min value out of range: %lld"
632 " (%d min)\n", o->name, ull, o->minval);
635 if (o->posval[0].ival) {
636 posval_sort(o, posval);
639 for (i = 0; i < PARSE_MAX_VP; i++) {
641 if (!vp->ival || vp->ival[0] == '\0')
643 if (vp->oval == ull) {
649 log_err("fio: value %llu not allowed:\n", ull);
650 show_option_values(o);
656 ret = fn(data, &ull);
658 if (o->type == FIO_OPT_INT) {
660 val_store(ilp, ull, o->off1, 0, data, o);
663 val_store(ilp, ull, o->off2, 0, data, o);
667 val_store(ilp, ull, o->off3, 0, data, o);
672 val_store(ilp, ull, o->off2, 0, data, o);
676 val_store(ilp, ull, o->off3, 0, data, o);
679 } else if (o->type == FIO_OPT_ULL) {
681 val_store(ullp, ull, o->off1, 0, data, o);
684 val_store(ullp, ull, o->off2, 0, data, o);
688 val_store(ullp, ull, o->off3, 0, data, o);
693 val_store(ullp, ull, o->off2, 0, data, o);
697 val_store(ullp, ull, o->off3, 0, data, o);
702 val_store(ullp, ull, o->off1, 0, data, o);
705 val_store(ullp, ull, o->off2, 0, data, o);
711 case FIO_OPT_FLOAT_LIST: {
716 ** Initialize precision to 0 and zero out list
717 ** in case specified list is shorter than default
721 ilp = td_var(data, o, o->off2);
725 flp = td_var(data, o, o->off1);
726 for(i = 0; i < o->maxlen; i++)
729 if (curr >= o->maxlen) {
730 log_err("the list exceeding max length %d\n",
734 if (!str_to_float(ptr, &uf, 0)) { /* this breaks if we ever have lists of times */
735 log_err("not a floating point value: %s\n", ptr);
738 if (o->minfp || o->maxfp) {
740 log_err("value out of range: %f"
741 " (range max: %f)\n", uf, o->maxfp);
745 log_err("value out of range: %f"
746 " (range min: %f)\n", uf, o->minfp);
751 flp = td_var(data, o, o->off1);
754 dprint(FD_PARSE, " out=%f\n", uf);
757 ** Calculate precision for output by counting
758 ** number of digits after period. Find first
759 ** period in entire remaining list each time
761 cp2 = strchr(ptr, '.');
765 while (*++cp2 != '\0' && *cp2 >= '0' && *cp2 <= '9')
769 ilp = td_var(data, o, o->off2);
777 case FIO_OPT_STR_STORE: {
778 fio_opt_str_fn *fn = o->cb;
784 cp = td_var(data, o, o->off1);
790 else if (o->posval[0].ival) {
791 posval_sort(o, posval);
794 for (i = 0; i < PARSE_MAX_VP; i++) {
796 if (!vp->ival || vp->ival[0] == '\0' || !cp)
799 if (!strncmp(vp->ival, ptr, str_match_len(vp, ptr))) {
805 rest = strstr(*cp ?: ptr, ":");
819 show_option_values(o);
828 case FIO_OPT_RANGE: {
832 tmp[sizeof(tmp) - 1] = '\0';
833 strncpy(tmp, ptr, sizeof(tmp) - 1);
835 /* Handle bsrange with separate read,write values: */
836 p1 = strchr(tmp, ',');
840 p1 = strchr(tmp, '-');
842 p1 = strchr(tmp, ':');
854 if (!check_range_bytes(p1, &ull1, data) &&
855 !check_range_bytes(p2, &ull2, data)) {
858 unsigned long long foo = ull1;
865 val_store(ullp, ull1, o->off1, 0, data, o);
866 val_store(ullp, ull2, o->off2, 0, data, o);
869 if (o->off3 && o->off4) {
870 val_store(ullp, ull1, o->off3, 0, data, o);
871 val_store(ullp, ull2, o->off4, 0, data, o);
875 if (o->off5 && o->off6) {
876 val_store(ullp, ull1, o->off5, 0, data, o);
877 val_store(ullp, ull2, o->off6, 0, data, o);
882 if (o->off3 && o->off4) {
883 val_store(ullp, ull1, o->off3, 0, data, o);
884 val_store(ullp, ull2, o->off4, 0, data, o);
888 if (o->off5 && o->off6) {
889 val_store(ullp, ull1, o->off5, 0, data, o);
890 val_store(ullp, ull2, o->off6, 0, data, o);
899 case FIO_OPT_STR_SET: {
900 fio_opt_int_fn *fn = o->cb;
903 ret = check_int(ptr, &il);
904 else if (o->type == FIO_OPT_BOOL)
909 dprint(FD_PARSE, " ret=%d, out=%d\n", ret, il);
914 if (o->maxval && il > (int) o->maxval) {
915 log_err("max value out of range: %d (%llu max)\n",
919 if (o->minval && il < o->minval) {
920 log_err("min value out of range: %d (%d min)\n",
932 val_store(ilp, il, o->off1, 0, data, o);
935 val_store(ilp, il, o->off2, 0, data, o);
940 case FIO_OPT_DEPRECATED:
943 case FIO_OPT_SOFT_DEPRECATED:
944 log_info("Option %s is deprecated\n", o->name);
947 log_err("Bad option type %u\n", o->type);
955 ret = o->verify(o, data);
957 log_err("Correct format for offending option\n");
958 log_err("%20s: %s\n", o->name, o->help);
959 show_option_help(o, 1);
966 static int handle_option(const struct fio_option *o, const char *__ptr,
969 char *o_ptr, *ptr, *ptr2;
972 dprint(FD_PARSE, "handle_option=%s, ptr=%s\n", o->name, __ptr);
976 o_ptr = ptr = strdup(__ptr);
979 * See if we have another set of parameters, hidden after a comma.
980 * Do this before parsing this round, to check if we should
981 * copy set 1 options to set 2.
990 (o->type != FIO_OPT_STR_STORE) &&
991 (o->type != FIO_OPT_STR) &&
992 (o->type != FIO_OPT_STR_ULL) &&
993 (o->type != FIO_OPT_FLOAT_LIST)) {
994 ptr2 = strchr(ptr, ',');
995 if (ptr2 && *(ptr2 + 1) == '\0')
997 if (o->type != FIO_OPT_STR_MULTI && o->type != FIO_OPT_RANGE) {
999 ptr2 = strchr(ptr, ':');
1001 ptr2 = strchr(ptr, '-');
1003 } else if (ptr && o->type == FIO_OPT_FLOAT_LIST) {
1004 ptr2 = strchr(ptr, ':');
1008 * Don't return early if parsing the first option fails - if
1009 * we are doing multiple arguments, we can allow the first one
1012 __ret = __handle_option(o, ptr, data, !done, !!ptr2, done);
1028 struct fio_option *find_option(struct fio_option *options, const char *opt)
1030 struct fio_option *o;
1032 for (o = &options[0]; o->name; o++) {
1033 if (!o_match(o, opt))
1035 if (o->type == FIO_OPT_UNSUPPORTED) {
1036 log_err("Option <%s>: %s\n", o->name, o->help);
1046 const struct fio_option *
1047 find_option_c(const struct fio_option *options, const char *opt)
1049 return find_option((struct fio_option *)options, opt);
1052 static const struct fio_option *
1053 get_option(char *opt, const struct fio_option *options, char **post)
1055 const struct fio_option *o;
1058 ret = strchr(opt, '=');
1064 strip_blank_end(ret);
1065 o = find_option_c(options, ret);
1067 o = find_option_c(options, opt);
1074 static int opt_cmp(const void *p1, const void *p2)
1076 const struct fio_option *o;
1083 s = strdup(*((char **) p1));
1084 o = get_option(s, __fio_options, &foo);
1090 s = strdup(*((char **) p2));
1091 o = get_option(s, __fio_options, &foo);
1097 return prio2 - prio1;
1100 void sort_options(char **opts, const struct fio_option *options, int num_opts)
1102 __fio_options = options;
1103 qsort(opts, num_opts, sizeof(char *), opt_cmp);
1104 __fio_options = NULL;
1107 static void add_to_dump_list(const struct fio_option *o,
1108 struct flist_head *dump_list, const char *post)
1110 struct print_option *p;
1115 p = malloc(sizeof(*p));
1116 p->name = strdup(o->name);
1118 p->value = strdup(post);
1122 flist_add_tail(&p->list, dump_list);
1125 int parse_cmd_option(const char *opt, const char *val,
1126 const struct fio_option *options, void *data,
1127 struct flist_head *dump_list)
1129 const struct fio_option *o;
1131 o = find_option_c(options, opt);
1133 log_err("Bad option <%s>\n", opt);
1137 if (handle_option(o, val, data)) {
1138 log_err("fio: failed parsing %s=%s\n", opt, val);
1142 add_to_dump_list(o, dump_list, val);
1146 int parse_option(char *opt, const char *input, const struct fio_option *options,
1147 const struct fio_option **o, void *data,
1148 struct flist_head *dump_list)
1153 log_err("fio: failed parsing %s\n", input);
1158 *o = get_option(opt, options, &post);
1161 int len = strlen(opt);
1162 if (opt + len + 1 != post)
1163 memmove(opt + len + 1, post, strlen(post));
1169 if (handle_option(*o, post, data)) {
1170 log_err("fio: failed parsing %s\n", input);
1174 add_to_dump_list(*o, dump_list, post);
1179 * Option match, levenshtein distance. Handy for not quite remembering what
1180 * the option name is.
1182 int string_distance(const char *s1, const char *s2)
1184 unsigned int s1_len = strlen(s1);
1185 unsigned int s2_len = strlen(s2);
1186 unsigned int *p, *q, *r;
1189 p = malloc(sizeof(unsigned int) * (s2_len + 1));
1190 q = malloc(sizeof(unsigned int) * (s2_len + 1));
1193 for (i = 1; i <= s2_len; i++)
1194 p[i] = p[i - 1] + 1;
1196 for (i = 1; i <= s1_len; i++) {
1198 for (j = 1; j <= s2_len; j++) {
1199 unsigned int sub = p[j - 1];
1202 if (s1[i - 1] != s2[j - 1])
1205 pmin = min(q[j - 1] + 1, sub);
1206 q[j] = min(p[j] + 1, pmin);
1220 * Make a guess of whether the distance from 's1' is significant enough
1221 * to warrant printing the guess. We set this to a 1/2 match.
1223 int string_distance_ok(const char *opt, int distance)
1228 len = (len + 1) / 2;
1229 return distance <= len;
1232 static const struct fio_option *find_child(const struct fio_option *options,
1233 const struct fio_option *o)
1235 const struct fio_option *__o;
1237 for (__o = options + 1; __o->name; __o++)
1238 if (__o->parent && !strcmp(__o->parent, o->name))
1244 static void __print_option(const struct fio_option *o,
1245 const struct fio_option *org,
1257 p += sprintf(p, "%s", " ");
1259 sprintf(p, "%s", o->name);
1261 log_info("%-24s: %s\n", name, o->help);
1264 static void print_option(const struct fio_option *o)
1266 const struct fio_option *parent;
1267 const struct fio_option *__o;
1268 unsigned int printed;
1271 __print_option(o, NULL, 0);
1278 while ((__o = find_child(o, parent)) != NULL) {
1279 __print_option(__o, o, level);
1288 int show_cmd_help(const struct fio_option *options, const char *name)
1290 const struct fio_option *o, *closest;
1291 unsigned int best_dist = -1U;
1295 if (!name || !strcmp(name, "all"))
1300 for (o = &options[0]; o->name; o++) {
1303 if (o->type == FIO_OPT_DEPRECATED ||
1304 o->type == FIO_OPT_SOFT_DEPRECATED)
1306 if (!exec_profile && o->prof_name)
1308 if (exec_profile && !(o->prof_name && !strcmp(exec_profile, o->prof_name)))
1312 if (!strcmp(name, o->name) ||
1313 (o->alias && !strcmp(name, o->alias)))
1318 dist = string_distance(name, o->name);
1319 if (dist < best_dist) {
1326 if (show_all || match) {
1329 log_info("%20s: %s\n", o->name, o->help);
1340 show_option_help(o, 0);
1346 log_err("No such command: %s", name);
1349 * Only print an appropriately close option, one where the edit
1350 * distance isn't too big. Otherwise we get crazy matches.
1352 if (closest && best_dist < 3) {
1353 log_info(" - showing closest match\n");
1354 log_info("%20s: %s\n", closest->name, closest->help);
1355 show_option_help(closest, 0);
1363 * Handle parsing of default parameters.
1365 void fill_default_options(void *data, const struct fio_option *options)
1367 const struct fio_option *o;
1369 dprint(FD_PARSE, "filling default options\n");
1371 for (o = &options[0]; o->name; o++)
1373 handle_option(o, o->def, data);
1376 static void option_init(struct fio_option *o)
1378 if (o->type == FIO_OPT_DEPRECATED || o->type == FIO_OPT_UNSUPPORTED ||
1379 o->type == FIO_OPT_SOFT_DEPRECATED)
1381 if (o->name && !o->lname)
1382 log_err("Option %s: missing long option name\n", o->name);
1383 if (o->type == FIO_OPT_BOOL) {
1387 if (o->type == FIO_OPT_INT) {
1389 o->maxval = UINT_MAX;
1391 if (o->type == FIO_OPT_ULL) {
1393 o->maxval = ULLONG_MAX;
1395 if (o->type == FIO_OPT_STR_SET && o->def && !o->no_warn_def) {
1396 log_err("Option %s: string set option with"
1397 " default will always be true\n", o->name);
1399 if (!o->cb && !o->off1)
1400 log_err("Option %s: neither cb nor offset given\n", o->name);
1402 log_info("Option %s: no category defined. Setting to misc\n", o->name);
1403 o->category = FIO_OPT_C_GENERAL;
1404 o->group = FIO_OPT_G_INVALID;
1409 * Sanitize the options structure. For now it just sets min/max for bool
1410 * values and whether both callback and offsets are given.
1412 void options_init(struct fio_option *options)
1414 struct fio_option *o;
1416 dprint(FD_PARSE, "init options\n");
1418 for (o = &options[0]; o->name; o++) {
1421 o->inv_opt = find_option(options, o->inverse);
1425 void options_mem_dupe(const struct fio_option *options, void *data)
1427 const struct fio_option *o;
1430 dprint(FD_PARSE, "dup options\n");
1432 for (o = &options[0]; o->name; o++) {
1433 if (o->type != FIO_OPT_STR_STORE)
1436 ptr = td_var(data, o, o->off1);
1438 *ptr = strdup(*ptr);
1442 void options_free(const struct fio_option *options, void *data)
1444 const struct fio_option *o;
1447 dprint(FD_PARSE, "free options\n");
1449 for (o = &options[0]; o->name; o++) {
1450 if (o->type != FIO_OPT_STR_STORE || !o->off1 || o->no_free)
1453 ptr = td_var(data, o, o->off1);