Disk image size data are not contained in the reply of query-blockstats but need to be gathered from query-block. For use with -blockdev we really need to call 'query-named-block-nodes' and process it to retrieve the correct data. This patch introduces qemuMonitorBlockStatsUpdateCapacityBlockdev which updates the capacity data by nodename rather than device name. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_monitor.c | 11 +++++++++++ src/qemu/qemu_monitor.h | 4 ++++ src/qemu/qemu_monitor_json.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 2 ++ 4 files changed, 63 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index bc9c7d53b0..a69fbb0749 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2339,6 +2339,17 @@ qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr mon, } +int +qemuMonitorBlockStatsUpdateCapacityBlockdev(qemuMonitorPtr mon, + virHashTablePtr stats) +{ + VIR_DEBUG("stats=%p", stats); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONBlockStatsUpdateCapacityBlockdev(mon, stats); +} + int qemuMonitorBlockResize(qemuMonitorPtr mon, const char *device, diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 8ede11c82c..d1a8f899d7 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -603,6 +603,10 @@ int qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr mon, bool backingChain) ATTRIBUTE_NONNULL(2); +int qemuMonitorBlockStatsUpdateCapacityBlockdev(qemuMonitorPtr mon, + virHashTablePtr stats) + ATTRIBUTE_NONNULL(2); + int qemuMonitorBlockResize(qemuMonitorPtr mon, const char *dev_name, unsigned long long size); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 02a3f09a8b..820e669d16 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2639,6 +2639,52 @@ qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr mon, } +static int +qemuMonitorJSONBlockStatsUpdateCapacityBlockdevWorker(size_t pos ATTRIBUTE_UNUSED, + virJSONValuePtr val, + void *opaque) +{ + virHashTablePtr stats = opaque; + virJSONValuePtr image; + const char *nodename; + + if (!(nodename = virJSONValueObjectGetString(val, "node-name")) || + !(image = virJSONValueObjectGetObject(val, "image"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("query-named-block-nodes entry was not in expected format")); + return -1; + } + + if (qemuMonitorJSONBlockStatsUpdateCapacityData(image, nodename, stats) < 0) + return -1; + + return 1; /* we don't want to steal the value from the JSON array */ +} + + +int +qemuMonitorJSONBlockStatsUpdateCapacityBlockdev(qemuMonitorPtr mon, + virHashTablePtr stats) +{ + virJSONValuePtr nodes; + int ret = -1; + + if (!(nodes = qemuMonitorJSONQueryNamedBlockNodes(mon))) + return -1; + + if (virJSONValueArrayForeachSteal(nodes, + qemuMonitorJSONBlockStatsUpdateCapacityBlockdevWorker, + stats) < 0) + goto cleanup; + + ret = 0; + + cleanup: + virJSONValueFree(nodes); + return ret; +} + + /* Return 0 on success, -1 on failure, or -2 if not supported. Size * is in bytes. */ int qemuMonitorJSONBlockResize(qemuMonitorPtr mon, diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 6042f7161f..ebf4d4e78b 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -95,6 +95,8 @@ int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, int qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr mon, virHashTablePtr stats, bool backingChain); +int qemuMonitorJSONBlockStatsUpdateCapacityBlockdev(qemuMonitorPtr mon, + virHashTablePtr stats); int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon, virHashTablePtr hash, int *nstats); -- 2.16.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list