mirror of https://gitee.com/openkylin/libvirt.git
qemu: driver: Refactor qemuDomainHelperGetVcpus
Change some of the control structures and switch to using the new vcpu structure.
This commit is contained in:
parent
e6b36736a8
commit
ce43cca0eb
|
@ -1422,11 +1422,17 @@ qemuGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, long *vm_rss,
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
|
qemuDomainHelperGetVcpus(virDomainObjPtr vm,
|
||||||
unsigned char *cpumaps, int maplen)
|
virVcpuInfoPtr info,
|
||||||
|
int maxinfo,
|
||||||
|
unsigned char *cpumaps,
|
||||||
|
int maplen)
|
||||||
{
|
{
|
||||||
size_t i, v;
|
size_t ncpuinfo = 0;
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
size_t i;
|
||||||
|
|
||||||
|
if (maxinfo == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (!qemuDomainHasVcpuPids(vm)) {
|
if (!qemuDomainHasVcpuPids(vm)) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
|
@ -1434,43 +1440,46 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clamp to actual number of vcpus */
|
if (info)
|
||||||
if (maxinfo > priv->nvcpupids)
|
|
||||||
maxinfo = priv->nvcpupids;
|
|
||||||
|
|
||||||
if (maxinfo >= 1) {
|
|
||||||
if (info != NULL) {
|
|
||||||
memset(info, 0, sizeof(*info) * maxinfo);
|
memset(info, 0, sizeof(*info) * maxinfo);
|
||||||
for (i = 0; i < maxinfo; i++) {
|
|
||||||
|
if (cpumaps)
|
||||||
|
memset(cpumaps, 0, sizeof(*cpumaps) * maxinfo);
|
||||||
|
|
||||||
|
for (i = 0; i < virDomainDefGetVcpusMax(vm->def) && ncpuinfo < maxinfo; i++) {
|
||||||
|
virDomainVcpuInfoPtr vcpu = virDomainDefGetVcpu(vm->def, i);
|
||||||
|
pid_t vcpupid = qemuDomainGetVcpuPid(vm, i);
|
||||||
|
|
||||||
|
if (!vcpu->online)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (info) {
|
||||||
info[i].number = i;
|
info[i].number = i;
|
||||||
info[i].state = VIR_VCPU_RUNNING;
|
info[i].state = VIR_VCPU_RUNNING;
|
||||||
|
|
||||||
if (qemuGetProcessInfo(&(info[i].cpuTime),
|
if (qemuGetProcessInfo(&(info[i].cpuTime), &(info[i].cpu), NULL,
|
||||||
&(info[i].cpu),
|
vm->pid, vcpupid) < 0) {
|
||||||
NULL,
|
|
||||||
vm->pid,
|
|
||||||
qemuDomainGetVcpuPid(vm, i)) < 0) {
|
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("cannot get vCPU placement & pCPU time"));
|
_("cannot get vCPU placement & pCPU time"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (cpumaps != NULL) {
|
if (cpumaps) {
|
||||||
for (v = 0; v < maxinfo; v++) {
|
unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, i);
|
||||||
unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v);
|
|
||||||
virBitmapPtr map = NULL;
|
virBitmapPtr map = NULL;
|
||||||
|
|
||||||
if (!(map = virProcessGetAffinity(qemuDomainGetVcpuPid(vm, v))))
|
if (!(map = virProcessGetAffinity(vcpupid)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
virBitmapToDataBuf(map, cpumap, maplen);
|
virBitmapToDataBuf(map, cpumap, maplen);
|
||||||
virBitmapFree(map);
|
virBitmapFree(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ncpuinfo++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return maxinfo;
|
return ncpuinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue