[RFC PATCH 06/16] qemuMonitorJSONBlockStatsUpdateCapacityData: Merge into caller

Peter Krempa via Devel posted 16 patches 2 weeks, 4 days ago
[RFC PATCH 06/16] qemuMonitorJSONBlockStatsUpdateCapacityData: Merge into caller
Posted by Peter Krempa via Devel 2 weeks, 4 days ago
From: Peter Krempa <pkrempa@redhat.com>

It's called just from
qemuMonitorJSONBlockStatsUpdateCapacityBlockdevWorker. Merging it in
makes the code much simpler especially when combined with a change to
APIs that can't fail.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_monitor_json.c | 48 ++++++++++--------------------------
 1 file changed, 13 insertions(+), 35 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 7b7d446b3a..44d7a35874 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2584,36 +2584,6 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitor *mon,
 }


-static int
-qemuMonitorJSONBlockStatsUpdateCapacityData(virJSONValue *image,
-                                            const char *name,
-                                            GHashTable *stats,
-                                            qemuBlockStats **entry)
-{
-    qemuBlockStats *bstats;
-
-    if (!(bstats = virHashLookup(stats, name))) {
-        bstats = qemuBlockStatsNew();
-        g_hash_table_insert(stats, g_strdup(name), bstats);
-    }
-
-    if (entry)
-        *entry = bstats;
-
-    /* failures can be ignored after this point */
-    if (virJSONValueObjectGetNumberUlong(image, "virtual-size",
-                                         &bstats->capacity) < 0)
-        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
 qemuMonitorJSONBlockStatsUpdateCapacityBlockdevWorker(size_t pos G_GNUC_UNUSED,
                                                       virJSONValue *val,
@@ -2631,12 +2601,20 @@ qemuMonitorJSONBlockStatsUpdateCapacityBlockdevWorker(size_t pos G_GNUC_UNUSED,
         return -1;
     }

-    if (qemuMonitorJSONBlockStatsUpdateCapacityData(image, nodename, stats, &entry) < 0)
-        return -1;
+    if (!(entry = virHashLookup(stats, nodename))) {
+        entry = qemuBlockStatsNew();
+        g_hash_table_insert(stats, g_strdup(nodename), entry);
+    }
+
+    /* updating actual size makes sense only when virtual size is present */
+    if (virJSONValueObjectGetNumberUlong(image, "virtual-size", &entry->capacity) == 0) {
+        /* if actual-size is missing, image is not thin provisioned */
+        if (virJSONValueObjectGetNumberUlong(image, "actual-size", &entry->physical) < 0)
+            entry->physical = entry->capacity;
+    }

-    if (entry)
-        ignore_value(virJSONValueObjectGetNumberUlong(val, "write_threshold",
-                                                      &entry->write_threshold));
+    ignore_value(virJSONValueObjectGetNumberUlong(val, "write_threshold",
+                                                  &entry->write_threshold));

     return 1; /* we don't want to steal the value from the JSON array */
 }
-- 
2.51.0