From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 958AC1FF16B
	for <inbox@lore.proxmox.com>; Thu,  3 Apr 2025 15:23:47 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 23728226C;
	Thu,  3 Apr 2025 15:23:36 +0200 (CEST)
From: Shannon Sterz <s.sterz@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Thu,  3 Apr 2025 15:23:01 +0200
Message-Id: <20250403132301.352771-1-s.sterz@proxmox.com>
X-Mailer: git-send-email 2.39.5
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.016 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pbs-devel] [PATCH proxmox-backup] datastore/api: add error message
 on failed removal due to old locking
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com>

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