提交 1dfa174a 编写于 作者: J Jiri Denemark

cpu: Store arch in virCPUData

上级 57d52b24
......@@ -198,29 +198,28 @@ cpuEncode(virArch arch,
return -1;
}
return driver->encode(cpu, forced, required,
return driver->encode(arch, cpu, forced, required,
optional, disabled, forbidden, vendor);
}
void
cpuDataFree(virArch arch,
virCPUDataPtr data)
cpuDataFree(virCPUDataPtr data)
{
struct cpuArchDriver *driver;
VIR_DEBUG("arch=%s, data=%p", virArchToString(arch), data);
VIR_DEBUG("data=%p", data);
if (data == NULL)
return;
if ((driver = cpuGetSubDriver(arch)) == NULL)
if ((driver = cpuGetSubDriver(data->arch)) == NULL)
return;
if (driver->free == NULL) {
virReportError(VIR_ERR_NO_SUPPORT,
_("cannot free CPU data for %s architecture"),
virArchToString(arch));
virArchToString(data->arch));
return;
}
......@@ -419,22 +418,20 @@ cpuUpdate(virCPUDefPtr guest,
}
int
cpuHasFeature(virArch arch,
const virCPUDataPtr data,
cpuHasFeature(const virCPUDataPtr data,
const char *feature)
{
struct cpuArchDriver *driver;
VIR_DEBUG("arch=%s, data=%p, feature=%s",
virArchToString(arch), data, feature);
VIR_DEBUG("data=%p, feature=%s", data, feature);
if ((driver = cpuGetSubDriver(arch)) == NULL)
if ((driver = cpuGetSubDriver(data->arch)) == NULL)
return -1;
if (driver->hasFeature == NULL) {
virReportError(VIR_ERR_NO_SUPPORT,
_("cannot check guest CPU data for %s architecture"),
virArchToString(arch));
virArchToString(data->arch));
return -1;
}
......
......@@ -32,12 +32,15 @@
# include "cpu_ppc_data.h"
typedef union _virCPUData virCPUData;
typedef struct _virCPUData virCPUData;
typedef virCPUData *virCPUDataPtr;
union _virCPUData {
struct cpuX86Data *x86;
struct cpuPPCData ppc;
/* generic driver needs no data */
struct _virCPUData {
virArch arch;
union {
struct cpuX86Data *x86;
struct cpuPPCData ppc;
/* generic driver needs no data */
} data;
};
......@@ -53,7 +56,8 @@ typedef int
const char *preferred);
typedef int
(*cpuArchEncode) (const virCPUDefPtr cpu,
(*cpuArchEncode) (virArch arch,
const virCPUDefPtr cpu,
virCPUDataPtr *forced,
virCPUDataPtr *required,
virCPUDataPtr *optional,
......@@ -130,8 +134,7 @@ cpuEncode (virArch arch,
virCPUDataPtr *vendor);
extern void
cpuDataFree (virArch arch,
virCPUDataPtr data);
cpuDataFree (virCPUDataPtr data);
extern virCPUDataPtr
cpuNodeData (virArch arch);
......@@ -159,8 +162,7 @@ cpuUpdate (virCPUDefPtr guest,
const virCPUDefPtr host);
extern int
cpuHasFeature(virArch arch,
const virCPUDataPtr data,
cpuHasFeature(const virCPUDataPtr data,
const char *feature);
......
......@@ -313,10 +313,10 @@ ppcDecode(virCPUDefPtr cpu,
if (data == NULL || (map = ppcLoadMap()) == NULL)
return -1;
if (!(model = ppcModelFindPVR(map, data->ppc.pvr))) {
if (!(model = ppcModelFindPVR(map, data->data.ppc.pvr))) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("Cannot find CPU model with PVR 0x%08x"),
data->ppc.pvr);
data->data.ppc.pvr);
goto cleanup;
}
......
......@@ -216,14 +216,15 @@ x86DataFree(struct cpuX86Data *data)
static virCPUDataPtr
x86MakeCPUData(struct cpuX86Data **data)
x86MakeCPUData(virArch arch, struct cpuX86Data **data)
{
virCPUDataPtr cpuData;
if (VIR_ALLOC(cpuData) < 0)
return NULL;
cpuData->x86 = *data;
cpuData->arch = arch;
cpuData->data.x86 = *data;
*data = NULL;
return cpuData;
......@@ -235,7 +236,7 @@ x86FreeCPUData(virCPUDataPtr data)
if (!data)
return;
x86DataFree(data->x86);
x86DataFree(data->data.x86);
VIR_FREE(data);
}
......@@ -1165,6 +1166,7 @@ x86Compute(virCPUDefPtr host,
struct x86_model *guest_model = NULL;
virCPUCompareResult ret;
enum compare_result result;
virArch arch;
size_t i;
if (cpu->arch != VIR_ARCH_NONE) {
......@@ -1187,6 +1189,9 @@ x86Compute(virCPUDefPtr host,
goto error;
return VIR_CPU_COMPARE_INCOMPATIBLE;
}
arch = cpu->arch;
} else {
arch = host->arch;
}
if (cpu->vendor &&
......@@ -1266,7 +1271,7 @@ x86Compute(virCPUDefPtr host,
x86DataSubtract(guest_model->data, cpu_disable->data);
if (!(guestData = x86DataCopy(guest_model->data)) ||
!(*guest = x86MakeCPUData(&guestData))) {
!(*guest = x86MakeCPUData(arch, &guestData))) {
x86DataFree(guestData);
goto error;
}
......@@ -1418,7 +1423,7 @@ x86DecodeCPUData(virCPUDefPtr cpu,
unsigned int nmodels,
const char *preferred)
{
return x86Decode(cpu, data->x86, models, nmodels, preferred);
return x86Decode(cpu, data->data.x86, models, nmodels, preferred);
}
......@@ -1442,7 +1447,8 @@ x86EncodePolicy(const virCPUDefPtr cpu,
static int
x86Encode(const virCPUDefPtr cpu,
x86Encode(virArch arch,
const virCPUDefPtr cpu,
virCPUDataPtr *forced,
virCPUDataPtr *required,
virCPUDataPtr *optional,
......@@ -1522,22 +1528,22 @@ x86Encode(const virCPUDefPtr cpu,
}
if (forced &&
!(*forced = x86MakeCPUData(&data_forced)))
!(*forced = x86MakeCPUData(arch, &data_forced)))
goto error;
if (required &&
!(*required = x86MakeCPUData(&data_required)))
!(*required = x86MakeCPUData(arch, &data_required)))
goto error;
if (optional &&
!(*optional = x86MakeCPUData(&data_optional)))
!(*optional = x86MakeCPUData(arch, &data_optional)))
goto error;
if (disabled &&
!(*disabled = x86MakeCPUData(&data_disabled)))
!(*disabled = x86MakeCPUData(arch, &data_disabled)))
goto error;
if (forbidden &&
!(*forbidden = x86MakeCPUData(&data_forbidden)))
!(*forbidden = x86MakeCPUData(arch, &data_forbidden)))
goto error;
if (vendor &&
!(*vendor = x86MakeCPUData(&data_vendor)))
!(*vendor = x86MakeCPUData(arch, &data_vendor)))
goto error;
ret = 0;
......@@ -1646,7 +1652,7 @@ x86NodeData(void)
goto error;
data->extended_len = ret;
if (!(cpuData = x86MakeCPUData(&data)))
if (!(cpuData = x86MakeCPUData(virArchFromHost(), &data)))
goto error;
return cpuData;
......@@ -1885,7 +1891,7 @@ static int x86HasFeature(const virCPUDataPtr data,
if (!(feature = x86FeatureFind(map, name)))
goto cleanup;
ret = x86DataIsSubset(data->x86, feature->data) ? 1 : 0;
ret = x86DataIsSubset(data->data.x86, feature->data) ? 1 : 0;
cleanup:
x86MapFree(map);
......
......@@ -857,7 +857,7 @@ virQEMUCapsInitCPU(virCapsPtr caps,
ret = 0;
cleanup:
cpuDataFree(arch, data);
cpuDataFree(data);
return ret;
......
......@@ -5704,7 +5704,7 @@ qemuBuildCpuArgStr(const virQEMUDriverPtr driver,
/* Only 'svm' requires --enable-nesting. The nested
* 'vmx' patches now simply hook off the CPU features
*/
hasSVM = cpuHasFeature(host->arch, data, "svm");
hasSVM = cpuHasFeature(data, "svm");
if (hasSVM < 0)
goto cleanup;
*hasHwVirt = hasSVM > 0 ? true : false;
......@@ -5845,8 +5845,7 @@ qemuBuildCpuArgStr(const virQEMUDriverPtr driver,
cleanup:
VIR_FREE(compare_msg);
if (host)
cpuDataFree(host->arch, data);
cpuDataFree(data);
virCPUDefFree(guest);
virCPUDefFree(cpu);
virObjectUnref(caps);
......@@ -9900,8 +9899,8 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
NULL, NULL, NULL, NULL) < 0)
goto cleanup;
is_32bit = (cpuHasFeature(VIR_ARCH_X86_64, cpuData, "lm") != 1);
cpuDataFree(VIR_ARCH_X86_64, cpuData);
is_32bit = (cpuHasFeature(cpuData, "lm") != 1);
cpuDataFree(cpuData);
} else if (model) {
is_32bit = STREQ(model, "qemu32");
}
......
......@@ -97,9 +97,9 @@ vmwareCapsInit(void)
* - Host CPU is x86_64 with virtualization extensions
*/
if (caps->host.arch == VIR_ARCH_X86_64 ||
(cpuHasFeature(caps->host.arch, data, "lm") &&
(cpuHasFeature(caps->host.arch, data, "vmx") ||
cpuHasFeature(caps->host.arch, data, "svm")))) {
(cpuHasFeature(data, "lm") &&
(cpuHasFeature(data, "vmx") ||
cpuHasFeature(data, "svm")))) {
if ((guest = virCapabilitiesAddGuest(caps,
"hvm",
......@@ -115,8 +115,7 @@ vmwareCapsInit(void)
cleanup:
virCPUDefFree(cpu);
if (caps)
cpuDataFree(caps->host.arch, data);
cpuDataFree(data);
return caps;
......
......@@ -308,8 +308,7 @@ cpuTestGuestData(const void *arg)
cleanup:
VIR_FREE(result);
if (host)
cpuDataFree(host->arch, guestData);
cpuDataFree(guestData);
virCPUDefFree(host);
virCPUDefFree(cpu);
virCPUDefFree(guest);
......@@ -427,7 +426,7 @@ cpuTestHasFeature(const void *arg)
NULL, NULL, NULL, NULL) < 0)
goto cleanup;
result = cpuHasFeature(host->arch, hostData, data->name);
result = cpuHasFeature(hostData, data->name);
if (data->result == -1)
virResetLastError();
......@@ -445,8 +444,7 @@ cpuTestHasFeature(const void *arg)
ret = 0;
cleanup:
if (host)
cpuDataFree(host->arch, hostData);
cpuDataFree(hostData);
virCPUDefFree(host);
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册