99cbc7
From 01aa947e223d82d4663270f1ac7ff2af3b31ccca Mon Sep 17 00:00:00 2001
99cbc7
Message-Id: <01aa947e223d82d4663270f1ac7ff2af3b31ccca@dist-git>
99cbc7
From: Michal Privoznik <mprivozn@redhat.com>
99cbc7
Date: Wed, 11 Jul 2018 17:27:28 +0200
99cbc7
Subject: [PATCH] qemu: Fetch pr-helper process info on reconnect
99cbc7
MIME-Version: 1.0
99cbc7
Content-Type: text/plain; charset=UTF-8
99cbc7
Content-Transfer-Encoding: 8bit
99cbc7
99cbc7
https://bugzilla.redhat.com/show_bug.cgi?id=1470007
99cbc7
99cbc7
If qemu-pr-helper process died while libvirtd was not running no
99cbc7
event is emitted. Therefore, when reconnecting to the monitor we
99cbc7
must check the qemu-pr-helper process status and act accordingly.
99cbc7
99cbc7
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
99cbc7
(cherry picked from commit ab435a4be4673a9a38e0315864b9cf4f9bee03e7)
99cbc7
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
99cbc7
Reviewed-by: Ján Tomko <jtomko@redhat.com>
99cbc7
---
99cbc7
 src/qemu/qemu_process.c | 60 +++++++++++++++++++++++++++++++++++++++++
99cbc7
 1 file changed, 60 insertions(+)
99cbc7
99cbc7
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
99cbc7
index fbc8529f3b..c903a8e5c8 100644
99cbc7
--- a/src/qemu/qemu_process.c
99cbc7
+++ b/src/qemu/qemu_process.c
99cbc7
@@ -2071,6 +2071,63 @@ qemuRefreshVirtioChannelState(virQEMUDriverPtr driver,
99cbc7
     return ret;
99cbc7
 }
99cbc7
 
99cbc7
+
99cbc7
+static int
99cbc7
+qemuProcessRefreshPRManagerState(virDomainObjPtr vm,
99cbc7
+                                 virHashTablePtr info)
99cbc7
+{
99cbc7
+    qemuDomainObjPrivatePtr priv = vm->privateData;
99cbc7
+    qemuMonitorPRManagerInfoPtr prManagerInfo;
99cbc7
+    const char *managedAlias = qemuDomainGetManagedPRAlias();
99cbc7
+    int ret = -1;
99cbc7
+
99cbc7
+    if (!(prManagerInfo = virHashLookup(info, managedAlias))) {
99cbc7
+        virReportError(VIR_ERR_OPERATION_FAILED,
99cbc7
+                       _("missing info on pr-manager %s"),
99cbc7
+                       managedAlias);
99cbc7
+        goto cleanup;
99cbc7
+    }
99cbc7
+
99cbc7
+    priv->prDaemonRunning = prManagerInfo->connected;
99cbc7
+
99cbc7
+    if (!priv->prDaemonRunning &&
99cbc7
+        qemuProcessStartManagedPRDaemon(vm) < 0)
99cbc7
+        goto cleanup;
99cbc7
+
99cbc7
+    ret = 0;
99cbc7
+ cleanup:
99cbc7
+    return ret;
99cbc7
+}
99cbc7
+
99cbc7
+
99cbc7
+static int
99cbc7
+qemuRefreshPRManagerState(virQEMUDriverPtr driver,
99cbc7
+                          virDomainObjPtr vm)
99cbc7
+{
99cbc7
+    qemuDomainObjPrivatePtr priv = vm->privateData;
99cbc7
+    virHashTablePtr info = NULL;
99cbc7
+    int ret = -1;
99cbc7
+
99cbc7
+    if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_PR_MANAGER_HELPER) ||
99cbc7
+        !virDomainDefHasManagedPR(vm->def))
99cbc7
+        return 0;
99cbc7
+
99cbc7
+    qemuDomainObjEnterMonitor(driver, vm);
99cbc7
+    ret = qemuMonitorGetPRManagerInfo(priv->mon, &info;;
99cbc7
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
99cbc7
+        ret = -1;
99cbc7
+
99cbc7
+    if (ret < 0)
99cbc7
+        goto cleanup;
99cbc7
+
99cbc7
+    ret = qemuProcessRefreshPRManagerState(vm, info);
99cbc7
+
99cbc7
+ cleanup:
99cbc7
+    virHashFree(info);
99cbc7
+    return ret;
99cbc7
+}
99cbc7
+
99cbc7
+
99cbc7
 static void
99cbc7
 qemuRefreshRTC(virQEMUDriverPtr driver,
99cbc7
                virDomainObjPtr vm)
99cbc7
@@ -7736,6 +7793,9 @@ qemuProcessReconnect(void *opaque)
99cbc7
     if (qemuProcessUpdateDevices(driver, obj) < 0)
99cbc7
         goto error;
99cbc7
 
99cbc7
+    if (qemuRefreshPRManagerState(driver, obj) < 0)
99cbc7
+        goto error;
99cbc7
+
99cbc7
     qemuProcessReconnectCheckMemAliasOrderMismatch(obj);
99cbc7
 
99cbc7
     if (qemuConnectAgent(driver, obj) < 0)
99cbc7
-- 
99cbc7
2.18.0
99cbc7