From f5b6bb85364fcb8b2ac8d922ca65afd9dfabc9bb Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 5 Mar 2010 10:09:59 +0100 Subject: [PATCH] Allow the adding of 'posval' for dynamic options like 'profile' Signed-off-by: Jens Axboe --- options.c | 39 +++++++++++++++++++++++++++++++++++++++ options.h | 26 ++++++++++++++++++++++++++ parse.c | 22 ---------------------- parse.h | 2 +- profile.c | 11 ++++++++--- profiles/tiobench.c | 2 +- 6 files changed, 75 insertions(+), 27 deletions(-) diff --git a/options.c b/options.c index da9d0be4..e2daf37d 100644 --- a/options.c +++ b/options.c @@ -2044,3 +2044,42 @@ void invalidate_profile_options(const char *prof_name) o++; } } + +void add_opt_posval(const char *optname, const char *ival, const char *help) +{ + struct fio_option *o; + unsigned int i; + + o = find_option(options, optname); + if (!o) + return; + + for (i = 0; i < PARSE_MAX_VP; i++) { + if (o->posval[i].ival) + continue; + + o->posval[i].ival = ival; + o->posval[i].help = help; + break; + } +} + +void del_opt_posval(const char *optname, const char *ival) +{ + struct fio_option *o; + unsigned int i; + + o = find_option(options, optname); + if (!o) + return; + + for (i = 0; i < PARSE_MAX_VP; i++) { + if (!o->posval[i].ival) + continue; + if (strcmp(o->posval[i].ival, ival)) + continue; + + o->posval[i].ival = NULL; + o->posval[i].help = NULL; + } +} diff --git a/options.h b/options.h index cf823fc6..c6c2086e 100644 --- a/options.h +++ b/options.h @@ -3,6 +3,7 @@ #define FIO_MAX_OPTS 512 +#include #include "parse.h" #include "flist.h" @@ -12,4 +13,29 @@ int add_option(struct fio_option *); void invalidate_profile_options(const char *); extern char *exec_profile; +void add_opt_posval(const char *, const char *, const char *); +void del_opt_posval(const char *, const char *); + +static inline int o_match(struct fio_option *o, const char *opt) +{ + if (!strcmp(o->name, opt)) + return 1; + else if (o->alias && !strcmp(o->alias, opt)) + return 1; + + return 0; +} + +static inline struct fio_option *find_option(struct fio_option *options, + const char *opt) +{ + struct fio_option *o; + + for (o = &options[0]; o->name; o++) + if (o_match(o, opt)) + return o; + + return NULL; +} + #endif diff --git a/parse.c b/parse.c index f5a35fbc..d8527b50 100644 --- a/parse.c +++ b/parse.c @@ -257,28 +257,6 @@ static int check_int(const char *p, int *val) return 1; } -static inline int o_match(struct fio_option *o, const char *opt) -{ - if (!strcmp(o->name, opt)) - return 1; - else if (o->alias && !strcmp(o->alias, opt)) - return 1; - - return 0; -} - -static struct fio_option *find_option(struct fio_option *options, - const char *opt) -{ - struct fio_option *o; - - for (o = &options[0]; o->name; o++) - if (o_match(o, opt)) - return o; - - return NULL; -} - #define val_store(ptr, val, off, data) \ do { \ ptr = td_var((data), (off)); \ diff --git a/parse.h b/parse.h index 8f7982ad..9cda5595 100644 --- a/parse.h +++ b/parse.h @@ -50,7 +50,7 @@ struct fio_option { void *cb; /* callback */ const char *help; /* help text for option */ const char *def; /* default setting */ - const struct value_pair posval[PARSE_MAX_VP];/* possible values */ + struct value_pair posval[PARSE_MAX_VP];/* possible values */ const char *parent; /* parent option */ int (*verify)(struct fio_option *, void *); const char *prof_name; /* only valid for specific profile */ diff --git a/profile.c b/profile.c index 354b06d3..92e19026 100644 --- a/profile.c +++ b/profile.c @@ -54,11 +54,15 @@ int register_profile(struct profile_ops *ops) int ret; dprint(FD_PROFILE, "register profile '%s'\n", ops->name); - flist_add_tail(&ops->list, &profile_list); + ret = add_profile_options(ops); - if (ret) - invalidate_profile_options(ops->name); + if (!ret) { + flist_add_tail(&ops->list, &profile_list); + add_opt_posval("profile", ops->name, ops->desc); + return 0; + } + invalidate_profile_options(ops->name); return ret; } @@ -67,4 +71,5 @@ void unregister_profile(struct profile_ops *ops) dprint(FD_PROFILE, "unregister profile '%s'\n", ops->name); flist_del(&ops->list); invalidate_profile_options(ops->name); + del_opt_posval("profile", ops->name); } diff --git a/profiles/tiobench.c b/profiles/tiobench.c index e8c478ec..f86a3378 100644 --- a/profiles/tiobench.c +++ b/profiles/tiobench.c @@ -85,7 +85,7 @@ static void tb_prep_cmdline(void) static struct profile_ops tiobench_profile = { .name = "tiobench", - .desc = "Emulate behaviour of the tiotest/tiobench benchmark", + .desc = "tiotest/tiobench benchmark", .options = options, .prep_cmd = tb_prep_cmdline, .cmdline = tb_opts, -- 2.25.1