public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server v2 1/4] agent: add should_fs_freeze helper
Date: Wed, 25 Mar 2026 22:28:02 +0100	[thread overview]
Message-ID: <20260325213415.3861690-2-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20260325213415.3861690-1-t.lamprecht@proxmox.com>

Add a centralized helper that checks whether guest filesystem
freeze/thaw should be attempted, combining the agent-enabled and
guest-fsfreeze setting checks. This replaces duplicated inline logic
and the scattered '// 1' default fallback across call sites.

No behavioral change intended, the helper returns the same result as
the previous inline expressions.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
 src/PVE/API2/Qemu.pm        | 10 ++++------
 src/PVE/QemuConfig.pm       |  5 ++---
 src/PVE/QemuServer/Agent.pm | 15 +++++++++++++++
 3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 1752f46a..020c68b2 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -374,8 +374,7 @@ my $import_from_volid = sub {
 
         my ($src_storeid) = PVE::Storage::parse_volume_id($src_volid);
 
-        my $qga = PVE::QemuServer::Agent::get_qga_key($src_conf, 'enabled')
-            && (PVE::QemuServer::Agent::get_qga_key($src_conf, 'guest-fsfreeze') // 1);
+        my $fs_freeze = PVE::QemuServer::Agent::should_fs_freeze($src_conf);
 
         return PVE::QemuServer::clone_disk(
             $storecfg,
@@ -385,7 +384,7 @@ my $import_from_volid = sub {
             $vollist,
             undef,
             undef,
-            $qga,
+            $fs_freeze,
             PVE::Storage::get_bandwidth_limit('clone', [$src_storeid, $dest_info->{storage}]),
         );
     };
@@ -4562,8 +4561,7 @@ __PACKAGE__->register_method({
                     $dest_info->{efisize} = PVE::QemuServer::get_efivars_size($oldconf)
                         if $opt eq 'efidisk0';
 
-                    my $qga = PVE::QemuServer::Agent::get_qga_key($oldconf, 'enabled')
-                        && (PVE::QemuServer::Agent::get_qga_key($oldconf, 'guest-fsfreeze') // 1);
+                    my $fs_freeze = PVE::QemuServer::Agent::should_fs_freeze($oldconf);
 
                     my $newdrive = PVE::QemuServer::clone_disk(
                         $storecfg,
@@ -4573,7 +4571,7 @@ __PACKAGE__->register_method({
                         $newvollist,
                         $jobs,
                         $completion,
-                        $qga,
+                        $fs_freeze,
                         $clonelimit,
                     );
 
diff --git a/src/PVE/QemuConfig.pm b/src/PVE/QemuConfig.pm
index 462d1d6d..839b6cd0 100644
--- a/src/PVE/QemuConfig.pm
+++ b/src/PVE/QemuConfig.pm
@@ -297,9 +297,8 @@ sub __snapshot_check_freeze_needed {
         return (
             $running,
             $running
-                && PVE::QemuServer::Agent::get_qga_key($config, 'enabled')
-                && PVE::QemuServer::Agent::qga_check_running($vmid)
-                && (PVE::QemuServer::Agent::get_qga_key($config, 'guest-fsfreeze') // 1),
+                && PVE::QemuServer::Agent::should_fs_freeze($config)
+                && PVE::QemuServer::Agent::qga_check_running($vmid),
         );
     } else {
         return ($running, 0);
diff --git a/src/PVE/QemuServer/Agent.pm b/src/PVE/QemuServer/Agent.pm
index 1e7b1895..7520dd6e 100644
--- a/src/PVE/QemuServer/Agent.pm
+++ b/src/PVE/QemuServer/Agent.pm
@@ -202,6 +202,21 @@ sub qemu_exec_status {
     return $res;
 }
 
+=head3 should_fs_freeze
+
+Returns whether guest filesystem freeze/thaw should be attempted based on the agent configuration.
+Does B<not> check whether the agent is actually running.
+
+=cut
+
+sub should_fs_freeze {
+    my ($conf) = @_;
+
+    my $agent = parse_guest_agent($conf);
+    return 0 if !$agent->{enabled};
+    return $agent->{'guest-fsfreeze'} // 1;
+}
+
 =head3 guest_fsfreeze
 
     guest_fsfreeze($vmid);
-- 
2.47.3





  reply	other threads:[~2026-03-25 21:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-25 21:28 [PATCH qemu-server v2 0/4] rework fs-freeze agent property Thomas Lamprecht
2026-03-25 21:28 ` Thomas Lamprecht [this message]
2026-03-26 12:55   ` [PATCH qemu-server v2 1/4] agent: add should_fs_freeze helper Fiona Ebner
2026-03-27  1:12     ` Thomas Lamprecht
2026-03-25 21:28 ` [PATCH qemu-server v2 2/4] agent: treat freeze-fs-on-backup as alias for guest-fsfreeze Thomas Lamprecht
2026-03-26 12:55   ` Fiona Ebner
2026-03-26 23:05     ` Thomas Lamprecht
2026-03-27  8:53       ` Fiona Ebner
2026-03-25 21:28 ` [PATCH qemu-server v2 3/4] tests: cfg2cmd: add agent guest-fsfreeze config tests Thomas Lamprecht
2026-03-26 12:55   ` Fiona Ebner
2026-03-25 21:28 ` [PATCH qemu-server v2 4/4] qga: rename guest-fsfreeze to freeze-fs Thomas Lamprecht
2026-03-26  9:08   ` Maximiliano Sandoval
2026-03-26 21:46     ` Thomas Lamprecht
2026-03-26 12:55   ` Fiona Ebner
2026-03-26 23:16 ` applied: [PATCH qemu-server v2 0/4] rework fs-freeze agent property Thomas Lamprecht

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=20260325213415.3861690-2-t.lamprecht@proxmox.com \
    --to=t.lamprecht@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