render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
032100
From 90d326f60706a990db3ed49ba338d911471578c0 Mon Sep 17 00:00:00 2001
032100
Message-Id: <90d326f60706a990db3ed49ba338d911471578c0@dist-git>
032100
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
032100
Date: Thu, 21 Jul 2022 19:29:10 +0200
032100
Subject: [PATCH] qemu: new function to retrieve migration blocker reasons from
032100
 QEMU
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 migration is blocked for some reason,
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, or other conditions, that would cause migration to fail.
032100
032100
This patch adds a function that sends this query via a QMP command and
032100
returns the resulting array of reasons. qemuMigrationSrcIsAllowed()
032100
will be able to use the new function to ask QEMU for migration
032100
blockers, instead of the hardcoded guesses that libvirt currently has.
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 7e52c4839fabac2d19c6f22c99142e992e3d898e)
032100
Resolves: https://bugzilla.redhat.com/2092833
032100
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
032100
---
032100
 src/qemu/qemu_monitor.c      | 12 ++++++++++
032100
 src/qemu/qemu_monitor.h      |  4 ++++
032100
 src/qemu/qemu_monitor_json.c | 46 ++++++++++++++++++++++++++++++++++++
032100
 src/qemu/qemu_monitor_json.h |  3 +++
032100
 4 files changed, 65 insertions(+)
032100
032100
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
032100
index fda5d2f368..865a3e69ed 100644
032100
--- a/src/qemu/qemu_monitor.c
032100
+++ b/src/qemu/qemu_monitor.c
032100
@@ -4541,3 +4541,15 @@ qemuMonitorMigrateRecover(qemuMonitor *mon,
032100
 
032100
     return qemuMonitorJSONMigrateRecover(mon, uri);
032100
 }
032100
+
032100
+
032100
+int
032100
+qemuMonitorGetMigrationBlockers(qemuMonitor *mon,
032100
+                                char ***blockers)
032100
+{
032100
+    VIR_DEBUG("blockers=%p", blockers);
032100
+
032100
+    QEMU_CHECK_MONITOR(mon);
032100
+
032100
+    return qemuMonitorJSONGetMigrationBlockers(mon, blockers);
032100
+}
032100
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
032100
index 95267ec6c7..0c3f023419 100644
032100
--- a/src/qemu/qemu_monitor.h
032100
+++ b/src/qemu/qemu_monitor.h
032100
@@ -1554,3 +1554,7 @@ qemuMonitorChangeMemoryRequestedSize(qemuMonitor *mon,
032100
 int
032100
 qemuMonitorMigrateRecover(qemuMonitor *mon,
032100
                           const char *uri);
032100
+
032100
+int
032100
+qemuMonitorGetMigrationBlockers(qemuMonitor *mon,
032100
+                                char ***blockers);
032100
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
032100
index 3aad2ab212..84f4589c42 100644
032100
--- a/src/qemu/qemu_monitor_json.c
032100
+++ b/src/qemu/qemu_monitor_json.c
032100
@@ -3434,6 +3434,52 @@ int qemuMonitorJSONMigrate(qemuMonitor *mon,
032100
     return 0;
032100
 }
032100
 
032100
+
032100
+/*
032100
+ * Get the exposed migration blockers.
032100
+ *
032100
+ * This function assume qemu has the capability of request them.
032100
+ *
032100
+ * It returns a NULL terminated array on blockers if there are any, or it set
032100
+ * it to NULL otherwise.
032100
+ */
032100
+int
032100
+qemuMonitorJSONGetMigrationBlockers(qemuMonitor *mon,
032100
+                                    char ***blockers)
032100
+{
032100
+    g_autoptr(virJSONValue) cmd = NULL;
032100
+    g_autoptr(virJSONValue) reply = NULL;
032100
+    virJSONValue *data;
032100
+    virJSONValue *jblockers;
032100
+    size_t i;
032100
+
032100
+    *blockers = NULL;
032100
+    if (!(cmd = qemuMonitorJSONMakeCommand("query-migrate", NULL)))
032100
+        return -1;
032100
+
032100
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
032100
+        return -1;
032100
+
032100
+    if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
032100
+        return -1;
032100
+
032100
+    data = virJSONValueObjectGetObject(reply, "return");
032100
+
032100
+    if (!(jblockers = virJSONValueObjectGetArray(data, "blocked-reasons")))
032100
+        return 0;
032100
+
032100
+    *blockers = g_new0(char *, virJSONValueArraySize(jblockers) + 1);
032100
+    for (i = 0; i < virJSONValueArraySize(jblockers); i++) {
032100
+        virJSONValue *jblocker = virJSONValueArrayGet(jblockers, i);
032100
+        const char *blocker = virJSONValueGetString(jblocker);
032100
+
032100
+        (*blockers)[i] = g_strdup(blocker);
032100
+    }
032100
+
032100
+    return 0;
032100
+}
032100
+
032100
+
032100
 int qemuMonitorJSONMigrateCancel(qemuMonitor *mon)
032100
 {
032100
     g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("migrate_cancel", NULL);
032100
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
032100
index ad3853ae69..4e7d6a1a8d 100644
032100
--- a/src/qemu/qemu_monitor_json.h
032100
+++ b/src/qemu/qemu_monitor_json.h
032100
@@ -199,6 +199,9 @@ qemuMonitorJSONMigrate(qemuMonitor *mon,
032100
                        unsigned int flags,
032100
                        const char *uri);
032100
 int
032100
+qemuMonitorJSONGetMigrationBlockers(qemuMonitor *mon,
032100
+                                    char ***blockers);
032100
+int
032100
 qemuMonitorJSONGetSpiceMigrationStatus(qemuMonitor *mon,
032100
                                        bool *spice_migrated);
032100
 
032100
-- 
032100
2.35.1
032100