From: zhengchuan <zhengch...@huawei.com>

Add qemuProcessGetPcpumap to get cpumap from migration
parameters when 'virsh migrationpin' is not called.

Signed-off-by:zhengchuan<zhengch...@huawei.com>
---
 src/qemu/qemu_process.c | 79 +++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_process.h |  4 +++
 2 files changed, 83 insertions(+)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index b6adcf2f2a..b2e9456b98 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3677,6 +3677,85 @@ qemuProcessRecoverMigration(virQEMUDriver *driver,
 }
 
 
+unsigned char *
+virParseCPUList(int *cpumaplen, const char *cpulist, int maxcpu)
+{
+    int lastcpu;
+    unsigned char *cpumap = NULL;
+    virBitmap *map = NULL;
+
+    if (cpulist[0] == 'r') {
+        map = virBitmapNew(maxcpu);
+        if (!map)
+            return NULL;
+        virBitmapSetAll(map);
+    } else {
+        if (virBitmapParse(cpulist, &map, 1024) < 0 ||
+            virBitmapIsAllClear(map)) {
+                goto cleanup;
+            }
+
+            lastcpu = virBitmapLastSetBit(map);
+            if (lastcpu >= maxcpu)
+                goto cleanup;
+    }
+
+    if (virBitmapToData(map, &cpumap, cpumaplen) < 0)
+        VIR_ERROR(_("Bitmap to data failure"));
+
+ cleanup:
+    virBitmapFree(map);
+    return cpumap;
+}
+
+
+/*
+ * The value of "virsh migrationpin" is saved to priv->pcpumap
+ * If priv->pcpumap is NULL, it means migrationpin command is not called,
+ * otherwise we set the affinity of migration thread by migrationpin
+ */
+static virBitmap*
+qemuProcessGetPcpumap(qemuDomainObjPrivate *priv)
+{
+    int cpumaplen = 0;
+    int maxcpu = 0;
+    virBitmap *pcpumap = NULL;
+    g_autofree unsigned char *cpumap = NULL;
+
+    if (priv->pcpumap)
+        return priv->pcpumap;
+
+    if (!(priv->migrationThreadPinList) || STREQ(priv->migrationThreadPinList, 
"")) {
+        VIR_ERROR(_("didn't set the migratin thread pin"));
+        return NULL;
+    }
+
+    /* judge whether set_migration_pin is default value or not */
+    if (STREQ(priv->migrationThreadPinList, "none"))
+        return NULL;
+
+    maxcpu = virHostCPUGetCount();
+    if (maxcpu < 0) {
+        VIR_ERROR(_("get the cpu count of host failure"));
+        return NULL;
+    }
+
+    cpumap = virParseCPUList(&cpumaplen, priv->migrationThreadPinList, maxcpu);
+    if (!cpumap) {
+        VIR_ERROR(_("parse migration.pin param failure : migration.pin = %s"),
+                  priv->migrationThreadPinList);
+        return NULL;
+    }
+
+    if (!(pcpumap = virBitmapNewData(cpumap, cpumaplen))) {
+        VIR_ERROR(_("Bitmap data failure"));
+        return NULL;
+    }
+
+    return pcpumap;
+}
+
+
 static int
 qemuProcessRecoverJob(virQEMUDriver *driver,
                       virDomainObj *vm,
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 9a24745f15..5b1e05b1f8 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -242,3 +242,7 @@ bool qemuProcessRebootAllowed(const virDomainDef *def);
 
 void qemuProcessCleanupMigrationJob(virQEMUDriver *driver,
                                     virDomainObj *vm);
+
+unsigned char *virParseCPUList(int *cpumaplen,
+                               const char *cpulist,
+                               int maxcpu);
-- 
2.33.0

Reply via email to