From 6656a916c6db824c9bd914d29709407013627b3d Mon Sep 17 00:00:00 2001
From: zhengchuan <zhengchuan@huawei.com>
Date: Wed, 30 Nov 2022 11:30:12 +0800
Subject: [PATCH] migration/migration-pin: add qemu monitor callback functions

add qemu monitor callback functions

Signed-off-by:zhengchuan<zhengchuan@huawei.com>
---
 src/qemu/qemu_monitor.c      | 12 ++++++++++++
 src/qemu/qemu_monitor.h      |  8 ++++++++
 src/qemu/qemu_monitor_json.c | 15 +++++++++++++++
 3 files changed, 35 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index a69ead6109..c2ab9b0070 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1401,6 +1401,18 @@ qemuMonitorEmitPRManagerStatusChanged(qemuMonitor *mon,
 }
 
 
+int
+qemuMonitorEmitMigrationPid(qemuMonitorPtr mon,
+                            int mpid)
+{
+    int ret = -1;
+    VIR_DEBUG("mon=%p, pass=%d", mon, mpid);
+    QEMU_MONITOR_CALLBACK(mon, ret, domainMigrationPid, mon->vm, mpid);
+
+    return ret;
+}
+
+
 void
 qemuMonitorEmitRdmaGidStatusChanged(qemuMonitor *mon,
                                     const char *netdev,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index c4af9b407d..44eaa00cd8 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -328,6 +328,11 @@ typedef void (*qemuMonitorDomainRdmaGidStatusChangedCallback)(qemuMonitor *mon,
 typedef void (*qemuMonitorDomainGuestCrashloadedCallback)(qemuMonitor *mon,
                                                           virDomainObj *vm);
 
+typedef int (*qemuMonitorDomainMigrationPidCallback)(qemuMonitorPtr mon,
+                                                     virDomainObjPtr vm,
+                                                     int mcpid,
+                                                     void *opaque);
+
 typedef enum {
     QEMU_MONITOR_MEMORY_FAILURE_RECIPIENT_HYPERVISOR,
     QEMU_MONITOR_MEMORY_FAILURE_RECIPIENT_GUEST,
@@ -400,6 +405,7 @@ struct _qemuMonitorCallbacks {
     qemuMonitorDomainMemoryFailureCallback domainMemoryFailure;
     qemuMonitorDomainMemoryDeviceSizeChange domainMemoryDeviceSizeChange;
     qemuMonitorDomainDeviceUnplugErrCallback domainDeviceUnplugError;
+    qemuMonitorDomainMigrationPidCallback domainMigrationPid;
     qemuMonitorDomainNetdevStreamDisconnectedCallback domainNetdevStreamDisconnected;
 };
 
@@ -505,6 +511,8 @@ void qemuMonitorEmitMigrationStatus(qemuMonitor *mon,
 void qemuMonitorEmitMigrationPass(qemuMonitor *mon,
                                   int pass);
 
+int qemuMonitorEmitMigrationPid(qemuMonitorPtr mon, int mpid);
+
 void qemuMonitorEmitAcpiOstInfo(qemuMonitor *mon,
                                 const char *alias,
                                 const char *slotType,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index a9133793f6..167fb7356a 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -84,6 +84,7 @@ static void qemuMonitorJSONHandleRdmaGidStatusChanged(qemuMonitor *mon, virJSONV
 static void qemuMonitorJSONHandleMemoryFailure(qemuMonitor *mon, virJSONValue *data);
 static void qemuMonitorJSONHandleMemoryDeviceSizeChange(qemuMonitor *mon, virJSONValue *data);
 static void qemuMonitorJSONHandleDeviceUnplugErr(qemuMonitor *mon, virJSONValue *data);
+static void qemuMonitorJSONHandleMigrationPid(qemuMonitorPtr mon, virJSONValuePtr data);
 static void qemuMonitorJSONHandleNetdevStreamDisconnected(qemuMonitor *mon, virJSONValue *data);
 
 typedef struct {
@@ -107,6 +108,7 @@ static qemuEventHandler eventHandlers[] = {
     { "MEMORY_FAILURE", qemuMonitorJSONHandleMemoryFailure, },
     { "MIGRATION", qemuMonitorJSONHandleMigrationStatus, },
     { "MIGRATION_PASS", qemuMonitorJSONHandleMigrationPass, },
+    { "MIGRATION_PID", qemuMonitorJSONHandleMigrationPid, },
     { "NETDEV_STREAM_DISCONNECTED", qemuMonitorJSONHandleNetdevStreamDisconnected, },
     { "NIC_RX_FILTER_CHANGED", qemuMonitorJSONHandleNicRxFilterChanged, },
     { "PR_MANAGER_STATUS_CHANGED", qemuMonitorJSONHandlePRManagerStatusChanged, },
@@ -131,6 +133,19 @@ static qemuEventHandler eventHandlers[] = {
     /* We use bsearch, so keep this list sorted.  */
 };
 
+static void qemuMonitorJSONHandleMigrationPid(qemuMonitorPtr mon,
+                                              virJSONValuePtr data)
+{
+    int mpid;
+
+    if (virJSONValueObjectGetNumberInt(data, "pid", &mpid) < 0) {
+        VIR_WARN("missing migration pid in migration-pid event");
+        return;
+    }
+
+    qemuMonitorEmitMigrationPid(mon, mpid);
+}
+
 static int
 qemuMonitorEventCompare(const void *key, const void *elt)
 {
-- 
2.27.0

