Add initial support for profile specific options
authorJens Axboe <jens.axboe@oracle.com>
Thu, 4 Mar 2010 13:05:48 +0000 (14:05 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 4 Mar 2010 13:05:48 +0000 (14:05 +0100)
Not complete yet, we need to split option parsing for profiles a
bit.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
options.c
options.h
parse.c
parse.h
profile.c
profile.h
profiles/tiobench.c

index 03b24377babde979427c4255cc451acd88b85343..2f38b4ae75edddd208d16b2624dac3cf40b4203a 100644 (file)
--- a/options.c
+++ b/options.c
@@ -1959,7 +1959,7 @@ void fio_fill_default_options(struct thread_data *td)
 
 int fio_show_option_help(const char *opt)
 {
-       return show_cmd_help(options, opt);
+       return show_cmd_help(options, &ext_opt_list, opt);
 }
 
 static void __options_mem(struct thread_data *td, int alloc)
@@ -2019,3 +2019,17 @@ void register_ext_option(struct ext_option *eopt)
        option_init(&eopt->o);
        flist_add_tail(&eopt->list, &ext_opt_list);
 }
+
+void prune_profile_options(const char *prof_name)
+{
+       struct ext_option *eo;
+       struct flist_head *n, *tmp;
+
+       flist_for_each_safe(n, tmp, &ext_opt_list) {
+               eo = flist_entry(n, struct ext_option, list);
+               if (strcmp(eo->prof_name, prof_name))
+                       continue;
+               flist_del(&eo->list);
+               free(eo);
+       }
+}
index 29bb7a162142ea0258d6b400301ae795e795fcaf..96c81a17c8770be00fa0f01a6a94676378b6bfd6 100644 (file)
--- a/options.h
+++ b/options.h
@@ -8,9 +8,11 @@
 
 struct ext_option {
        struct flist_head list;
+       const char *prof_name;
        struct fio_option o;
 };
 
-void register_option(struct ext_option *);
+void register_ext_option(struct ext_option *);
+void prune_profile_options(const char *);
 
 #endif
diff --git a/parse.c b/parse.c
index 2cdac54012515e2629baa7e91a4e52308e752466..9c0965f002d31d01156749eebf7868ad0b813e0e 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -852,8 +852,11 @@ 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(struct fio_option *options, struct flist_head *ext_opts,
+                 const char *name)
 {
+       struct flist_head *n;
+       struct ext_option *eo;
        struct fio_option *o, *closest;
        unsigned int best_dist;
        int found = 0;
@@ -905,6 +908,18 @@ int show_cmd_help(struct fio_option *options, const char *name)
        if (found)
                return 0;
 
+       flist_for_each(n, ext_opts) {
+               eo = flist_entry(n, struct ext_option, list);
+               o = &eo->o;
+               if (!strcmp(name, o->name) ||
+                   (o->alias && !strcmp(name, o->alias))) {
+                       printf("%20s: %s\n", o->name, o->help);
+                       show_option_help(o, stdout);
+                       printf("%20s: External, valid for '%s'\n", "Restriction", eo->prof_name);
+                       return 0;
+               }
+       }
+
        printf("No such command: %s", name);
        if (closest) {
                printf(" - showing closest match\n");
@@ -942,13 +957,14 @@ void option_init(struct fio_option *o)
                fprintf(stderr, "Option %s: string set option with"
                                " default will always be true\n", o->name);
        }
-       if (!o->cb && !o->off1) {
+       if (!o->cb && (!o->off1 && !o->roff1)) {
                fprintf(stderr, "Option %s: neither cb nor offset given\n",
                                                        o->name);
        }
        if (o->type == FIO_OPT_STR || o->type == FIO_OPT_STR_STORE)
                return;
-       if (o->cb && (o->off1 || o->off2 || o->off3 || o->off4)) {
+       if (o->cb && ((o->off1 || o->off2 || o->off3 || o->off4) ||
+                     (o->roff1 || o->roff2 || o->roff3 || o->roff4))) {
                fprintf(stderr, "Option %s: both cb and offset given\n",
                                                         o->name);
        }
diff --git a/parse.h b/parse.h
index 95d99f56c08d4cdef2bb41a3a18fc5b0efb05cd6..5f602a37966e180a30feab7d9699d301e12e5d64 100644 (file)
--- a/parse.h
+++ b/parse.h
@@ -59,7 +59,7 @@ typedef int (str_cb_fn)(void *, char *);
 extern int parse_option(const char *, struct fio_option *, struct flist_head *, void *);
 extern void sort_options(char **, struct fio_option *, int);
 extern int parse_cmd_option(const char *t, const char *l, struct fio_option *, struct flist_head *, void *);
-extern int show_cmd_help(struct fio_option *, const char *);
+extern int show_cmd_help(struct fio_option *, struct flist_head *, const char *);
 extern void fill_default_options(void *, struct fio_option *);
 extern void option_init(struct fio_option *);
 extern void options_init(struct fio_option *);
index e56ca29b8060fa84f8ea414a8418992d6f2ead07..9f588a17bfc75e9f91db53ec1ae8a44cff02cba2 100644 (file)
--- a/profile.c
+++ b/profile.c
@@ -2,6 +2,7 @@
 #include "profile.h"
 #include "debug.h"
 #include "flist.h"
+#include "options.h"
 
 static FLIST_HEAD(profile_list);
 
@@ -29,14 +30,34 @@ int load_profile(const char *profile)
        return 1;
 }
 
+static void add_profile_options(struct profile_ops *ops)
+{
+       struct fio_option *fo;
+       struct ext_option *eo;
+       
+       if (!ops->options)
+               return;
+
+       fo = ops->options;
+       while (fo->name) {
+               eo = malloc(sizeof(*eo));
+               eo->prof_name = ops->name;
+               memcpy(&eo->o, fo, sizeof(*fo));
+               register_ext_option(eo);
+               fo++;
+       }
+}
+
 void register_profile(struct profile_ops *ops)
 {
        dprint(FD_PROFILE, "register profile '%s'\n", ops->name);
        flist_add_tail(&ops->list, &profile_list);
+       add_profile_options(ops);
 }
 
 void unregister_profile(struct profile_ops *ops)
 {
        dprint(FD_PROFILE, "unregister profile '%s'\n", ops->name);
        flist_del(&ops->list);
+       prune_profile_options(ops->name);
 }
index 6b1960623f8bccb4fe177599efbfc1c63a131fb3..5268d4aec21f57bb2dda9df2b0c1cfaf5fe128cd 100644 (file)
--- a/profile.h
+++ b/profile.h
@@ -12,6 +12,7 @@ struct profile_ops {
        int flags;
 
        const char **def_ops;
+       struct fio_option *options;
 };
 
 void register_profile(struct profile_ops *);
index d239468f9f3272269089e08590c8ac69d52c4ddc..873be994dd8748ef4d8a0a8e5eb863fec717cf6e 100644 (file)
@@ -1,5 +1,11 @@
 #include "../fio.h"
 #include "../profile.h"
+#include "../parse.h"
+
+static unsigned long size;
+static unsigned long loops;
+static unsigned long bs;
+static char *dir;
 
 static const char *tb_opts[] = {
        "buffered=0", "size=4*1024*$mb_memory", "bs=4k", "timeout=600",
@@ -11,10 +17,42 @@ static const char *tb_opts[] = {
        "name=randread", "stonewall", "rw=randread", NULL,
 };
 
+static struct fio_option options[] = {
+       {
+               .name   = "size",
+               .type   = FIO_OPT_INT,
+               .roff1  = &size,
+               .help   = "Size in MB",
+       },
+       {
+               .name   = "block",
+               .type   = FIO_OPT_INT,
+               .roff1  = &bs,
+               .help   = "Block size in bytes",
+               .def    = "4k",
+       },
+       {
+               .name   = "numruns",
+               .type   = FIO_OPT_INT,
+               .roff1  = &loops,
+               .help   = "Number of runs",
+       },
+       {
+               .name   = "dir",
+               .type   = FIO_OPT_STR_STORE,
+               .roff1  = &dir,
+               .help   = "Test directory",
+       },
+       {
+               .name   = NULL,
+       },
+};
+
 static struct profile_ops tiobench_profile = {
        .name           = "tiobench",
        .version        = FIO_PROFILE_VERSION,
        .def_ops        = tb_opts,
+       .options        = options,
 };
 
 static void fio_init tiobench_register(void)