From c934558ff8d535a91146be93d45c730b8023a8cd Mon Sep 17 00:00:00 2001
From: zhengchuan <zhengchuan@huawei.com>
Date: Wed, 14 Dec 2022 11:07:58 +0800
Subject: [PATCH] migration/migration-pin:add some migration/multiFd params

add migration/multiFd params.

Signed-off-by:zhengchuan<zhengchuan@huawei.com>
---
 src/conf/domain_conf.c    |  8 ++++++++
 src/conf/domain_conf.h    | 12 ++++++++++++
 src/libvirt_private.syms  |  1 +
 src/qemu/qemu_domain.c    |  6 ++++++
 src/qemu/qemu_domain.h    |  5 ++++-
 src/qemu/qemu_migration.c |  1 +
 src/util/vircgroup.c      |  3 +++
 src/util/vircgroup.h      |  1 +
 8 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 22ad43e1d7..f54f99f379 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -31075,6 +31075,14 @@ virDomainDefHasSpiceGraphics(const virDomainDef *def)
     return false;
 }
 
+void
+virDomainMigrationIDDefFree(virDomainMigrationIDDefPtr def)
+{
+    if (!def)
+        return;
+    virBitmapFree(def->cpumask);
+    VIR_FREE(def);
+}
 
 ssize_t
 virDomainWatchdogDefFind(const virDomainDef *def,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ed07859bc5..196053d950 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -27,6 +27,7 @@
 #include <libxml/xpath.h>
 
 #include "internal.h"
+#include "viralloc.h"
 #include "virconftypes.h"
 #include "capabilities.h"
 #include "cpu_conf.h"
@@ -4498,3 +4499,14 @@ virDomainObjGetMessages(virDomainObj *vm,
 
 bool
 virDomainDefHasSpiceGraphics(const virDomainDef *def);
+
+typedef struct _virDomainMigrationIDDef virDomainMigrationIDDef;
+typedef virDomainMigrationIDDef *virDomainMigrationIDDefPtr;
+struct _virDomainMigrationIDDef {
+    bool autofill;
+    int thread_id;
+    virBitmap *cpumask;
+    virDomainThreadSchedParam sched;
+};
+
+void virDomainMigrationIDDefFree(virDomainMigrationIDDefPtr def);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 553b01b8c0..4d712f0d79 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -523,6 +523,7 @@ virDomainMemoryModelTypeToString;
 virDomainMemoryRemove;
 virDomainMemorySourceTypeFromString;
 virDomainMemorySourceTypeToString;
+virDomainMigrationIDDefFree;
 virDomainMouseModeTypeFromString;
 virDomainMouseModeTypeToString;
 virDomainNetAllocateActualDevice;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 953808fcfe..6b09c15f7a 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1879,6 +1879,12 @@ qemuDomainObjPrivateFree(void *data)
     virObjectUnref(priv->monConfig);
     g_free(priv->lockState);
     g_free(priv->origname);
+    VIR_FREE(priv->migrationPids);
+    virBitmapFree(priv->pcpumap);
+
+    VIR_FREE(priv->migrationMultiFdPids);
+    priv->migrationMultiFdPids = NULL;
+    priv->migrationMultiFdCount = 0;
 
     virChrdevFree(priv->devs);
 
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 1e56e50672..0eff9eab72 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -146,7 +146,9 @@ struct _qemuDomainObjPrivate {
     unsigned long long preMigrationMemlock; /* Original RLIMIT_MEMLOCK in case
                                                it was changed for the current
                                                migration job. */
-
+    char *migrationPids;
+    char *migrationMultiFdPids;
+    unsigned int migrationMultiFdCount;
     virChrdevs *devs;
 
     qemuDomainCleanupCallback *cleanupCallbacks;
@@ -166,6 +168,7 @@ struct _qemuDomainObjPrivate {
     /* Bitmaps below hold data from the auto NUMA feature */
     virBitmap *autoNodeset;
     virBitmap *autoCpuset;
+    virBitmap *pcpumap;
 
     bool signalIOError; /* true if the domain condition should be signalled on
                            I/O error */
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 7ae1cd7051..b13f2e0c24 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3362,6 +3362,7 @@ qemuMigrationDstPrepareFresh(virQEMUDriver *driver,
 
     priv = vm->privateData;
     priv->origname = g_strdup(origname);
+    VIR_FREE(priv->migrationPids);
 
     if (taint_hook) {
         /* Domain XML has been altered by a hook script. */
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index b424e1b5d4..62c6df2206 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1123,6 +1123,9 @@ virCgroupNewThread(virCgroup *domain,
     case VIR_CGROUP_THREAD_IOTHREAD:
         name = g_strdup_printf("iothread%d", id);
         break;
+    case VIR_CGROUP_THREAD_MIGRATION_THREAD:
+        name = g_strdup_printf("migthread%d", id);
+        break;
     case VIR_CGROUP_THREAD_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected name value %1$d"), nameval);
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index adf3850b22..c5f6ddd7a6 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -53,6 +53,7 @@ typedef enum {
     VIR_CGROUP_THREAD_VCPU = 0,
     VIR_CGROUP_THREAD_EMULATOR,
     VIR_CGROUP_THREAD_IOTHREAD,
+    VIR_CGROUP_THREAD_MIGRATION_THREAD,
 
     VIR_CGROUP_THREAD_LAST
 } virCgroupThreadName;
-- 
2.27.0

