cpu: Rework cpuDataFree

The new API is called virCPUDataFree. Individual CPU drivers are no
longer required to implement their own freeing function unless they need
to free architecture specific data from virCPUData.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2017-02-02 15:37:40 +01:00
parent 5acdd4a6b4
commit f6d55a5f42
17 changed files with 38 additions and 59 deletions

View File

@ -68,7 +68,7 @@ virBhyveCapsInitCPU(virCapsPtr caps,
ret = 0;
cleanup:
cpuDataFree(data);
virCPUDataFree(data);
return ret;

View File

@ -331,7 +331,7 @@ virCPUDataNew(virArch arch)
/**
* cpuDataFree:
* virCPUDataFree:
*
* @data: CPU data structure to be freed
*
@ -340,26 +340,19 @@ virCPUDataNew(virArch arch)
* Returns nothing.
*/
void
cpuDataFree(virCPUDataPtr data)
virCPUDataFree(virCPUDataPtr data)
{
struct cpuArchDriver *driver;
VIR_DEBUG("data=%p", data);
if (data == NULL)
if (!data)
return;
if ((driver = cpuGetSubDriver(data->arch)) == NULL)
return;
if (driver->free == NULL) {
virReportError(VIR_ERR_NO_SUPPORT,
_("cannot free CPU data for %s architecture"),
virArchToString(data->arch));
return;
}
(driver->free)(data);
if ((driver = cpuGetSubDriver(data->arch)) && driver->dataFree)
driver->dataFree(data);
else
VIR_FREE(data);
}

View File

@ -116,7 +116,7 @@ struct cpuArchDriver {
virCPUArchCompare compare;
cpuArchDecode decode;
cpuArchEncode encode;
cpuArchDataFree free;
cpuArchDataFree dataFree;
cpuArchNodeData nodeData;
cpuArchBaseline baseline;
virCPUArchUpdate update;
@ -166,7 +166,7 @@ virCPUDataPtr
virCPUDataNew(virArch arch);
void
cpuDataFree (virCPUDataPtr data);
virCPUDataFree(virCPUDataPtr data);
virCPUDataPtr
cpuNodeData (virArch arch);

View File

@ -37,12 +37,6 @@ static const virArch archs[] = {
VIR_ARCH_AARCH64,
};
static void
armDataFree(virCPUDataPtr data)
{
VIR_FREE(data);
}
static int
virCPUarmUpdate(virCPUDefPtr guest,
@ -117,7 +111,6 @@ struct cpuArchDriver cpuDriverArm = {
.compare = virCPUarmCompare,
.decode = NULL,
.encode = NULL,
.free = armDataFree,
.nodeData = NULL,
.baseline = armBaseline,
.update = virCPUarmUpdate,

View File

@ -705,7 +705,7 @@ ppc64DriverDecode(virCPUDefPtr cpu,
}
static void
ppc64DriverFree(virCPUDataPtr data)
virCPUppc64DataFree(virCPUDataPtr data)
{
if (!data)
return;
@ -741,7 +741,7 @@ ppc64DriverNodeData(virArch arch)
return nodeData;
error:
ppc64DriverFree(nodeData);
virCPUppc64DataFree(nodeData);
return NULL;
}
@ -901,7 +901,7 @@ struct cpuArchDriver cpuDriverPPC64 = {
.compare = virCPUppc64Compare,
.decode = ppc64DriverDecode,
.encode = NULL,
.free = ppc64DriverFree,
.dataFree = virCPUppc64DataFree,
.nodeData = ppc64DriverNodeData,
.baseline = ppc64DriverBaseline,
.update = virCPUppc64Update,

View File

@ -33,12 +33,6 @@
static const virArch archs[] = { VIR_ARCH_S390, VIR_ARCH_S390X };
static void
s390DataFree(virCPUDataPtr data)
{
VIR_FREE(data);
}
static virCPUCompareResult
virCPUs390Compare(virCPUDefPtr host ATTRIBUTE_UNUSED,
virCPUDefPtr cpu ATTRIBUTE_UNUSED,
@ -115,7 +109,6 @@ struct cpuArchDriver cpuDriverS390 = {
.compare = virCPUs390Compare,
.decode = NULL,
.encode = NULL,
.free = s390DataFree,
.nodeData = NULL,
.baseline = NULL,
.update = virCPUs390Update,

View File

@ -304,7 +304,7 @@ virCPUx86DataClear(virCPUx86Data *data)
static void
x86FreeCPUData(virCPUDataPtr data)
virCPUx86DataFree(virCPUDataPtr data)
{
if (!data)
return;
@ -1455,7 +1455,7 @@ virCPUx86DataParse(xmlXPathContextPtr ctxt)
return cpuData;
error:
x86FreeCPUData(cpuData);
virCPUx86DataFree(cpuData);
cpuData = NULL;
goto cleanup;
}
@ -1641,7 +1641,7 @@ x86Compute(virCPUDefPtr host,
return ret;
error:
x86FreeCPUData(guestData);
virCPUx86DataFree(guestData);
ret = VIR_CPU_COMPARE_ERROR;
goto cleanup;
}
@ -2033,12 +2033,12 @@ x86Encode(virArch arch,
return 0;
error:
x86FreeCPUData(data_forced);
x86FreeCPUData(data_required);
x86FreeCPUData(data_optional);
x86FreeCPUData(data_disabled);
x86FreeCPUData(data_forbidden);
x86FreeCPUData(data_vendor);
virCPUx86DataFree(data_forced);
virCPUx86DataFree(data_required);
virCPUx86DataFree(data_optional);
virCPUx86DataFree(data_disabled);
virCPUx86DataFree(data_forbidden);
virCPUx86DataFree(data_vendor);
return -1;
}
@ -2380,7 +2380,7 @@ x86NodeData(virArch arch)
return cpuData;
error:
x86FreeCPUData(cpuData);
virCPUx86DataFree(cpuData);
return NULL;
}
#endif
@ -2718,7 +2718,7 @@ struct cpuArchDriver cpuDriverX86 = {
.compare = virCPUx86Compare,
.decode = x86DecodeCPUData,
.encode = x86Encode,
.free = x86FreeCPUData,
.dataFree = virCPUx86DataFree,
#if defined(__i386__) || defined(__x86_64__)
.nodeData = x86NodeData,
#else

View File

@ -984,7 +984,6 @@ virSecretObjSetValueSize;
# cpu/cpu.h
cpuBaseline;
cpuBaselineXML;
cpuDataFree;
cpuDecode;
cpuEncode;
cpuNodeData;
@ -994,6 +993,7 @@ virCPUCompareXML;
virCPUConvertLegacy;
virCPUDataCheckFeature;
virCPUDataFormat;
virCPUDataFree;
virCPUDataNew;
virCPUDataParse;
virCPUGetModels;

View File

@ -145,7 +145,7 @@ libxlCapsNodeData(virCPUDefPtr cpu, libxl_hwcap hwcap,
return cpudata;
error:
cpuDataFree(cpudata);
virCPUDataFree(cpudata);
return NULL;
}
@ -198,7 +198,7 @@ libxlCapsInitCPU(virCapsPtr caps, libxl_physinfo *phy_info,
}
cleanup:
cpuDataFree(data);
virCPUDataFree(data);
return ret;

View File

@ -1090,7 +1090,7 @@ virQEMUCapsInitCPU(virCapsPtr caps,
ret = 0;
cleanup:
cpuDataFree(data);
virCPUDataFree(data);
return ret;

View File

@ -6571,7 +6571,7 @@ qemuMonitorJSONParseCPUx86Features(virJSONValuePtr data)
return cpudata;
error:
cpuDataFree(cpudata);
virCPUDataFree(cpudata);
return NULL;
}

View File

@ -1606,7 +1606,7 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
goto cleanup;
is_32bit = (virCPUDataCheckFeature(cpuData, "lm") != 1);
cpuDataFree(cpuData);
virCPUDataFree(cpuData);
} else if (model) {
is_32bit = STREQ(model, "qemu32");
}

View File

@ -3815,7 +3815,7 @@ qemuProcessVerifyGuestCPU(virQEMUDriverPtr driver,
ret = true;
cleanup:
cpuDataFree(guestcpu);
virCPUDataFree(guestcpu);
return ret;
}

View File

@ -118,7 +118,7 @@ vmwareCapsInit(void)
cleanup:
virCPUDefFree(cpu);
cpuDataFree(data);
virCPUDataFree(data);
return caps;

View File

@ -151,7 +151,7 @@ vzBuildCapabilities(void)
}
cleanup:
cpuDataFree(data);
virCPUDataFree(data);
return caps;
error:

View File

@ -439,7 +439,7 @@ cpuTestHasFeature(const void *arg)
ret = 0;
cleanup:
cpuDataFree(hostData);
virCPUDataFree(hostData);
virCPUDefFree(host);
return ret;
}
@ -489,7 +489,7 @@ cpuTestCPUID(bool guest, const void *arg)
cleanup:
VIR_FREE(hostFile);
VIR_FREE(host);
cpuDataFree(hostData);
virCPUDataFree(hostData);
virCPUDefFree(cpu);
VIR_FREE(result);
return ret;
@ -549,7 +549,7 @@ cpuTestJSONCPUID(const void *arg)
cleanup:
qemuMonitorTestFree(testMon);
cpuDataFree(cpuData);
virCPUDataFree(cpuData);
virCPUDefFree(cpu);
VIR_FREE(result);
VIR_FREE(json);

View File

@ -2410,7 +2410,7 @@ testQemuMonitorJSONGetCPUData(const void *opaque)
VIR_FREE(dataFile);
VIR_FREE(jsonStr);
VIR_FREE(actual);
cpuDataFree(cpuData);
virCPUDataFree(cpuData);
qemuMonitorTestFree(test);
return ret;
}
@ -2455,7 +2455,7 @@ testQemuMonitorJSONGetNonExistingCPUData(const void *opaque)
ret = 0;
cleanup:
qemuMonitorTestFree(test);
cpuDataFree(cpuData);
virCPUDataFree(cpuData);
return ret;
}