]> git.proxmox.com Git - mirror_qemu.git/commitdiff
blockdev: add a function to parse enum ids from strings
authorPeter Lieven <pl@kamp.de>
Sat, 17 May 2014 22:58:18 +0000 (00:58 +0200)
committerKevin Wolf <kwolf@redhat.com>
Mon, 19 May 2014 10:21:17 +0000 (12:21 +0200)
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>
blockdev.c

index 7810e9fb68caa4905dc797b9ea379e75cf7e42df..78b927f045607d8572629af8de4c40d9f3932b12 100644 (file)
@@ -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)) {