summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Van Assche <bart.vanassche@wdc.com>2018-04-03 13:04:02 -0700
committerBart Van Assche <bart.vanassche@wdc.com>2018-04-04 13:51:39 -0700
commit9109883a1c20c2cbadd2d2cb8ca80d03835eaa66 (patch)
tree30b9247c68efd8697b7e5235815e290c86af0865
parent69349699d5a6e244fd9e74665ff2962cbca3d329 (diff)
option parsing: Mark arguments that are not modified as 'const'
This patch does not modify any functionality but makes the option parsing code slightly easier to read by marking arguments that are not modified explicitly as 'const'. A new function has been added, find_option_c(), that behaves identically to find_option(). Only the function signature differs between these two functions. Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
-rw-r--r--options.c16
-rw-r--r--options.h9
-rw-r--r--parse.c83
-rw-r--r--parse.h23
4 files changed, 73 insertions, 58 deletions
diff --git a/options.c b/options.c
index 45a5b82..17d7245 100644
--- a/options.c
+++ b/options.c
@@ -1517,7 +1517,7 @@ static int str_ioengine_external_cb(void *data, const char *str)
return 0;
}
-static int rw_verify(struct fio_option *o, void *data)
+static int rw_verify(const struct fio_option *o, void *data)
{
struct thread_data *td = cb_data_to_td(data);
@@ -1530,7 +1530,7 @@ static int rw_verify(struct fio_option *o, void *data)
return 0;
}
-static int gtod_cpu_verify(struct fio_option *o, void *data)
+static int gtod_cpu_verify(const struct fio_option *o, void *data)
{
#ifndef FIO_HAVE_CPU_AFFINITY
struct thread_data *td = cb_data_to_td(data);
@@ -4904,7 +4904,7 @@ int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
opts_copy = dup_and_sub_options(opts, num_opts);
for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
- struct fio_option *o;
+ const struct fio_option *o;
int newret = parse_option(opts_copy[i], opts[i], fio_options,
&o, &td->o, &td->opt_list);
@@ -4930,7 +4930,7 @@ int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
opts = opts_copy;
}
for (i = 0; i < num_opts; i++) {
- struct fio_option *o = NULL;
+ const struct fio_option *o = NULL;
int newret = 1;
if (!opts_copy[i])
@@ -4961,9 +4961,9 @@ int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
ret = parse_cmd_option(opt, val, fio_options, &td->o, &td->opt_list);
if (!ret) {
- struct fio_option *o;
+ const struct fio_option *o;
- o = find_option(fio_options, opt);
+ o = find_option_c(fio_options, opt);
if (o)
fio_option_mark_set(&td->o, o);
}
@@ -5028,7 +5028,7 @@ unsigned int fio_get_kb_base(void *data)
return kb_base;
}
-int add_option(struct fio_option *o)
+int add_option(const struct fio_option *o)
{
struct fio_option *__o;
int opt_index = 0;
@@ -5165,7 +5165,7 @@ bool __fio_option_is_set(struct thread_options *o, unsigned int off1)
return false;
}
-void fio_option_mark_set(struct thread_options *o, struct fio_option *opt)
+void fio_option_mark_set(struct thread_options *o, const struct fio_option *opt)
{
unsigned int opt_off, index, offset;
diff --git a/options.h b/options.h
index 59024ef..e53eb1b 100644
--- a/options.h
+++ b/options.h
@@ -8,7 +8,7 @@
#include "parse.h"
#include "lib/types.h"
-int add_option(struct fio_option *);
+int add_option(const struct fio_option *);
void invalidate_profile_options(const char *);
extern char *exec_profile;
@@ -31,9 +31,10 @@ extern bool __fio_option_is_set(struct thread_options *, unsigned int off);
__r; \
})
-extern void fio_option_mark_set(struct thread_options *, struct fio_option *);
+extern void fio_option_mark_set(struct thread_options *,
+ const struct fio_option *);
-static inline bool o_match(struct fio_option *o, const char *opt)
+static inline bool o_match(const struct fio_option *o, const char *opt)
{
if (!strcmp(o->name, opt))
return true;
@@ -44,6 +45,8 @@ static inline bool o_match(struct fio_option *o, const char *opt)
}
extern struct fio_option *find_option(struct fio_option *, const char *);
+extern const struct fio_option *
+find_option_c(const struct fio_option *, const char *);
extern struct fio_option *fio_option_find(const char *);
extern unsigned int fio_get_kb_base(void *);
diff --git a/parse.c b/parse.c
index 33fcf46..adeb63f 100644
--- a/parse.c
+++ b/parse.c
@@ -39,7 +39,7 @@ static const char *opt_type_names[] = {
"OPT_UNSUPPORTED",
};
-static struct fio_option *__fio_options;
+static const struct fio_option *__fio_options;
static int vp_cmp(const void *p1, const void *p2)
{
@@ -49,7 +49,7 @@ static int vp_cmp(const void *p1, const void *p2)
return strlen(vp2->ival) - strlen(vp1->ival);
}
-static void posval_sort(struct fio_option *o, struct value_pair *vpmap)
+static void posval_sort(const struct fio_option *o, struct value_pair *vpmap)
{
const struct value_pair *vp;
int entries;
@@ -67,7 +67,7 @@ static void posval_sort(struct fio_option *o, struct value_pair *vpmap)
qsort(vpmap, entries, sizeof(struct value_pair), vp_cmp);
}
-static void show_option_range(struct fio_option *o,
+static void show_option_range(const struct fio_option *o,
size_t (*logger)(const char *format, ...))
{
if (o->type == FIO_OPT_FLOAT_LIST) {
@@ -89,7 +89,7 @@ static void show_option_range(struct fio_option *o,
}
}
-static void show_option_values(struct fio_option *o)
+static void show_option_values(const struct fio_option *o)
{
int i;
@@ -109,7 +109,7 @@ static void show_option_values(struct fio_option *o)
log_info("\n");
}
-static void show_option_help(struct fio_option *o, int is_err)
+static void show_option_help(const struct fio_option *o, int is_err)
{
const char *typehelp[] = {
"invalid",
@@ -484,7 +484,7 @@ static int str_match_len(const struct value_pair *vp, const char *str)
*ptr = (val); \
} while (0)
-static const char *opt_type_name(struct fio_option *o)
+static const char *opt_type_name(const struct fio_option *o)
{
compiletime_assert(ARRAY_SIZE(opt_type_names) - 1 == FIO_OPT_UNSUPPORTED,
"opt_type_names[] index");
@@ -495,8 +495,8 @@ static const char *opt_type_name(struct fio_option *o)
return "OPT_UNKNOWN?";
}
-static int __handle_option(struct fio_option *o, const char *ptr, void *data,
- int first, int more, int curr)
+static int __handle_option(const struct fio_option *o, const char *ptr,
+ void *data, int first, int more, int curr)
{
int il=0, *ilp;
fio_fp64_t *flp;
@@ -892,7 +892,8 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
return ret;
}
-static int handle_option(struct fio_option *o, const char *__ptr, void *data)
+static int handle_option(const struct fio_option *o, const char *__ptr,
+ void *data)
{
char *o_ptr, *ptr, *ptr2;
int ret, done;
@@ -970,11 +971,16 @@ struct fio_option *find_option(struct fio_option *options, const char *opt)
return NULL;
}
+const struct fio_option *
+find_option_c(const struct fio_option *options, const char *opt)
+{
+ return find_option((struct fio_option *)options, opt);
+}
-static struct fio_option *get_option(char *opt,
- struct fio_option *options, char **post)
+static const struct fio_option *
+get_option(char *opt, const struct fio_option *options, char **post)
{
- struct fio_option *o;
+ const struct fio_option *o;
char *ret;
ret = strchr(opt, '=');
@@ -984,9 +990,9 @@ static struct fio_option *get_option(char *opt,
ret = opt;
(*post)++;
strip_blank_end(ret);
- o = find_option(options, ret);
+ o = find_option_c(options, ret);
} else {
- o = find_option(options, opt);
+ o = find_option_c(options, opt);
*post = NULL;
}
@@ -995,7 +1001,7 @@ static struct fio_option *get_option(char *opt,
static int opt_cmp(const void *p1, const void *p2)
{
- struct fio_option *o;
+ const struct fio_option *o;
char *s, *foo;
int prio1, prio2;
@@ -1019,15 +1025,15 @@ static int opt_cmp(const void *p1, const void *p2)
return prio2 - prio1;
}
-void sort_options(char **opts, struct fio_option *options, int num_opts)
+void sort_options(char **opts, const struct fio_option *options, int num_opts)
{
__fio_options = options;
qsort(opts, num_opts, sizeof(char *), opt_cmp);
__fio_options = NULL;
}
-static void add_to_dump_list(struct fio_option *o, struct flist_head *dump_list,
- const char *post)
+static void add_to_dump_list(const struct fio_option *o,
+ struct flist_head *dump_list, const char *post)
{
struct print_option *p;
@@ -1045,12 +1051,12 @@ static void add_to_dump_list(struct fio_option *o, struct flist_head *dump_list,
}
int parse_cmd_option(const char *opt, const char *val,
- struct fio_option *options, void *data,
+ const struct fio_option *options, void *data,
struct flist_head *dump_list)
{
- struct fio_option *o;
+ const struct fio_option *o;
- o = find_option(options, opt);
+ o = find_option_c(options, opt);
if (!o) {
log_err("Bad option <%s>\n", opt);
return 1;
@@ -1065,8 +1071,8 @@ int parse_cmd_option(const char *opt, const char *val,
return 0;
}
-int parse_option(char *opt, const char *input,
- struct fio_option *options, struct fio_option **o, void *data,
+int parse_option(char *opt, const char *input, const struct fio_option *options,
+ const struct fio_option **o, void *data,
struct flist_head *dump_list)
{
char *post;
@@ -1151,10 +1157,10 @@ int string_distance_ok(const char *opt, int distance)
return distance <= len;
}
-static struct fio_option *find_child(struct fio_option *options,
- struct fio_option *o)
+static const struct fio_option *find_child(const struct fio_option *options,
+ const struct fio_option *o)
{
- struct fio_option *__o;
+ const struct fio_option *__o;
for (__o = options + 1; __o->name; __o++)
if (__o->parent && !strcmp(__o->parent, o->name))
@@ -1163,7 +1169,8 @@ static struct fio_option *find_child(struct fio_option *options,
return NULL;
}
-static void __print_option(struct fio_option *o, struct fio_option *org,
+static void __print_option(const struct fio_option *o,
+ const struct fio_option *org,
int level)
{
char name[256], *p;
@@ -1184,10 +1191,10 @@ static void __print_option(struct fio_option *o, struct fio_option *org,
log_info("%-24s: %s\n", name, o->help);
}
-static void print_option(struct fio_option *o)
+static void print_option(const struct fio_option *o)
{
- struct fio_option *parent;
- struct fio_option *__o;
+ const struct fio_option *parent;
+ const struct fio_option *__o;
unsigned int printed;
unsigned int level;
@@ -1208,9 +1215,9 @@ static void print_option(struct fio_option *o)
} while (printed);
}
-int show_cmd_help(struct fio_option *options, const char *name)
+int show_cmd_help(const struct fio_option *options, const char *name)
{
- struct fio_option *o, *closest;
+ const struct fio_option *o, *closest;
unsigned int best_dist = -1U;
int found = 0;
int show_all = 0;
@@ -1284,9 +1291,9 @@ int show_cmd_help(struct fio_option *options, const char *name)
/*
* Handle parsing of default parameters.
*/
-void fill_default_options(void *data, struct fio_option *options)
+void fill_default_options(void *data, const struct fio_option *options)
{
- struct fio_option *o;
+ const struct fio_option *o;
dprint(FD_PARSE, "filling default options\n");
@@ -1346,9 +1353,9 @@ void options_init(struct fio_option *options)
}
}
-void options_mem_dupe(struct fio_option *options, void *data)
+void options_mem_dupe(const struct fio_option *options, void *data)
{
- struct fio_option *o;
+ const struct fio_option *o;
char **ptr;
dprint(FD_PARSE, "dup options\n");
@@ -1363,9 +1370,9 @@ void options_mem_dupe(struct fio_option *options, void *data)
}
}
-void options_free(struct fio_option *options, void *data)
+void options_free(const struct fio_option *options, void *data)
{
- struct fio_option *o;
+ const struct fio_option *o;
char **ptr;
dprint(FD_PARSE, "free options\n");
diff --git a/parse.h b/parse.h
index f919291..4ad92d9 100644
--- a/parse.h
+++ b/parse.h
@@ -68,7 +68,7 @@ struct fio_option {
int hide_on_set; /* hide on set, not on unset */
const char *inverse; /* if set, apply opposite action to this option */
struct fio_option *inv_opt; /* cached lookup */
- int (*verify)(struct fio_option *, void *);
+ int (*verify)(const struct fio_option *, void *);
const char *prof_name; /* only valid for specific profile */
void *prof_opts;
uint64_t category; /* what type of option */
@@ -81,14 +81,18 @@ struct fio_option {
int no_free;
};
-extern int parse_option(char *, const char *, struct fio_option *, struct fio_option **, void *, struct flist_head *);
-extern void sort_options(char **, struct fio_option *, int);
-extern int parse_cmd_option(const char *t, const char *l, struct fio_option *, void *, struct flist_head *);
-extern int show_cmd_help(struct fio_option *, const char *);
-extern void fill_default_options(void *, struct fio_option *);
+extern int parse_option(char *, const char *, const struct fio_option *,
+ const struct fio_option **, void *,
+ struct flist_head *);
+extern void sort_options(char **, const struct fio_option *, int);
+extern int parse_cmd_option(const char *t, const char *l,
+ const struct fio_option *, void *,
+ struct flist_head *);
+extern int show_cmd_help(const struct fio_option *, const char *);
+extern void fill_default_options(void *, const struct fio_option *);
extern void options_init(struct fio_option *);
-extern void options_mem_dupe(struct fio_option *, void *);
-extern void options_free(struct fio_option *, void *);
+extern void options_mem_dupe(const struct fio_option *, void *);
+extern void options_free(const struct fio_option *, void *);
extern void strip_blank_front(char **);
extern void strip_blank_end(char *);
@@ -108,7 +112,8 @@ typedef int (fio_opt_str_val_fn)(void *, long long *);
typedef int (fio_opt_int_fn)(void *, int *);
struct thread_options;
-static inline void *td_var(void *to, struct fio_option *o, unsigned int offset)
+static inline void *td_var(void *to, const struct fio_option *o,
+ unsigned int offset)
{
void *ret;