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/api: add error message on failed removal due to old locking
Date: Thu,  3 Apr 2025 15:23:01 +0200	[thread overview]
Message-ID: <20250403132301.352771-1-s.sterz@proxmox.com> (raw)

group or namespace removal can fail if the old locking mechanism is
still in use, as it is unsafe to properly clean up in that scenario.
return an error message that explains how to rectify that situation.

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
---
 pbs-datastore/src/backup_info.rs |  2 +-
 pbs-datastore/src/datastore.rs   |  6 +++++-
 src/api2/admin/datastore.rs      | 22 ++++++++++++++++------
 src/api2/admin/namespace.rs      |  8 +++++++-
 4 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/pbs-datastore/src/backup_info.rs b/pbs-datastore/src/backup_info.rs
index f7805eaf..2ff1f492 100644
--- a/pbs-datastore/src/backup_info.rs
+++ b/pbs-datastore/src/backup_info.rs
@@ -27,7 +27,7 @@ pub const DATASTORE_LOCKS_DIR: &str = "/run/proxmox-backup/locks";
 // of the file. this should only happen if a user messes with the `/run/proxmox-backup` directory.
 // if that happens, a lot more should fail as we rely on the existence of the directory throughout
 // the code. so just panic with a reasonable message.
-static OLD_LOCKING: LazyLock<bool> = LazyLock::new(|| {
+pub(crate) static OLD_LOCKING: LazyLock<bool> = LazyLock::new(|| {
     std::fs::exists("/run/proxmox-backup/old-locking")
         .expect("cannot read `/run/proxmox-backup`, please check permissions")
 });
diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index ae4fb7f8..7926d486 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -25,7 +25,7 @@ use pbs_api_types::{
 };
 use pbs_config::BackupLockGuard;
 
-use crate::backup_info::{BackupDir, BackupGroup};
+use crate::backup_info::{BackupDir, BackupGroup, OLD_LOCKING};
 use crate::chunk_store::ChunkStore;
 use crate::dynamic_index::{DynamicIndexReader, DynamicIndexWriter};
 use crate::fixed_index::{FixedIndexReader, FixedIndexWriter};
@@ -1558,4 +1558,8 @@ impl DataStore {
 
         Ok(())
     }
+
+    pub fn old_locking(&self) -> bool {
+        *OLD_LOCKING
+    }
 }
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 3e532636..14e80432 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -313,13 +313,23 @@ pub async fn delete_group(
         )?;
 
         let delete_stats = datastore.remove_backup_group(&ns, &group)?;
-        if !delete_stats.all_removed() {
-            if error_on_protected {
-                bail!("group only partially deleted due to protected snapshots");
-            } else {
-                warn!("group only partially deleted due to protected snapshots");
-            }
+
+        let error_msg = if datastore.old_locking() {
+            "could not remove group properly due to old locking mechanism.\n\
+                please reboot PBS or ensure no old backup job is running anymore, then remove \
+                the file '/run/proxmox-backup/old-locking' and reload all PBS daemons"
+        } else if !delete_stats.all_removed() {
+            "group only partially deleted due to protected snapshots"
+        } else {
+            return Ok(delete_stats);
+        };
+
+        if error_on_protected {
+            bail!(error_msg);
+        } else {
+            warn!(error_msg);
         }
+
         Ok(delete_stats)
     })
     .await?
diff --git a/src/api2/admin/namespace.rs b/src/api2/admin/namespace.rs
index e2a5ccd5..ee54797a 100644
--- a/src/api2/admin/namespace.rs
+++ b/src/api2/admin/namespace.rs
@@ -167,7 +167,13 @@ pub fn delete_namespace(
     let (removed_all, stats) = datastore.remove_namespace_recursive(&ns, delete_groups)?;
     if !removed_all {
         let err_msg = if delete_groups {
-            "group only partially deleted due to protected snapshots"
+            if datastore.old_locking() {
+                "could not remove groups due to old locking mechanism.\n\
+                    please reboot PBS or ensure no old backup job is running anymore, then remove \
+                    the file '/run/proxmox-backup/old-locking', and reload all PBS daemons"
+            } else {
+                "group only partially deleted due to protected snapshots"
+            }
         } else {
             "only partially deleted due to existing groups but `delete-groups` not true"
         };
-- 
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 13:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03 13:23 Shannon Sterz [this message]
2025-04-03 16:07 ` [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=20250403132301.352771-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