yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-rename-parse_enum_option-to-qapi_enum_parse-and-make.patch

958e1b
From af8241e3dc9a94d82423cb106114ae77a0333f32 Mon Sep 17 00:00:00 2001
958e1b
From: Max Reitz <mreitz@redhat.com>
958e1b
Date: Mon, 10 Nov 2014 09:14:04 +0100
958e1b
Subject: [PATCH 27/41] rename parse_enum_option to qapi_enum_parse and make it
958e1b
 public
958e1b
958e1b
Message-id: <1415610847-15383-2-git-send-email-mreitz@redhat.com>
958e1b
Patchwork-id: 62237
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH v2 1/4] rename parse_enum_option to qapi_enum_parse and make it public
958e1b
Bugzilla: 1087724
958e1b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
958e1b
RH-Acked-by: Fam Zheng <famz@redhat.com>
958e1b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
958e1b
From: Peter Lieven <pl@kamp.de>
958e1b
958e1b
relaxing the license to LGPLv2+ is intentional.
958e1b
958e1b
Suggested-by: Markus Armbruster <armbru@redhat.com>
958e1b
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
958e1b
Signed-off-by: Peter Lieven <pl@kamp.de>
958e1b
Reviewed-by: Eric Blake <eblake@redhat.com>
958e1b
Reviewed-by: Benoit Canet <benoit.canet@nodalink.com>
958e1b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
(cherry picked from commit 9e7dac7c6c6003ad9d4aca0125f0278233fcf761)
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
958e1b
Conflicts:
958e1b
	blockdev.c
958e1b
	qapi/Makefile.objs
958e1b
958e1b
Since detect-zeroes does not exist downstream, there was no
958e1b
parse_enum_option() in blockdev.c and therefore no changes to that file
958e1b
are necessary.
958e1b
958e1b
Signed-off-by: Max Reitz <mreitz@redhat.com>
958e1b
---
958e1b
 include/qapi/util.h | 17 +++++++++++++++++
958e1b
 qapi/Makefile.objs  |  1 +
958e1b
 qapi/qapi-util.c    | 34 ++++++++++++++++++++++++++++++++++
958e1b
 3 files changed, 52 insertions(+)
958e1b
 create mode 100644 include/qapi/util.h
958e1b
 create mode 100644 qapi/qapi-util.c
958e1b
958e1b
diff --git a/include/qapi/util.h b/include/qapi/util.h
958e1b
new file mode 100644
958e1b
index 0000000..de9238b
958e1b
--- /dev/null
958e1b
+++ b/include/qapi/util.h
958e1b
@@ -0,0 +1,17 @@
958e1b
+/*
958e1b
+ * QAPI util functions
958e1b
+ *
958e1b
+ * Copyright Fujitsu, Inc. 2014
958e1b
+ *
958e1b
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
958e1b
+ * See the COPYING.LIB file in the top-level directory.
958e1b
+ *
958e1b
+ */
958e1b
+
958e1b
+#ifndef QAPI_UTIL_H
958e1b
+#define QAPI_UTIL_H
958e1b
+
958e1b
+int qapi_enum_parse(const char *lookup[], const char *buf,
958e1b
+                    int max, int def, Error **errp);
958e1b
+
958e1b
+#endif
958e1b
diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs
958e1b
index 1f9c973..d896ef0 100644
958e1b
--- a/qapi/Makefile.objs
958e1b
+++ b/qapi/Makefile.objs
958e1b
@@ -3,3 +3,4 @@ util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o
958e1b
 util-obj-y += string-input-visitor.o string-output-visitor.o
958e1b
 
958e1b
 util-obj-y += opts-visitor.o
958e1b
+util-obj-y += qapi-util.o
958e1b
diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c
958e1b
new file mode 100644
958e1b
index 0000000..1d8fb96
958e1b
--- /dev/null
958e1b
+++ b/qapi/qapi-util.c
958e1b
@@ -0,0 +1,34 @@
958e1b
+/*
958e1b
+ * QAPI util functions
958e1b
+ *
958e1b
+ * Authors:
958e1b
+ *  Hu Tao       <hutao@cn.fujitsu.com>
958e1b
+ *  Peter Lieven <pl@kamp.de>
958e1b
+ * 
958e1b
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
958e1b
+ * See the COPYING.LIB file in the top-level directory.
958e1b
+ *
958e1b
+ */
958e1b
+
958e1b
+#include "qemu-common.h"
958e1b
+#include "qapi/error.h"
958e1b
+#include "qapi/util.h"
958e1b
+
958e1b
+int qapi_enum_parse(const char *lookup[], const char *buf,
958e1b
+                    int max, int def, Error **errp)
958e1b
+{
958e1b
+    int i;
958e1b
+
958e1b
+    if (!buf) {
958e1b
+        return def;
958e1b
+    }
958e1b
+
958e1b
+    for (i = 0; i < max; i++) {
958e1b
+        if (!strcmp(buf, lookup[i])) {
958e1b
+            return i;
958e1b
+        }
958e1b
+    }
958e1b
+
958e1b
+    error_setg(errp, "invalid parameter value: %s", buf);
958e1b
+    return def;
958e1b
+}
958e1b
-- 
958e1b
1.8.3.1
958e1b