From 760e248164be819bebc03893ace58e0ddae7e440 Mon Sep 17 00:00:00 2001
Message-Id: <760e248164be819bebc03893ace58e0ddae7e440@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Tue, 26 May 2020 10:58:52 +0200
Subject: [PATCH] cpu_x86: Prepare virCPUx86UpdateLive for easier extension
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Adding more checks into the existing if statements would turn them into
an unreadable mess.
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 8dc791b5d3b20552cc0b8d6c04e34dd0f3ebe2ff)
https://bugzilla.redhat.com/show_bug.cgi?id=1839999
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Message-Id: <169ed0334144715b52575ca3f7e67ce3170ba91a.1590483392.git.jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/cpu/cpu_x86.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 9b7981d574..9e686a86d2 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -3036,9 +3036,15 @@ virCPUx86UpdateLive(virCPUDefPtr cpu,
for (i = 0; i < map->nfeatures; i++) {
virCPUx86FeaturePtr feature = map->features[i];
+ virCPUFeaturePolicy expected = VIR_CPU_FEATURE_LAST;
- if (x86DataIsSubset(&enabled, &feature->data) &&
- !x86DataIsSubset(&model->data, &feature->data)) {
+ if (x86DataIsSubset(&model->data, &feature->data))
+ expected = VIR_CPU_FEATURE_REQUIRE;
+ else
+ expected = VIR_CPU_FEATURE_DISABLE;
+
+ if (expected == VIR_CPU_FEATURE_DISABLE &&
+ x86DataIsSubset(&enabled, &feature->data)) {
VIR_DEBUG("Feature '%s' enabled by the hypervisor", feature->name);
if (cpu->check == VIR_CPU_CHECK_FULL)
virBufferAsprintf(&bufAdded, "%s,", feature->name);
@@ -3048,7 +3054,7 @@ virCPUx86UpdateLive(virCPUDefPtr cpu,
}
if (x86DataIsSubset(&disabled, &feature->data) ||
- (x86DataIsSubset(&model->data, &feature->data) &&
+ (expected == VIR_CPU_FEATURE_REQUIRE &&
!x86DataIsSubset(&enabled, &feature->data))) {
VIR_DEBUG("Feature '%s' disabled by the hypervisor", feature->name);
if (cpu->check == VIR_CPU_CHECK_FULL)
--
2.26.2