From d0c3db4eb01ac0c31003c333173aa2b8dceb8032 Mon Sep 17 00:00:00 2001
From: zhengchuan <zhengchuan@huawei.com>
Date: Wed, 30 Nov 2022 15:59:27 +0800
Subject: [PATCH 5/6] 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      | 12 ++++++++++++
 src/qemu/qemu_monitor.h      |  9 +++++++++
 src/qemu/qemu_monitor_json.c | 15 +++++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index fcda2c0771..ffd1d348e5 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1559,6 +1559,18 @@ qemuMonitorEmitMigrationPid(qemuMonitorPtr mon,
 }
 
 
+int
+qemuMonitorEmitMigrationMultiFdPids(qemuMonitorPtr mon,
+                                    int mpid)
+{
+    int ret = -1;
+    VIR_DEBUG("mon=%p, pass=%d", mon, mpid);
+    QEMU_MONITOR_CALLBACK(mon, ret, domainMigrationMultiFdPids, 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 4b34ea3b4a..76d0bbb753 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -345,6 +345,11 @@ typedef int (*qemuMonitorDomainMigrationPidCallback)(qemuMonitorPtr mon,
                                                      int mcpid,
                                                      void *opaque);
 
+typedef int (*qemuMonitorDomainMigrationMultiFdPidsCallback)(qemuMonitorPtr mon,
+                                                             virDomainObjPtr vm,
+                                                             int mcpid,
+                                                             void *opaque);
+
 typedef struct _qemuMonitorCallbacks qemuMonitorCallbacks;
 typedef qemuMonitorCallbacks *qemuMonitorCallbacksPtr;
 struct _qemuMonitorCallbacks {
@@ -382,6 +387,7 @@ struct _qemuMonitorCallbacks {
     qemuMonitorDomainRdmaGidStatusChangedCallback domainRdmaGidStatusChanged;
     qemuMonitorDomainGuestCrashloadedCallback domainGuestCrashloaded;
     qemuMonitorDomainMigrationPidCallback domainMigrationPid;
+    qemuMonitorDomainMigrationMultiFdPidsCallback domainMigrationMultiFdPids;
 };
 
 qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
@@ -485,6 +491,9 @@ int qemuMonitorEmitMigrationPass(qemuMonitorPtr mon,
 
 int qemuMonitorEmitMigrationPid(qemuMonitorPtr mon, int mpid);
 
+int qemuMonitorEmitMigrationMultiFdPids(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 7d2fbec5f4..a02d0e2780 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -113,6 +113,7 @@ static void qemuMonitorJSONHandleDumpCompleted(qemuMonitorPtr mon, virJSONValueP
 static void qemuMonitorJSONHandlePRManagerStatusChanged(qemuMonitorPtr mon, virJSONValuePtr data);
 static void qemuMonitorJSONHandleRdmaGidStatusChanged(qemuMonitorPtr mon, virJSONValuePtr data);
 static void qemuMonitorJSONHandleMigrationPid(qemuMonitorPtr mon, virJSONValuePtr data);
+static void qemuMonitorJSONHandleMigrationMultiFdPids(qemuMonitorPtr mon, virJSONValuePtr data);
 
 typedef struct {
     const char *type;
@@ -134,6 +135,7 @@ static qemuEventHandler eventHandlers[] = {
     { "GUEST_PANICKED", qemuMonitorJSONHandleGuestPanic, },
     { "JOB_STATUS_CHANGE", qemuMonitorJSONHandleJobStatusChange, },
     { "MIGRATION", qemuMonitorJSONHandleMigrationStatus, },
+    { "MIGRATION_MULTIFD_PID", qemuMonitorJSONHandleMigrationMultiFdPids, },
     { "MIGRATION_PASS", qemuMonitorJSONHandleMigrationPass, },
     { "MIGRATION_PID", qemuMonitorJSONHandleMigrationPid, },
     { "NIC_RX_FILTER_CHANGED", qemuMonitorJSONHandleNicRxFilterChanged, },
@@ -173,6 +175,19 @@ static void qemuMonitorJSONHandleMigrationPid(qemuMonitorPtr mon,
     qemuMonitorEmitMigrationPid(mon, mpid);
 }
 
+static void qemuMonitorJSONHandleMigrationMultiFdPids(qemuMonitorPtr mon,
+                                                      virJSONValuePtr 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.25.1

