From c9074196761ed6c180a53ccdc0bb692f31491158 Mon Sep 17 00:00:00 2001
From: zhengchuan <zhengchuan@huawei.com>
Date: Wed, 30 Nov 2022 15:59:27 +0800
Subject: [PATCH] migration/multifd-pin: add qemu monitor callback functions

add qemu monitor callback functions

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

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 1d5d47ea22..e4a1852d05 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1410,6 +1410,15 @@ qemuMonitorEmitMigrationPid(qemuMonitor *mon,
 }
 
 
+void
+qemuMonitorEmitMigrationMultiFdPids(qemuMonitor *mon,
+                                    int mpid)
+{
+    VIR_DEBUG("mon=%p, pass=%d", mon, mpid);
+    QEMU_MONITOR_CALLBACK(mon, domainMigrationMultiFdPids, mon->vm, mpid);
+}
+
+
 void
 qemuMonitorEmitRdmaGidStatusChanged(qemuMonitor *mon,
                                     const char *netdev,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 646e97a8e6..e893542971 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -332,6 +332,10 @@ typedef void (*qemuMonitorDomainMigrationPidCallback)(qemuMonitor *mon,
                                                       virDomainObj *vm,
                                                       int mcpid);
 
+typedef void (*qemuMonitorDomainMigrationMultiFdPidsCallback)(qemuMonitor *mon,
+                                                             virDomainObj *vm,
+                                                             int mcpid);
+
 typedef enum {
     QEMU_MONITOR_MEMORY_FAILURE_RECIPIENT_HYPERVISOR,
     QEMU_MONITOR_MEMORY_FAILURE_RECIPIENT_GUEST,
@@ -405,6 +409,7 @@ struct _qemuMonitorCallbacks {
     qemuMonitorDomainMemoryDeviceSizeChange domainMemoryDeviceSizeChange;
     qemuMonitorDomainDeviceUnplugErrCallback domainDeviceUnplugError;
     qemuMonitorDomainMigrationPidCallback domainMigrationPid;
+    qemuMonitorDomainMigrationMultiFdPidsCallback domainMigrationMultiFdPids;
     qemuMonitorDomainNetdevStreamDisconnectedCallback domainNetdevStreamDisconnected;
 };
 
@@ -512,6 +517,9 @@ void qemuMonitorEmitMigrationPass(qemuMonitor *mon,
 
 void qemuMonitorEmitMigrationPid(qemuMonitor *mon, int mpid);
 
+void qemuMonitorEmitMigrationMultiFdPids(qemuMonitor *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 4c1b8c9eb7..acd5ce5297 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -85,6 +85,7 @@ static void qemuMonitorJSONHandleMemoryFailure(qemuMonitor *mon, virJSONValue *d
 static void qemuMonitorJSONHandleMemoryDeviceSizeChange(qemuMonitor *mon, virJSONValue *data);
 static void qemuMonitorJSONHandleDeviceUnplugErr(qemuMonitor *mon, virJSONValue *data);
 static void qemuMonitorJSONHandleMigrationPid(qemuMonitor *mon, virJSONValue *data);
+static void qemuMonitorJSONHandleMigrationMultiFdPids(qemuMonitor *mon, virJSONValue *data);
 static void qemuMonitorJSONHandleNetdevStreamDisconnected(qemuMonitor *mon, virJSONValue *data);
 
 typedef struct {
@@ -107,6 +108,7 @@ static qemuEventHandler eventHandlers[] = {
     { "MEMORY_DEVICE_SIZE_CHANGE", qemuMonitorJSONHandleMemoryDeviceSizeChange, },
     { "MEMORY_FAILURE", qemuMonitorJSONHandleMemoryFailure, },
     { "MIGRATION", qemuMonitorJSONHandleMigrationStatus, },
+    { "MIGRATION_MULTIFD_PID", qemuMonitorJSONHandleMigrationMultiFdPids, },
     { "MIGRATION_PASS", qemuMonitorJSONHandleMigrationPass, },
     { "MIGRATION_PID", qemuMonitorJSONHandleMigrationPid, },
     { "NETDEV_STREAM_DISCONNECTED", qemuMonitorJSONHandleNetdevStreamDisconnected, },
@@ -146,6 +148,19 @@ static void qemuMonitorJSONHandleMigrationPid(qemuMonitor *mon,
     qemuMonitorEmitMigrationPid(mon, mpid);
 }
 
+static void qemuMonitorJSONHandleMigrationMultiFdPids(qemuMonitor *mon,
+                                                      virJSONValue *data)
+{
+    int mpid;
+
+    if (virJSONValueObjectGetNumberInt(data, "pid", &mpid) < 0) {
+        VIR_WARN("missing multifd pid in migration-multifd-pid event");
+        return;
+    }
+
+    qemuMonitorEmitMigrationMultiFdPids(mon, mpid);
+}
+
 static int
 qemuMonitorEventCompare(const void *key, const void *elt)
 {
-- 
2.27.0

