Use the 'query-nodes' flag to return all stats. The flag was introduced
prior to qemu-2.11 so we can always use it, but we invoke it only when
querying stats. The other invocation is used for detecting the nodenames
which is fragile code.

The images without a frontend don't have the device field so the
extraction code checks need to be relaxed.

Signed-off-by: Peter Krempa <pkre...@redhat.com>
---
 src/qemu/qemu_monitor.c      |  4 ++--
 src/qemu/qemu_monitor_json.c | 20 +++++++++-----------
 src/qemu/qemu_monitor_json.h |  3 ++-
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 908ee0d302..1fbf1eb5c7 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2038,14 +2038,14 @@ qemuMonitorGetBlockInfo(qemuMonitor *mon)
  * qemuMonitorQueryBlockstats:
  * @mon: monitor object
  *
- * Returns data from a call to 'query-blockstats'.
+ * Returns data from a call to 'query-blockstats' without using 'query-nodes'
  */
 virJSONValue *
 qemuMonitorQueryBlockstats(qemuMonitor *mon)
 {
     QEMU_CHECK_MONITOR_NULL(mon);

-    return qemuMonitorJSONQueryBlockstats(mon);
+    return qemuMonitorJSONQueryBlockstats(mon, false);
 }


diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index e9be9bdabd..7f5d9f7cad 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2435,12 +2435,15 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValue *dev,


 virJSONValue *
-qemuMonitorJSONQueryBlockstats(qemuMonitor *mon)
+qemuMonitorJSONQueryBlockstats(qemuMonitor *mon,
+                               bool queryNodes)
 {
     g_autoptr(virJSONValue) cmd = NULL;
     g_autoptr(virJSONValue) reply = NULL;

-    if (!(cmd = qemuMonitorJSONMakeCommand("query-blockstats", NULL)))
+    if (!(cmd = qemuMonitorJSONMakeCommand("query-blockstats",
+                                           "B:query-nodes", queryNodes,
+                                           NULL)))
         return NULL;

     if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
@@ -2462,7 +2465,7 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitor *mon,
     size_t i;
     g_autoptr(virJSONValue) devices = NULL;

-    if (!(devices = qemuMonitorJSONQueryBlockstats(mon)))
+    if (!(devices = qemuMonitorJSONQueryBlockstats(mon, true)))
         return -1;

     for (i = 0; i < virJSONValueArraySize(devices); i++) {
@@ -2476,16 +2479,11 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitor *mon,
             return -1;
         }

-        if (!(dev_name = virJSONValueObjectGetString(dev, "device"))) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("blockstats device entry was not "
-                             "in expected format"));
-            return -1;
+        if ((dev_name = virJSONValueObjectGetString(dev, "device"))) {
+            if (*dev_name == '\0')
+                dev_name = NULL;
         }

-        if (*dev_name == '\0')
-            dev_name = NULL;
-
         rc = qemuMonitorJSONGetOneBlockStatsInfo(dev, dev_name, 0, hash);

         if (rc < 0)
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index f9e01e5bf5..aa70d35bfb 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -75,7 +75,8 @@ int qemuMonitorJSONSetMemoryStatsPeriod(qemuMonitor *mon,
 int qemuMonitorJSONGetBlockInfo(qemuMonitor *mon,
                                 GHashTable *table);

-virJSONValue *qemuMonitorJSONQueryBlockstats(qemuMonitor *mon);
+virJSONValue *qemuMonitorJSONQueryBlockstats(qemuMonitor *mon,
+                                             bool queryNodes);
 int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitor *mon,
                                         GHashTable *hash);
 int qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitor *mon,
-- 
2.31.1

Reply via email to