mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
qemu: monitor: Remove weird return values from qemuMonitorSetCPU
Let the function report errors internally and change it to return standard return codes.
This commit is contained in:
parent
8cf65dabf2
commit
7912d87920
@ -4698,7 +4698,6 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
|
||||
{
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
size_t i;
|
||||
int rc = 1;
|
||||
int ret = -1;
|
||||
int oldvcpus = virDomainDefGetVcpus(vm->def);
|
||||
int vcpus = oldvcpus;
|
||||
@ -4712,10 +4711,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
|
||||
|
||||
for (i = vcpus; i < nvcpus; i++) {
|
||||
/* Online new CPU */
|
||||
rc = qemuMonitorSetCPU(priv->mon, i, true);
|
||||
if (rc == 0)
|
||||
goto unsupported;
|
||||
if (rc < 0)
|
||||
if (qemuMonitorSetCPU(priv->mon, i, true) < 0)
|
||||
goto exit_monitor;
|
||||
|
||||
vcpus++;
|
||||
@ -4794,14 +4790,11 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
|
||||
if (virDomainObjIsActive(vm) &&
|
||||
virDomainDefSetVcpus(vm->def, vcpus) < 0)
|
||||
ret = -1;
|
||||
virDomainAuditVcpu(vm, oldvcpus, nvcpus, "update", rc == 1);
|
||||
virDomainAuditVcpu(vm, oldvcpus, nvcpus, "update", ret == 0);
|
||||
if (cgroup_vcpu)
|
||||
virCgroupFree(&cgroup_vcpu);
|
||||
return ret;
|
||||
|
||||
unsupported:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("cannot change vcpu count of this domain"));
|
||||
exit_monitor:
|
||||
ignore_value(qemuDomainObjExitMonitor(driver, vm));
|
||||
goto cleanup;
|
||||
@ -4815,7 +4808,6 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
|
||||
{
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
size_t i;
|
||||
int rc = 1;
|
||||
int ret = -1;
|
||||
int oldvcpus = virDomainDefGetVcpus(vm->def);
|
||||
int vcpus = oldvcpus;
|
||||
@ -4826,10 +4818,7 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
|
||||
|
||||
for (i = vcpus - 1; i >= nvcpus; i--) {
|
||||
/* Offline old CPU */
|
||||
rc = qemuMonitorSetCPU(priv->mon, i, false);
|
||||
if (rc == 0)
|
||||
goto unsupported;
|
||||
if (rc < 0)
|
||||
if (qemuMonitorSetCPU(priv->mon, i, false) < 0)
|
||||
goto exit_monitor;
|
||||
|
||||
vcpus--;
|
||||
@ -4888,12 +4877,9 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
|
||||
if (virDomainObjIsActive(vm) &&
|
||||
virDomainDefSetVcpus(vm->def, vcpus) < 0)
|
||||
ret = -1;
|
||||
virDomainAuditVcpu(vm, oldvcpus, nvcpus, "update", rc == 1);
|
||||
virDomainAuditVcpu(vm, oldvcpus, nvcpus, "update", ret == 0);
|
||||
return ret;
|
||||
|
||||
unsupported:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("cannot change vcpu count of this domain"));
|
||||
exit_monitor:
|
||||
ignore_value(qemuDomainObjExitMonitor(driver, vm));
|
||||
goto cleanup;
|
||||
|
@ -1955,6 +1955,9 @@ qemuMonitorSetBalloon(qemuMonitorPtr mon,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns: 0 if CPU modification was successful or -1 on failure
|
||||
*/
|
||||
int
|
||||
qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, bool online)
|
||||
{
|
||||
|
@ -2158,10 +2158,6 @@ qemuMonitorJSONSetBalloon(qemuMonitorPtr mon,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns: 0 if CPU hotplug not supported, +1 if CPU hotplug worked
|
||||
* or -1 on failure
|
||||
*/
|
||||
int qemuMonitorJSONSetCPU(qemuMonitorPtr mon,
|
||||
int cpu, bool online)
|
||||
{
|
||||
@ -2188,10 +2184,6 @@ int qemuMonitorJSONSetCPU(qemuMonitorPtr mon,
|
||||
else
|
||||
ret = qemuMonitorJSONCheckError(cmd, reply);
|
||||
|
||||
/* this function has non-standard return values, so adapt it */
|
||||
if (ret == 0)
|
||||
ret = 1;
|
||||
|
||||
cleanup:
|
||||
virJSONValueFree(cmd);
|
||||
virJSONValueFree(reply);
|
||||
|
@ -1136,10 +1136,6 @@ qemuMonitorTextSetBalloon(qemuMonitorPtr mon,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns: 0 if CPU hotplug not supported, +1 if CPU hotplug worked
|
||||
* or -1 on failure
|
||||
*/
|
||||
int qemuMonitorTextSetCPU(qemuMonitorPtr mon, int cpu, bool online)
|
||||
{
|
||||
char *cmd;
|
||||
@ -1149,22 +1145,23 @@ int qemuMonitorTextSetCPU(qemuMonitorPtr mon, int cpu, bool online)
|
||||
if (virAsprintf(&cmd, "cpu_set %d %s", cpu, online ? "online" : "offline") < 0)
|
||||
return -1;
|
||||
|
||||
if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) {
|
||||
VIR_FREE(cmd);
|
||||
return -1;
|
||||
}
|
||||
VIR_FREE(cmd);
|
||||
if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* If the command failed qemu prints: 'unknown command'
|
||||
* No message is printed on success it seems */
|
||||
if (strstr(reply, "unknown command:")) {
|
||||
/* Don't set error - it is expected CPU onlining fails on many qemu - caller will handle */
|
||||
ret = 0;
|
||||
} else {
|
||||
ret = 1;
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("cannot change vcpu count of this domain"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(reply);
|
||||
VIR_FREE(cmd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user