提交 9358b63a 编写于 作者: D Daniel P. Berrange

qemu: do upfront check for vcpupids being null when querying pinning

The qemuDomainHelperGetVcpus attempted to report an error when the
vcpupids info was NULL. Unfortunately earlier code would clamp the
value of 'maxinfo' to 0 when nvcpupids was 0, so the error reporting
would end up being skipped.

This lead to 'virsh vcpuinfo <dom>' just returning an empty list
instead of giving the user a clear error.
上级 a103bb10
...@@ -1376,6 +1376,12 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo, ...@@ -1376,6 +1376,12 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
if ((hostcpus = nodeGetCPUCount()) < 0) if ((hostcpus = nodeGetCPUCount()) < 0)
return -1; return -1;
if (priv->vcpupids == NULL) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cpu affinity is not supported"));
return -1;
}
maxcpu = maplen * 8; maxcpu = maplen * 8;
if (maxcpu > hostcpus) if (maxcpu > hostcpus)
maxcpu = hostcpus; maxcpu = hostcpus;
...@@ -1391,8 +1397,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo, ...@@ -1391,8 +1397,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
info[i].number = i; info[i].number = i;
info[i].state = VIR_VCPU_RUNNING; info[i].state = VIR_VCPU_RUNNING;
if (priv->vcpupids != NULL && if (qemuGetProcessInfo(&(info[i].cpuTime),
qemuGetProcessInfo(&(info[i].cpuTime),
&(info[i].cpu), &(info[i].cpu),
NULL, NULL,
vm->pid, vm->pid,
...@@ -1406,28 +1411,22 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo, ...@@ -1406,28 +1411,22 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
if (cpumaps != NULL) { if (cpumaps != NULL) {
memset(cpumaps, 0, maplen * maxinfo); memset(cpumaps, 0, maplen * maxinfo);
if (priv->vcpupids != NULL) { for (v = 0; v < maxinfo; v++) {
for (v = 0; v < maxinfo; v++) { unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v);
unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v); virBitmapPtr map = NULL;
virBitmapPtr map = NULL; unsigned char *tmpmap = NULL;
unsigned char *tmpmap = NULL; int tmpmapLen = 0;
int tmpmapLen = 0;
if (virProcessGetAffinity(priv->vcpupids[v],
if (virProcessGetAffinity(priv->vcpupids[v], &map, maxcpu) < 0)
&map, maxcpu) < 0) return -1;
return -1; virBitmapToData(map, &tmpmap, &tmpmapLen);
virBitmapToData(map, &tmpmap, &tmpmapLen); if (tmpmapLen > maplen)
if (tmpmapLen > maplen) tmpmapLen = maplen;
tmpmapLen = maplen; memcpy(cpumap, tmpmap, tmpmapLen);
memcpy(cpumap, tmpmap, tmpmapLen);
VIR_FREE(tmpmap);
VIR_FREE(tmpmap); virBitmapFree(map);
virBitmapFree(map);
}
} else {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cpu affinity is not available"));
return -1;
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册