qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 03/22] QemuOpts: add function to set QemuOpts from d


From: Anthony Liguori
Subject: [Qemu-devel] [PATCH 03/22] QemuOpts: add function to set QemuOpts from defaults
Date: Mon, 7 Jun 2010 18:51:51 -0500

This lets us hard code a list of default QemuOpts values in a structured way.

Signed-off-by: Anthony Liguori <address@hidden>

diff --git a/qemu-option.c b/qemu-option.c
index 03b1ef7..b990cf5 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -954,3 +954,23 @@ int qemu_opts_foreach(QemuOptsList *list, 
qemu_opts_loopfunc func, void *opaque,
     loc_pop(&loc);
     return rc;
 }
+
+int qemu_opts_set_defaults(QemuOpts *opts, const QemuOptValue *defvals)
+{
+    int i;
+
+    for (i = 0; defvals[i].name; i++) {
+        int ret;
+
+        if (qemu_opt_get(opts, defvals[i].name)) {
+            continue;
+        }
+        
+        ret = qemu_opt_set(opts, defvals[i].name, defvals[i].value);
+        if (ret < 0) {
+            return ret;
+        }
+    }
+
+    return 0;
+}
diff --git a/qemu-option.h b/qemu-option.h
index 4823219..4a6717c 100644
--- a/qemu-option.h
+++ b/qemu-option.h
@@ -104,6 +104,11 @@ struct QemuOptsList {
     QemuOptDesc desc[];
 };
 
+typedef struct QemuOptValue {
+    const char *name;
+    const char *value;
+} QemuOptValue;
+
 const char *qemu_opt_get(QemuOpts *opts, const char *name);
 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);
@@ -113,6 +118,8 @@ typedef int (*qemu_opt_loopfunc)(const char *name, const 
char *value, void *opaq
 int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
                      int abort_on_failure);
 
+int qemu_opts_set_defaults(QemuOpts *opts, const QemuOptValue *defvals);
+
 QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
 QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int 
fail_if_exists);
 int qemu_opts_set(QemuOptsList *list, const char *id,
-- 
1.7.0.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]