From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 3B7AE60328 for ; Wed, 14 Oct 2020 14:17:19 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 324189B0B for ; Wed, 14 Oct 2020 14:16:49 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 1FB689AA2 for ; Wed, 14 Oct 2020 14:16:47 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D646F45D67 for ; Wed, 14 Oct 2020 14:16:46 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Wed, 14 Oct 2020 14:16:31 +0200 Message-Id: <20201014121639.25276-4-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201014121639.25276-1-s.reiter@proxmox.com> References: <20201014121639.25276-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.039 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [fs.rs, backup.rs] Subject: [pbs-devel] [PATCH proxmox-backup 03/11] backup: use shared flock for base snapshot 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: , X-List-Received-Date: Wed, 14 Oct 2020 12:17:19 -0000 To allow other reading operations on the base snapshot as well. No semantic changes with this patch alone, as all other locks on snapshots are exclusive. Signed-off-by: Stefan Reiter --- src/api2/backup.rs | 4 ++-- src/tools/fs.rs | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/api2/backup.rs b/src/api2/backup.rs index 8a2a2409..8b2b0e1a 100644 --- a/src/api2/backup.rs +++ b/src/api2/backup.rs @@ -16,7 +16,7 @@ use crate::backup::*; use crate::api2::types::*; use crate::config::acl::PRIV_DATASTORE_BACKUP; use crate::config::cached_user_info::CachedUserInfo; -use crate::tools::fs::lock_dir_noblock; +use crate::tools::fs::lock_dir_noblock_shared; mod environment; use environment::*; @@ -144,7 +144,7 @@ async move { // lock last snapshot to prevent forgetting/pruning it during backup let full_path = datastore.snapshot_path(&last.backup_dir); - Some(lock_dir_noblock(&full_path, "snapshot", "base snapshot is already locked by another operation")?) + Some(lock_dir_noblock_shared(&full_path, "snapshot", "base snapshot is already locked by another operation")?) } else { None }; diff --git a/src/tools/fs.rs b/src/tools/fs.rs index 5aaaecda..72a530d8 100644 --- a/src/tools/fs.rs +++ b/src/tools/fs.rs @@ -265,11 +265,31 @@ impl Default for FSXAttr { } } +/// Attempt to acquire a shared flock on the given path, 'what' and +/// 'would_block_message' are used for error formatting. +pub fn lock_dir_noblock_shared( + path: &std::path::Path, + what: &str, + would_block_msg: &str, +) -> Result { + do_lock_dir_noblock(path, what, would_block_msg, false) +} +/// Attempt to acquire an exclusive flock on the given path, 'what' and +/// 'would_block_message' are used for error formatting. pub fn lock_dir_noblock( path: &std::path::Path, what: &str, would_block_msg: &str, +) -> Result { + do_lock_dir_noblock(path, what, would_block_msg, true) +} + +fn do_lock_dir_noblock( + path: &std::path::Path, + what: &str, + would_block_msg: &str, + exclusive: bool, ) -> Result { let mut handle = Dir::open(path, OFlag::O_RDONLY, Mode::empty()) .map_err(|err| { @@ -278,7 +298,7 @@ pub fn lock_dir_noblock( // acquire in non-blocking mode, no point in waiting here since other // backups could still take a very long time - proxmox::tools::fs::lock_file(&mut handle, true, Some(std::time::Duration::from_nanos(0))) + proxmox::tools::fs::lock_file(&mut handle, exclusive, Some(std::time::Duration::from_nanos(0))) .map_err(|err| { format_err!( "unable to acquire lock on {} directory {:?} - {}", what, path, -- 2.20.1