qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/2] Add opt_set_bool function
@ 2011-10-12  7:53 M. Mohan Kumar
  2011-10-12  7:53 ` [Qemu-devel] [PATCH V4 2/2] hw/9pfs: Add readonly support for 9p export M. Mohan Kumar
  2011-10-12 16:17 ` [Qemu-devel] [PATCH 1/2] Add opt_set_bool function Andreas Färber
  0 siblings, 2 replies; 6+ messages in thread
From: M. Mohan Kumar @ 2011-10-12  7:53 UTC (permalink / raw)
  To: qemu-devel

In addition to qemu_opt_set function, we need a function to set bool value
also.

Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
---
 qemu-option.c |   35 +++++++++++++++++++++++++++++++++++
 qemu-option.h |    1 +
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/qemu-option.c b/qemu-option.c
index 105d760..d6bc908 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -636,6 +636,41 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
     return 0;
 }
 
+int qemu_opt_set_bool(QemuOpts *opts, const char *name, int val)
+{
+    QemuOpt *opt;
+    const QemuOptDesc *desc = opts->list->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 -> allow any */;
+        } else {
+            qerror_report(QERR_INVALID_PARAMETER, name);
+            return -1;
+        }
+    }
+
+    opt = g_malloc0(sizeof(*opt));
+    opt->name = g_strdup(name);
+    opt->opts = opts;
+    QTAILQ_INSERT_TAIL(&opts->head, opt, next);
+    if (desc[i].name != NULL) {
+        opt->desc = desc+i;
+    }
+    opt->value.boolean = !!val;
+    if (qemu_opt_parse(opt) < 0) {
+        qemu_opt_del(opt);
+        return -1;
+    }
+    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 b515813..af4d36b 100644
--- a/qemu-option.h
+++ b/qemu-option.h
@@ -109,6 +109,7 @@ int qemu_opt_get_bool(QemuOpts *opts, const char *name, int 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, int 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.6

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-10-14  4:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-12  7:53 [Qemu-devel] [PATCH 1/2] Add opt_set_bool function M. Mohan Kumar
2011-10-12  7:53 ` [Qemu-devel] [PATCH V4 2/2] hw/9pfs: Add readonly support for 9p export M. Mohan Kumar
2011-10-12 14:08   ` Aneesh Kumar K.V
2011-10-12 15:31     ` M. Mohan Kumar
2011-10-12 16:17 ` [Qemu-devel] [PATCH 1/2] Add opt_set_bool function Andreas Färber
2011-10-14  4:24   ` M. Mohan Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).