render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
982648
From 4332debbdbe28cf3194bb782c543710aa14097f3 Mon Sep 17 00:00:00 2001
982648
Message-Id: <4332debbdbe28cf3194bb782c543710aa14097f3@dist-git>
982648
From: Michal Privoznik <mprivozn@redhat.com>
982648
Date: Wed, 11 Jul 2018 17:27:26 +0200
982648
Subject: [PATCH] qemu: Wire up PR_MANAGER_STATUS_CHANGED event
982648
MIME-Version: 1.0
982648
Content-Type: text/plain; charset=UTF-8
982648
Content-Transfer-Encoding: 8bit
982648
982648
https://bugzilla.redhat.com/show_bug.cgi?id=1470007
982648
982648
This event is emitted on the monitor if one of pr-managers lost
982648
connection to its pr-helper process. What libvirt needs to do is
982648
restart the pr-helper process iff it corresponds to managed
982648
pr-manager.
982648
982648
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
982648
(cherry picked from commit 6fbda83330293ed8bec1ea9e3ba7273c4ee2b9e2)
982648
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
982648
Reviewed-by: Ján Tomko <jtomko@redhat.com>
982648
---
982648
 src/qemu/qemu_domain.c       |  1 +
982648
 src/qemu/qemu_domain.h       |  1 +
982648
 src/qemu/qemu_driver.c       | 17 +++++++++++
982648
 src/qemu/qemu_monitor.c      | 15 ++++++++++
982648
 src/qemu/qemu_monitor.h      | 11 ++++++++
982648
 src/qemu/qemu_monitor_json.c | 23 +++++++++++++++
982648
 src/qemu/qemu_process.c      | 55 ++++++++++++++++++++++++++++++++++++
982648
 7 files changed, 123 insertions(+)
982648
982648
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
982648
index cfecbaca74..dec057e021 100644
982648
--- a/src/qemu/qemu_domain.c
982648
+++ b/src/qemu/qemu_domain.c
982648
@@ -12979,6 +12979,7 @@ qemuProcessEventFree(struct qemuProcessEvent *event)
982648
     case QEMU_PROCESS_EVENT_MONITOR_EOF:
982648
         VIR_FREE(event->data);
982648
         break;
982648
+    case QEMU_PROCESS_EVENT_PR_DISCONNECT:
982648
     case QEMU_PROCESS_EVENT_LAST:
982648
         break;
982648
     }
982648
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
982648
index 30d186a921..e748d78adb 100644
982648
--- a/src/qemu/qemu_domain.h
982648
+++ b/src/qemu/qemu_domain.h
982648
@@ -477,6 +477,7 @@ typedef enum {
982648
     QEMU_PROCESS_EVENT_SERIAL_CHANGED,
982648
     QEMU_PROCESS_EVENT_BLOCK_JOB,
982648
     QEMU_PROCESS_EVENT_MONITOR_EOF,
982648
+    QEMU_PROCESS_EVENT_PR_DISCONNECT,
982648
 
982648
     QEMU_PROCESS_EVENT_LAST
982648
 } qemuProcessEventType;
982648
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
982648
index 00952a55e7..4cb05bf81c 100644
982648
--- a/src/qemu/qemu_driver.c
982648
+++ b/src/qemu/qemu_driver.c
982648
@@ -4790,6 +4790,20 @@ processMonitorEOFEvent(virQEMUDriverPtr driver,
982648
 }
982648
 
982648
 
982648
+static void
982648
+processPRDisconnectEvent(virDomainObjPtr vm)
982648
+{
982648
+    qemuDomainObjPrivatePtr priv = vm->privateData;
982648
+
982648
+    if (!virDomainObjIsActive(vm))
982648
+        return;
982648
+
982648
+    if (!priv->prDaemonRunning &&
982648
+        virDomainDefHasManagedPR(vm->def))
982648
+        qemuProcessStartManagedPRDaemon(vm);
982648
+}
982648
+
982648
+
982648
 static void qemuProcessEventHandler(void *data, void *opaque)
982648
 {
982648
     struct qemuProcessEvent *processEvent = data;
982648
@@ -4827,6 +4841,9 @@ static void qemuProcessEventHandler(void *data, void *opaque)
982648
     case QEMU_PROCESS_EVENT_MONITOR_EOF:
982648
         processMonitorEOFEvent(driver, vm);
982648
         break;
982648
+    case QEMU_PROCESS_EVENT_PR_DISCONNECT:
982648
+        processPRDisconnectEvent(vm);
982648
+        break;
982648
     case QEMU_PROCESS_EVENT_LAST:
982648
         break;
982648
     }
982648
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
982648
index 8d1c358f67..0de2b91cee 100644
982648
--- a/src/qemu/qemu_monitor.c
982648
+++ b/src/qemu/qemu_monitor.c
982648
@@ -1669,6 +1669,21 @@ qemuMonitorEmitDumpCompleted(qemuMonitorPtr mon,
982648
 }
982648
 
982648
 
982648
+int
982648
+qemuMonitorEmitPRManagerStatusChanged(qemuMonitorPtr mon,
982648
+                                      const char *prManager,
982648
+                                      bool connected)
982648
+{
982648
+    int ret = -1;
982648
+    VIR_DEBUG("mon=%p, prManager='%s', connected=%d", mon, prManager, connected);
982648
+
982648
+    QEMU_MONITOR_CALLBACK(mon, ret, domainPRManagerStatusChanged,
982648
+                          mon->vm, prManager, connected);
982648
+
982648
+    return ret;
982648
+}
982648
+
982648
+
982648
 int
982648
 qemuMonitorSetCapabilities(qemuMonitorPtr mon)
982648
 {
982648
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
982648
index 7bfd4b23a2..22bc1468e7 100644
982648
--- a/src/qemu/qemu_monitor.h
982648
+++ b/src/qemu/qemu_monitor.h
982648
@@ -273,6 +273,12 @@ typedef int (*qemuMonitorDomainDumpCompletedCallback)(qemuMonitorPtr mon,
982648
                                                       const char *error,
982648
                                                       void *opaque);
982648
 
982648
+typedef int (*qemuMonitorDomainPRManagerStatusChangedCallback)(qemuMonitorPtr mon,
982648
+                                                               virDomainObjPtr vm,
982648
+                                                               const char *prManager,
982648
+                                                               bool connected,
982648
+                                                               void *opaque);
982648
+
982648
 typedef struct _qemuMonitorCallbacks qemuMonitorCallbacks;
982648
 typedef qemuMonitorCallbacks *qemuMonitorCallbacksPtr;
982648
 struct _qemuMonitorCallbacks {
982648
@@ -305,6 +311,7 @@ struct _qemuMonitorCallbacks {
982648
     qemuMonitorDomainAcpiOstInfoCallback domainAcpiOstInfo;
982648
     qemuMonitorDomainBlockThresholdCallback domainBlockThreshold;
982648
     qemuMonitorDomainDumpCompletedCallback domainDumpCompleted;
982648
+    qemuMonitorDomainPRManagerStatusChangedCallback domainPRManagerStatusChanged;
982648
 };
982648
 
982648
 char *qemuMonitorEscapeArg(const char *in);
982648
@@ -433,6 +440,10 @@ int qemuMonitorEmitDumpCompleted(qemuMonitorPtr mon,
982648
                                  qemuMonitorDumpStatsPtr stats,
982648
                                  const char *error);
982648
 
982648
+int qemuMonitorEmitPRManagerStatusChanged(qemuMonitorPtr mon,
982648
+                                          const char *prManager,
982648
+                                          bool connected);
982648
+
982648
 int qemuMonitorStartCPUs(qemuMonitorPtr mon);
982648
 int qemuMonitorStopCPUs(qemuMonitorPtr mon);
982648
 
982648
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
982648
index 1bc5b662ae..0c172b6e3c 100644
982648
--- a/src/qemu/qemu_monitor_json.c
982648
+++ b/src/qemu/qemu_monitor_json.c
982648
@@ -91,6 +91,7 @@ static void qemuMonitorJSONHandleMigrationPass(qemuMonitorPtr mon, virJSONValueP
982648
 static void qemuMonitorJSONHandleAcpiOstInfo(qemuMonitorPtr mon, virJSONValuePtr data);
982648
 static void qemuMonitorJSONHandleBlockThreshold(qemuMonitorPtr mon, virJSONValuePtr data);
982648
 static void qemuMonitorJSONHandleDumpCompleted(qemuMonitorPtr mon, virJSONValuePtr data);
982648
+static void qemuMonitorJSONHandlePRManagerStatusChanged(qemuMonitorPtr mon, virJSONValuePtr data);
982648
 
982648
 typedef struct {
982648
     const char *type;
982648
@@ -113,6 +114,7 @@ static qemuEventHandler eventHandlers[] = {
982648
     { "MIGRATION_PASS", qemuMonitorJSONHandleMigrationPass, },
982648
     { "NIC_RX_FILTER_CHANGED", qemuMonitorJSONHandleNicRxFilterChanged, },
982648
     { "POWERDOWN", qemuMonitorJSONHandlePowerdown, },
982648
+    { "PR_MANAGER_STATUS_CHANGED", qemuMonitorJSONHandlePRManagerStatusChanged, },
982648
     { "RESET", qemuMonitorJSONHandleReset, },
982648
     { "RESUME", qemuMonitorJSONHandleResume, },
982648
     { "RTC_CHANGE", qemuMonitorJSONHandleRTCChange, },
982648
@@ -1303,6 +1305,27 @@ qemuMonitorJSONHandleDumpCompleted(qemuMonitorPtr mon,
982648
 }
982648
 
982648
 
982648
+static void qemuMonitorJSONHandlePRManagerStatusChanged(qemuMonitorPtr mon,
982648
+                                                        virJSONValuePtr data)
982648
+{
982648
+    const char *name;
982648
+    bool connected;
982648
+
982648
+    if (!(name = virJSONValueObjectGetString(data, "id"))) {
982648
+        VIR_WARN("missing pr-manager alias in PR_MANAGER_STATUS_CHANGED event");
982648
+        return;
982648
+    }
982648
+
982648
+    if (virJSONValueObjectGetBoolean(data, "connected", &connected) < 0) {
982648
+        VIR_WARN("missing connected state for %s "
982648
+                 "in PR_MANAGER_STATUS_CHANGED event", name);
982648
+        return;
982648
+    }
982648
+
982648
+    qemuMonitorEmitPRManagerStatusChanged(mon, name, connected);
982648
+}
982648
+
982648
+
982648
 int
982648
 qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
982648
                                   const char *cmd_str,
982648
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
982648
index f200729cb1..fbc8529f3b 100644
982648
--- a/src/qemu/qemu_process.c
982648
+++ b/src/qemu/qemu_process.c
982648
@@ -1615,6 +1615,60 @@ qemuProcessHandleDumpCompleted(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
982648
 }
982648
 
982648
 
982648
+static int
982648
+qemuProcessHandlePRManagerStatusChanged(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
982648
+                                        virDomainObjPtr vm,
982648
+                                        const char *prManager,
982648
+                                        bool connected,
982648
+                                        void *opaque)
982648
+{
982648
+    virQEMUDriverPtr driver = opaque;
982648
+    qemuDomainObjPrivatePtr priv;
982648
+    struct qemuProcessEvent *processEvent = NULL;
982648
+    const char *managedAlias = qemuDomainGetManagedPRAlias();
982648
+    int ret = -1;
982648
+
982648
+    virObjectLock(vm);
982648
+
982648
+    VIR_DEBUG("pr-manager %s status changed for domain %p %s connected=%d",
982648
+              prManager, vm, vm->def->name, connected);
982648
+
982648
+    if (connected) {
982648
+        /* Connect events are boring. */
982648
+        ret = 0;
982648
+        goto cleanup;
982648
+    }
982648
+    /* Disconnect events are more interesting. */
982648
+
982648
+    if (STRNEQ(prManager, managedAlias)) {
982648
+        VIR_DEBUG("pr-manager %s not managed, ignoring event",
982648
+                  prManager);
982648
+        ret = 0;
982648
+        goto cleanup;
982648
+    }
982648
+
982648
+    priv = vm->privateData;
982648
+    priv->prDaemonRunning = false;
982648
+
982648
+    if (VIR_ALLOC(processEvent) < 0)
982648
+        goto cleanup;
982648
+
982648
+    processEvent->eventType = QEMU_PROCESS_EVENT_PR_DISCONNECT;
982648
+    processEvent->vm = virObjectRef(vm);
982648
+
982648
+    if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
982648
+        qemuProcessEventFree(processEvent);
982648
+        virObjectUnref(vm);
982648
+        goto cleanup;
982648
+    }
982648
+
982648
+    ret = 0;
982648
+ cleanup:
982648
+    virObjectUnlock(vm);
982648
+    return ret;
982648
+}
982648
+
982648
+
982648
 static qemuMonitorCallbacks monitorCallbacks = {
982648
     .eofNotify = qemuProcessHandleMonitorEOF,
982648
     .errorNotify = qemuProcessHandleMonitorError,
982648
@@ -1643,6 +1697,7 @@ static qemuMonitorCallbacks monitorCallbacks = {
982648
     .domainAcpiOstInfo = qemuProcessHandleAcpiOstInfo,
982648
     .domainBlockThreshold = qemuProcessHandleBlockThreshold,
982648
     .domainDumpCompleted = qemuProcessHandleDumpCompleted,
982648
+    .domainPRManagerStatusChanged = qemuProcessHandlePRManagerStatusChanged,
982648
 };
982648
 
982648
 static void
982648
-- 
982648
2.18.0
982648