]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMonitorJSONBlockStatsUpdateCapacityData: Merge into caller
authorPeter Krempa <pkrempa@redhat.com>
Wed, 1 Oct 2025 14:16:58 +0000 (16:16 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 21 Oct 2025 13:35:45 +0000 (15:35 +0200)
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>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_monitor_json.c

index 47cf147f6374ff77fd082d079312f1a6becfaec7..7d061cbb97704a02b5c9ca0a7464c7d99730f93a 100644 (file)
@@ -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 */
 }