提交 9d993394 编写于 作者: G Gerd Hoffmann 提交者: Anthony Liguori

QemuOpts: dump config.

Add a function to write the QemuOpts configuration to a git-style
config file.
Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 ddc97855
......@@ -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);
}
}
......@@ -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 */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册