Make string-set options behave more like bool options
authorJens Axboe <jaxboe@fusionio.com>
Fri, 15 Jul 2011 07:09:15 +0000 (09:09 +0200)
committerJens Axboe <jaxboe@fusionio.com>
Fri, 15 Jul 2011 07:09:15 +0000 (09:09 +0200)
Before this change, string-set options (like time_based) would not
complain if passed an argument, they would just always evaluate
to being set. This is very confusing if someone uses them negated,
ala:

time_based=0

since fio would interpret that as the option being set. Now we'll
do the right thing, time_based=0 will be identical to not having
the option set. And time_based=1 or just time_based will equate
to the option being set.

Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
parse.c

diff --git a/parse.c b/parse.c
index ef23fbe90ed6b3ce8b4309bfe8751b56c23ae9aa..ad2782f0fbe93c9ddc822015343390d37f967a98 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -498,10 +498,17 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
 
                break;
        }
 
                break;
        }
-       case FIO_OPT_BOOL: {
+       case FIO_OPT_BOOL:
+       case FIO_OPT_STR_SET: {
                fio_opt_int_fn *fn = o->cb;
 
                fio_opt_int_fn *fn = o->cb;
 
-               ret = check_int(ptr, &il);
+               if (ptr)
+                       ret = check_int(ptr, &il);
+               else if (o->type == FIO_OPT_BOOL)
+                       ret = 1;
+               else
+                       il = 1;
+
                if (ret)
                        break;
 
                if (ret)
                        break;
 
@@ -537,27 +544,6 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                }
                break;
        }
                }
                break;
        }
-       case FIO_OPT_STR_SET: {
-               fio_opt_str_set_fn *fn = o->cb;
-
-               if (fn)
-                       ret = fn(data);
-               else {
-                       if (first) {
-                               if (o->roff1)
-                                       *(unsigned int *) o->roff1 = 1;
-                               else
-                                       val_store(ilp, 1, o->off1, 0, data);
-                       }
-                       if (!more) {
-                               if (o->roff2)
-                                       *(unsigned int *) o->roff2 = 1;
-                               else if (o->off2)
-                                       val_store(ilp, 1, o->off2, 0, data);
-                       }
-               }
-               break;
-       }
        case FIO_OPT_DEPRECATED:
                fprintf(stdout, "Option %s is deprecated\n", o->name);
                break;
        case FIO_OPT_DEPRECATED:
                fprintf(stdout, "Option %s is deprecated\n", o->name);
                break;