From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 7C3061FF2D5 for ; Mon, 15 Jul 2024 12:16:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 83D5B123; Mon, 15 Jul 2024 12:17:19 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Mon, 15 Jul 2024 12:15:54 +0200 Message-Id: <20240715101602.274244-17-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240715101602.274244-1-c.ebner@proxmox.com> References: <20240715101602.274244-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.021 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 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] [RFC proxmox-backup 16/24] server: sync: factor out namespace depth check into sync module X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" By moving and refactoring the check for a sync job exceeding the global maximum namespace limit, the same function can be reused for sync jobs in push direction. Signed-off-by: Christian Ebner --- src/server/pull.rs | 20 +++----------------- src/server/sync.rs | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/server/pull.rs b/src/server/pull.rs index d18c6d643..3117f7d2c 100644 --- a/src/server/pull.rs +++ b/src/server/pull.rs @@ -28,8 +28,8 @@ use pbs_datastore::{check_backup_owner, DataStore, StoreProgress}; use pbs_tools::sha::sha256; use super::sync::{ - LocalSource, RemoteSource, RemovedVanishedStats, SkipInfo, SkipReason, SyncSource, - SyncSourceReader, SyncStats, + check_namespace_depth_limit, LocalSource, RemoteSource, RemovedVanishedStats, SkipInfo, + SkipReason, SyncSource, SyncSourceReader, SyncStats, }; use crate::backup::{check_ns_modification_privs, check_ns_privs}; use crate::tools::parallel_handler::ParallelHandler; @@ -735,21 +735,7 @@ pub(crate) async fn pull_store(mut params: PullParameters) -> Result MAX_NAMESPACE_DEPTH { - bail!( - "Syncing would exceed max allowed namespace depth. ({}+{} > {})", - ns_layers_to_be_pulled, - target_depth, - MAX_NAMESPACE_DEPTH - ); - } + check_namespace_depth_limit(¶ms.source.get_ns(), ¶ms.target.ns, &namespaces)?; errors |= old_max_depth != params.max_depth; // fail job if we switched to backwards-compat mode namespaces.sort_unstable_by_key(|a| a.name_len()); diff --git a/src/server/sync.rs b/src/server/sync.rs index ee40d0b9d..bd68dda46 100644 --- a/src/server/sync.rs +++ b/src/server/sync.rs @@ -547,3 +547,24 @@ 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(()) +} -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel