[pve-devel] [PATCH qemu-server 01/11] agent: drop unused $noerr argument from helpers
Fiona Ebner
f.ebner at proxmox.com
Mon May 5 14:57:14 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>
---
PVE/API2/Qemu/Agent.pm | 4 ++--
PVE/CLI/qm.pm | 2 +-
PVE/QemuServer/Agent.pm | 26 ++++++++------------------
3 files changed, 11 insertions(+), 21 deletions(-)
diff --git a/PVE/API2/Qemu/Agent.pm b/PVE/API2/Qemu/Agent.pm
index dceee770..e3102b0a 100644
--- a/PVE/API2/Qemu/Agent.pm
+++ b/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;
@@ -189,7 +189,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/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index 3e3a4c91..35e85597 100755
--- a/PVE/CLI/qm.pm
+++ b/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/PVE/QemuServer/Agent.pm b/PVE/QemuServer/Agent.pm
index 548c020c..945a11c0 100644
--- a/PVE/QemuServer/Agent.pm
+++ b/PVE/QemuServer/Agent.pm
@@ -11,7 +11,6 @@ use base 'Exporter';
our @EXPORT_OK = qw(
check_agent_error
-agent_available
agent_cmd
);
@@ -36,32 +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.39.5
More information about the pve-devel
mailing list