Blob Blame History Raw
From e917c5aa46ccffb608dad2068861e555b60e10fa Mon Sep 17 00:00:00 2001
Message-Id: <e917c5aa46ccffb608dad2068861e555b60e10fa@dist-git>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Tue, 7 Mar 2023 12:27:05 +0100
Subject: [PATCH] qemu: Move cpuset preference evaluation into a separate
 function

The set of if()-s that determines the preference in cpumask used
for setting things like emulatorpin, vcpupin, etc. is going to be
re-used. Separate it out into a function.

You may think that this changes behaviour, but
qemuProcessPrepareDomainNUMAPlacement() ensures that
priv->autoCpuset is set for VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
(cherry picked from commit b4ccb0dc412bcdb09863b2fa1ee65d09808a2c08)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2185039
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_domain.c  | 18 ++++++++++++++++++
 src/qemu/qemu_domain.h  |  5 +++++
 src/qemu/qemu_process.c |  9 ++-------
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 374b881146..443b6442ca 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -12335,3 +12335,21 @@ qemuDomainStartupCleanup(virDomainObj *vm)
     for (i = 0; i < vm->def->ndisks; i++)
         qemuDomainCleanupStorageSourceFD(vm->def->disks[i]->src);
 }
+
+
+virBitmap *
+qemuDomainEvaluateCPUMask(const virDomainDef *def,
+                          virBitmap *cpumask,
+                          virBitmap *autoCpuset)
+{
+    if (cpumask) {
+        return cpumask;
+    } else if (autoCpuset &&
+               def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) {
+        return autoCpuset;
+    } else if (def->cpumask) {
+        return def->cpumask;
+    }
+
+    return NULL;
+}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index fb9ab4c5ed..b01b394287 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -1139,3 +1139,8 @@ qemuDomainSchedCoreStart(virQEMUDriverConfig *cfg,
 
 void
 qemuDomainSchedCoreStop(qemuDomainObjPrivate *priv);
+
+virBitmap *
+qemuDomainEvaluateCPUMask(const virDomainDef *def,
+                          virBitmap *cpumask,
+                          virBitmap *autoCpuset);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index e5c438aa26..3154fa5b10 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2575,13 +2575,8 @@ qemuProcessSetupPid(virDomainObj *vm,
     }
 
     /* Infer which cpumask shall be used. */
-    if (cpumask) {
-        use_cpumask = cpumask;
-    } else if (vm->def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) {
-        use_cpumask = priv->autoCpuset;
-    } else if (vm->def->cpumask) {
-        use_cpumask = vm->def->cpumask;
-    } else {
+    if (!(use_cpumask = qemuDomainEvaluateCPUMask(vm->def,
+                                                  cpumask, priv->autoCpuset))) {
         /* You may think this is redundant, but we can't assume libvirtd
          * itself is running on all pCPUs, so we need to explicitly set
          * the spawned QEMU instance to all pCPUs if no map is given in
-- 
2.40.0