all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
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	[thread overview]
Message-ID: <20260423124004.115303-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20260423124004.115303-1-f.ebner@proxmox.com>

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 <f.ebner@proxmox.com>
---

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<not> 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





  reply	other threads:[~2026-04-23 12:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23 12:35 [PATCH-SERIES qemu-server v2 0/7] fix #7383: agent: fsfreeze: skip freeze if already frozen Fiona Ebner
2026-04-23 12:35 ` Fiona Ebner [this message]
2026-04-23 12:35 ` [PATCH qemu-server v2 2/7] agent: rename guest_fs{freeze,thaw} to guest_fs_{freeze,thaw} Fiona Ebner
2026-04-23 12:35 ` [PATCH qemu-server v2 3/7] agent: parse: change signature to take property string rather than full VM config Fiona Ebner
2026-04-23 12:35 ` [PATCH qemu-server v2 4/7] agent: should fs freeze: " Fiona Ebner
2026-04-23 12:35 ` [PATCH qemu-server v2 5/7] clone disk/block jobs: change signatures to take guest agent property string Fiona Ebner
2026-04-23 12:35 ` [PATCH qemu-server v2 6/7] agent: fs freeze: harmonize checks for guest fs freeze Fiona Ebner
2026-04-23 12:35 ` [PATCH qemu-server v2 7/7] fix #7383: agent: fsfreeze: skip freeze if already frozen 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=20260423124004.115303-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal