From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 674641FF189 for ; Thu, 4 Sep 2025 16:37:55 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8F2533254F; Thu, 4 Sep 2025 16:38:11 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Thu, 4 Sep 2025 16:37:35 +0200 Message-ID: <20250904143735.125857-7-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250904143735.125857-1-h.laimer@proxmox.com> References: <20250904143735.125857-1-h.laimer@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1756996640925 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.026 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] [PATCH proxmox-backup 4/4] api: backup: wait for semaphore if one exists 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" Backups will start in the order they started waiting, so basically a FIFO queue. Signed-off-by: Hannes Laimer --- src/api2/backup/mod.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/api2/backup/mod.rs b/src/api2/backup/mod.rs index ae61ff69..a52a736e 100644 --- a/src/api2/backup/mod.rs +++ b/src/api2/backup/mod.rs @@ -19,6 +19,8 @@ use proxmox_router::{ }; use proxmox_schema::*; use proxmox_sortable_macro::sortable; +use proxmox_sys::error::SysError; +use proxmox_sys::semaphore::PosixSemaphore; use pbs_api_types::{ ArchiveType, Authid, BackupNamespace, BackupType, Operation, VerifyState, @@ -226,6 +228,20 @@ fn upgrade_to_backup_protocol( Some(ip) => format!(" from {ip}"), None => "".into(), }; + let sem = match PosixSemaphore::open(&format!("/{}_concurrent", &store)) { + Ok(_) if benchmark => None, + Ok(sem) => Some(sem), + Err(ref err) if err.not_found() => None, + Err(err) => bail!("could not open semaphore: {err}"), + }; + + if let Some(ref sem) = sem { + if let Ok(false) = sem.try_wait() { + log::info!("max amount of concurrent tasks reached, waiting for one to finish..."); + sem.wait()?; + } + } + env.log(format!( "starting new {worker_type} on datastore '{store}'{origin}: {path:?}", )); @@ -295,7 +311,7 @@ fn upgrade_to_backup_protocol( } }; - match (res, env.ensure_finished()) { + let r = match (res, env.ensure_finished()) { (Ok(_), Ok(())) => { env.log("backup finished successfully"); verify(env); @@ -319,7 +335,11 @@ fn upgrade_to_backup_protocol( proxmox_async::runtime::block_in_place(|| env.remove_backup())?; Err(err) } - } + }; + if let Some(ref sem) = sem { + let _ = sem.post(); + }; + r }, )?; -- 2.47.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel