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:
Peter Krempa 2015-10-27 14:26:03 +01:00
parent 8cf65dabf2
commit 7912d87920
4 changed files with 17 additions and 39 deletions

View File

@ -4698,7 +4698,6 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
size_t i; size_t i;
int rc = 1;
int ret = -1; int ret = -1;
int oldvcpus = virDomainDefGetVcpus(vm->def); int oldvcpus = virDomainDefGetVcpus(vm->def);
int vcpus = oldvcpus; int vcpus = oldvcpus;
@ -4712,10 +4711,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
for (i = vcpus; i < nvcpus; i++) { for (i = vcpus; i < nvcpus; i++) {
/* Online new CPU */ /* Online new CPU */
rc = qemuMonitorSetCPU(priv->mon, i, true); if (qemuMonitorSetCPU(priv->mon, i, true) < 0)
if (rc == 0)
goto unsupported;
if (rc < 0)
goto exit_monitor; goto exit_monitor;
vcpus++; vcpus++;
@ -4794,14 +4790,11 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
if (virDomainObjIsActive(vm) && if (virDomainObjIsActive(vm) &&
virDomainDefSetVcpus(vm->def, vcpus) < 0) virDomainDefSetVcpus(vm->def, vcpus) < 0)
ret = -1; ret = -1;
virDomainAuditVcpu(vm, oldvcpus, nvcpus, "update", rc == 1); virDomainAuditVcpu(vm, oldvcpus, nvcpus, "update", ret == 0);
if (cgroup_vcpu) if (cgroup_vcpu)
virCgroupFree(&cgroup_vcpu); virCgroupFree(&cgroup_vcpu);
return ret; return ret;
unsupported:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot change vcpu count of this domain"));
exit_monitor: exit_monitor:
ignore_value(qemuDomainObjExitMonitor(driver, vm)); ignore_value(qemuDomainObjExitMonitor(driver, vm));
goto cleanup; goto cleanup;
@ -4815,7 +4808,6 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
size_t i; size_t i;
int rc = 1;
int ret = -1; int ret = -1;
int oldvcpus = virDomainDefGetVcpus(vm->def); int oldvcpus = virDomainDefGetVcpus(vm->def);
int vcpus = oldvcpus; int vcpus = oldvcpus;
@ -4826,10 +4818,7 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
for (i = vcpus - 1; i >= nvcpus; i--) { for (i = vcpus - 1; i >= nvcpus; i--) {
/* Offline old CPU */ /* Offline old CPU */
rc = qemuMonitorSetCPU(priv->mon, i, false); if (qemuMonitorSetCPU(priv->mon, i, false) < 0)
if (rc == 0)
goto unsupported;
if (rc < 0)
goto exit_monitor; goto exit_monitor;
vcpus--; vcpus--;
@ -4888,12 +4877,9 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
if (virDomainObjIsActive(vm) && if (virDomainObjIsActive(vm) &&
virDomainDefSetVcpus(vm->def, vcpus) < 0) virDomainDefSetVcpus(vm->def, vcpus) < 0)
ret = -1; ret = -1;
virDomainAuditVcpu(vm, oldvcpus, nvcpus, "update", rc == 1); virDomainAuditVcpu(vm, oldvcpus, nvcpus, "update", ret == 0);
return ret; return ret;
unsupported:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot change vcpu count of this domain"));
exit_monitor: exit_monitor:
ignore_value(qemuDomainObjExitMonitor(driver, vm)); ignore_value(qemuDomainObjExitMonitor(driver, vm));
goto cleanup; goto cleanup;

View File

@ -1955,6 +1955,9 @@ qemuMonitorSetBalloon(qemuMonitorPtr mon,
} }
/*
* Returns: 0 if CPU modification was successful or -1 on failure
*/
int int
qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, bool online) qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, bool online)
{ {

View File

@ -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 qemuMonitorJSONSetCPU(qemuMonitorPtr mon,
int cpu, bool online) int cpu, bool online)
{ {
@ -2188,10 +2184,6 @@ int qemuMonitorJSONSetCPU(qemuMonitorPtr mon,
else else
ret = qemuMonitorJSONCheckError(cmd, reply); ret = qemuMonitorJSONCheckError(cmd, reply);
/* this function has non-standard return values, so adapt it */
if (ret == 0)
ret = 1;
cleanup: cleanup:
virJSONValueFree(cmd); virJSONValueFree(cmd);
virJSONValueFree(reply); virJSONValueFree(reply);

View File

@ -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) int qemuMonitorTextSetCPU(qemuMonitorPtr mon, int cpu, bool online)
{ {
char *cmd; 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) if (virAsprintf(&cmd, "cpu_set %d %s", cpu, online ? "online" : "offline") < 0)
return -1; return -1;
if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) { if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0)
VIR_FREE(cmd); goto cleanup;
return -1;
}
VIR_FREE(cmd);
/* If the command failed qemu prints: 'unknown command' /* If the command failed qemu prints: 'unknown command'
* No message is printed on success it seems */ * No message is printed on success it seems */
if (strstr(reply, "unknown command:")) { if (strstr(reply, "unknown command:")) {
/* Don't set error - it is expected CPU onlining fails on many qemu - caller will handle */ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
ret = 0; _("cannot change vcpu count of this domain"));
} else { goto cleanup;
ret = 1;
} }
ret = 0;
cleanup:
VIR_FREE(reply); VIR_FREE(reply);
VIR_FREE(cmd);
return ret; return ret;
} }