[PATCH] Introduce bool option type
authorJens Axboe <jens.axboe@oracle.com>
Wed, 10 Jan 2007 12:14:02 +0000 (13:14 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Wed, 10 Jan 2007 12:14:02 +0000 (13:14 +0100)
We can automatically flag those with min/max values.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
init.c
parse.c
parse.h

diff --git a/init.c b/init.c
index 11fd3e283f0c2f7026b68cca1e825515085d8b6a..79b6e5cb0c0d4748a940d15b95d9d7d54402de5a 100644 (file)
--- a/init.c
+++ b/init.c
@@ -178,7 +178,7 @@ static struct fio_option options[] = {
        },
        {
                .name   = "randrepeat",
-               .type   = FIO_OPT_INT,
+               .type   = FIO_OPT_BOOL,
                .off1   = td_var_offset(rand_repeatable),
                .help   = "Use repeatable random IO pattern",
                .def    = "1",
@@ -303,14 +303,14 @@ static struct fio_option options[] = {
        },
        {
                .name   = "invalidate",
-               .type   = FIO_OPT_INT,
+               .type   = FIO_OPT_BOOL,
                .off1   = td_var_offset(invalidate_cache),
                .help   = "Invalidate buffer/page cache prior to running job",
                .def    = "1",
        },
        {
                .name   = "sync",
-               .type   = FIO_OPT_INT,
+               .type   = FIO_OPT_BOOL,
                .off1   = td_var_offset(sync_io),
                .help   = "Use O_SYNC for buffered writes",
                .def    = "0",
@@ -324,14 +324,14 @@ static struct fio_option options[] = {
        },
        {
                .name   = "create_serialize",
-               .type   = FIO_OPT_INT,
+               .type   = FIO_OPT_BOOL,
                .off1   = td_var_offset(create_serialize),
                .help   = "Serialize creating of job files",
                .def    = "1",
        },
        {
                .name   = "create_fsync",
-               .type   = FIO_OPT_INT,
+               .type   = FIO_OPT_BOOL,
                .off1   = td_var_offset(create_fsync),
                .help   = "Fsync file after creation",
                .def    = "1",
@@ -364,14 +364,14 @@ static struct fio_option options[] = {
        },
        {
                .name   = "direct",
-               .type   = FIO_OPT_INT,
+               .type   = FIO_OPT_BOOL,
                .off1   = td_var_offset(odirect),
                .help   = "Use O_DIRECT IO",
                .def    = "1",
        },
        {
                .name   = "overwrite",
-               .type   = FIO_OPT_INT,
+               .type   = FIO_OPT_BOOL,
                .off1   = td_var_offset(overwrite),
                .help   = "When writing, set whether to overwrite current data",
                .def    = "0",
@@ -386,14 +386,14 @@ static struct fio_option options[] = {
 #endif
        {
                .name   = "end_fsync",
-               .type   = FIO_OPT_INT,
+               .type   = FIO_OPT_BOOL,
                .off1   = td_var_offset(end_fsync),
                .help   = "Include fsync at the end of job",
                .def    = "0",
        },
        {
                .name   = "unlink",
-               .type   = FIO_OPT_INT,
+               .type   = FIO_OPT_BOOL,
                .off1   = td_var_offset(unlink),
                .help   = "Unlink created files after job has completed",
                .def    = "1",
@@ -1327,6 +1327,8 @@ int parse_options(int argc, char *argv[])
        f_out = stdout;
        f_err = stderr;
 
+       options_init(options);
+
        dupe_job_options();
 
        if (setup_thread_area())
diff --git a/parse.c b/parse.c
index 5347f675b07e6d7a88d6a6ade63bbcd0574f129b..1cc55dc63ed8b1af03b9e81a51592311fdc748f3 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -244,7 +244,8 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
 
                break;
        }
-       case FIO_OPT_INT: {
+       case FIO_OPT_INT:
+       case FIO_OPT_BOOL: {
                fio_opt_int_fn *fn = o->cb;
 
                ret = check_int(ptr, &il);
@@ -410,6 +411,7 @@ int show_cmd_help(struct fio_option *options, const char *name)
                "string (opt=bla)",
                "string with dual range (opt=1k-4k,4k-8k)",
                "integer value (opt=100)",
+               "boolean value (opt=1)",
                "no argument (opt)",
        };
        int found = 0;
@@ -438,6 +440,9 @@ int show_cmd_help(struct fio_option *options, const char *name)
        return 1;
 }
 
+/*
+ * Handle parsing of default parameters.
+ */
 void fill_default_options(void *data, struct fio_option *options)
 {
        struct fio_option *o = &options[0];
@@ -448,3 +453,20 @@ void fill_default_options(void *data, struct fio_option *options)
                o++;
        }
 }
+
+/*
+ * Sanitize the options structure. For now it just sets min/max for bool
+ * values.
+ */
+void options_init(struct fio_option *options)
+{
+       struct fio_option *o = &options[0];
+
+       while (o->name) {
+               if (o->type == FIO_OPT_BOOL) {
+                       o->minval = 0;
+                       o->maxval = 1;
+               }
+               o++;
+       }
+}
diff --git a/parse.h b/parse.h
index 3e3c9d9f596c59b9c4e6b6b5269c097adf04fceb..414f77c859849046d116a6e76d06fa5342fd3d0c 100644 (file)
--- a/parse.h
+++ b/parse.h
@@ -12,6 +12,7 @@ enum fio_opt_type {
        FIO_OPT_STR_STORE,
        FIO_OPT_RANGE,
        FIO_OPT_INT,
+       FIO_OPT_BOOL,
        FIO_OPT_STR_SET,
 };
 
@@ -39,6 +40,7 @@ extern int parse_option(const char *, struct fio_option *, void *);
 extern int parse_cmd_option(const char *t, const char *l, struct fio_option *, void *);
 extern int show_cmd_help(struct fio_option *, const char *);
 extern void fill_default_options(void *, struct fio_option *);
+extern void options_init(struct fio_option *);
 
 extern void strip_blank_front(char **);
 extern void strip_blank_end(char *);