The code is useful also when gathering statistics per node name, so extract it to a separate functions. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_monitor_json.c | 51 ++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index e41c1d47aa..37a4e59189 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2253,26 +2253,15 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon, } -static int -qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev, - const char *dev_name, - int depth, - virHashTablePtr hash, - bool backingChain) +static qemuBlockStatsPtr +qemuMonitorJSONBlockStatsCollectData(virJSONValuePtr dev, + int *nstats) { qemuBlockStatsPtr bstats = NULL; - virJSONValuePtr stats; + qemuBlockStatsPtr ret = NULL; virJSONValuePtr parent; virJSONValuePtr parentstats; - int ret = -1; - int nstats = 0; - char *entry_name = qemuDomainStorageAlias(dev_name, depth); - virJSONValuePtr backing; - - if (!entry_name) - goto cleanup; - if (VIR_ALLOC(bstats) < 0) - goto cleanup; + virJSONValuePtr stats; if ((stats = virJSONValueObjectGetObject(dev, "stats")) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -2281,6 +2270,9 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev, goto cleanup; } + if (VIR_ALLOC(bstats) < 0) + goto cleanup; + #define QEMU_MONITOR_BLOCK_STAT_GET(NAME, VAR, MANDATORY) \ if (MANDATORY || virJSONValueObjectHasKey(stats, NAME)) { \ nstats++; \ @@ -2307,6 +2299,33 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev, bstats->wr_highest_offset_valid = true; } + VIR_STEAL_PTR(ret, bstats); + + cleanup: + VIR_FREE(bstats); + return ret; +} + + +static int +qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev, + const char *dev_name, + int depth, + virHashTablePtr hash, + bool backingChain) +{ + qemuBlockStatsPtr bstats = NULL; + int ret = -1; + int nstats = 0; + char *entry_name = qemuDomainStorageAlias(dev_name, depth); + virJSONValuePtr backing; + + if (!entry_name) + goto cleanup; + + if (!(bstats = qemuMonitorJSONBlockStatsCollectData(dev, &nstats))) + goto cleanup; + if (virHashAddEntry(hash, entry_name, bstats) < 0) goto cleanup; bstats = NULL; -- 2.16.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list