[PATCH qemu-server v3 07/18] blockdev: switch get_node_name_below_throttle() to use QMP peer

Fiona Ebner
2026-04-23T09:39:52Z

The get_block_info() function can only be used when the main QEMU
instance is the QMP peer, because it gets the information from the
front-end devices. In case of QSD, the relevant information can be
obtained with the 'query-named-block-nodes' QMP command.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
src/PVE/QemuServer.pm | 8 +++++---
src/PVE/QemuServer/BlockJob.pm | 2 +-
src/PVE/QemuServer/Blockdev.pm | 20 +++++++++++++++-----
src/PVE/QemuServer/VolumeChain.pm | 7 ++++---
4 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 76f32894..eea5ac3b 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -7302,7 +7302,8 @@ sub pbs_live_restore {
# removes itself once all backing images vanish with 'auto-remove=on')
my $jobs = {};
for my $ds (sort keys %$restored_disks) {
- my $node_name = PVE::QemuServer::Blockdev::get_node_name_below_throttle($vmid, $ds);
+ my $node_name =
+ PVE::QemuServer::Blockdev::get_node_name_below_throttle(vm_qmp_peer($vmid), $ds);
my $job_id = "restore-$ds";
mon_cmd(
$vmid, 'block-stream',
@@ -7420,8 +7421,9 @@ sub live_import_from_files {
# removes itself once all backing images vanish with 'auto-remove=on')
my $jobs = {};
for my $ds (sort keys %$live_restore_backing) {
- my $node_name =
- PVE::QemuServer::Blockdev::get_node_name_below_throttle($vmid, "drive-$ds");
+ my $node_name = PVE::QemuServer::Blockdev::get_node_name_below_throttle(
+ vm_qmp_peer($vmid), "drive-$ds",
+ );
my $job_id = "restore-$ds";
mon_cmd(
$vmid, 'block-stream',
diff --git a/src/PVE/QemuServer/BlockJob.pm b/src/PVE/QemuServer/BlockJob.pm
index 97ada28b..59b33482 100644
--- a/src/PVE/QemuServer/BlockJob.pm
+++ b/src/PVE/QemuServer/BlockJob.pm
@@ -455,7 +455,7 @@ sub blockdev_mirror {
# Need to replace the node below the top node. This is not necessarily a format node, for
# example, it can also be a zeroinit node by a previous mirror! So query QEMU itself.
my $source_node_name =
- PVE::QemuServer::Blockdev::get_node_name_below_throttle($vmid, $device_id, 1);
+ PVE::QemuServer::Blockdev::get_node_name_below_throttle(vm_qmp_peer($vmid), $device_id, 1);

# Copy original drive config (aio, cache, discard, ...):
my $dest_drive = dclone($source->{drive});
diff --git a/src/PVE/QemuServer/Blockdev.pm b/src/PVE/QemuServer/Blockdev.pm
index c96b76da..495aff50 100644
--- a/src/PVE/QemuServer/Blockdev.pm
+++ b/src/PVE/QemuServer/Blockdev.pm
@@ -166,12 +166,22 @@ sub top_node_name {
}

sub get_node_name_below_throttle {
- my ($vmid, $device_id, $assert_top_is_throttle) = @_;
+ my ($qmp_peer, $device_id, $assert_top_is_throttle) = @_;

- my $block_info = get_block_info($vmid);
- my $drive_id = $device_id =~ s/^drive-//r;
- my $top = $block_info->{$drive_id}->{inserted}
- or die "no block node inserted for drive '$drive_id'\n";
+ my $top;
+ if ($qmp_peer->{type} eq 'qmp') { # get_block_info() only works if there are front-end devices.
+ my $block_info = get_block_info($qmp_peer->{id});
+ my $drive_id = $device_id =~ s/^drive-//r;
+ $top = $block_info->{$drive_id}->{inserted};
+ } else {
+ my $named_block_node_info = qmp_cmd($qmp_peer, 'query-named-block-nodes');
+ for my $info ($named_block_node_info->@*) {
+ next if $info->{'node-name'} ne $device_id;
+ $top = $info;
+ last;
+ }
+ }
+ die "no block node found for drive '$device_id'\n" if !$top;

if ($top->{drv} ne 'throttle') {
die "$device_id: unexpected top node $top->{'node-name'} ($top->{drv})\n"
diff --git a/src/PVE/QemuServer/VolumeChain.pm b/src/PVE/QemuServer/VolumeChain.pm
index 9aaf6bbe..08acbc05 100644
--- a/src/PVE/QemuServer/VolumeChain.pm
+++ b/src/PVE/QemuServer/VolumeChain.pm
@@ -11,7 +11,7 @@ use PVE::Storage;
use PVE::QemuServer::Blockdev qw(generate_file_blockdev generate_format_blockdev);
use PVE::QemuServer::BlockJob;
use PVE::QemuServer::Drive;
-use PVE::QemuServer::Monitor qw(mon_cmd);
+use PVE::QemuServer::Monitor qw(mon_cmd vm_qmp_peer);

sub blockdev_external_snapshot {
my ($storecfg, $vmid, $machine_version, $deviceid, $drive, $snap, $parent_snap) = @_;
@@ -106,8 +106,9 @@ sub blockdev_replace {
my $src_blockdev_name;
if ($src_snap eq 'current') {
# there might be other nodes on top like zeroinit, look up the current node below throttle
- $src_blockdev_name =
- PVE::QemuServer::Blockdev::get_node_name_below_throttle($vmid, $deviceid, 1);
+ $src_blockdev_name = PVE::QemuServer::Blockdev::get_node_name_below_throttle(
+ vm_qmp_peer($vmid), $deviceid, 1,
+ );
} else {
$src_name_options = { 'snapshot-name' => $src_snap };
$src_blockdev_name =
--
2.47.3