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