@@ -252,6 +252,20 @@ Password: ********
ETEXI
{
+ .name = "writeconfig",
+ .args_type = "filename:F",
+ .params = "filename",
+ .help = "write config file",
+ .cmd = hmp_writeconfig,
+ },
+
+STEXI
+@item writeconfig @var{filename}
+@findex writeconfig
+Write config file @var{filename}.
+ETEXI
+
+ {
.name = "screendump",
.args_type = "filename:F",
.params = "filename",
@@ -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");
@@ -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);
@@ -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.
@@ -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);
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 <eduardo.otubo@profitbricks.com> --- hmp-commands.hx | 14 ++++++++++++++ hmp.c | 9 +++++++++ hmp.h | 1 + qapi-schema.json | 20 ++++++++++++++++++++ ui/console.c | 14 ++++++++++++++ 5 files changed, 58 insertions(+)