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

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