Allocate the hash table in the monitor wrapper function instead of the worker itself so that the text monitor impl that will be added in the next patch doesn't have to duplicate it. --- src/qemu/qemu_monitor.c | 13 ++++++++++++- src/qemu/qemu_monitor_json.c | 14 +++++--------- src/qemu/qemu_monitor_json.h | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 24e87b7..95a6989 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1864,7 +1864,18 @@ qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon, return -1; } - return qemuMonitorJSONGetAllBlockStatsInfo(mon, ret_stats, backingChain); + if (!(*ret_stats = virHashCreate(10, virHashValueFree))) + goto error; + + if (qemuMonitorJSONGetAllBlockStatsInfo(mon, *ret_stats, backingChain) < 0) + goto error; + + return 0; + + error: + virHashFree(*ret_stats); + *ret_stats = NULL; + return -1; } diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 612553b..c88c7c3 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1695,7 +1695,10 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon, if (flush_total_times) *flush_total_times = -1; - if (qemuMonitorJSONGetAllBlockStatsInfo(mon, &blockstats, false) < 0) + if (!(blockstats = virHashCreate(10, virHashValueFree))) + goto cleanup; + + if (qemuMonitorJSONGetAllBlockStatsInfo(mon, blockstats, false) < 0) goto cleanup; if (!(stats = virHashLookup(blockstats, dev_name))) { @@ -1870,7 +1873,7 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev, int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, - virHashTablePtr *ret_stats, + virHashTablePtr hash, bool backingChain) { int ret = -1; @@ -1879,14 +1882,10 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, virJSONValuePtr cmd; virJSONValuePtr reply = NULL; virJSONValuePtr devices; - virHashTablePtr hash = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("query-blockstats", NULL))) return -1; - if (!(hash = virHashCreate(10, virHashValueFree))) - goto cleanup; - if ((rc = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) goto cleanup; @@ -1924,12 +1923,9 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, } - *ret_stats = hash; - hash = NULL; ret = 0; cleanup: - virHashFree(hash); virJSONValueFree(cmd); virJSONValueFree(reply); return ret; diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 23589cf..0fcb0c0 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -82,7 +82,7 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon, long long *flush_req, long long *flush_total_times); int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, - virHashTablePtr *ret_stats, + virHashTablePtr hash, bool backingChain); int qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr mon, virHashTablePtr stats, -- 2.2.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list