[PATCH v2 2/9] qemu: Rework qemuMigrationSrcConnect

Martin Kletzander posted 9 patches 5 years, 5 months ago
There is a newer version of this series
[PATCH v2 2/9] qemu: Rework qemuMigrationSrcConnect
Posted by Martin Kletzander 5 years, 5 months ago
Instead of saving some data from a union up front and changing an overlayed
struct before using said data, let's just set the new values after they are
decided.  This will increase the readability of future commit(s).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
 src/qemu/qemu_migration.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 60ddfde65d46..1a3cdb71f424 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3368,24 +3368,24 @@ qemuMigrationSrcConnect(virQEMUDriverPtr driver,
                         qemuMigrationSpecPtr spec)
 {
     virNetSocketPtr sock;
-    const char *host;
     g_autofree char *port = NULL;
+    int fd_qemu = -1;
     int ret = -1;
 
-    host = spec->dest.host.name;
-    port = g_strdup_printf("%d", spec->dest.host.port);
-
-    spec->destType = MIGRATION_DEST_FD;
-    spec->dest.fd.qemu = -1;
-
     if (qemuSecuritySetSocketLabel(driver->securityManager, vm->def) < 0)
         goto cleanup;
-    if (virNetSocketNewConnectTCP(host, port,
+    port = g_strdup_printf("%d", spec->dest.host.port);
+    if (virNetSocketNewConnectTCP(spec->dest.host.name,
+                                  port,
                                   AF_UNSPEC,
                                   &sock) == 0) {
-        spec->dest.fd.qemu = virNetSocketDupFD(sock, true);
+        fd_qemu = virNetSocketDupFD(sock, true);
         virObjectUnref(sock);
     }
+
+    spec->destType = MIGRATION_DEST_FD;
+    spec->dest.fd.qemu = fd_qemu;
+
     if (qemuSecurityClearSocketLabel(driver->securityManager, vm->def) < 0 ||
         spec->dest.fd.qemu == -1)
         goto cleanup;
-- 
2.28.0

Re: [PATCH v2 2/9] qemu: Rework qemuMigrationSrcConnect
Posted by Jiri Denemark 5 years, 5 months ago
On Tue, Sep 01, 2020 at 16:36:53 +0200, Martin Kletzander wrote:
> Instead of saving some data from a union up front and changing an overlayed
> struct before using said data, let's just set the new values after they are
> decided.  This will increase the readability of future commit(s).
> 
> Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
> ---
>  src/qemu/qemu_migration.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>