Blame SOURCES/libvirt-qemu-query-QEMU-for-migration-blockers-before-our-own-harcoded-checks.patch

032100
From 9764a6c484d4f3586b0e0be33e8c53de63b11edd Mon Sep 17 00:00:00 2001
032100
Message-Id: <9764a6c484d4f3586b0e0be33e8c53de63b11edd@dist-git>
032100
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
032100
Date: Thu, 21 Jul 2022 19:29:13 +0200
032100
Subject: [PATCH] qemu: query QEMU for migration blockers before our own
032100
 harcoded checks
032100
MIME-Version: 1.0
032100
Content-Type: text/plain; charset=UTF-8
032100
Content-Transfer-Encoding: 8bit
032100
032100
Since QEMU 6.0, if QEMU knows that a migration would fail,
032100
'query-migrate' will return an array of error strings describing the
032100
migration blockers.  This can be used to check whether there are any
032100
devices/conditions blocking migration.
032100
032100
This patch adds a call to this query at the top of
032100
qemuMigrationSrcIsAllowed().
032100
032100
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
032100
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
032100
Reviewed-by: Laine Stump <laine@redhat.com>
032100
032100
(cherry picked from commit 156e99f686690855be4e45d9b8b3194191a8bc31)
032100
Resolves: https://bugzilla.redhat.com/2092833
032100
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
032100
---
032100
 src/qemu/qemu_migration.c | 30 ++++++++++++++++++++++++++++++
032100
 1 file changed, 30 insertions(+)
032100
032100
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
032100
index 2a6b7b7819..cfb7626bb0 100644
032100
--- a/src/qemu/qemu_migration.c
032100
+++ b/src/qemu/qemu_migration.c
032100
@@ -1415,6 +1415,22 @@ qemuMigrationSrcIsAllowedHostdev(const virDomainDef *def)
032100
 }
032100
 
032100
 
032100
+static int
032100
+qemuDomainGetMigrationBlockers(virQEMUDriver *driver,
032100
+                               virDomainObj *vm,
032100
+                               char ***blockers)
032100
+{
032100
+    qemuDomainObjPrivate *priv = vm->privateData;
032100
+    int rc;
032100
+
032100
+    qemuDomainObjEnterMonitor(driver, vm);
032100
+    rc = qemuMonitorGetMigrationBlockers(priv->mon, blockers);
032100
+    qemuDomainObjExitMonitor(vm);
032100
+
032100
+    return rc;
032100
+}
032100
+
032100
+
032100
 /**
032100
  * qemuMigrationSrcIsAllowed:
032100
  * @driver: qemu driver struct
032100
@@ -1440,6 +1456,20 @@ qemuMigrationSrcIsAllowed(virQEMUDriver *driver,
032100
     int pauseReason;
032100
     size_t i;
032100
 
032100
+    /* Ask qemu if it has a migration blocker */
032100
+    if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATION_BLOCKED_REASONS)) {
032100
+        g_auto(GStrv) blockers = NULL;
032100
+        if (qemuDomainGetMigrationBlockers(driver, vm, &blockers) < 0)
032100
+            return false;
032100
+
032100
+        if (blockers && blockers[0]) {
032100
+            g_autofree char *reasons = g_strjoinv("; ", blockers);
032100
+            virReportError(VIR_ERR_OPERATION_INVALID,
032100
+                           _("cannot migrate domain: %s"), reasons);
032100
+            return false;
032100
+        }
032100
+    }
032100
+
032100
     /* perform these checks only when migrating to remote hosts */
032100
     if (remote) {
032100
         nsnapshots = virDomainSnapshotObjListNum(vm->snapshots, NULL, 0);
032100
-- 
032100
2.35.1
032100