Ensure 'arch' is always set in cpuArchNodeData

The s390, ppc and arm CPU drivers never set the 'arch' field
in their impl of cpuArchNodeData. This leads to error messages
being reported from cpuDataFree later, due to trying to use
VIR_ARCH_NONE.

 #0  virRaiseErrorFull (filename=filename@entry=0x76f94434 "cpu/cpu.c", funcname=funcname@entry=0x76f942dc <__FUNCTION__.18096> "cpuGetSubDriver", linenr=linenr@entry=58,
     domain=domain@entry=31, code=code@entry=1, level=level@entry=VIR_ERR_ERROR, str1=0x76f70e18 "internal error: %s",
     str2=str2@entry=0x7155f2ec "undefined hardware architecture", str3=str3@entry=0x0, int1=int1@entry=-1, int2=int2@entry=-1, fmt=0x76f70e18 "internal error: %s")
     at util/virerror.c:646
 #1  0x76e682ea in virReportErrorHelper (domcode=domcode@entry=31, errorcode=errorcode@entry=1, filename=0x76f94434 "cpu/cpu.c",
     funcname=0x76f942dc <__FUNCTION__.18096> "cpuGetSubDriver", linenr=linenr@entry=58, fmt=0x76f7e7e4 "%s") at util/virerror.c:1292
 #2  0x76ed82d4 in cpuGetSubDriver (arch=<optimized out>) at cpu/cpu.c:57
 #3  cpuGetSubDriver (arch=VIR_ARCH_NONE) at cpu/cpu.c:51
 #4  0x76ed8818 in cpuDataFree (data=data@entry=0x70c22d78) at cpu/cpu.c:216
 #5  0x716aaec0 in virQEMUCapsInitCPU (arch=VIR_ARCH_ARMV7L, caps=0x70c29a08) at qemu/qemu_capabilities.c:867

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2013-09-04 17:41:55 +01:00
parent bbcdd9b5dc
commit 66ec11ade4
6 changed files with 18 additions and 14 deletions

View File

@ -244,7 +244,7 @@ cpuNodeData(virArch arch)
return NULL;
}
return driver->nodeData();
return driver->nodeData(arch);
}

View File

@ -70,7 +70,7 @@ typedef void
(*cpuArchDataFree) (virCPUDataPtr data);
typedef virCPUDataPtr
(*cpuArchNodeData) (void);
(*cpuArchNodeData) (virArch arch);
typedef virCPUCompareResult
(*cpuArchGuestData) (virCPUDefPtr host,

View File

@ -31,11 +31,15 @@
static const virArch archs[] = { VIR_ARCH_ARMV7L };
static virCPUDataPtr
ArmNodeData(void)
ArmNodeData(virArch arch)
{
virCPUDataPtr data;
ignore_value(VIR_ALLOC(data));
if (VIR_ALLOC(data) < 0)
return NULL;
data->arch = arch;
return data;
}

View File

@ -353,21 +353,23 @@ ppcDataFree(virCPUDataPtr data)
VIR_FREE(data);
}
#if defined(__powerpc__) || defined(__powerpc64__)
static virCPUDataPtr
ppcNodeData(void)
ppcNodeData(virArch arch)
{
virCPUDataPtr cpuData;
if (VIR_ALLOC(cpuData) < 0)
return NULL;
cpuData->arch = arch;
#if defined(__powerpc__) || defined(__powerpc64__)
asm("mfpvr %0"
: "=r" (cpuData->data.ppc.pvr));
#endif
return cpuData;
}
#endif
static int
ppcUpdate(virCPUDefPtr guest ATTRIBUTE_UNUSED,
@ -474,11 +476,7 @@ struct cpuArchDriver cpuDriverPowerPC = {
.decode = ppcDecode,
.encode = NULL,
.free = ppcDataFree,
#if defined(__powerpc__) || defined(__powerpc64__)
.nodeData = ppcNodeData,
#else
.nodeData = NULL,
#endif
.guestData = NULL,
.baseline = ppcBaseline,
.update = ppcUpdate,

View File

@ -32,13 +32,15 @@
static const virArch archs[] = { VIR_ARCH_S390, VIR_ARCH_S390X };
static virCPUDataPtr
s390NodeData(void)
s390NodeData(virArch arch)
{
virCPUDataPtr data;
if (VIR_ALLOC(data) < 0)
return NULL;
data->arch = arch;
return data;
}

View File

@ -1675,7 +1675,7 @@ cpuidSet(uint32_t base, struct cpuX86cpuid **set)
static virCPUDataPtr
x86NodeData(void)
x86NodeData(virArch arch)
{
virCPUDataPtr cpuData = NULL;
struct cpuX86Data *data;
@ -1692,7 +1692,7 @@ x86NodeData(void)
goto error;
data->extended_len = ret;
if (!(cpuData = x86MakeCPUData(virArchFromHost(), &data)))
if (!(cpuData = x86MakeCPUData(arch, &data)))
goto error;
return cpuData;