|
|
b971b8 |
From b8162d4174443babbd260b36ea4645469eca7d67 Mon Sep 17 00:00:00 2001
|
|
|
b971b8 |
Message-Id: <b8162d4174443babbd260b36ea4645469eca7d67@dist-git>
|
|
|
b971b8 |
From: Jiri Denemark <jdenemar@redhat.com>
|
|
|
b971b8 |
Date: Tue, 26 May 2020 10:59:13 +0200
|
|
|
b971b8 |
Subject: [PATCH] cpu_x86: Use g_auto* in x86Compute
|
|
|
b971b8 |
MIME-Version: 1.0
|
|
|
b971b8 |
Content-Type: text/plain; charset=UTF-8
|
|
|
b971b8 |
Content-Transfer-Encoding: 8bit
|
|
|
b971b8 |
|
|
|
b971b8 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
b971b8 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
b971b8 |
(cherry picked from commit edf3c9045f1742d6c132066e4ba2da25c9ad7b26)
|
|
|
b971b8 |
|
|
|
b971b8 |
https://bugzilla.redhat.com/show_bug.cgi?id=1840010
|
|
|
b971b8 |
|
|
|
b971b8 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
b971b8 |
Message-Id: <6022f3717ce7ab0df25d31f2aaa08cac1c5f82de.1590483392.git.jdenemar@redhat.com>
|
|
|
b971b8 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
b971b8 |
---
|
|
|
b971b8 |
src/cpu/cpu_x86.c | 65 +++++++++++++++++------------------------------
|
|
|
b971b8 |
1 file changed, 24 insertions(+), 41 deletions(-)
|
|
|
b971b8 |
|
|
|
b971b8 |
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
|
|
|
b971b8 |
index 107fd9227d..1a1c846383 100644
|
|
|
b971b8 |
--- a/src/cpu/cpu_x86.c
|
|
|
b971b8 |
+++ b/src/cpu/cpu_x86.c
|
|
|
b971b8 |
@@ -1680,7 +1680,6 @@ virCPUx86DataParse(xmlXPathContextPtr ctxt)
|
|
|
b971b8 |
* redundant code:
|
|
|
b971b8 |
* MSG: error message
|
|
|
b971b8 |
* CPU_DEF: a virCPUx86Data pointer with flags that are conflicting
|
|
|
b971b8 |
- * RET: return code to set
|
|
|
b971b8 |
*
|
|
|
b971b8 |
* This macro generates the error string outputs it into logs.
|
|
|
b971b8 |
*/
|
|
|
b971b8 |
@@ -1689,13 +1688,12 @@ virCPUx86DataParse(xmlXPathContextPtr ctxt)
|
|
|
b971b8 |
char *flagsStr = NULL; \
|
|
|
b971b8 |
if (!(flagsStr = x86FeatureNames(map, ", ", (CPU_DEF)))) { \
|
|
|
b971b8 |
virReportOOMError(); \
|
|
|
b971b8 |
- goto error; \
|
|
|
b971b8 |
+ return VIR_CPU_COMPARE_ERROR; \
|
|
|
b971b8 |
} \
|
|
|
b971b8 |
if (message) \
|
|
|
b971b8 |
*message = g_strdup_printf("%s: %s", _(MSG), flagsStr); \
|
|
|
b971b8 |
VIR_DEBUG("%s: %s", MSG, flagsStr); \
|
|
|
b971b8 |
VIR_FREE(flagsStr); \
|
|
|
b971b8 |
- ret = VIR_CPU_COMPARE_INCOMPATIBLE; \
|
|
|
b971b8 |
} while (0)
|
|
|
b971b8 |
|
|
|
b971b8 |
|
|
|
b971b8 |
@@ -1706,15 +1704,15 @@ x86Compute(virCPUDefPtr host,
|
|
|
b971b8 |
char **message)
|
|
|
b971b8 |
{
|
|
|
b971b8 |
virCPUx86MapPtr map = NULL;
|
|
|
b971b8 |
- virCPUx86ModelPtr host_model = NULL;
|
|
|
b971b8 |
- virCPUx86ModelPtr cpu_force = NULL;
|
|
|
b971b8 |
- virCPUx86ModelPtr cpu_require = NULL;
|
|
|
b971b8 |
- virCPUx86ModelPtr cpu_optional = NULL;
|
|
|
b971b8 |
- virCPUx86ModelPtr cpu_disable = NULL;
|
|
|
b971b8 |
- virCPUx86ModelPtr cpu_forbid = NULL;
|
|
|
b971b8 |
- virCPUx86ModelPtr diff = NULL;
|
|
|
b971b8 |
- virCPUx86ModelPtr guest_model = NULL;
|
|
|
b971b8 |
- virCPUDataPtr guestData = NULL;
|
|
|
b971b8 |
+ g_autoptr(virCPUx86Model) host_model = NULL;
|
|
|
b971b8 |
+ g_autoptr(virCPUx86Model) cpu_force = NULL;
|
|
|
b971b8 |
+ g_autoptr(virCPUx86Model) cpu_require = NULL;
|
|
|
b971b8 |
+ g_autoptr(virCPUx86Model) cpu_optional = NULL;
|
|
|
b971b8 |
+ g_autoptr(virCPUx86Model) cpu_disable = NULL;
|
|
|
b971b8 |
+ g_autoptr(virCPUx86Model) cpu_forbid = NULL;
|
|
|
b971b8 |
+ g_autoptr(virCPUx86Model) diff = NULL;
|
|
|
b971b8 |
+ g_autoptr(virCPUx86Model) guest_model = NULL;
|
|
|
b971b8 |
+ g_autoptr(virCPUData) guestData = NULL;
|
|
|
b971b8 |
virCPUCompareResult ret;
|
|
|
b971b8 |
virCPUx86CompareResult result;
|
|
|
b971b8 |
virArch arch;
|
|
|
b971b8 |
@@ -1764,13 +1762,13 @@ x86Compute(virCPUDefPtr host,
|
|
|
b971b8 |
!(cpu_optional = x86ModelFromCPU(cpu, map, VIR_CPU_FEATURE_OPTIONAL)) ||
|
|
|
b971b8 |
!(cpu_disable = x86ModelFromCPU(cpu, map, VIR_CPU_FEATURE_DISABLE)) ||
|
|
|
b971b8 |
!(cpu_forbid = x86ModelFromCPU(cpu, map, VIR_CPU_FEATURE_FORBID)))
|
|
|
b971b8 |
- goto error;
|
|
|
b971b8 |
+ return VIR_CPU_COMPARE_ERROR;
|
|
|
b971b8 |
|
|
|
b971b8 |
x86DataIntersect(&cpu_forbid->data, &host_model->data);
|
|
|
b971b8 |
if (!x86DataIsEmpty(&cpu_forbid->data)) {
|
|
|
b971b8 |
virX86CpuIncompatible(N_("Host CPU provides forbidden features"),
|
|
|
b971b8 |
&cpu_forbid->data);
|
|
|
b971b8 |
- goto cleanup;
|
|
|
b971b8 |
+ return VIR_CPU_COMPARE_INCOMPATIBLE;
|
|
|
b971b8 |
}
|
|
|
b971b8 |
|
|
|
b971b8 |
/* first remove features that were inherited from the CPU model and were
|
|
|
b971b8 |
@@ -1785,20 +1783,20 @@ x86Compute(virCPUDefPtr host,
|
|
|
b971b8 |
virX86CpuIncompatible(N_("Host CPU does not provide required "
|
|
|
b971b8 |
"features"),
|
|
|
b971b8 |
&cpu_require->data);
|
|
|
b971b8 |
- goto cleanup;
|
|
|
b971b8 |
+ return VIR_CPU_COMPARE_INCOMPATIBLE;
|
|
|
b971b8 |
}
|
|
|
b971b8 |
|
|
|
b971b8 |
- ret = VIR_CPU_COMPARE_IDENTICAL;
|
|
|
b971b8 |
-
|
|
|
b971b8 |
if (!(diff = x86ModelCopy(host_model)))
|
|
|
b971b8 |
- goto error;
|
|
|
b971b8 |
+ return VIR_CPU_COMPARE_ERROR;
|
|
|
b971b8 |
|
|
|
b971b8 |
x86DataSubtract(&diff->data, &cpu_optional->data);
|
|
|
b971b8 |
x86DataSubtract(&diff->data, &cpu_require->data);
|
|
|
b971b8 |
x86DataSubtract(&diff->data, &cpu_disable->data);
|
|
|
b971b8 |
x86DataSubtract(&diff->data, &cpu_force->data);
|
|
|
b971b8 |
|
|
|
b971b8 |
- if (!x86DataIsEmpty(&diff->data))
|
|
|
b971b8 |
+ if (x86DataIsEmpty(&diff->data))
|
|
|
b971b8 |
+ ret = VIR_CPU_COMPARE_IDENTICAL;
|
|
|
b971b8 |
+ else
|
|
|
b971b8 |
ret = VIR_CPU_COMPARE_SUPERSET;
|
|
|
b971b8 |
|
|
|
b971b8 |
if (ret == VIR_CPU_COMPARE_SUPERSET
|
|
|
b971b8 |
@@ -1807,54 +1805,39 @@ x86Compute(virCPUDefPtr host,
|
|
|
b971b8 |
virX86CpuIncompatible(N_("Host CPU does not strictly match guest CPU: "
|
|
|
b971b8 |
"Extra features"),
|
|
|
b971b8 |
&diff->data);
|
|
|
b971b8 |
- goto cleanup;
|
|
|
b971b8 |
+ return VIR_CPU_COMPARE_INCOMPATIBLE;
|
|
|
b971b8 |
}
|
|
|
b971b8 |
|
|
|
b971b8 |
if (guest) {
|
|
|
b971b8 |
if (!(guest_model = x86ModelCopy(host_model)))
|
|
|
b971b8 |
- goto error;
|
|
|
b971b8 |
+ return VIR_CPU_COMPARE_ERROR;
|
|
|
b971b8 |
|
|
|
b971b8 |
if (cpu->vendor && host_model->vendor &&
|
|
|
b971b8 |
virCPUx86DataAddItem(&guest_model->data,
|
|
|
b971b8 |
&host_model->vendor->data) < 0)
|
|
|
b971b8 |
- goto error;
|
|
|
b971b8 |
+ return VIR_CPU_COMPARE_ERROR;
|
|
|
b971b8 |
|
|
|
b971b8 |
if (host_model->signatures &&
|
|
|
b971b8 |
x86DataAddSignature(&guest_model->data, *host_model->signatures) < 0)
|
|
|
b971b8 |
- goto error;
|
|
|
b971b8 |
+ return VIR_CPU_COMPARE_ERROR;
|
|
|
b971b8 |
|
|
|
b971b8 |
if (cpu->type == VIR_CPU_TYPE_GUEST
|
|
|
b971b8 |
&& cpu->match == VIR_CPU_MATCH_EXACT)
|
|
|
b971b8 |
x86DataSubtract(&guest_model->data, &diff->data);
|
|
|
b971b8 |
|
|
|
b971b8 |
if (x86DataAdd(&guest_model->data, &cpu_force->data))
|
|
|
b971b8 |
- goto error;
|
|
|
b971b8 |
+ return VIR_CPU_COMPARE_ERROR;
|
|
|
b971b8 |
|
|
|
b971b8 |
x86DataSubtract(&guest_model->data, &cpu_disable->data);
|
|
|
b971b8 |
|
|
|
b971b8 |
if (!(guestData = virCPUDataNew(arch)))
|
|
|
b971b8 |
- goto error;
|
|
|
b971b8 |
+ return VIR_CPU_COMPARE_ERROR;
|
|
|
b971b8 |
x86DataCopy(&guestData->data.x86, &guest_model->data);
|
|
|
b971b8 |
|
|
|
b971b8 |
- *guest = guestData;
|
|
|
b971b8 |
+ *guest = g_steal_pointer(&guestData);
|
|
|
b971b8 |
}
|
|
|
b971b8 |
|
|
|
b971b8 |
- cleanup:
|
|
|
b971b8 |
- x86ModelFree(host_model);
|
|
|
b971b8 |
- x86ModelFree(diff);
|
|
|
b971b8 |
- x86ModelFree(cpu_force);
|
|
|
b971b8 |
- x86ModelFree(cpu_require);
|
|
|
b971b8 |
- x86ModelFree(cpu_optional);
|
|
|
b971b8 |
- x86ModelFree(cpu_disable);
|
|
|
b971b8 |
- x86ModelFree(cpu_forbid);
|
|
|
b971b8 |
- x86ModelFree(guest_model);
|
|
|
b971b8 |
-
|
|
|
b971b8 |
return ret;
|
|
|
b971b8 |
-
|
|
|
b971b8 |
- error:
|
|
|
b971b8 |
- virCPUx86DataFree(guestData);
|
|
|
b971b8 |
- ret = VIR_CPU_COMPARE_ERROR;
|
|
|
b971b8 |
- goto cleanup;
|
|
|
b971b8 |
}
|
|
|
b971b8 |
#undef virX86CpuIncompatible
|
|
|
b971b8 |
|
|
|
b971b8 |
--
|
|
|
b971b8 |
2.26.2
|
|
|
b971b8 |
|