public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH proxmox-backup v8 02/13] datastore: lift check_namespace_depth_limit to pbs-datastore
Date: Wed, 22 Apr 2026 15:39:40 +0200	[thread overview]
Message-ID: <20260422133951.192862-3-h.laimer@proxmox.com> (raw)
In-Reply-To: <20260422133951.192862-1-h.laimer@proxmox.com>

Move-namespace needs the same depth check sync (push/pull) already
uses. Move it to pbs-datastore as a free helper so both share one
implementation.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 pbs-datastore/src/datastore.rs | 25 ++++++++++++++++++++++++-
 pbs-datastore/src/lib.rs       |  6 +++---
 src/server/pull.rs             |  9 +++++----
 src/server/push.rs             |  7 +++----
 src/server/sync.rs             | 21 ---------------------
 5 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index f1475d77..5cdf6a4a 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -34,7 +34,7 @@ use pbs_api_types::{
     ArchiveType, Authid, BackupGroupDeleteStats, BackupNamespace, BackupType, ChunkOrder,
     DataStoreConfig, DatastoreBackendConfig, DatastoreBackendType, DatastoreFSyncLevel,
     DatastoreTuning, GarbageCollectionCacheStats, GarbageCollectionStatus, MaintenanceMode,
-    MaintenanceType, Operation, S3Statistics, UPID,
+    MaintenanceType, Operation, S3Statistics, MAX_NAMESPACE_DEPTH, UPID,
 };
 use pbs_config::s3::S3_CFG_TYPE_ID;
 use pbs_config::{BackupLockGuard, ConfigVersionCache};
@@ -89,6 +89,29 @@ const S3_DELETE_BATCH_LIMIT: usize = 100;
 // max defer time for s3 batch deletions
 const S3_DELETE_DEFER_LIMIT_SECONDS: Duration = Duration::from_secs(60 * 5);
 
+/// Check that moving/syncing `namespaces` from `source` to `target` stays within
+/// `MAX_NAMESPACE_DEPTH`.
+pub fn check_namespace_depth_limit(
+    source: &BackupNamespace,
+    target: &BackupNamespace,
+    namespaces: &[BackupNamespace],
+) -> Result<(), Error> {
+    let target_depth = target.depth();
+    let sub_depth = namespaces
+        .iter()
+        .map(BackupNamespace::depth)
+        .max()
+        .map_or(0, |v| v - source.depth());
+
+    if sub_depth + target_depth > MAX_NAMESPACE_DEPTH {
+        bail!(
+            "namespace depth limit exceeded: source subtree depth ({sub_depth}) + target \
+            depth ({target_depth}) would exceed max ({MAX_NAMESPACE_DEPTH})",
+        );
+    }
+    Ok(())
+}
+
 /// checks if auth_id is owner, or, if owner is a token, if
 /// auth_id is the user of the token
 pub fn check_backup_owner(owner: &Authid, auth_id: &Authid) -> Result<(), Error> {
diff --git a/pbs-datastore/src/lib.rs b/pbs-datastore/src/lib.rs
index 9fa9dd59..4d8ac505 100644
--- a/pbs-datastore/src/lib.rs
+++ b/pbs-datastore/src/lib.rs
@@ -216,9 +216,9 @@ pub use store_progress::StoreProgress;
 
 mod datastore;
 pub use datastore::{
-    check_backup_owner, ensure_datastore_is_mounted, get_datastore_mount_status, DataStore,
-    DataStoreLookup, DatastoreBackend, S3_CLIENT_REQUEST_COUNTER_BASE_PATH,
-    S3_DATASTORE_IN_USE_MARKER,
+    check_backup_owner, check_namespace_depth_limit, ensure_datastore_is_mounted,
+    get_datastore_mount_status, DataStore, DataStoreLookup, DatastoreBackend,
+    S3_CLIENT_REQUEST_COUNTER_BASE_PATH, S3_DATASTORE_IN_USE_MARKER,
 };
 
 mod hierarchy;
diff --git a/src/server/pull.rs b/src/server/pull.rs
index 688f9557..16a59fee 100644
--- a/src/server/pull.rs
+++ b/src/server/pull.rs
@@ -25,13 +25,14 @@ use pbs_datastore::fixed_index::FixedIndexReader;
 use pbs_datastore::index::IndexFile;
 use pbs_datastore::manifest::{BackupManifest, FileInfo};
 use pbs_datastore::read_chunk::AsyncReadChunk;
-use pbs_datastore::{check_backup_owner, DataStore, DatastoreBackend, StoreProgress};
+use pbs_datastore::{
+    check_backup_owner, check_namespace_depth_limit, DataStore, DatastoreBackend, StoreProgress,
+};
 use pbs_tools::sha::sha256;
 
 use super::sync::{
-    check_namespace_depth_limit, exclude_not_verified_or_encrypted,
-    ignore_not_verified_or_encrypted, LocalSource, RemoteSource, RemovedVanishedStats, SkipInfo,
-    SkipReason, SyncSource, SyncSourceReader, SyncStats,
+    exclude_not_verified_or_encrypted, ignore_not_verified_or_encrypted, LocalSource, RemoteSource,
+    RemovedVanishedStats, SkipInfo, SkipReason, SyncSource, SyncSourceReader, SyncStats,
 };
 use crate::backup::{check_ns_modification_privs, check_ns_privs};
 use crate::tools::parallel_handler::ParallelHandler;
diff --git a/src/server/push.rs b/src/server/push.rs
index e69973b4..82319993 100644
--- a/src/server/push.rs
+++ b/src/server/push.rs
@@ -26,12 +26,11 @@ use pbs_datastore::dynamic_index::DynamicIndexReader;
 use pbs_datastore::fixed_index::FixedIndexReader;
 use pbs_datastore::index::IndexFile;
 use pbs_datastore::read_chunk::AsyncReadChunk;
-use pbs_datastore::{DataStore, StoreProgress};
+use pbs_datastore::{check_namespace_depth_limit, DataStore, StoreProgress};
 
 use super::sync::{
-    check_namespace_depth_limit, exclude_not_verified_or_encrypted,
-    ignore_not_verified_or_encrypted, LocalSource, RemovedVanishedStats, SkipInfo, SkipReason,
-    SyncSource, SyncStats,
+    exclude_not_verified_or_encrypted, ignore_not_verified_or_encrypted, LocalSource,
+    RemovedVanishedStats, SkipInfo, SkipReason, SyncSource, SyncStats,
 };
 use crate::api2::config::remote;
 
diff --git a/src/server/sync.rs b/src/server/sync.rs
index aedf4a27..47badf1f 100644
--- a/src/server/sync.rs
+++ b/src/server/sync.rs
@@ -570,27 +570,6 @@ impl std::fmt::Display for SkipInfo {
     }
 }
 
-/// Check if a sync from source to target of given namespaces exceeds the global namespace depth limit
-pub(crate) fn check_namespace_depth_limit(
-    source_namespace: &BackupNamespace,
-    target_namespace: &BackupNamespace,
-    namespaces: &[BackupNamespace],
-) -> Result<(), Error> {
-    let target_ns_depth = target_namespace.depth();
-    let sync_ns_depth = namespaces
-        .iter()
-        .map(BackupNamespace::depth)
-        .max()
-        .map_or(0, |v| v - source_namespace.depth());
-
-    if sync_ns_depth + target_ns_depth > MAX_NAMESPACE_DEPTH {
-        bail!(
-            "Syncing would exceed max allowed namespace depth. ({sync_ns_depth}+{target_ns_depth} > {MAX_NAMESPACE_DEPTH})",
-        );
-    }
-    Ok(())
-}
-
 /// Run a sync job in given direction
 pub fn do_sync_job(
     mut job: Job,
-- 
2.47.3





  parent reply	other threads:[~2026-04-22 13:40 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-22 13:39 [PATCH proxmox-backup v8 00/13] fixes #6195: add support for moving groups and namespaces Hannes Laimer
2026-04-22 13:39 ` [PATCH proxmox-backup v8 01/13] ui: show empty groups Hannes Laimer
2026-04-22 13:39 ` Hannes Laimer [this message]
2026-04-22 13:39 ` [PATCH proxmox-backup v8 03/13] datastore: have BackupGroup::destroy consume the group lock Hannes Laimer
2026-04-22 13:39 ` [PATCH proxmox-backup v8 04/13] datastore: split remove_namespace into flat and recursive variants Hannes Laimer
2026-04-22 13:39 ` [PATCH proxmox-backup v8 05/13] datastore: add move journal for coordinating with gc phase 1 Hannes Laimer
2026-04-22 13:39 ` [PATCH proxmox-backup v8 06/13] datastore: add move-group Hannes Laimer
2026-04-22 13:39 ` [PATCH proxmox-backup v8 07/13] datastore: add move-namespace Hannes Laimer
2026-04-22 13:39 ` [PATCH proxmox-backup v8 08/13] docs: add section on moving namespaces and groups Hannes Laimer
2026-04-22 13:39 ` [PATCH proxmox-backup v8 09/13] api: add POST endpoint for move-group Hannes Laimer
2026-04-22 13:39 ` [PATCH proxmox-backup v8 10/13] api: add POST endpoint for move-namespace Hannes Laimer
2026-04-22 13:39 ` [PATCH proxmox-backup v8 11/13] ui: add move group action Hannes Laimer
2026-04-23 13:35   ` Michael Köppl
2026-04-23 13:47     ` Hannes Laimer
2026-04-22 13:39 ` [PATCH proxmox-backup v8 12/13] ui: add move namespace action Hannes Laimer
2026-04-23 14:49   ` Michael Köppl
2026-04-22 13:39 ` [PATCH proxmox-backup v8 13/13] cli: add move-namespace and move-group commands Hannes Laimer
2026-04-23 16:29 ` [PATCH proxmox-backup v8 00/13] fixes #6195: add support for moving groups and namespaces Michael Köppl
2026-04-23 22:38 ` applied: " Thomas Lamprecht
2026-04-24  8:31   ` Fabian Grünbichler
2026-04-24  8:43     ` Hannes Laimer

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=20260422133951.192862-3-h.laimer@proxmox.com \
    --to=h.laimer@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