[PATCH V8 03/39] migration: simplify savevm

Steve Sistare posted 39 patches 3 years, 7 months ago
Maintainers: Stefano Stabellini <sstabellini@kernel.org>, Anthony Perard <anthony.perard@citrix.com>, Paul Durrant <paul@xen.org>, David Hildenbrand <david@redhat.com>, Igor Mammedov <imammedo@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Alex Williamson <alex.williamson@redhat.com>, Steve Sistare <steven.sistare@oracle.com>, Mark Kanda <mark.kanda@oracle.com>, Peter Xu <peterx@redhat.com>, Juan Quintela <quintela@redhat.com>, Markus Armbruster <armbru@redhat.com>, Michael Roth <michael.roth@amd.com>, John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>, Beraldo Leal <bleal@redhat.com>, Eric Blake <eblake@redhat.com>, Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>, Wainer dos Santos Moschetta <wainersm@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Stefan Weil <sw@weilnetz.de>
There is a newer version of this series
[PATCH V8 03/39] migration: simplify savevm
Posted by Steve Sistare 3 years, 7 months ago
Use qemu_file_open to simplify a few functions in savevm.c.
No functional change.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 migration/savevm.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/migration/savevm.c b/migration/savevm.c
index d907689..0b2c5cd 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -2931,7 +2931,6 @@ void qmp_xen_save_devices_state(const char *filename, bool has_live, bool live,
                                 Error **errp)
 {
     QEMUFile *f;
-    QIOChannelFile *ioc;
     int saved_vm_running;
     int ret;
 
@@ -2945,14 +2944,11 @@ void qmp_xen_save_devices_state(const char *filename, bool has_live, bool live,
     vm_stop(RUN_STATE_SAVE_VM);
     global_state_store_running();
 
-    ioc = qio_channel_file_new_path(filename, O_WRONLY | O_CREAT | O_TRUNC,
-                                    0660, errp);
-    if (!ioc) {
+    f = qemu_fopen_file(filename, O_WRONLY | O_CREAT | O_TRUNC, 0660,
+                        "migration-xen-save-state", errp);
+    if (!f) {
         goto the_end;
     }
-    qio_channel_set_name(QIO_CHANNEL(ioc), "migration-xen-save-state");
-    f = qemu_fopen_channel_output(QIO_CHANNEL(ioc));
-    object_unref(OBJECT(ioc));
     ret = qemu_save_device_state(f);
     if (ret < 0 || qemu_fclose(f) < 0) {
         error_setg(errp, QERR_IO_ERROR);
@@ -2981,7 +2977,6 @@ void qmp_xen_save_devices_state(const char *filename, bool has_live, bool live,
 void qmp_xen_load_devices_state(const char *filename, Error **errp)
 {
     QEMUFile *f;
-    QIOChannelFile *ioc;
     int ret;
 
     /* Guest must be paused before loading the device state; the RAM state
@@ -2993,14 +2988,11 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp)
     }
     vm_stop(RUN_STATE_RESTORE_VM);
 
-    ioc = qio_channel_file_new_path(filename, O_RDONLY | O_BINARY, 0, errp);
-    if (!ioc) {
+    f = qemu_fopen_file(filename, O_RDONLY | O_BINARY, 0,
+                        "migration-xen-load-state", errp);
+    if (!f) {
         return;
     }
-    qio_channel_set_name(QIO_CHANNEL(ioc), "migration-xen-load-state");
-    f = qemu_fopen_channel_input(QIO_CHANNEL(ioc));
-    object_unref(OBJECT(ioc));
-
     ret = qemu_loadvm_state(f);
     qemu_fclose(f);
     if (ret < 0) {
-- 
1.8.3.1
Re: [PATCH V8 03/39] migration: simplify savevm
Posted by Marc-André Lureau 3 years, 7 months ago
Hi

On Wed, Jun 15, 2022 at 6:57 PM Steve Sistare <steven.sistare@oracle.com>
wrote:

> Use qemu_file_open to simplify a few functions in savevm.c.
> No functional change.
>
> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
>

(ok, I get why you keep the mode_t in fopen)

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

---
>  migration/savevm.c | 20 ++++++--------------
>  1 file changed, 6 insertions(+), 14 deletions(-)
>
> diff --git a/migration/savevm.c b/migration/savevm.c
> index d907689..0b2c5cd 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -2931,7 +2931,6 @@ void qmp_xen_save_devices_state(const char
> *filename, bool has_live, bool live,
>                                  Error **errp)
>  {
>      QEMUFile *f;
> -    QIOChannelFile *ioc;
>      int saved_vm_running;
>      int ret;
>
> @@ -2945,14 +2944,11 @@ void qmp_xen_save_devices_state(const char
> *filename, bool has_live, bool live,
>      vm_stop(RUN_STATE_SAVE_VM);
>      global_state_store_running();
>
> -    ioc = qio_channel_file_new_path(filename, O_WRONLY | O_CREAT |
> O_TRUNC,
> -                                    0660, errp);
> -    if (!ioc) {
> +    f = qemu_fopen_file(filename, O_WRONLY | O_CREAT | O_TRUNC, 0660,
> +                        "migration-xen-save-state", errp);
> +    if (!f) {
>          goto the_end;
>      }
> -    qio_channel_set_name(QIO_CHANNEL(ioc), "migration-xen-save-state");
> -    f = qemu_fopen_channel_output(QIO_CHANNEL(ioc));
> -    object_unref(OBJECT(ioc));
>      ret = qemu_save_device_state(f);
>      if (ret < 0 || qemu_fclose(f) < 0) {
>          error_setg(errp, QERR_IO_ERROR);
> @@ -2981,7 +2977,6 @@ void qmp_xen_save_devices_state(const char
> *filename, bool has_live, bool live,
>  void qmp_xen_load_devices_state(const char *filename, Error **errp)
>  {
>      QEMUFile *f;
> -    QIOChannelFile *ioc;
>      int ret;
>
>      /* Guest must be paused before loading the device state; the RAM state
> @@ -2993,14 +2988,11 @@ void qmp_xen_load_devices_state(const char
> *filename, Error **errp)
>      }
>      vm_stop(RUN_STATE_RESTORE_VM);
>
> -    ioc = qio_channel_file_new_path(filename, O_RDONLY | O_BINARY, 0,
> errp);
> -    if (!ioc) {
> +    f = qemu_fopen_file(filename, O_RDONLY | O_BINARY, 0,
> +                        "migration-xen-load-state", errp);
> +    if (!f) {
>          return;
>      }
> -    qio_channel_set_name(QIO_CHANNEL(ioc), "migration-xen-load-state");
> -    f = qemu_fopen_channel_input(QIO_CHANNEL(ioc));
> -    object_unref(OBJECT(ioc));
> -
>      ret = qemu_loadvm_state(f);
>      qemu_fclose(f);
>      if (ret < 0) {
> --
> 1.8.3.1
>
>
>

-- 
Marc-André Lureau