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.eb...@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 via email to