aboutsummaryrefslogtreecommitdiff
path: root/blockdev.c
diff options
context:
space:
mode:
authorPeter Lieven <pl@kamp.de>2014-05-18 00:58:18 +0200
committerKevin Wolf <kwolf@redhat.com>2014-05-19 12:21:17 +0200
commit82a402e99f3f8c6177528ad6d561bf07ff6ee606 (patch)
treef53898d4be8e10ab779a91ed9b1753a7a005d931 /blockdev.c
parent43f35cb5e0cff62e1d3fb1c116fbb8e028f2a5c8 (diff)
blockdev: add a function to parse enum ids from strings
this adds a generic function to recover the enum id of a parameter given as a string. Signed-off-by: Peter Lieven <pl@kamp.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r--blockdev.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/blockdev.c b/blockdev.c
index 7810e9fb68..78b927f045 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -288,6 +288,25 @@ static int parse_block_error_action(const char *buf, bool is_read, Error **errp)
}
}
+static inline int parse_enum_option(const char *lookup[], const char *buf,
+ int max, int def, Error **errp)
+{
+ int i;
+
+ if (!buf) {
+ return def;
+ }
+
+ for (i = 0; i < max; i++) {
+ if (!strcmp(buf, lookup[i])) {
+ return i;
+ }
+ }
+
+ error_setg(errp, "invalid parameter value: %s", buf);
+ return def;
+}
+
static bool check_throttle_config(ThrottleConfig *cfg, Error **errp)
{
if (throttle_conflicting(cfg)) {