]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Implement new QMP command for cpu hotplug
authorPeter Krempa <pkrempa@redhat.com>
Mon, 27 May 2013 14:08:30 +0000 (16:08 +0200)
committerCole Robinson <crobinso@redhat.com>
Thu, 11 Jul 2013 21:29:48 +0000 (17:29 -0400)
This patch implements support for the "cpu-add" QMP command that plugs
CPUs into a live guest. The "cpu-add" command was introduced in QEMU
1.5. For the hotplug to work machine type "pc-i440fx-1.5" is required.

(cherry picked from commit c12b2be5169298708cf727ed9ccd42e9d89a9737)

src/qemu/qemu_monitor_json.c

index 6fdd650d8887c56e5763ac1e9d0ab2b1e6c73ade..7f3e0a60121c645af5685bfbb7d2acdf758713de 100644 (file)
@@ -2086,9 +2086,42 @@ cleanup:
 int qemuMonitorJSONSetCPU(qemuMonitorPtr mon,
                           int cpu, int online)
 {
-    /* XXX Update to use QMP, if QMP ever adds support for cpu hotplug */
+    int ret = -1;
+    virJSONValuePtr cmd = NULL;
+    virJSONValuePtr reply = NULL;
+
+    if (online) {
+        cmd = qemuMonitorJSONMakeCommand("cpu-add",
+                                         "i:id", cpu,
+                                         NULL);
+    } else {
+        /* offlining is not yet implemented in qmp */
+        goto fallback;
+    }
+    if (!cmd)
+        goto cleanup;
+
+    if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
+        goto cleanup;
+
+    if (qemuMonitorJSONHasError(reply, "CommandNotFound"))
+        goto fallback;
+    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);
+    return ret;
+
+fallback:
     VIR_DEBUG("no QMP support for cpu_set, trying HMP");
-    return qemuMonitorTextSetCPU(mon, cpu, online);
+    ret = qemuMonitorTextSetCPU(mon, cpu, online);
+    goto cleanup;
 }