]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: monitor: More strict checking of 'query-cpus' if hotplug is supported
authorPeter Krempa <pkrempa@redhat.com>
Sun, 4 Dec 2016 17:53:03 +0000 (18:53 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 18 Jan 2017 08:57:06 +0000 (09:57 +0100)
In cases where CPU hotplug is supported by qemu force the monitor to
reject invalid or broken responses to 'query-cpus'. It's expected that
the command returns usable data in such case.

src/qemu/qemu_monitor.c
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
tests/qemumonitorjsontest.c

index 1610ae3f4ea001f8cb6a972d507eaa63ef333f0c..b7be5e7f47ffe674488aaa7a8a68deb099e0e7d4 100644 (file)
@@ -1921,12 +1921,12 @@ qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
         goto cleanup;
 
     if (mon->json)
-        rc = qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries);
+        rc = qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, hotplug);
     else
         rc = qemuMonitorTextQueryCPUs(mon, &cpuentries, &ncpuentries);
 
     if (rc < 0) {
-        if (rc == -2) {
+        if (!hotplug && rc == -2) {
             VIR_STEAL_PTR(*vcpus, info);
             ret = 0;
         }
@@ -1974,7 +1974,7 @@ qemuMonitorGetCpuHalted(qemuMonitorPtr mon,
     QEMU_CHECK_MONITOR_NULL(mon);
 
     if (mon->json)
-        rc = qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries);
+        rc = qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, false);
     else
         rc = qemuMonitorTextQueryCPUs(mon, &cpuentries, &ncpuentries);
 
index 5e057997c370adae0f54676573c71bc01d80f0c8..6c38ad7e38ce1b4adae524113bca885b6f737d47 100644 (file)
@@ -1394,7 +1394,8 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data,
 int
 qemuMonitorJSONQueryCPUs(qemuMonitorPtr mon,
                          struct qemuMonitorQueryCpusEntry **entries,
-                         size_t *nentries)
+                         size_t *nentries,
+                         bool force)
 {
     int ret = -1;
     virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-cpus", NULL);
@@ -1407,6 +1408,9 @@ qemuMonitorJSONQueryCPUs(qemuMonitorPtr mon,
     if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
         goto cleanup;
 
+    if (force && qemuMonitorJSONCheckError(cmd, reply) < 0)
+        goto cleanup;
+
     if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
         ret = -2;
         goto cleanup;
index 18b508d9cacc92908497229a181fa9a8b170dc50..79688c82f7c32dbede67de88e4ab1ee9eba85cf1 100644 (file)
@@ -60,7 +60,8 @@ int qemuMonitorJSONSystemReset(qemuMonitorPtr mon);
 
 int qemuMonitorJSONQueryCPUs(qemuMonitorPtr mon,
                              struct qemuMonitorQueryCpusEntry **entries,
-                             size_t *nentries);
+                             size_t *nentries,
+                             bool force);
 int qemuMonitorJSONGetVirtType(qemuMonitorPtr mon,
                                virDomainVirtType *virtType);
 int qemuMonitorJSONUpdateVideoMemorySize(qemuMonitorPtr mon,
index 535fb63de32943064b8676af18a090a39c6c8c65..5b2d6bb343efcd3b7745319e2ca5957350ba6c19 100644 (file)
@@ -1407,7 +1407,7 @@ testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const void *data)
         goto cleanup;
 
     if (qemuMonitorJSONQueryCPUs(qemuMonitorTestGetMonitor(test),
-                                 &cpudata, &ncpudata) < 0)
+                                 &cpudata, &ncpudata, true) < 0)
         goto cleanup;
 
     if (ncpudata != 4) {