public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server 2/2] fix #6556: vm status: fix querying block stats
Date: Wed, 23 Jul 2025 13:10:47 +0200	[thread overview]
Message-ID: <20250723111105.72422-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250723111105.72422-1-f.ebner@proxmox.com>

With the switch to '-blockdev', the 'device' property in the return
value of the 'query-blockstats' QMP command is not initialized. This
can be seen in the QEMU source code (the device property is the name
of the block backend and blk->name is assigned a value only in a code
path reached via drive_new()). This was done to avoid confusion/clashes
with node names, because they live in the same namespace as block
backend names.

The node names cannot be relied on either, because an empty CD-ROM
drive does not have an associated block node. So use the qdev ID as a
fallback.

The stats are reported for the block backend, so it does not matter
that the block node structure changed with the switch to '-blockdev'.

Fixes: aaf48d8e ("command line: switch to blockdev starting with machine version 10.0")
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/QemuServer.pm | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index d0c537e0..7f42256c 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -2705,8 +2705,20 @@ sub vmstatus {
             $totalrdbytes = $totalrdbytes + $blockstat->{stats}->{rd_bytes};
             $totalwrbytes = $totalwrbytes + $blockstat->{stats}->{wr_bytes};
 
-            $blockstat->{device} =~ s/drive-//;
-            $res->{$vmid}->{blockstat}->{ $blockstat->{device} } = $blockstat->{stats};
+            # With the switch to -blockdev, the block backend in QEMU has no name, so need to also
+            # consider the qdev ID. Note that empty CD-ROM drives do not have a node name, so that
+            # cannot be used as a fallback instead of the qdev ID.
+            my $drive_id;
+            if ($blockstat->{device}) {
+                $drive_id = $blockstat->{device} =~ s/drive-//r;
+            } elsif ($blockstat->{qdev}) {
+                $drive_id = PVE::QemuServer::Blockdev::qdev_id_to_drive_id($blockstat->{qdev});
+            } else {
+                print "blockstats callback: unexpected missing drive ID\n";
+                next;
+            }
+
+            $res->{$vmid}->{blockstat}->{$drive_id} = $blockstat->{stats};
         }
         $res->{$vmid}->{diskread} = $totalrdbytes;
         $res->{$vmid}->{diskwrite} = $totalwrbytes;
-- 
2.47.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  reply	other threads:[~2025-07-23 11:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-23 11:10 [pve-devel] [PATCH qemu-server 1/2] drive device: fix regression with missing '/dev/disk/by-id' paths Fiona Ebner
2025-07-23 11:10 ` Fiona Ebner [this message]
2025-07-23 12:51 ` Hannes Duerr
2025-07-23 12:55 ` Hannes Duerr
2025-07-23 13:12   ` Thomas Lamprecht
2025-07-23 13:19     ` Fiona Ebner
2025-07-23 13:35 ` [pve-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250723111105.72422-2-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal