From 13335ddb0e304efa0fc96593dd1fd995ec6f68d7 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 10 Jan 2007 13:14:02 +0100 Subject: [PATCH] [PATCH] Introduce bool option type We can automatically flag those with min/max values. Signed-off-by: Jens Axboe --- init.c | 20 +++++++++++--------- parse.c | 24 +++++++++++++++++++++++- parse.h | 2 ++ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/init.c b/init.c index 11fd3e28..79b6e5cb 100644 --- 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 5347f675..1cc55dc6 100644 --- 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 3e3c9d9f..414f77c8 100644 --- 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 *); -- 2.25.1