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 63F80602C9 for ; Wed, 14 Oct 2020 14:17:18 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5B5BA9ADA for ; Wed, 14 Oct 2020 14:16:48 +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 2456A9AAA 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 D985845D57 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:32 +0200 Message-Id: <20201014121639.25276-5-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.040 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. [datastore.rs, reader.rs] Subject: [pbs-devel] [PATCH proxmox-backup 04/11] reader: acquire shared flock on open 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:18 -0000 ...to avoid it being forgotten or pruned while in use. Update lock error message for deletions to be consistent. Signed-off-by: Stefan Reiter --- src/api2/reader.rs | 19 ++++++++++++++----- src/backup/datastore.rs | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/api2/reader.rs b/src/api2/reader.rs index 4c870eda..8f47047e 100644 --- a/src/api2/reader.rs +++ b/src/api2/reader.rs @@ -17,6 +17,7 @@ use crate::tools; use crate::config::acl::{PRIV_DATASTORE_READ, PRIV_DATASTORE_BACKUP}; use crate::config::cached_user_info::CachedUserInfo; use crate::api2::helpers; +use crate::tools::fs::lock_dir_noblock_shared; mod environment; use environment::*; @@ -98,6 +99,11 @@ fn upgrade_to_backup_reader_protocol( } } + let _guard = lock_dir_noblock_shared( + &datastore.snapshot_path(&backup_dir), + "snapshot", + "locked by another operation")?; + let path = datastore.base_path(); //let files = BackupInfo::list_files(&path, &backup_dir)?; @@ -146,11 +152,14 @@ fn upgrade_to_backup_reader_protocol( use futures::future::Either; futures::future::select(req_fut, abort_future) - .map(|res| match res { - Either::Left((Ok(res), _)) => Ok(res), - Either::Left((Err(err), _)) => Err(err), - Either::Right((Ok(res), _)) => Ok(res), - Either::Right((Err(err), _)) => Err(err), + .map(move |res| { + let _guard = _guard; + match res { + Either::Left((Ok(res), _)) => Ok(res), + Either::Left((Err(err), _)) => Err(err), + Either::Right((Ok(res), _)) => Ok(res), + Either::Right((Err(err), _)) => Err(err), + } }) .map_ok(move |_| env.log("reader finished successfully")) })?; diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 1f708293..a77c5f1d 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -227,7 +227,7 @@ impl DataStore { let _guard; if !force { - _guard = lock_dir_noblock(&full_path, "snapshot", "possibly running or used as base")?; + _guard = lock_dir_noblock(&full_path, "snapshot", "possibly running or in use")?; } log::info!("removing backup snapshot {:?}", full_path); -- 2.20.1