提交 451b955d 编写于 作者: P Peter Krempa

qemu: domain: Prepare qemuDomainDetectVcpuPids for reuse

Free the old vcpupids array in case when this function is called again
during the run of the VM. It will be later reused in the vCPU hotplug
code. The function now returns the number of detected VCPUs.
上级 e97d1d20
...@@ -4290,7 +4290,8 @@ qemuDomainGetVcpuPid(virDomainObjPtr vm, ...@@ -4290,7 +4290,8 @@ qemuDomainGetVcpuPid(virDomainObjPtr vm,
* *
* Updates vCPU thread ids in the private data of @vm. * Updates vCPU thread ids in the private data of @vm.
* *
* Returns 0 on success -1 on error and reports an appropriate error. * Returns number of detected vCPU threads on success, -1 on error and reports
* an appropriate error.
*/ */
int int
qemuDomainDetectVcpuPids(virQEMUDriverPtr driver, qemuDomainDetectVcpuPids(virQEMUDriverPtr driver,
...@@ -4298,7 +4299,7 @@ qemuDomainDetectVcpuPids(virQEMUDriverPtr driver, ...@@ -4298,7 +4299,7 @@ qemuDomainDetectVcpuPids(virQEMUDriverPtr driver,
int asyncJob) int asyncJob)
{ {
pid_t *cpupids = NULL; pid_t *cpupids = NULL;
int ncpupids; int ncpupids = 0;
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
/* /*
...@@ -4329,26 +4330,23 @@ qemuDomainDetectVcpuPids(virQEMUDriverPtr driver, ...@@ -4329,26 +4330,23 @@ qemuDomainDetectVcpuPids(virQEMUDriverPtr driver,
* Just disable CPU pinning with TCG until someone wants * Just disable CPU pinning with TCG until someone wants
* to try to do this hard work. * to try to do this hard work.
*/ */
if (vm->def->virtType == VIR_DOMAIN_VIRT_QEMU) { if (vm->def->virtType == VIR_DOMAIN_VIRT_QEMU)
priv->nvcpupids = 0; goto done;
priv->vcpupids = NULL;
return 0;
}
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
return -1; return -1;
ncpupids = qemuMonitorGetCPUInfo(priv->mon, &cpupids); ncpupids = qemuMonitorGetCPUInfo(priv->mon, &cpupids);
if (qemuDomainObjExitMonitor(driver, vm) < 0) if (qemuDomainObjExitMonitor(driver, vm) < 0) {
VIR_FREE(cpupids);
return -1; return -1;
/* failure to get the VCPU<-> PID mapping or to execute the query }
/* failure to get the VCPU <-> PID mapping or to execute the query
* command will not be treated fatal as some versions of qemu don't * command will not be treated fatal as some versions of qemu don't
* support this command */ * support this command */
if (ncpupids <= 0) { if (ncpupids <= 0) {
virResetLastError(); virResetLastError();
ncpupids = 0;
priv->nvcpupids = 0; goto done;
priv->vcpupids = NULL;
return 0;
} }
if (ncpupids != virDomainDefGetVcpus(vm->def)) { if (ncpupids != virDomainDefGetVcpus(vm->def)) {
...@@ -4360,7 +4358,9 @@ qemuDomainDetectVcpuPids(virQEMUDriverPtr driver, ...@@ -4360,7 +4358,9 @@ qemuDomainDetectVcpuPids(virQEMUDriverPtr driver,
return -1; return -1;
} }
done:
VIR_FREE(priv->vcpupids);
priv->nvcpupids = ncpupids; priv->nvcpupids = ncpupids;
priv->vcpupids = cpupids; priv->vcpupids = cpupids;
return 0; return ncpupids;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册