[PATCH qemu-server v3 05/18] monitor: add qsd_peer() helper

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

Avoid duplicating this information to ensure consistency and improve
readability.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
src/PVE/QemuServer/Blockdev.pm | 9 ++-------
src/PVE/QemuServer/Monitor.pm | 10 ++++++++--
src/PVE/QemuServer/QSD.pm | 11 ++++-------
3 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/src/PVE/QemuServer/Blockdev.pm b/src/PVE/QemuServer/Blockdev.pm
index 80c1178e..3c27e721 100644
--- a/src/PVE/QemuServer/Blockdev.pm
+++ b/src/PVE/QemuServer/Blockdev.pm
@@ -14,7 +14,7 @@ use PVE::Storage;
use PVE::QemuServer::Drive qw(drive_is_cdrom);
use PVE::QemuServer::Helpers;
use PVE::QemuServer::Machine;
-use PVE::QemuServer::Monitor qw(mon_cmd qmp_cmd vm_qmp_peer);
+use PVE::QemuServer::Monitor qw(mon_cmd qmp_cmd qsd_peer vm_qmp_peer);

use base qw(Exporter);

@@ -584,12 +584,7 @@ state image.
sub attach {
my ($storecfg, $id, $drive, $options) = @_;

- my $qmp_peer;
- if ($options->{qsd}) {
- $qmp_peer = { name => "QEMU storage daemon $id", id => $id, type => 'qsd' };
- } else {
- $qmp_peer = vm_qmp_peer($id);
- }
+ my $qmp_peer = $options->{qsd} ? qsd_peer($id) : vm_qmp_peer($id);

my $machine_version;
if ($options->{qsd}) { # qemu-storage-daemon runs with the installed binary version
diff --git a/src/PVE/QemuServer/Monitor.pm b/src/PVE/QemuServer/Monitor.pm
index e7f08e23..1b1ce4ea 100644
--- a/src/PVE/QemuServer/Monitor.pm
+++ b/src/PVE/QemuServer/Monitor.pm
@@ -11,6 +11,7 @@ use base 'Exporter';
our @EXPORT_OK = qw(
mon_cmd
qmp_cmd
+ qsd_peer
vm_qmp_peer
);

@@ -109,11 +110,16 @@ sub vm_qmp_peer {
return { name => "VM $vmid", id => $vmid, type => 'qmp' };
}

+sub qsd_peer {
+ my ($id) = @_;
+
+ return { name => "QEMU storage daemon $id", id => $id, type => 'qsd' };
+}
+
sub qsd_cmd {
my ($id, $execute, %params) = @_;

- return qmp_cmd({ name => "QEMU storage daemon $id", id => $id, type => 'qsd' },
- $execute, %params);
+ return qmp_cmd(qsd_peer($id), $execute, %params);
}

sub mon_cmd {
diff --git a/src/PVE/QemuServer/QSD.pm b/src/PVE/QemuServer/QSD.pm
index 9c30f7fd..bb85085a 100644
--- a/src/PVE/QemuServer/QSD.pm
+++ b/src/PVE/QemuServer/QSD.pm
@@ -11,7 +11,7 @@ use PVE::Tools;

use PVE::QemuServer::Blockdev;
use PVE::QemuServer::Helpers;
-use PVE::QemuServer::Monitor;
+use PVE::QemuServer::Monitor qw(qsd_peer);

=head3 start

@@ -22,13 +22,10 @@ Start a QEMU storage daemon instance with ID C<$id>.
=cut

sub start($id) {
- my $name = "QEMU storage daemon $id";
-
# If something is still mounted, that could block the new instance, try to clean up first.
PVE::QemuServer::Helpers::qsd_fuse_export_cleanup_files($id);

- my $qmp_socket_path =
- PVE::QemuServer::Helpers::qmp_socket({ name => $name, id => $id, type => 'qsd' });
+ my $qmp_socket_path = PVE::QemuServer::Helpers::qmp_socket(qsd_peer($id));
my $pidfile = PVE::QemuServer::Helpers::qsd_pidfile_name($id);

my $cmd = [
@@ -45,7 +42,7 @@ sub start($id) {
PVE::Tools::run_command($cmd);

my $pid = PVE::QemuServer::Helpers::qsd_running_locally($id);
- syslog("info", "$name started with PID $pid.");
+ syslog("info", "QEMU storage daemon $id started with PID $pid.");

return;
}
@@ -134,7 +131,7 @@ sub quit($id) {
}

unlink PVE::QemuServer::Helpers::qsd_pidfile_name($id);
- unlink PVE::QemuServer::Helpers::qmp_socket({ name => $name, id => $id, type => 'qsd' });
+ unlink PVE::QemuServer::Helpers::qmp_socket(qsd_peer($id));

PVE::QemuServer::Helpers::qsd_fuse_export_cleanup_files($id);

--
2.47.3