]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: monitor: Remove weird return values from qemuMonitorSetCPU
authorPeter Krempa <pkrempa@redhat.com>
Tue, 27 Oct 2015 13:26:03 +0000 (14:26 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 9 Dec 2015 13:57:12 +0000 (14:57 +0100)
Let the function report errors internally and change it to return
standard return codes.

src/qemu/qemu_driver.c
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_text.c

index bbd43f494fa28820d07b376d66c0e140934d672e..0ffe079829d4cb6991b227b0c33df817086a5d80 100644 (file)
@@ -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;
index bc5ed3363e75d5ed169c10f626bb56853e74af26..4906faa93edb2a6717e3aad7c16346901fad07f0 100644 (file)
@@ -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)
 {
index 86b8c7ba813378d91a9c96329c5a4bd3d6f8f039..84c0be20ffa66782d55bb11d84dea5b4baf472bc 100644 (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 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);
index f44da20fc97b0975ba7ee6f39320e3840ecdf0b3..665723d54311afc1c2af2b265533cefdb496de59 100644 (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)
 {
     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;
 }