Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
Version 2:
- no change
src/cpu/cpu_x86.c | 147 ++++++++++++++++++-----------------------
src/cpu/cpu_x86.h | 3 -
src/libvirt_private.syms | 1 -
src/libxl/libxl_capabilities.c | 18 ++---
src/qemu/qemu_monitor_json.c | 33 ++++-----
5 files changed, 92 insertions(+), 110 deletions(-)
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index d9764a260..ccd68b681 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -303,22 +303,6 @@ virCPUx86DataClear(virCPUx86Data *data)
}
-virCPUDataPtr
-virCPUx86MakeData(virArch arch, virCPUx86Data *data)
-{
- virCPUDataPtr cpuData;
-
- if (VIR_ALLOC(cpuData) < 0)
- return NULL;
-
- cpuData->arch = arch;
- cpuData->data.x86 = *data;
- data->len = 0;
- data->data = NULL;
-
- return cpuData;
-}
-
static void
x86FreeCPUData(virCPUDataPtr data)
{
@@ -1441,7 +1425,6 @@ virCPUx86DataParse(xmlXPathContextPtr ctxt)
{
xmlNodePtr *nodes = NULL;
virCPUDataPtr cpuData = NULL;
- virCPUx86Data data = VIR_CPU_X86_DATA_INIT;
virCPUx86CPUID cpuid;
size_t i;
int n;
@@ -1450,26 +1433,31 @@ virCPUx86DataParse(xmlXPathContextPtr ctxt)
if (n <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("no x86 CPU data found"));
- goto cleanup;
+ goto error;
}
+ if (!(cpuData = virCPUDataNew(VIR_ARCH_X86_64)))
+ goto error;
+
for (i = 0; i < n; i++) {
ctxt->node = nodes[i];
if (x86ParseCPUID(ctxt, &cpuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse cpuid[%zu]"), i);
- goto cleanup;
+ goto error;
}
- if (virCPUx86DataAddCPUID(&data, &cpuid) < 0)
- goto cleanup;
+ if (virCPUx86DataAddCPUID(&cpuData->data.x86, &cpuid) < 0)
+ goto error;
}
- cpuData = virCPUx86MakeData(VIR_ARCH_X86_64, &data);
-
cleanup:
VIR_FREE(nodes);
- virCPUx86DataClear(&data);
return cpuData;
+
+ error:
+ x86FreeCPUData(cpuData);
+ cpuData = NULL;
+ goto cleanup;
}
@@ -1514,7 +1502,7 @@ x86Compute(virCPUDefPtr host,
virCPUx86ModelPtr cpu_forbid = NULL;
virCPUx86ModelPtr diff = NULL;
virCPUx86ModelPtr guest_model = NULL;
- virCPUx86Data guestData = VIR_CPU_X86_DATA_INIT;
+ virCPUDataPtr guestData = NULL;
virCPUCompareResult ret;
virCPUx86CompareResult result;
virArch arch;
@@ -1633,9 +1621,11 @@ x86Compute(virCPUDefPtr host,
x86DataSubtract(&guest_model->data, &cpu_disable->data);
- if (x86DataCopy(&guestData, &guest_model->data) < 0 ||
- !(*guest = virCPUx86MakeData(arch, &guestData)))
+ if (!(guestData = virCPUDataNew(arch)) ||
+ x86DataCopy(&guestData->data.x86, &guest_model->data) < 0)
goto error;
+
+ *guest = guestData;
}
cleanup:
@@ -1647,11 +1637,11 @@ x86Compute(virCPUDefPtr host,
x86ModelFree(cpu_disable);
x86ModelFree(cpu_forbid);
x86ModelFree(guest_model);
- virCPUx86DataClear(&guestData);
return ret;
error:
+ x86FreeCPUData(guestData);
ret = VIR_CPU_COMPARE_ERROR;
goto cleanup;
}
@@ -1958,12 +1948,12 @@ x86Encode(virArch arch,
virCPUDataPtr *vendor)
{
virCPUx86MapPtr map = NULL;
- virCPUx86Data data_forced = VIR_CPU_X86_DATA_INIT;
- virCPUx86Data data_required = VIR_CPU_X86_DATA_INIT;
- virCPUx86Data data_optional = VIR_CPU_X86_DATA_INIT;
- virCPUx86Data data_disabled = VIR_CPU_X86_DATA_INIT;
- virCPUx86Data data_forbidden = VIR_CPU_X86_DATA_INIT;
- virCPUx86Data data_vendor = VIR_CPU_X86_DATA_INIT;
+ virCPUDataPtr data_forced = NULL;
+ virCPUDataPtr data_required = NULL;
+ virCPUDataPtr data_optional = NULL;
+ virCPUDataPtr data_disabled = NULL;
+ virCPUDataPtr data_forbidden = NULL;
+ virCPUDataPtr data_vendor = NULL;
if (forced)
*forced = NULL;
@@ -1982,23 +1972,33 @@ x86Encode(virArch arch,
goto error;
if (forced &&
- x86EncodePolicy(&data_forced, cpu, map, VIR_CPU_FEATURE_FORCE) < 0)
+ (!(data_forced = virCPUDataNew(arch)) ||
+ x86EncodePolicy(&data_forced->data.x86, cpu, map,
+ VIR_CPU_FEATURE_FORCE) < 0))
goto error;
if (required &&
- x86EncodePolicy(&data_required, cpu, map, VIR_CPU_FEATURE_REQUIRE) < 0)
+ (!(data_required = virCPUDataNew(arch)) ||
+ x86EncodePolicy(&data_required->data.x86, cpu, map,
+ VIR_CPU_FEATURE_REQUIRE) < 0))
goto error;
if (optional &&
- x86EncodePolicy(&data_optional, cpu, map, VIR_CPU_FEATURE_OPTIONAL) < 0)
+ (!(data_optional = virCPUDataNew(arch)) ||
+ x86EncodePolicy(&data_optional->data.x86, cpu, map,
+ VIR_CPU_FEATURE_OPTIONAL) < 0))
goto error;
if (disabled &&
- x86EncodePolicy(&data_disabled, cpu, map, VIR_CPU_FEATURE_DISABLE) < 0)
+ (!(data_disabled = virCPUDataNew(arch)) ||
+ x86EncodePolicy(&data_disabled->data.x86, cpu, map,
+ VIR_CPU_FEATURE_DISABLE) < 0))
goto error;
if (forbidden &&
- x86EncodePolicy(&data_forbidden, cpu, map, VIR_CPU_FEATURE_FORBID) < 0)
+ (!(data_forbidden = virCPUDataNew(arch)) ||
+ x86EncodePolicy(&data_forbidden->data.x86, cpu, map,
+ VIR_CPU_FEATURE_FORBID) < 0))
goto error;
if (vendor) {
@@ -2010,50 +2010,35 @@ x86Encode(virArch arch,
goto error;
}
- if (v && virCPUx86DataAddCPUID(&data_vendor, &v->cpuid) <
0)
+ if (!(data_vendor = virCPUDataNew(arch)))
+ goto error;
+
+ if (v && virCPUx86DataAddCPUID(&data_vendor->data.x86,
&v->cpuid) < 0)
goto error;
}
- if (forced &&
- !(*forced = virCPUx86MakeData(arch, &data_forced)))
- goto error;
- if (required &&
- !(*required = virCPUx86MakeData(arch, &data_required)))
- goto error;
- if (optional &&
- !(*optional = virCPUx86MakeData(arch, &data_optional)))
- goto error;
- if (disabled &&
- !(*disabled = virCPUx86MakeData(arch, &data_disabled)))
- goto error;
- if (forbidden &&
- !(*forbidden = virCPUx86MakeData(arch, &data_forbidden)))
- goto error;
- if (vendor &&
- !(*vendor = virCPUx86MakeData(arch, &data_vendor)))
- goto error;
+ if (forced)
+ *forced = data_forced;
+ if (required)
+ *required = data_required;
+ if (optional)
+ *optional = data_optional;
+ if (disabled)
+ *disabled = data_disabled;
+ if (forbidden)
+ *forbidden = data_forbidden;
+ if (vendor)
+ *vendor = data_vendor;
return 0;
error:
- virCPUx86DataClear(&data_forced);
- virCPUx86DataClear(&data_required);
- virCPUx86DataClear(&data_optional);
- virCPUx86DataClear(&data_disabled);
- virCPUx86DataClear(&data_forbidden);
- virCPUx86DataClear(&data_vendor);
- if (forced)
- x86FreeCPUData(*forced);
- if (required)
- x86FreeCPUData(*required);
- if (optional)
- x86FreeCPUData(*optional);
- if (disabled)
- x86FreeCPUData(*disabled);
- if (forbidden)
- x86FreeCPUData(*forbidden);
- if (vendor)
- x86FreeCPUData(*vendor);
+ x86FreeCPUData(data_forced);
+ x86FreeCPUData(data_required);
+ x86FreeCPUData(data_optional);
+ x86FreeCPUData(data_disabled);
+ x86FreeCPUData(data_forbidden);
+ x86FreeCPUData(data_vendor);
return -1;
}
@@ -2382,22 +2367,20 @@ static virCPUDataPtr
x86NodeData(virArch arch)
{
virCPUDataPtr cpuData = NULL;
- virCPUx86Data data = VIR_CPU_X86_DATA_INIT;
- if (cpuidSet(CPUX86_BASIC, &data) < 0)
+ if (!(cpuData = virCPUDataNew(arch)))
goto error;
- if (cpuidSet(CPUX86_EXTENDED, &data) < 0)
+ if (cpuidSet(CPUX86_BASIC, &cpuData->data.x86) < 0)
goto error;
- if (!(cpuData = virCPUx86MakeData(arch, &data)))
+ if (cpuidSet(CPUX86_EXTENDED, &cpuData->data.x86) < 0)
goto error;
return cpuData;
error:
- virCPUx86DataClear(&data);
-
+ x86FreeCPUData(cpuData);
return NULL;
}
#endif
diff --git a/src/cpu/cpu_x86.h b/src/cpu/cpu_x86.h
index 09b95a5a2..8c8c6ed4f 100644
--- a/src/cpu/cpu_x86.h
+++ b/src/cpu/cpu_x86.h
@@ -34,7 +34,4 @@ int virCPUx86DataAddCPUID(virCPUx86Data *data,
void virCPUx86DataClear(virCPUx86Data *data);
-virCPUDataPtr virCPUx86MakeData(virArch arch,
- virCPUx86Data *data);
-
#endif /* __VIR_CPU_X86_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a2bcc6241..b4f61c87e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1007,7 +1007,6 @@ virCPUUpdate;
# cpu/cpu_x86.h
virCPUx86DataAddCPUID;
virCPUx86DataClear;
-virCPUx86MakeData;
# datatypes.h
diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c
index 2bbd2d1b4..622e9f6bb 100644
--- a/src/libxl/libxl_capabilities.c
+++ b/src/libxl/libxl_capabilities.c
@@ -65,14 +65,14 @@ struct guest_arch {
#define XEN_CAP_REGEX
"(xen|hvm)-[[:digit:]]+\\.[[:digit:]]+-(aarch64|armv7l|x86_32|x86_64|ia64|powerpc64)(p|be)?"
static int
-libxlCapsAddCPUID(virCPUx86Data *data, virCPUx86CPUID *cpuid, ssize_t ncaps)
+libxlCapsAddCPUID(virCPUDataPtr data, virCPUx86CPUID *cpuid, ssize_t ncaps)
{
size_t i;
for (i = 0; i < ncaps; i++) {
virCPUx86CPUID *c = &cpuid[i];
- if (virCPUx86DataAddCPUID(data, c) < 0) {
+ if (virCPUx86DataAddCPUID(&data->data.x86, c) < 0) {
VIR_DEBUG("Failed to add CPUID(%x,%x)", c->eax_in,
c->ecx_in);
return -1;
}
@@ -112,7 +112,6 @@ libxlCapsNodeData(virCPUDefPtr cpu, libxl_hwcap hwcap,
{
ssize_t ncaps;
virCPUDataPtr cpudata = NULL;
- virCPUx86Data data = VIR_CPU_X86_DATA_INIT;
virCPUx86CPUID cpuid[] = {
{ .eax_in = 0x00000001,
.edx = hwcap[0] },
@@ -131,20 +130,23 @@ libxlCapsNodeData(virCPUDefPtr cpu, libxl_hwcap hwcap,
{ .eax_in = 0x80000007, .ecx_in = 0U, .edx = hwcap[7] },
};
+ if (!(cpudata = virCPUDataNew(cpu->arch)))
+ goto error;
+
ncaps = ARRAY_CARDINALITY(cpuid);
- if (libxlCapsAddCPUID(&data, cpuid, ncaps) < 0)
+ if (libxlCapsAddCPUID(cpudata, cpuid, ncaps) < 0)
goto error;
ncaps = ARRAY_CARDINALITY(cpuid_ver1);
if (version > LIBXL_HWCAP_V0 &&
- libxlCapsAddCPUID(&data, cpuid_ver1, ncaps) < 0)
+ libxlCapsAddCPUID(cpudata, cpuid_ver1, ncaps) < 0)
goto error;
- cpudata = virCPUx86MakeData(cpu->arch, &data);
+ return cpudata;
error:
- virCPUx86DataClear(&data);
- return cpudata;
+ cpuDataFree(cpudata);
+ return NULL;
}
/* hw_caps is an array of 32-bit words whose meaning is listed in
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 415761525..b4da12167 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6565,37 +6565,35 @@ qemuMonitorJSONParseCPUx86FeatureWord(virJSONValuePtr data,
}
-static int
-qemuMonitorJSONParseCPUx86Features(virJSONValuePtr data,
- virCPUDataPtr *cpudata)
+static virCPUDataPtr
+qemuMonitorJSONParseCPUx86Features(virJSONValuePtr data)
{
- virCPUx86Data x86Data = VIR_CPU_X86_DATA_INIT;
+ virCPUDataPtr cpudata = NULL;
virCPUx86CPUID cpuid;
size_t i;
ssize_t n;
- int ret = -1;
if (!data || (n = virJSONValueArraySize(data)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("invalid array of CPUID features"));
- return -1;
+ goto error;
}
+ if (!(cpudata = virCPUDataNew(VIR_ARCH_X86_64)))
+ goto error;
+
for (i = 0; i < n; i++) {
if (qemuMonitorJSONParseCPUx86FeatureWord(virJSONValueArrayGet(data, i),
&cpuid) < 0 ||
- virCPUx86DataAddCPUID(&x86Data, &cpuid) < 0)
- goto cleanup;
+ virCPUx86DataAddCPUID(&cpudata->data.x86, &cpuid) < 0)
+ goto error;
}
- if (!(*cpudata = virCPUx86MakeData(VIR_ARCH_X86_64, &x86Data)))
- goto cleanup;
+ return cpudata;
- ret = 0;
-
- cleanup:
- virCPUx86DataClear(&x86Data);
- return ret;
+ error:
+ cpuDataFree(cpudata);
+ return NULL;
}
@@ -6622,7 +6620,10 @@ qemuMonitorJSONGetCPUx86Data(qemuMonitorPtr mon,
goto cleanup;
data = virJSONValueObjectGetArray(reply, "return");
- ret = qemuMonitorJSONParseCPUx86Features(data, cpudata);
+ if (!(*cpudata = qemuMonitorJSONParseCPUx86Features(data)))
+ goto cleanup;
+
+ ret = 0;
cleanup:
virJSONValueFree(cmd);
--
2.11.1