render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 44d255b6cc7315537e66f1d97e4893e321b694b8 Mon Sep 17 00:00:00 2001
Message-Id: <44d255b6cc7315537e66f1d97e4893e321b694b8@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 4 Feb 2020 15:08:02 +0100
Subject: [PATCH] qemuMigrationCookieAddNBD: Exit early if there are no disks
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Refactor the logic to skip the body of the function if there's nothing
to do.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit bdff9d4513694da8d9b2bb60a1f808fb1c286388)

https://bugzilla.redhat.com/show_bug.cgi?id=1793263
Message-Id: <b12c9b8c4ca78e848e43ab4ae7706a5694cfb49c.1580824112.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_migration_cookie.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c
index 299bf17c9e..73ae815818 100644
--- a/src/qemu/qemu_migration_cookie.c
+++ b/src/qemu/qemu_migration_cookie.c
@@ -464,8 +464,13 @@ qemuMigrationCookieAddNBD(qemuMigrationCookiePtr mig,
     if (VIR_ALLOC(mig->nbd) < 0)
         return -1;
 
-    if (vm->def->ndisks &&
-        VIR_ALLOC_N(mig->nbd->disks, vm->def->ndisks) < 0)
+    mig->nbd->port = priv->nbdPort;
+    mig->flags |= QEMU_MIGRATION_COOKIE_NBD;
+
+    if (vm->def->ndisks == 0)
+        return 0;
+
+    if (VIR_ALLOC_N(mig->nbd->disks, vm->def->ndisks) < 0)
         return -1;
     mig->nbd->ndisks = 0;
 
@@ -496,9 +501,6 @@ qemuMigrationCookieAddNBD(qemuMigrationCookiePtr mig,
         mig->nbd->ndisks++;
     }
 
-    mig->nbd->port = priv->nbdPort;
-    mig->flags |= QEMU_MIGRATION_COOKIE_NBD;
-
     ret = 0;
  cleanup:
     virHashFree(stats);
-- 
2.25.0