render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
7a3408
From a72b20b3cb4837a87cdeb50fd625ccfe7a6c76a7 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <a72b20b3cb4837a87cdeb50fd625ccfe7a6c76a7@dist-git>
7a3408
From: Jiri Denemark <jdenemar@redhat.com>
7a3408
Date: Thu, 28 May 2015 13:35:52 +0200
7a3408
Subject: [PATCH] qemu_monitor: Wire up MIGRATION event
7a3408
7a3408
Thanks to Juan's work QEMU finally emits an event whenever migration
7a3408
state changes.
7a3408
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
(cherry picked from commit a60ee613c499c255faf7c36e7cd8582b5a79ca57)
7a3408
7a3408
https://bugzilla.redhat.com/show_bug.cgi?id=1212077
7a3408
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/qemu/qemu_capabilities.c |  2 ++
7a3408
 src/qemu/qemu_capabilities.h |  1 +
7a3408
 src/qemu/qemu_monitor.c      | 14 ++++++++++++++
7a3408
 src/qemu/qemu_monitor.h      |  8 ++++++++
7a3408
 src/qemu/qemu_monitor_json.c | 23 +++++++++++++++++++++++
7a3408
 5 files changed, 48 insertions(+)
7a3408
7a3408
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
7a3408
index 89d63e5..b4a6961 100644
7a3408
--- a/src/qemu/qemu_capabilities.c
7a3408
+++ b/src/qemu/qemu_capabilities.c
7a3408
@@ -287,6 +287,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
7a3408
               "aarch64-off",
7a3408
 
7a3408
               "vhost-user-multiqueue", /* 190 */
7a3408
+              "migration-event",
7a3408
     );
7a3408
 
7a3408
 
7a3408
@@ -1506,6 +1507,7 @@ struct virQEMUCapsStringFlags virQEMUCapsEvents[] = {
7a3408
     { "BALLOON_CHANGE", QEMU_CAPS_BALLOON_EVENT },
7a3408
     { "SPICE_MIGRATE_COMPLETED", QEMU_CAPS_SEAMLESS_MIGRATION },
7a3408
     { "DEVICE_DELETED", QEMU_CAPS_DEVICE_DEL_EVENT },
7a3408
+    { "MIGRATION", QEMU_CAPS_MIGRATION_EVENT },
7a3408
 };
7a3408
 
7a3408
 struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = {
7a3408
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
7a3408
index 30aa504..f77bd06 100644
7a3408
--- a/src/qemu/qemu_capabilities.h
7a3408
+++ b/src/qemu/qemu_capabilities.h
7a3408
@@ -230,6 +230,7 @@ typedef enum {
7a3408
     QEMU_CAPS_DEVICE_PCI_SERIAL  = 188, /* -device pci-serial */
7a3408
     QEMU_CAPS_CPU_AARCH64_OFF    = 189, /* -cpu ...,aarch64=off */
7a3408
     QEMU_CAPS_VHOSTUSER_MULTIQUEUE = 190, /* vhost-user with -netdev queues= */
7a3408
+    QEMU_CAPS_MIGRATION_EVENT    = 191, /* MIGRATION event */
7a3408
 
7a3408
     QEMU_CAPS_LAST,                   /* this must always be the last item */
7a3408
 } virQEMUCapsFlags;
7a3408
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
7a3408
index 9c70211..dd742cf 100644
7a3408
--- a/src/qemu/qemu_monitor.c
7a3408
+++ b/src/qemu/qemu_monitor.c
7a3408
@@ -1498,6 +1498,20 @@ qemuMonitorEmitSpiceMigrated(qemuMonitorPtr mon)
7a3408
 
7a3408
 
7a3408
 int
7a3408
+qemuMonitorEmitMigrationStatus(qemuMonitorPtr mon,
7a3408
+                               int status)
7a3408
+{
7a3408
+    int ret = -1;
7a3408
+    VIR_DEBUG("mon=%p, status=%s",
7a3408
+              mon, NULLSTR(qemuMonitorMigrationStatusTypeToString(status)));
7a3408
+
7a3408
+    QEMU_MONITOR_CALLBACK(mon, ret, domainMigrationStatus, mon->vm, status);
7a3408
+
7a3408
+    return ret;
7a3408
+}
7a3408
+
7a3408
+
7a3408
+int
7a3408
 qemuMonitorSetCapabilities(qemuMonitorPtr mon)
7a3408
 {
7a3408
     QEMU_CHECK_MONITOR(mon);
7a3408
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
7a3408
index 87167e3..d2b2f94 100644
7a3408
--- a/src/qemu/qemu_monitor.h
7a3408
+++ b/src/qemu/qemu_monitor.h
7a3408
@@ -186,6 +186,11 @@ typedef int (*qemuMonitorDomainSpiceMigratedCallback)(qemuMonitorPtr mon,
7a3408
                                                       virDomainObjPtr vm,
7a3408
                                                       void *opaque);
7a3408
 
7a3408
+typedef int (*qemuMonitorDomainMigrationStatusCallback)(qemuMonitorPtr mon,
7a3408
+                                                        virDomainObjPtr vm,
7a3408
+                                                        int status,
7a3408
+                                                        void *opaque);
7a3408
+
7a3408
 typedef struct _qemuMonitorCallbacks qemuMonitorCallbacks;
7a3408
 typedef qemuMonitorCallbacks *qemuMonitorCallbacksPtr;
7a3408
 struct _qemuMonitorCallbacks {
7a3408
@@ -214,6 +219,7 @@ struct _qemuMonitorCallbacks {
7a3408
     qemuMonitorDomainNicRxFilterChangedCallback domainNicRxFilterChanged;
7a3408
     qemuMonitorDomainSerialChangeCallback domainSerialChange;
7a3408
     qemuMonitorDomainSpiceMigratedCallback domainSpiceMigrated;
7a3408
+    qemuMonitorDomainMigrationStatusCallback domainMigrationStatus;
7a3408
 };
7a3408
 
7a3408
 char *qemuMonitorEscapeArg(const char *in);
7a3408
@@ -313,6 +319,8 @@ int qemuMonitorEmitSerialChange(qemuMonitorPtr mon,
7a3408
                                 const char *devAlias,
7a3408
                                 bool connected);
7a3408
 int qemuMonitorEmitSpiceMigrated(qemuMonitorPtr mon);
7a3408
+int qemuMonitorEmitMigrationStatus(qemuMonitorPtr mon,
7a3408
+                                   int status);
7a3408
 
7a3408
 int qemuMonitorStartCPUs(qemuMonitorPtr mon,
7a3408
                          virConnectPtr conn);
7a3408
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
7a3408
index 065c7fe..4323c2a 100644
7a3408
--- a/src/qemu/qemu_monitor_json.c
7a3408
+++ b/src/qemu/qemu_monitor_json.c
7a3408
@@ -84,6 +84,7 @@ static void qemuMonitorJSONHandleDeviceDeleted(qemuMonitorPtr mon, virJSONValueP
7a3408
 static void qemuMonitorJSONHandleNicRxFilterChanged(qemuMonitorPtr mon, virJSONValuePtr data);
7a3408
 static void qemuMonitorJSONHandleSerialChange(qemuMonitorPtr mon, virJSONValuePtr data);
7a3408
 static void qemuMonitorJSONHandleSpiceMigrated(qemuMonitorPtr mon, virJSONValuePtr data);
7a3408
+static void qemuMonitorJSONHandleMigrationStatus(qemuMonitorPtr mon, virJSONValuePtr data);
7a3408
 
7a3408
 typedef struct {
7a3408
     const char *type;
7a3408
@@ -99,6 +100,7 @@ static qemuEventHandler eventHandlers[] = {
7a3408
     { "DEVICE_DELETED", qemuMonitorJSONHandleDeviceDeleted, },
7a3408
     { "DEVICE_TRAY_MOVED", qemuMonitorJSONHandleTrayChange, },
7a3408
     { "GUEST_PANICKED", qemuMonitorJSONHandleGuestPanic, },
7a3408
+    { "MIGRATION", qemuMonitorJSONHandleMigrationStatus, },
7a3408
     { "NIC_RX_FILTER_CHANGED", qemuMonitorJSONHandleNicRxFilterChanged, },
7a3408
     { "POWERDOWN", qemuMonitorJSONHandlePowerdown, },
7a3408
     { "RESET", qemuMonitorJSONHandleReset, },
7a3408
@@ -990,6 +992,27 @@ qemuMonitorJSONHandleSpiceMigrated(qemuMonitorPtr mon,
7a3408
 }
7a3408
 
7a3408
 
7a3408
+static void
7a3408
+qemuMonitorJSONHandleMigrationStatus(qemuMonitorPtr mon,
7a3408
+                                     virJSONValuePtr data)
7a3408
+{
7a3408
+    const char *str;
7a3408
+    int status;
7a3408
+
7a3408
+    if (!(str = virJSONValueObjectGetString(data, "status"))) {
7a3408
+        VIR_WARN("missing status in migration event");
7a3408
+        return;
7a3408
+    }
7a3408
+
7a3408
+    if ((status = qemuMonitorMigrationStatusTypeFromString(str)) == -1) {
7a3408
+        VIR_WARN("unknown status '%s' in migration event", str);
7a3408
+        return;
7a3408
+    }
7a3408
+
7a3408
+    qemuMonitorEmitMigrationStatus(mon, status);
7a3408
+}
7a3408
+
7a3408
+
7a3408
 int
7a3408
 qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
7a3408
                                   const char *cmd_str,
7a3408
-- 
7a3408
2.4.5
7a3408