From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id AC82E1FF17C for <inbox@lore.proxmox.com>; Wed, 25 Jun 2025 17:58:03 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3646E18FD4; Wed, 25 Jun 2025 17:58:04 +0200 (CEST) From: Fiona Ebner <f.ebner@proxmox.com> To: pve-devel@lists.proxmox.com Date: Wed, 25 Jun 2025 17:56:32 +0200 Message-ID: <20250625155751.268047-10-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250625155751.268047-1-f.ebner@proxmox.com> References: <20250625155751.268047-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.030 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH qemu-server 09/31] agent: drop unused $noerr argument from helpers X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> 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@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 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel