[pve-devel] [PATCH qemu-server 09/31] agent: drop unused $noerr argument from helpers
Fiona Ebner
f.ebner at proxmox.com
Wed Jun 25 17:56:32 CEST 2025
Both agent_available() and agent_cmd() have no callers that use the
$noerr argument.
The current implementation was not ideal: agent_cmd() did not check
the return value of agent_available() in the $noerr scenario. It
should return early. In agent_available(), failure was silently
ignored in the $noerr scenario. Having a message or warning then would
have been more useful.
The agent_available() function is renamed to assert_agent_available()
and it is not exported anymore, the single caller outside the module
can just call it with the full module path.
The import of 'agent_available' in qm.pm was not used and is dropped.
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
src/PVE/API2/Qemu/Agent.pm | 4 ++--
src/PVE/CLI/qm.pm | 2 +-
src/PVE/QemuServer/Agent.pm | 27 ++++++++-------------------
3 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/src/PVE/API2/Qemu/Agent.pm b/src/PVE/API2/Qemu/Agent.pm
index ef464403..3d1952a6 100644
--- a/src/PVE/API2/Qemu/Agent.pm
+++ b/src/PVE/API2/Qemu/Agent.pm
@@ -6,7 +6,7 @@ use warnings;
use PVE::RESTHandler;
use PVE::JSONSchema qw(get_standard_option);
use PVE::QemuServer;
-use PVE::QemuServer::Agent qw(agent_available agent_cmd check_agent_error);
+use PVE::QemuServer::Agent qw(agent_cmd check_agent_error);
use PVE::QemuServer::Monitor qw(mon_cmd);
use MIME::Base64 qw(encode_base64 decode_base64);
use JSON;
@@ -195,7 +195,7 @@ sub register_command {
my $conf = PVE::QemuConfig->load_config($vmid); # check if VM exists
- agent_available($vmid, $conf);
+ PVE::QemuServer::Agent::assert_agent_available($vmid, $conf);
my $cmd = $param->{command} // $command;
my $res = mon_cmd($vmid, "guest-$cmd");
diff --git a/src/PVE/CLI/qm.pm b/src/PVE/CLI/qm.pm
index c4be9eb3..a7f08cc2 100755
--- a/src/PVE/CLI/qm.pm
+++ b/src/PVE/CLI/qm.pm
@@ -32,7 +32,7 @@ use PVE::API2::Qemu;
use PVE::QemuConfig;
use PVE::QemuServer::Drive qw(is_valid_drivename);
use PVE::QemuServer::Helpers;
-use PVE::QemuServer::Agent qw(agent_available);
+use PVE::QemuServer::Agent;
use PVE::QemuServer::ImportDisk;
use PVE::QemuServer::Monitor qw(mon_cmd);
use PVE::QemuServer::QMPHelpers;
diff --git a/src/PVE/QemuServer/Agent.pm b/src/PVE/QemuServer/Agent.pm
index 47405963..9212a0c3 100644
--- a/src/PVE/QemuServer/Agent.pm
+++ b/src/PVE/QemuServer/Agent.pm
@@ -11,7 +11,6 @@ use base 'Exporter';
our @EXPORT_OK = qw(
check_agent_error
- agent_available
agent_cmd
);
@@ -36,33 +35,23 @@ sub check_agent_error {
return 1;
}
-sub agent_available {
- my ($vmid, $conf, $noerr) = @_;
+sub assert_agent_available {
+ my ($vmid, $conf) = @_;
- eval {
- die "No QEMU guest agent configured\n" if !defined($conf->{agent});
- die "VM $vmid is not running\n" if !PVE::QemuServer::check_running($vmid);
- die "QEMU guest agent is not running\n"
- if !PVE::QemuServer::qga_check_running($vmid, 1);
- };
-
- if (my $err = $@) {
- die $err if !$noerr;
- return;
- }
-
- return 1;
+ die "No QEMU guest agent configured\n" if !defined($conf->{agent});
+ die "VM $vmid is not running\n" if !PVE::QemuServer::check_running($vmid);
+ die "QEMU guest agent is not running\n" if !PVE::QemuServer::qga_check_running($vmid, 1);
}
# loads config, checks if available, executes command, checks for errors
sub agent_cmd {
- my ($vmid, $cmd, $params, $errormsg, $noerr) = @_;
+ my ($vmid, $cmd, $params, $errormsg) = @_;
my $conf = PVE::QemuConfig->load_config($vmid); # also checks if VM exists
- agent_available($vmid, $conf, $noerr);
+ assert_agent_available($vmid, $conf);
my $res = PVE::QemuServer::Monitor::mon_cmd($vmid, "guest-$cmd", %$params);
- check_agent_error($res, $errormsg, $noerr);
+ check_agent_error($res, $errormsg);
return $res;
}
--
2.47.2
More information about the pve-devel
mailing list