Patchwork [03/22] QemuOpts: add function to set QemuOpts from defaults

login
register
mail settings
Submitter Anthony Liguori
Date June 7, 2010, 11:51 p.m.
Message ID <1275954730-8196-4-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/54896/
State New
Headers show

Comments

Anthony Liguori - June 7, 2010, 11:51 p.m.
This lets us hard code a list of default QemuOpts values in a structured way.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

Patch

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,