Extract the code for future reuse.
Signed-off-by: Peter Krempa
---
src/qemu/qemu_monitor_json.c | 43 +++
1 file changed, 27 insertions(+), 16 deletions(-)
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 37a4e59189..81043e2af5 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2423,39 +2423,50 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
static int
-qemuMonitorJSONBlockStatsUpdateCapacityOne(virJSONValuePtr image,
- const char *dev_name,
- int depth,
- virHashTablePtr stats,
- bool backingChain)
+qemuMonitorJSONBlockStatsUpdateCapacityData(virJSONValuePtr image,
+const char *name,
+virHashTablePtr stats)
{
qemuBlockStatsPtr bstats;
-int ret = -1;
-char *entry_name = qemuDomainStorageAlias(dev_name, depth);
-virJSONValuePtr backing;
-if (!(bstats = virHashLookup(stats, entry_name))) {
+if (!(bstats = virHashLookup(stats, name))) {
if (VIR_ALLOC(bstats) < 0)
-goto cleanup;
+return -1;
-if (virHashAddEntry(stats, entry_name, bstats) < 0) {
+if (virHashAddEntry(stats, name, bstats) < 0) {
VIR_FREE(bstats);
-goto cleanup;
+return -1;
}
}
-/* After this point, we ignore failures; the stats were
- * zero-initialized when created which is a sane fallback. */
-ret = 0;
+/* failures can be ignored after this point */
if (virJSONValueObjectGetNumberUlong(image, "virtual-size",
&bstats->capacity) < 0)
-goto cleanup;
+return 0;
/* if actual-size is missing, image is not thin provisioned */
if (virJSONValueObjectGetNumberUlong(image, "actual-size",
&bstats->physical) < 0)
bstats->physical = bstats->capacity;
+return 0;
+}
+
+
+static int
+qemuMonitorJSONBlockStatsUpdateCapacityOne(virJSONValuePtr image,
+ const char *dev_name,
+ int depth,
+ virHashTablePtr stats,
+ bool backingChain)
+{
+int ret = -1;
+char *entry_name = qemuDomainStorageAlias(dev_name, depth);
+virJSONValuePtr backing;
+
+if (qemuMonitorJSONBlockStatsUpdateCapacityData(image, entry_name, stats)
< 0)
+goto cleanup;
+
if (backingChain &&
(backing = virJSONValueObjectGetObject(image, "backing-image"))) {
ret = qemuMonitorJSONBlockStatsUpdateCapacityOne(backing,
--
2.16.2
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list