[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/2] qmp/hmp: add writeconfig
From: |
Eduardo Otubo |
Subject: |
[Qemu-devel] [PATCH 1/2] qmp/hmp: add writeconfig |
Date: |
Wed, 15 Feb 2017 11:14:26 +0100 |
This patch adds support for the command `writeconfig' on the QMP and HMP
consoles. This is a simple way to keep track of current state of VM
after series of hotplugs and/or hotunplugs of different devices:
(qemu) writeconfig qemu.conf
Signed-off-by: Eduardo Otubo <address@hidden>
---
hmp-commands.hx | 14 ++++++++++++++
hmp.c | 9 +++++++++
hmp.h | 1 +
qapi-schema.json | 20 ++++++++++++++++++++
ui/console.c | 14 ++++++++++++++
5 files changed, 58 insertions(+)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 88192817b2..ac562192bb 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -252,6 +252,20 @@ Password: ********
ETEXI
{
+ .name = "writeconfig",
+ .args_type = "filename:F",
+ .params = "filename",
+ .help = "write config file",
+ .cmd = hmp_writeconfig,
+ },
+
+STEXI
address@hidden writeconfig @var{filename}
address@hidden writeconfig
+Write config file @var{filename}.
+ETEXI
+
+ {
.name = "screendump",
.args_type = "filename:F",
.params = "filename",
diff --git a/hmp.c b/hmp.c
index 2bc4f062bb..4f2b8a10d2 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1913,6 +1913,15 @@ err_out:
goto out;
}
+void hmp_writeconfig(Monitor *mon, const QDict *qdict)
+{
+ const char *filename = qdict_get_str(qdict, "filename");
+ Error *err = NULL;
+
+ qmp_writeconfig(filename, &err);
+ hmp_handle_error(mon, &err);
+}
+
void hmp_screendump(Monitor *mon, const QDict *qdict)
{
const char *filename = qdict_get_str(qdict, "filename");
diff --git a/hmp.h b/hmp.h
index 05daf7cd5c..63d44fe50f 100644
--- a/hmp.h
+++ b/hmp.h
@@ -94,6 +94,7 @@ void hmp_getfd(Monitor *mon, const QDict *qdict);
void hmp_closefd(Monitor *mon, const QDict *qdict);
void hmp_sendkey(Monitor *mon, const QDict *qdict);
void hmp_screendump(Monitor *mon, const QDict *qdict);
+void hmp_writeconfig(Monitor *mon, const QDict *qdict);
void hmp_nbd_server_start(Monitor *mon, const QDict *qdict);
void hmp_nbd_server_add(Monitor *mon, const QDict *qdict);
void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict);
diff --git a/qapi-schema.json b/qapi-schema.json
index 5edb08d621..c19b1ff3df 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4696,6 +4696,26 @@
'data': { 'keys': ['KeyValue'], '*hold-time': 'int' } }
##
+# @writeconfig:
+#
+# Write config to file.
+#
+# @filename: the path of a new file to store the current config
+#
+# Returns: Nothing on success
+#
+# Since: 2.7.0
+#
+# Example:
+#
+# -> { "execute": "writeconfig",
+# "arguments": { "filename": "/tmp/qemu.conf" } }
+# <- { "return": {} }
+#
+##
+{ 'command': 'writeconfig', 'data': {'filename': 'str'} }
+
+##
# @screendump:
#
# Write a PPM of the VGA screen to a file.
diff --git a/ui/console.c b/ui/console.c
index 49d0740b40..d2e3d753a8 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -30,6 +30,7 @@
#include "sysemu/char.h"
#include "trace.h"
#include "exec/memory.h"
+#include "qemu/config-file.h"
#define DEFAULT_BACKSCROLL 512
#define CONSOLE_CURSOR_PERIOD 500
@@ -342,6 +343,19 @@ write_err:
goto out;
}
+void qmp_writeconfig(const char *filename, Error **errp)
+{
+ if (filename == NULL) {
+ error_setg(errp, "You must specify a filename.");
+ return;
+ }
+
+ FILE *fp;
+ fp = fopen(filename, "w");
+ qemu_config_write(fp);
+ fclose(fp);
+}
+
void qmp_screendump(const char *filename, Error **errp)
{
QemuConsole *con = qemu_console_lookup_by_index(0);
--
2.11.0