Calls to query block organize the data by using the 'device' field in the returned JSON. When -blockdev is used instead of -drive the 'device' field is empty and thus can't be used. This patch allows callers to specify that the 'qdev' field shoudl be usedinstead to refer to the devices by the QOM handle. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_monitor.c | 5 +++-- src/qemu/qemu_monitor.h | 3 ++- src/qemu/qemu_monitor_json.c | 33 +++++++++++++++++++++++++++------ src/qemu/qemu_monitor_json.h | 3 ++- src/qemu/qemu_process.c | 2 +- tests/qemumonitorjsontest.c | 2 +- 7 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8fe51a0067..9114800821 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18749,7 +18749,7 @@ qemuDomainGetDiskErrors(virDomainPtr dom, } qemuDomainObjEnterMonitor(driver, vm); - table = qemuMonitorGetBlockInfo(priv->mon); + table = qemuMonitorGetBlockInfo(priv->mon, false); if (qemuDomainObjExitMonitor(driver, vm) < 0) goto endjob; if (!table) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 3b88354f4f..9d58217376 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2219,7 +2219,8 @@ qemuDomainDiskInfoFree(void *value, const void *name ATTRIBUTE_UNUSED) virHashTablePtr -qemuMonitorGetBlockInfo(qemuMonitorPtr mon) +qemuMonitorGetBlockInfo(qemuMonitorPtr mon, + bool blockdev) { int ret; virHashTablePtr table; @@ -2229,7 +2230,7 @@ qemuMonitorGetBlockInfo(qemuMonitorPtr mon) if (!(table = virHashCreate(32, qemuDomainDiskInfoFree))) return NULL; - ret = qemuMonitorJSONGetBlockInfo(mon, table); + ret = qemuMonitorJSONGetBlockInfo(mon, table, blockdev); if (ret < 0) { virHashFree(table); diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 26405ddd26..3e902e1e8b 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -561,7 +561,8 @@ int qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon, int period); int qemuMonitorBlockIOStatusToError(const char *status); -virHashTablePtr qemuMonitorGetBlockInfo(qemuMonitorPtr mon); +virHashTablePtr qemuMonitorGetBlockInfo(qemuMonitorPtr mon, + bool blockdev); virJSONValuePtr qemuMonitorQueryBlockstats(qemuMonitorPtr mon, bool nodenames); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 8c1db3149e..6d76f4a2d5 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2187,11 +2187,12 @@ qemuMonitorJSONGetBlockDev(virJSONValuePtr devices, static const char * -qemuMonitorJSONGetBlockDevDevice(virJSONValuePtr dev) +qemuMonitorJSONGetBlockDevName(virJSONValuePtr dev, + const char *key) { const char *thisdev; - if (!(thisdev = virJSONValueObjectGetString(dev, "device"))) { + if (!(thisdev = virJSONValueObjectGetString(dev, key))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-block device entry was not in expected format")); return NULL; @@ -2201,8 +2202,23 @@ qemuMonitorJSONGetBlockDevDevice(virJSONValuePtr dev) } +static const char * +qemuMonitorJSONGetBlockDevDevice(virJSONValuePtr dev) +{ + return qemuMonitorJSONGetBlockDevName(dev, "device"); +} + + +static const char * +qemuMonitorJSONGetBlockDevQdev(virJSONValuePtr dev) +{ + return qemuMonitorJSONGetBlockDevName(dev, "qdev"); +} + + int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon, - virHashTablePtr table) + virHashTablePtr table, + bool blockdev) { int ret = -1; size_t i; @@ -2223,10 +2239,15 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon, if (!(dev = qemuMonitorJSONGetBlockDev(devices, i))) goto cleanup; - if (!(thisdev = qemuMonitorJSONGetBlockDevDevice(dev))) - goto cleanup; + if (blockdev) { + if (!(thisdev = qemuMonitorJSONGetBlockDevQdev(dev))) + goto cleanup; + } else { + if (!(thisdev = qemuMonitorJSONGetBlockDevDevice(dev))) + goto cleanup; - thisdev = qemuAliasDiskDriveSkipPrefix(thisdev); + thisdev = qemuAliasDiskDriveSkipPrefix(thisdev); + } if (VIR_ALLOC(info) < 0) goto cleanup; diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 3d1e40b53f..7cdec6e231 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -84,7 +84,8 @@ int qemuMonitorJSONSetMemoryStatsPeriod(qemuMonitorPtr mon, char *balloonpath, int period); int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon, - virHashTablePtr table); + virHashTablePtr table, + bool blockdev); virJSONValuePtr qemuMonitorJSONQueryBlockstats(qemuMonitorPtr mon, bool nodenames); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 928036172d..2c3133d678 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7564,7 +7564,7 @@ qemuProcessRefreshDisks(virQEMUDriverPtr driver, size_t i; if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) == 0) { - table = qemuMonitorGetBlockInfo(priv->mon); + table = qemuMonitorGetBlockInfo(priv->mon, false); if (qemuDomainObjExitMonitor(driver, vm) < 0) goto cleanup; } diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 5a0b64dace..526b1f87f2 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1660,7 +1660,7 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *data) if (qemuMonitorTestAddItem(test, "query-block", queryBlockReply) < 0) goto cleanup; - if (qemuMonitorJSONGetBlockInfo(qemuMonitorTestGetMonitor(test), blockDevices) < 0) + if (qemuMonitorJSONGetBlockInfo(qemuMonitorTestGetMonitor(test), blockDevices, false) < 0) goto cleanup; if (!virHashEqual(blockDevices, expectedBlockDevices, testHashEqualQemuDomainDiskInfo)) { -- 2.16.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list