From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 67DCD1FF13F for ; Thu, 23 Apr 2026 14:41:03 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 07BD816C71; Thu, 23 Apr 2026 14:40:48 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v2 1/7] agent: migrate to v5.36 and use subroutine signatures Date: Thu, 23 Apr 2026 14:35:12 +0200 Message-ID: <20260423124004.115303-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260423124004.115303-1-f.ebner@proxmox.com> References: <20260423124004.115303-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1776947918955 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.008 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [agent.pm] Message-ID-Hash: LLUGJPWHTDAZM7KTUVJJEW6BISMPRN7O X-Message-ID-Hash: LLUGJPWHTDAZM7KTUVJJEW6BISMPRN7O X-MailFrom: f.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: parse_guest_agent($conf) get_qga_key($conf, $key) assert_agent_available($vmid, $conf) agent_cmd($vmid, $conf, $cmd, $params, $errormsg) qemu_exec($vmid, $conf, $input_data, $cmd) qemu_exec_status($vmid, $conf, $pid) should_fs_freeze($conf) guest_fsfreeze($vmid) guest_fsthaw($vmid) For these functions, all arguments are declared as mandatory, and all existing callers pass all arguments. qga_check_running($vmid, $nowarn = 0) $vmid is mandatory, all existing callers pass the first argument, $nowarn is set to 0 by default for compatibility. check_agent_error($result, $errmsg, $noerr = 0) $result and $errmsg are mandatory, all existing callers pass the first two arguments, $noerr is set to 0 by default for compatibility. Signed-off-by: Fiona Ebner --- New in v2. src/PVE/QemuServer/Agent.pm | 47 ++++++++++--------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/src/PVE/QemuServer/Agent.pm b/src/PVE/QemuServer/Agent.pm index 5a3eb983..ec3827d6 100644 --- a/src/PVE/QemuServer/Agent.pm +++ b/src/PVE/QemuServer/Agent.pm @@ -1,7 +1,6 @@ package PVE::QemuServer::Agent; -use strict; -use warnings; +use v5.36; use JSON; use MIME::Base64 qw(decode_base64 encode_base64); @@ -62,9 +61,7 @@ our $agent_fmt = { }, }; -sub parse_guest_agent { - my ($conf) = @_; - +sub parse_guest_agent($conf) { return {} if !defined($conf->{agent}); my $res = eval { PVE::JSONSchema::parse_property_string($agent_fmt, $conf->{agent}) }; @@ -75,17 +72,14 @@ sub parse_guest_agent { return $res; } -sub get_qga_key { - my ($conf, $key) = @_; +sub get_qga_key($conf, $key) { return undef if !defined($conf->{agent}); my $agent = parse_guest_agent($conf); return $agent->{$key}; } -sub qga_check_running { - my ($vmid, $nowarn) = @_; - +sub qga_check_running($vmid, $nowarn = 0) { eval { PVE::QemuServer::Monitor::mon_cmd($vmid, "guest-ping", timeout => 3); }; if ($@) { warn "QEMU Guest Agent is not running - $@" if !$nowarn; @@ -94,10 +88,7 @@ sub qga_check_running { return 1; } -sub check_agent_error { - my ($result, $errmsg, $noerr) = @_; - - $errmsg //= ''; +sub check_agent_error($result, $errmsg, $noerr = 0) { my $error = ''; if (ref($result) eq 'HASH' && $result->{error} && $result->{error}->{desc}) { $error = "Agent error: $result->{error}->{desc}\n"; @@ -115,18 +106,14 @@ sub check_agent_error { return 1; } -sub assert_agent_available { - my ($vmid, $conf) = @_; - +sub assert_agent_available($vmid, $conf) { die "No QEMU guest agent configured\n" if !defined($conf->{agent}); die "VM $vmid is not running\n" if !PVE::QemuServer::Helpers::vm_running_locally($vmid); die "QEMU guest agent is not running\n" if !qga_check_running($vmid, 1); } # loads config, checks if available, executes command, checks for errors -sub agent_cmd { - my ($vmid, $conf, $cmd, $params, $errormsg) = @_; - +sub agent_cmd($vmid, $conf, $cmd, $params, $errormsg) { assert_agent_available($vmid, $conf); my $res = PVE::QemuServer::Monitor::mon_cmd($vmid, "guest-$cmd", %$params); @@ -135,9 +122,7 @@ sub agent_cmd { return $res; } -sub qemu_exec { - my ($vmid, $conf, $input_data, $cmd) = @_; - +sub qemu_exec($vmid, $conf, $input_data, $cmd) { my $args = { 'capture-output' => JSON::true, }; @@ -165,9 +150,7 @@ sub qemu_exec { return $res; } -sub qemu_exec_status { - my ($vmid, $conf, $pid) = @_; - +sub qemu_exec_status($vmid, $conf, $pid) { my $res = agent_cmd($vmid, $conf, "exec-status", { pid => $pid }, "can't get exec status for '$pid'"); @@ -204,9 +187,7 @@ Does B check whether the agent is actually running. =cut -sub should_fs_freeze { - my ($conf) = @_; - +sub should_fs_freeze($conf) { my $agent = parse_guest_agent($conf); return 0 if !$agent->{enabled}; return $agent->{'freeze-fs'} // 1; @@ -235,9 +216,7 @@ the time the socket is blocked after a lost command is at most 10 minutes. =cut -sub guest_fsfreeze { - my ($vmid) = @_; - +sub guest_fsfreeze($vmid) { my $timeout = 10 * 60; my $result = eval { @@ -290,9 +269,7 @@ See C<$guest_fsfreeze> for more details. =cut -sub guest_fsthaw { - my ($vmid) = @_; - +sub guest_fsthaw($vmid) { my $res = PVE::QemuServer::Monitor::mon_cmd($vmid, "guest-fsfreeze-thaw"); check_agent_error($res, "unable to thaw guest filesystem"); -- 2.47.3