public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup] datastore/api: add error message on failed removal due to old locking
@ 2025-04-03 13:23 Shannon Sterz
  2025-04-03 16:07 ` [pbs-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Shannon Sterz @ 2025-04-03 13:23 UTC (permalink / raw)
  To: pbs-devel

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pbs-devel] applied: [PATCH proxmox-backup] datastore/api: add error message on failed removal due to old locking
  2025-04-03 13:23 [pbs-devel] [PATCH proxmox-backup] datastore/api: add error message on failed removal due to old locking Shannon Sterz
@ 2025-04-03 16:07 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2025-04-03 16:07 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Shannon Sterz

Am 03.04.25 um 15:23 schrieb Shannon Sterz:
> 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(-)
> 
>

applied, with some fine-tuning of the error message (mostly adding "if you're
an admin"), thanks!


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-04-03 16:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-03 13:23 [pbs-devel] [PATCH proxmox-backup] datastore/api: add error message on failed removal due to old locking Shannon Sterz
2025-04-03 16:07 ` [pbs-devel] applied: " Thomas Lamprecht

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