Allow getting the raw data from query-blockstats, so that we can use it to detect the backing chain later on. --- src/qemu/qemu_monitor.c | 15 +++++++++++++++ src/qemu/qemu_monitor.h | 2 ++ src/qemu/qemu_monitor_json.c | 44 +++++++++++++++++++++++++++++--------------- src/qemu/qemu_monitor_json.h | 2 ++ 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 2b0afcc21..19082d8bf 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2242,6 +2242,21 @@ qemuMonitorGetBlockInfo(qemuMonitorPtr mon) /** + * qemuMonitorQueryBlockstats: + * @mon: monitor object + * + * Returns data from a call to 'query-blockstats'. + */ +virJSONValuePtr +qemuMonitorQueryBlockstats(qemuMonitorPtr mon) +{ + QEMU_CHECK_MONITOR_JSON_NULL(mon); + + return qemuMonitorJSONQueryBlockstats(mon); +} + + +/** * qemuMonitorGetAllBlockStatsInfo: * @mon: monitor object * @ret_stats: pointer that is filled with a hash table containing the stats diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 1697db55c..31f7e97ba 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -523,6 +523,8 @@ int qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon, int qemuMonitorBlockIOStatusToError(const char *status); virHashTablePtr qemuMonitorGetBlockInfo(qemuMonitorPtr mon); +virJSONValuePtr qemuMonitorQueryBlockstats(qemuMonitorPtr mon); + typedef struct _qemuBlockStats qemuBlockStats; typedef qemuBlockStats *qemuBlockStatsPtr; struct _qemuBlockStats { diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 65b1fbb8e..b8a68154a 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2061,34 +2061,49 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev, } -int -qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, - virHashTablePtr hash, - bool backingChain) +virJSONValuePtr +qemuMonitorJSONQueryBlockstats(qemuMonitorPtr mon) { - int ret = -1; - int nstats = 0; - int rc; - size_t i; virJSONValuePtr cmd; virJSONValuePtr reply = NULL; - virJSONValuePtr devices; + virJSONValuePtr ret = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("query-blockstats", NULL))) - return -1; + return NULL; - if ((rc = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; if (qemuMonitorJSONCheckError(cmd, reply) < 0) goto cleanup; - if (!(devices = virJSONValueObjectGetArray(reply, "return"))) { + if (!(ret = virJSONValueObjectStealArray(reply, "return"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("blockstats reply was missing device list")); + _("query-blockstats reply was missing device list")); goto cleanup; } + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} + + +int +qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, + virHashTablePtr hash, + bool backingChain) +{ + int ret = -1; + int nstats = 0; + int rc; + size_t i; + virJSONValuePtr devices; + + if (!(devices = qemuMonitorJSONQueryBlockstats(mon))) + return -1; + for (i = 0; i < virJSONValueArraySize(devices); i++) { virJSONValuePtr dev = virJSONValueArrayGet(devices, i); const char *dev_name; @@ -2120,8 +2135,7 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, ret = nstats; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); + virJSONValueFree(devices); return ret; } diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index d090d5709..7462967b5 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -81,6 +81,8 @@ int qemuMonitorJSONSetMemoryStatsPeriod(qemuMonitorPtr mon, int period); int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon, virHashTablePtr table); + +virJSONValuePtr qemuMonitorJSONQueryBlockstats(qemuMonitorPtr mon); int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, virHashTablePtr hash, bool backingChain); -- 2.13.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list