[PATCH] Introduce bool option type

We can automatically flag those with min/max values.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/init.c b/init.c
index 11fd3e2..79b6e5c 100644
--- a/init.c
+++ b/init.c
@@ -178,7 +178,7 @@
 	},
 	{
 		.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 @@
 	},
 	{
 		.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 @@
 	},
 	{
 		.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 @@
 	},
 	{
 		.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 @@
 #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 @@
 	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 5347f67..1cc55dc 100644
--- a/parse.c
+++ b/parse.c
@@ -244,7 +244,8 @@
 
 		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 @@
 		"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 @@
 	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 @@
 		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 3e3c9d9..414f77c 100644
--- a/parse.h
+++ b/parse.h
@@ -12,6 +12,7 @@
 	FIO_OPT_STR_STORE,
 	FIO_OPT_RANGE,
 	FIO_OPT_INT,
+	FIO_OPT_BOOL,
 	FIO_OPT_STR_SET,
 };
 
@@ -39,6 +40,7 @@
 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 *);