public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server 01/11] agent: drop unused $noerr argument from helpers
Date: Mon,  5 May 2025 14:57:14 +0200	[thread overview]
Message-ID: <20250505125724.75620-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250505125724.75620-1-f.ebner@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


  reply	other threads:[~2025-05-05 12:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-05 12:57 [pve-devel] [PATCH-SERIES qemu-server 00/11] better handle lost freeze command Fiona Ebner
2025-05-05 12:57 ` Fiona Ebner [this message]
2025-05-05 12:57 ` [pve-devel] [PATCH qemu-server 02/11] api: agent: improve module imports Fiona Ebner
2025-05-05 12:57 ` [pve-devel] [PATCH qemu-server 03/11] agent: code style: order module imports according to style guide Fiona Ebner
2025-05-05 12:57 ` [pve-devel] [PATCH qemu-server 04/11] agent: avoid dependency on QemuConfig module Fiona Ebner
2025-05-05 12:57 ` [pve-devel] [PATCH qemu-server 05/11] qmp client: remove erroneous comment Fiona Ebner
2025-05-05 12:57 ` [pve-devel] [PATCH qemu-server 06/11] qmp client: add $noerr argument Fiona Ebner
2025-05-05 12:57 ` [pve-devel] [PATCH qemu-server 07/11] agent: implement fsfreeze helper to better handle lost commands Fiona Ebner
2025-05-05 13:57   ` Mira Limbeck
2025-05-05 14:01     ` Fiona Ebner
2025-05-05 12:57 ` [pve-devel] [PATCH qemu-server 08/11] agent: avoid use of deprecated check_running() function Fiona Ebner
2025-05-05 12:57 ` [pve-devel] [PATCH qemu-server 09/11] agent: move qga_check_running() helper to agent module Fiona Ebner
2025-05-05 12:57 ` [pve-devel] [PATCH qemu-server 10/11] agent: prefer usage of get_qga_key() helper Fiona Ebner
2025-05-05 12:57 ` [pve-devel] [PATCH qemu-server 11/11] agent: move guest agent format and parsing to agent module Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250505125724.75620-2-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal