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 [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 2E8FE1FF162 for <inbox@lore.proxmox.com>; Mon, 5 May 2025 14:58:31 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5AC2C1C506; Mon, 5 May 2025 14:58:03 +0200 (CEST) From: Fiona Ebner <f.ebner@proxmox.com> To: pve-devel@lists.proxmox.com Date: Mon, 5 May 2025 14:57:14 +0200 Message-Id: <20250505125724.75620-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250505125724.75620-1-f.ebner@proxmox.com> References: <20250505125724.75620-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.037 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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 01/11] 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> --- 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 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel