Let the function report errors internally and change it to return
standard return codes.
---
src/qemu/qemu_driver.c | 22 ++++------------------
src/qemu/qemu_monitor.c | 3 +++
src/qemu/qemu_monitor_json.c | 8 --------
src/qemu/qemu_monitor_text.c | 23 ++++++++++-------------
4 files changed, 17 insertions(+), 39 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index bbd43f4..0ffe079 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -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;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index bc5ed33..4906faa 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -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)
{
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 86b8c7b..84c0be2 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -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);
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index f44da20..665723d 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -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;
}
--
2.6.2