diff mbox series

[1/4] qmp: introduce 'writeconfig' command

Message ID 20171023151310.6462-2-vadim.galitsyn@profitbricks.com
State New
Headers show
Series [1/4] qmp: introduce 'writeconfig' command | expand

Commit Message

Vadim Galitsyn Oct. 23, 2017, 3:13 p.m. UTC
Add support for `writeconfig' command for QMP monitor.
This is a simple way to keep track of current state of VM
after series of hotplugs and/or hotunplugs of different devices.

Signed-off-by: Vadim Galitsyn <vadim.galitsyn@profitbricks.com>
Signed-off-by: Eduardo Otubo <eduardo.otubo@profitbricks.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org
---
 qapi-schema.json | 18 ++++++++++++++++++
 qmp.c            | 21 +++++++++++++++++++++
 2 files changed, 39 insertions(+)

Comments

Eduardo Otubo Oct. 25, 2017, 12:02 p.m. UTC | #1
On Mon, Oct 23, 2017 at 05:13:07PM +0200, Vadim Galitsyn wrote:
> Add support for `writeconfig' command for QMP monitor.
> This is a simple way to keep track of current state of VM
> after series of hotplugs and/or hotunplugs of different devices.
> 
> Signed-off-by: Vadim Galitsyn <vadim.galitsyn@profitbricks.com>
> Signed-off-by: Eduardo Otubo <eduardo.otubo@profitbricks.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> Cc: Eric Blake <eblake@redhat.com>
> Cc: qemu-devel@nongnu.org
> ---
>  qapi-schema.json | 18 ++++++++++++++++++
>  qmp.c            | 21 +++++++++++++++++++++
>  2 files changed, 39 insertions(+)
> 
> diff --git a/qapi-schema.json b/qapi-schema.json
> index a9dd043f65..083f8f3258 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -3200,3 +3200,21 @@
>  # Since: 2.11
>  ##
>  { 'command': 'watchdog-set-action', 'data' : {'action': 'WatchdogAction'} }
> +
> +##
> +# @writeconfig:
> +#
> +# Dump current configuration into specified file
> +#
> +# @file: pathname of a file to store current configuration
> +#
> +# Since: 2.11
> +#
> +# Example:
> +#
> +# -> { "execute": "writeconfig",
> +#      "arguments": { "file": "/tmp/qemu.conf" } }
> +# <- { "return": {} }
> +#
> +##
> +{ 'command': 'writeconfig', 'data': {'file': 'str'} }
> diff --git a/qmp.c b/qmp.c
> index e8c303116a..fcb911cabb 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -722,3 +722,24 @@ MemoryInfo *qmp_query_memory_size_summary(Error **errp)
>  
>      return mem_info;
>  }
> +
> +void qmp_writeconfig(const char *file, Error **errp)
> +{
> +    int fd;
> +    FILE *fp;
> +
> +    fd = qemu_open(file,  O_WRONLY | O_CREAT | O_TRUNC, 0600);
> +    if (fd != -1) {
> +
> +        fp = fdopen(fd, "wb");
> +        if (fp) {
> +            qemu_config_write(fp);
> +            fclose(fp);
> +            return;
> +        }
> +
> +        qemu_close(fd);
> +    }
> +
> +    error_setg(errp, "cannot write configuration file: '%s'", file);
> +}
> -- 
> 2.13.1.394.g41dd433
> 
> 

Reviewed-by: Eduardo Otubo <otubo@redhat.com>
Marc-André Lureau Oct. 26, 2017, 11:37 a.m. UTC | #2
Hi

On Mon, Oct 23, 2017 at 5:13 PM, Vadim Galitsyn <
vadim.galitsyn@profitbricks.com> wrote:

> Add support for `writeconfig' command for QMP monitor.
> This is a simple way to keep track of current state of VM
> after series of hotplugs and/or hotunplugs of different devices.
>
> Signed-off-by: Vadim Galitsyn <vadim.galitsyn@profitbricks.com>
> Signed-off-by: Eduardo Otubo <eduardo.otubo@profitbricks.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> Cc: Eric Blake <eblake@redhat.com>
> Cc: qemu-devel@nongnu.org
> ---
>  qapi-schema.json | 18 ++++++++++++++++++
>  qmp.c            | 21 +++++++++++++++++++++
>  2 files changed, 39 insertions(+)
>
> diff --git a/qapi-schema.json b/qapi-schema.json
> index a9dd043f65..083f8f3258 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -3200,3 +3200,21 @@
>  # Since: 2.11
>  ##
>  { 'command': 'watchdog-set-action', 'data' : {'action': 'WatchdogAction'}
> }
> +
> +##
> +# @writeconfig:
> +#
> +# Dump current configuration into specified file
> +#
> +# @file: pathname of a file to store current configuration
> +#
> +# Since: 2.11
> +#
> +# Example:
> +#
> +# -> { "execute": "writeconfig",
> +#      "arguments": { "file": "/tmp/qemu.conf" } }
> +# <- { "return": {} }
> +#
> +##
> +{ 'command': 'writeconfig', 'data': {'file': 'str'} }
> diff --git a/qmp.c b/qmp.c
> index e8c303116a..fcb911cabb 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -722,3 +722,24 @@ MemoryInfo *qmp_query_memory_size_summary(Error
> **errp)
>
>      return mem_info;
>  }
> +
> +void qmp_writeconfig(const char *file, Error **errp)
> +{
> +    int fd;
> +    FILE *fp;
> +
> +    fd = qemu_open(file,  O_WRONLY | O_CREAT | O_TRUNC, 0600);
> +    if (fd != -1) {
> +
> +        fp = fdopen(fd, "wb");
> +        if (fp) {
> +            qemu_config_write(fp);
> +            fclose(fp);
>

If you use /dev/fdset, this will close the underlying file, but not remove
the file from the fdset.

Dup it or remove it with monitor_fdset_dup_fd_remove() etc?

+            return;
> +        }
> +
> +        qemu_close(fd);
>

But this will close & remove it from fdset (when the operation failed)

Whatever we do, I think it make sense to document the behaviour.



> +    }
> +
> +    error_setg(errp, "cannot write configuration file: '%s'", file);
> +}
> --
> 2.13.1.394.g41dd433
>
>
>
diff mbox series

Patch

diff --git a/qapi-schema.json b/qapi-schema.json
index a9dd043f65..083f8f3258 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3200,3 +3200,21 @@ 
 # Since: 2.11
 ##
 { 'command': 'watchdog-set-action', 'data' : {'action': 'WatchdogAction'} }
+
+##
+# @writeconfig:
+#
+# Dump current configuration into specified file
+#
+# @file: pathname of a file to store current configuration
+#
+# Since: 2.11
+#
+# Example:
+#
+# -> { "execute": "writeconfig",
+#      "arguments": { "file": "/tmp/qemu.conf" } }
+# <- { "return": {} }
+#
+##
+{ 'command': 'writeconfig', 'data': {'file': 'str'} }
diff --git a/qmp.c b/qmp.c
index e8c303116a..fcb911cabb 100644
--- a/qmp.c
+++ b/qmp.c
@@ -722,3 +722,24 @@  MemoryInfo *qmp_query_memory_size_summary(Error **errp)
 
     return mem_info;
 }
+
+void qmp_writeconfig(const char *file, Error **errp)
+{
+    int fd;
+    FILE *fp;
+
+    fd = qemu_open(file,  O_WRONLY | O_CREAT | O_TRUNC, 0600);
+    if (fd != -1) {
+
+        fp = fdopen(fd, "wb");
+        if (fp) {
+            qemu_config_write(fp);
+            fclose(fp);
+            return;
+        }
+
+        qemu_close(fd);
+    }
+
+    error_setg(errp, "cannot write configuration file: '%s'", file);
+}