All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduardo Otubo <eduardo.otubo@profitbricks.com>
To: qemu-devel@nongnu.org
Cc: dgilbert@redhat.com, armbru@redhat.com,
	Eduardo Otubo <eduardo.otubo@profitbricks.com>
Subject: [Qemu-devel] [PATCH 1/2] qmp/hmp: add writeconfig
Date: Wed, 15 Feb 2017 11:14:26 +0100	[thread overview]
Message-ID: <20170215101427.23736-2-eduardo.otubo@profitbricks.com> (raw)
In-Reply-To: <20170215101427.23736-1-eduardo.otubo@profitbricks.com>

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(+)

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
+@item writeconfig @var{filename}
+@findex 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

  reply	other threads:[~2017-02-15 10:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-15 10:14 [Qemu-devel] [PATCH 0/2] add writeconfig command on monitor Eduardo Otubo
2017-02-15 10:14 ` Eduardo Otubo [this message]
2017-02-16 16:12   ` [Qemu-devel] [PATCH 1/2] qmp/hmp: add writeconfig Eric Blake
2017-02-15 10:14 ` [Qemu-devel] [PATCH 2/2] object_add not registering option Eduardo Otubo
2017-02-16  9:23 ` [Qemu-devel] [PATCH 0/2] add writeconfig command on monitor Markus Armbruster
2017-02-16  9:53   ` Dr. David Alan Gilbert
2017-02-16 10:31     ` Eduardo Otubo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170215101427.23736-2-eduardo.otubo@profitbricks.com \
    --to=eduardo.otubo@profitbricks.com \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.