Allow the adding of 'posval' for dynamic options like 'profile'

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/options.c b/options.c
index da9d0be..e2daf37 100644
--- a/options.c
+++ b/options.c
@@ -2044,3 +2044,42 @@
 		o++;
 	}
 }
+
+void add_opt_posval(const char *optname, const char *ival, const char *help)
+{
+	struct fio_option *o;
+	unsigned int i;
+
+	o = find_option(options, optname);
+	if (!o)
+		return;
+
+	for (i = 0; i < PARSE_MAX_VP; i++) {
+		if (o->posval[i].ival)
+			continue;
+
+		o->posval[i].ival = ival;
+		o->posval[i].help = help;
+		break;
+	}
+}
+
+void del_opt_posval(const char *optname, const char *ival)
+{
+	struct fio_option *o;
+	unsigned int i;
+
+	o = find_option(options, optname);
+	if (!o)
+		return;
+
+	for (i = 0; i < PARSE_MAX_VP; i++) {
+		if (!o->posval[i].ival)
+			continue;
+		if (strcmp(o->posval[i].ival, ival))
+			continue;
+
+		o->posval[i].ival = NULL;
+		o->posval[i].help = NULL;
+	}
+}
diff --git a/options.h b/options.h
index cf823fc..c6c2086 100644
--- a/options.h
+++ b/options.h
@@ -3,6 +3,7 @@
 
 #define FIO_MAX_OPTS		512
 
+#include <string.h>
 #include "parse.h"
 #include "flist.h"
 
@@ -12,4 +13,29 @@
 void invalidate_profile_options(const char *);
 extern char *exec_profile;
 
+void add_opt_posval(const char *, const char *, const char *);
+void del_opt_posval(const char *, const char *);
+
+static inline int o_match(struct fio_option *o, const char *opt)
+{
+	if (!strcmp(o->name, opt))
+		return 1;
+	else if (o->alias && !strcmp(o->alias, opt))
+		return 1;
+
+	return 0;
+}
+
+static inline struct fio_option *find_option(struct fio_option *options,
+					     const char *opt)
+{
+	struct fio_option *o;
+
+	for (o = &options[0]; o->name; o++)
+		if (o_match(o, opt))
+			return o;
+
+	return NULL;
+}
+
 #endif
diff --git a/parse.c b/parse.c
index f5a35fb..d8527b5 100644
--- a/parse.c
+++ b/parse.c
@@ -257,28 +257,6 @@
 	return 1;
 }
 
-static inline int o_match(struct fio_option *o, const char *opt)
-{
-	if (!strcmp(o->name, opt))
-		return 1;
-	else if (o->alias && !strcmp(o->alias, opt))
-		return 1;
-
-	return 0;
-}
-
-static struct fio_option *find_option(struct fio_option *options,
-				      const char *opt)
-{
-	struct fio_option *o;
-
-	for (o = &options[0]; o->name; o++)
-		if (o_match(o, opt))
-			return o;
-
-	return NULL;
-}
-
 #define val_store(ptr, val, off, data)			\
 	do {						\
 		ptr = td_var((data), (off));		\
diff --git a/parse.h b/parse.h
index 8f7982a..9cda559 100644
--- a/parse.h
+++ b/parse.h
@@ -50,7 +50,7 @@
 	void *cb;			/* callback */
 	const char *help;		/* help text for option */
 	const char *def;		/* default setting */
-	const struct value_pair posval[PARSE_MAX_VP];/* possible values */
+	struct value_pair posval[PARSE_MAX_VP];/* possible values */
 	const char *parent;		/* parent option */
 	int (*verify)(struct fio_option *, void *);
 	const char *prof_name;		/* only valid for specific profile */
diff --git a/profile.c b/profile.c
index 354b06d..92e1902 100644
--- a/profile.c
+++ b/profile.c
@@ -54,11 +54,15 @@
 	int ret;
 
 	dprint(FD_PROFILE, "register profile '%s'\n", ops->name);
-	flist_add_tail(&ops->list, &profile_list);
-	ret = add_profile_options(ops);
-	if (ret)
-		invalidate_profile_options(ops->name);
 
+	ret = add_profile_options(ops);
+	if (!ret) {
+		flist_add_tail(&ops->list, &profile_list);
+		add_opt_posval("profile", ops->name, ops->desc);
+		return 0;
+	}
+
+	invalidate_profile_options(ops->name);
 	return ret;
 }
 
@@ -67,4 +71,5 @@
 	dprint(FD_PROFILE, "unregister profile '%s'\n", ops->name);
 	flist_del(&ops->list);
 	invalidate_profile_options(ops->name);
+	del_opt_posval("profile", ops->name);
 }
diff --git a/profiles/tiobench.c b/profiles/tiobench.c
index e8c478e..f86a337 100644
--- a/profiles/tiobench.c
+++ b/profiles/tiobench.c
@@ -85,7 +85,7 @@
 
 static struct profile_ops tiobench_profile = {
 	.name		= "tiobench",
-	.desc		= "Emulate behaviour of the tiotest/tiobench benchmark",
+	.desc		= "tiotest/tiobench benchmark",
 	.options	= options,
 	.prep_cmd	= tb_prep_cmdline,
 	.cmdline	= tb_opts,