public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Shannon Sterz <s.sterz@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] datastore: ignore group locking errors when removing snapshots
Date: Thu,  3 Apr 2025 12:14:15 +0200	[thread overview]
Message-ID: <20250403101415.141669-1-s.sterz@proxmox.com> (raw)

this is only needed for removing the group if the last snapshot is
removed, ignore locking failures, as the user can't do anything to
rectify the situation anymore.

log the locking error for debugging purposes, though.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
---
 pbs-datastore/src/backup_info.rs | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/pbs-datastore/src/backup_info.rs b/pbs-datastore/src/backup_info.rs
index 557bb196..f7805eaf 100644
--- a/pbs-datastore/src/backup_info.rs
+++ b/pbs-datastore/src/backup_info.rs
@@ -599,12 +599,25 @@ impl BackupDir {
         let _ = std::fs::remove_file(self.lock_path()); // ignore errors

         let group = BackupGroup::from(self);
-        let _guard = group.lock().with_context(|| {
+        let guard = group.lock().with_context(|| {
             format!("while checking if group '{group:?}' is empty during snapshot destruction")
-        })?;
+        });

-        if group.list_backups()?.is_empty() && !*OLD_LOCKING {
+        // only remove the group if:
+        //
+        // - we can lock it: if we can't lock the group, it is still in use (either by another backup process or a
+        // parent caller (who needs to take care that empty groups are removed themselves).
+        // - it is now empty: if the group isn't empty, removing it will fail (to avoid removing
+        // backups that might still be used).
+        // - the new locking mechanism is used: if the old mechanism is used, a group removal here
+        // could lead to a race condition.
+        //
+        // do not error out, as we have already removed the snapshot, there is nothing a user could
+        // do to rectify the situation.
+        if guard.is_ok() && group.list_backups()?.is_empty() && !*OLD_LOCKING {
             group.remove_group_dir()?;
+        } else if let Err(err) = guard {
+            log::debug!("{err:#}");
         }

         Ok(())
--
2.39.5



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


             reply	other threads:[~2025-04-03 10:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03 10:14 Shannon Sterz [this message]
2025-04-03 11:54 ` [pbs-devel] applied: " 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=20250403101415.141669-1-s.sterz@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=pbs-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