提交 9d5ac29e 编写于 作者: P Peter Krempa

qemu: refactor qemuDomainHotunplugVcpus

Refactor the code flow so that 'exit_monitor:' can be removed.

This patch moves the auditing functions into places where it's certain
that hotunplug was or was not successful and reports errors from
qemuMonitorGetCPUInfo properly.
上级 de3db7d2
...@@ -4798,48 +4798,36 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver, ...@@ -4798,48 +4798,36 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
int ret = -1; int ret = -1;
int rc;
int oldvcpus = virDomainDefGetVcpus(vm->def); int oldvcpus = virDomainDefGetVcpus(vm->def);
int vcpus = oldvcpus;
pid_t *cpupids = NULL; pid_t *cpupids = NULL;
int ncpupids; int ncpupids = 0;
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
if (qemuMonitorSetCPU(priv->mon, vcpu, false) < 0) rc = qemuMonitorSetCPU(priv->mon, vcpu, false);
goto exit_monitor;
vcpus--; if (rc == 0)
ncpupids = qemuMonitorGetCPUInfo(priv->mon, &cpupids);
/* After hotplugging the CPUs we need to re-detect threads corresponding
* to the virtual CPUs. Some older versions don't provide the thread ID
* or don't have the "info cpus" command (and they don't support multiple
* CPUs anyways), so errors in the re-detection will not be treated
* fatal */
if ((ncpupids = qemuMonitorGetCPUInfo(priv->mon, &cpupids)) <= 0) {
virResetLastError();
ret = 0;
goto exit_monitor;
}
if (qemuDomainObjExitMonitor(driver, vm) < 0) if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto cleanup; goto cleanup;
/* check if hotunplug has failed */ virDomainAuditVcpu(vm, oldvcpus, oldvcpus - 1, "update",
if (ncpupids == oldvcpus) { rc == 0 && ncpupids == oldvcpus -1);
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("qemu didn't unplug the vCPUs properly")); if (rc < 0 || ncpupids < 0)
vcpus = oldvcpus;
goto cleanup; goto cleanup;
}
if (ncpupids != vcpus) { /* check if hotunplug has failed */
virReportError(VIR_ERR_INTERNAL_ERROR, if (ncpupids != oldvcpus - 1) {
_("got wrong number of vCPU pids from QEMU monitor. " virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
"got %d, wanted %d"), _("qemu didn't unplug vCPU '%u' properly"), vcpu);
ncpupids, vcpus);
vcpus = oldvcpus;
goto cleanup; goto cleanup;
} }
ignore_value(virDomainDefSetVcpus(vm->def, oldvcpus - 1));
if (qemuDomainDelCgroupForThread(priv->cgroup, if (qemuDomainDelCgroupForThread(priv->cgroup,
VIR_CGROUP_THREAD_VCPU, vcpu) < 0) VIR_CGROUP_THREAD_VCPU, vcpu) < 0)
goto cleanup; goto cleanup;
...@@ -4858,15 +4846,7 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver, ...@@ -4858,15 +4846,7 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
cleanup: cleanup:
VIR_FREE(cpupids); VIR_FREE(cpupids);
if (virDomainObjIsActive(vm) &&
virDomainDefSetVcpus(vm->def, vcpus) < 0)
ret = -1;
virDomainAuditVcpu(vm, oldvcpus, vcpus, "update", ret == 0);
return ret; return ret;
exit_monitor:
ignore_value(qemuDomainObjExitMonitor(driver, vm));
goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册