Allow the adding of 'posval' for dynamic options like 'profile'
authorJens Axboe <jens.axboe@oracle.com>
Fri, 5 Mar 2010 09:09:59 +0000 (10:09 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 5 Mar 2010 09:09:59 +0000 (10:09 +0100)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
options.c
options.h
parse.c
parse.h
profile.c
profiles/tiobench.c

index da9d0be464274fdf02fc6a6467857978ac5f1a31..e2daf37df09c26be2663a36a0b2f3aa031477ba8 100644 (file)
--- 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;
+       }
+}
index cf823fc62535a7158c6e5de0552dc2fb3bec67a1..c6c2086e0a76286a87f44bbb469307ccdddc09e4 100644 (file)
--- a/options.h
+++ b/options.h
@@ -3,6 +3,7 @@
 
 #define FIO_MAX_OPTS           512
 
+#include <string.h>
 #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 f5a35fbce7e9e086da5e4cdb2e6cf35a1ba69d66..d8527b50d8877b8644529d4764bc374522a070bc 100644 (file)
--- 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 8f7982ad1f57dc4942402875740c902a2b24fe51..9cda559550c9f836f5b17aaf51641b8e87736b69 100644 (file)
--- 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 */
index 354b06d3c2e923dd2391b68be0ad224ffe94f020..92e19026f2e0f0abe6a6d0402a691efc7ad1eee4 100644 (file)
--- 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);
 }
index e8c478ec6ce817c819fcd8fc21724b901e343dcb..f86a33787d9ca4e5f25fe2d096089c04b902154d 100644 (file)
@@ -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,