<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From 1da10b8444cf1be1b052820761ef1d90221195f6 Mon Sep 17 00:00:00 2001
Message-Id: &lt;1da10b8444cf1be1b052820761ef1d90221195f6.1374754301.git.minovotn@redhat.com&gt;
In-Reply-To: &lt;5d75a8513d08b33975bdf5971871c0c977167cd1.1374754301.git.minovotn@redhat.com&gt;
References: &lt;5d75a8513d08b33975bdf5971871c0c977167cd1.1374754301.git.minovotn@redhat.com&gt;
From: Gerd Hoffmann &lt;kraxel@redhat.com&gt;
Date: Mon, 24 Jun 2013 07:05:23 +0200
Subject: [PATCH 12/65] qemu: Add opt_set_bool functionality

RH-Author: Gerd Hoffmann &lt;kraxel@redhat.com&gt;
Message-id: &lt;1372057576-26450-13-git-send-email-kraxel@redhat.com&gt;
Patchwork-id: 52116
O-Subject: [RHEL-6.5 qemu-kvm PATCH v2 12/65] qemu: Add opt_set_bool functionality
Bugzilla: 676568
RH-Acked-by: Laszlo Ersek &lt;lersek@redhat.com&gt;
RH-Acked-by: Hans de Goede &lt;hdegoede@redhat.com&gt;
RH-Acked-by: Luiz Capitulino &lt;lcapitulino@redhat.com&gt;

From: "M. Mohan Kumar" &lt;mohan@in.ibm.com&gt;

Signed-off-by: M. Mohan Kumar &lt;mohan@in.ibm.com&gt;
Signed-off-by: Aneesh Kumar K.V &lt;aneesh.kumar@linux.vnet.ibm.com&gt;
(cherry picked from commit f02b77c9bfc5c3ac93a89026f8c1d320f61f02c9)

Conflicts:

	qemu-option.c
---
 qemu-option.c |   39 +++++++++++++++++++++++++++++++++++----
 qemu-option.h |    3 ++-
 2 files changed, 37 insertions(+), 5 deletions(-)

Signed-off-by: Michal Novotny &lt;minovotn@redhat.com&gt;
---
 qemu-option.c | 39 +++++++++++++++++++++++++++++++++++----
 qemu-option.h |  3 ++-
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/qemu-option.c b/qemu-option.c
index 4b0511c..39ecec2 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -168,7 +168,7 @@ QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
     return NULL;
 }
 
-static int parse_option_bool(const char *name, const char *value, int *ret)
+static int parse_option_bool(const char *name, const char *value, bool *ret)
 {
     if (value != NULL) {
         if (!strcmp(value, "on")) {
@@ -258,7 +258,7 @@ static int parse_option_size(const char *name, const char *value, uint64_t *ret)
 int set_option_parameter(QEMUOptionParameter *list, const char *name,
     const char *value)
 {
-    int flag;
+    bool flag;
 
     // Find a matching parameter
     list = get_option_parameter(list, name);
@@ -515,7 +515,7 @@ struct QemuOpt {
 
     QemuOptDesc  *desc;
     union {
-        int      boolean;
+        bool boolean;
         uint64_t uint;
     } value;
 
@@ -549,7 +549,7 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
     return opt ? opt-&gt;str : NULL;
 }
 
-int qemu_opt_get_bool(QemuOpts *opts, const char *name, int defval)
+bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
 {
     QemuOpt *opt = qemu_opt_find(opts, name);
 
@@ -653,6 +653,37 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
     return opt_set(opts, name, value, false);
 }
 
+int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
+{
+    QemuOpt *opt;
+    QemuOptDesc *desc = opts-&gt;list-&gt;desc;
+    int i;
+
+    for (i = 0; desc[i].name != NULL; i++) {
+        if (strcmp(desc[i].name, name) == 0) {
+            break;
+        }
+    }
+    if (desc[i].name == NULL) {
+        if (i == 0) {
+            /* empty list -&gt; allow any */;
+        } else {
+            qerror_report(QERR_INVALID_PARAMETER, name);
+            return -1;
+        }
+    }
+
+    opt = g_malloc0(sizeof(*opt));
+    opt-&gt;name = g_strdup(name);
+    opt-&gt;opts = opts;
+    QTAILQ_INSERT_TAIL(&amp;opts-&gt;head, opt, next);
+    if (desc[i].name != NULL) {
+        opt-&gt;desc = desc+i;
+    }
+    opt-&gt;value.boolean = !!val;
+    return 0;
+}
+
 int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
                      int abort_on_failure)
 {
diff --git a/qemu-option.h b/qemu-option.h
index 5f300df..4f65730 100644
--- a/qemu-option.h
+++ b/qemu-option.h
@@ -106,10 +106,11 @@ struct QemuOptsList {
 };
 
 const char *qemu_opt_get(QemuOpts *opts, const char *name);
-int qemu_opt_get_bool(QemuOpts *opts, const char *name, int defval);
+bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval);
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval);
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
 int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
+int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val);
 typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque);
 int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
                      int abort_on_failure);
-- 
1.7.11.7

</pre></body></html>