[PATCH] qemuDomainBlocksStatsGather: Fix blockstats gathering after refactor

Peter Krempa via Devel posted 1 patch 1 month, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/65ac8842419eb0ee974d2c401df86171d7e4767a.1761667997.git.pkrempa@redhat.com
src/qemu/qemu_driver.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[PATCH] qemuDomainBlocksStatsGather: Fix blockstats gathering after refactor
Posted by Peter Krempa via Devel 1 month, 2 weeks ago
From: Peter Krempa <pkrempa@redhat.com>

Commit 58aa005f3e95114 which refactored how block stats are stored
intended to change the code path where stats for all devices are totaled
together by allocating new stats object and using that but the commit
forgot to actually change the pointers inside the loop.

Unfortunately this was not caught by the compiler as there were
pre-existing pointers of the same type with the same name, which
resulted into a NULL dereference.

Fixes: 58aa005f3e95114b4f2dab76ee4ade06182a3f20
Closes: https://gitlab.com/libvirt/libvirt/-/issues/827
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_driver.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b0eff443aa..5fe4568d98 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9657,6 +9657,8 @@ qemuDomainBlocksStatsGather(virDomainObj *vm,
         g_autoptr(qemuBlockStats) stats = qemuBlockStatsNew();

         for (i = 0; i < vm->def->ndisks; i++) {
+            qemuBlockStats *entry;
+
             disk = vm->def->disks[i];
             entryname = disk->info.alias;

@@ -9670,13 +9672,13 @@ qemuDomainBlocksStatsGather(virDomainObj *vm,
             if (!entryname)
                 continue;

-            if (!(stats = virHashLookup(blockstats, entryname))) {
+            if (!(entry = virHashLookup(blockstats, entryname))) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("cannot find statistics for device '%1$s'"), entryname);
                 return -1;
             }

-            qemuDomainBlockStatsGatherTotals(stats, *retstats);
+            qemuDomainBlockStatsGatherTotals(entry, stats);
         }

         *retstats = g_steal_pointer(&stats);
-- 
2.51.0
Re: [PATCH] qemuDomainBlocksStatsGather: Fix blockstats gathering after refactor
Posted by Jiri Denemark via Devel 1 month, 2 weeks ago
On Tue, Oct 28, 2025 at 17:13:17 +0100, Peter Krempa wrote:
> From: Peter Krempa <pkrempa@redhat.com>
> 
> Commit 58aa005f3e95114 which refactored how block stats are stored
> intended to change the code path where stats for all devices are totaled
> together by allocating new stats object and using that but the commit
> forgot to actually change the pointers inside the loop.
> 
> Unfortunately this was not caught by the compiler as there were
> pre-existing pointers of the same type with the same name, which
> resulted into a NULL dereference.
> 
> Fixes: 58aa005f3e95114b4f2dab76ee4ade06182a3f20
> Closes: https://gitlab.com/libvirt/libvirt/-/issues/827
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/qemu/qemu_driver.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>