aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-10-14 10:39:26 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-11-09 08:43:13 -0600
commit9d993394a1a63e500194b4eabd8a01b1af401a8f (patch)
tree3af0c2cd1c06e7f562042674db450c79672345d7
parentddc978550db144aa44098cd00c87d1436a78dd1b (diff)
downloadqemu-9d993394a1a63e500194b4eabd8a01b1af401a8f.zip
qemu-9d993394a1a63e500194b4eabd8a01b1af401a8f.tar.gz
qemu-9d993394a1a63e500194b4eabd8a01b1af401a8f.tar.bz2
QemuOpts: dump config.
Add a function to write the QemuOpts configuration to a git-style config file. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--qemu-config.c39
-rw-r--r--qemu-config.h2
2 files changed, 41 insertions, 0 deletions
diff --git a/qemu-config.c b/qemu-config.c
index cb2c213..ab2135a 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -257,3 +257,42 @@ int qemu_set_option(const char *str)
return 0;
}
+struct ConfigWriteData {
+ QemuOptsList *list;
+ FILE *fp;
+};
+
+static int config_write_opt(const char *name, const char *value, void *opaque)
+{
+ struct ConfigWriteData *data = opaque;
+
+ fprintf(data->fp, " %s = \"%s\"\n", name, value);
+ return 0;
+}
+
+static int config_write_opts(QemuOpts *opts, void *opaque)
+{
+ struct ConfigWriteData *data = opaque;
+ const char *id = qemu_opts_id(opts);
+
+ if (id) {
+ fprintf(data->fp, "[%s \"%s\"]\n", data->list->name, id);
+ } else {
+ fprintf(data->fp, "[%s]\n", data->list->name);
+ }
+ qemu_opt_foreach(opts, config_write_opt, data, 0);
+ fprintf(data->fp, "\n");
+ return 0;
+}
+
+void qemu_config_write(FILE *fp)
+{
+ struct ConfigWriteData data = { .fp = fp };
+ int i;
+
+ fprintf(fp, "# qemu config file\n\n");
+ for (i = 0; lists[i] != NULL; i++) {
+ data.list = lists[i];
+ qemu_opts_foreach(data.list, config_write_opts, &data, 0);
+ }
+}
diff --git a/qemu-config.h b/qemu-config.h
index 3cc8864..83f9300 100644
--- a/qemu-config.h
+++ b/qemu-config.h
@@ -10,4 +10,6 @@ extern QemuOptsList qemu_rtc_opts;
int qemu_set_option(const char *str);
+void qemu_config_write(FILE *fp);
+
#endif /* QEMU_CONFIG_H */