From b0035c45ecfed66f0406a6064b33f296fd65afd9 Mon Sep 17 00:00:00 2001
From: zhengchuan <zhengchuan@huawei.com>
Date: Wed, 30 Nov 2022 11:30:12 +0800
Subject: [PATCH 2/6] 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 04592fdcd5..fcda2c0771 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1547,6 +1547,18 @@ qemuMonitorEmitPRManagerStatusChanged(qemuMonitorPtr 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;
+}
+
+
 int
 qemuMonitorEmitRdmaGidStatusChanged(qemuMonitorPtr mon,
                                     const char *netdev,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 4f9b70d820..4b34ea3b4a 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -340,6 +340,11 @@ typedef int (*qemuMonitorDomainGuestCrashloadedCallback)(qemuMonitorPtr mon,
                                                          virDomainObjPtr vm,
                                                          void *opaque);
 
+typedef int (*qemuMonitorDomainMigrationPidCallback)(qemuMonitorPtr mon,
+                                                     virDomainObjPtr vm,
+                                                     int mcpid,
+                                                     void *opaque);
+
 typedef struct _qemuMonitorCallbacks qemuMonitorCallbacks;
 typedef qemuMonitorCallbacks *qemuMonitorCallbacksPtr;
 struct _qemuMonitorCallbacks {
@@ -376,6 +381,7 @@ struct _qemuMonitorCallbacks {
     qemuMonitorDomainPRManagerStatusChangedCallback domainPRManagerStatusChanged;
     qemuMonitorDomainRdmaGidStatusChangedCallback domainRdmaGidStatusChanged;
     qemuMonitorDomainGuestCrashloadedCallback domainGuestCrashloaded;
+    qemuMonitorDomainMigrationPidCallback domainMigrationPid;
 };
 
 qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
@@ -477,6 +483,8 @@ int qemuMonitorEmitMigrationStatus(qemuMonitorPtr mon,
 int qemuMonitorEmitMigrationPass(qemuMonitorPtr mon,
                                  int pass);
 
+int qemuMonitorEmitMigrationPid(qemuMonitorPtr mon, int mpid);
+
 int qemuMonitorEmitAcpiOstInfo(qemuMonitorPtr mon,
                                const char *alias,
                                const char *slotType,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index a1617cdfed..7d2fbec5f4 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -112,6 +112,7 @@ static void qemuMonitorJSONHandleBlockThreshold(qemuMonitorPtr mon, virJSONValue
 static void qemuMonitorJSONHandleDumpCompleted(qemuMonitorPtr mon, virJSONValuePtr data);
 static void qemuMonitorJSONHandlePRManagerStatusChanged(qemuMonitorPtr mon, virJSONValuePtr data);
 static void qemuMonitorJSONHandleRdmaGidStatusChanged(qemuMonitorPtr mon, virJSONValuePtr data);
+static void qemuMonitorJSONHandleMigrationPid(qemuMonitorPtr mon, virJSONValuePtr data);
 
 typedef struct {
     const char *type;
@@ -134,6 +135,7 @@ static qemuEventHandler eventHandlers[] = {
     { "JOB_STATUS_CHANGE", qemuMonitorJSONHandleJobStatusChange, },
     { "MIGRATION", qemuMonitorJSONHandleMigrationStatus, },
     { "MIGRATION_PASS", qemuMonitorJSONHandleMigrationPass, },
+    { "MIGRATION_PID", qemuMonitorJSONHandleMigrationPid, },
     { "NIC_RX_FILTER_CHANGED", qemuMonitorJSONHandleNicRxFilterChanged, },
     { "POWERDOWN", qemuMonitorJSONHandlePowerdown, },
     { "PR_MANAGER_STATUS_CHANGED", qemuMonitorJSONHandlePRManagerStatusChanged, },
@@ -158,6 +160,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.25.1

