qemu: monitor: More strict checking of 'query-cpus' if hotplug is supported

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.
This commit is contained in:
Peter Krempa 2016-12-04 18:53:03 +01:00
parent 35296ad4a7
commit 5cd670fea8
4 changed files with 11 additions and 6 deletions

View 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);

View 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;

View 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,

View 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) {