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 C062069862 for ; Fri, 7 Aug 2020 10:18:42 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BDC2822F67 for ; Fri, 7 Aug 2020 10:18:42 +0200 (CEST) Received: from elsa.proxmox.com (212-186-127-178.static.upcbusiness.at [212.186.127.178]) by firstgate.proxmox.com (Proxmox) with ESMTP id CDE9122F38 for ; Fri, 7 Aug 2020 10:18:41 +0200 (CEST) Received: by elsa.proxmox.com (Postfix, from userid 0) id BB3D7AE3B5E; Fri, 7 Aug 2020 10:18:41 +0200 (CEST) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com, s.reiter@proxmox.com Date: Fri, 7 Aug 2020 10:18:23 +0200 Message-Id: <20200807081823.17200-4-dietmar@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200807081823.17200-1-dietmar@proxmox.com> References: <20200807081823.17200-1-dietmar@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -1.011 Adjusted score from AWL reputation of From: address 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 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] Subject: [pbs-devel] [PATCH proxmox-backup 3/3] src/backup/backup_info.rs: remove BackupInfo lock() 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: Fri, 07 Aug 2020 08:18:42 -0000 And use new lock_dir_noblock() instead. --- src/backup/backup_info.rs | 53 +++------------------------------------ src/backup/datastore.rs | 4 +-- 2 files changed, 6 insertions(+), 51 deletions(-) diff --git a/src/backup/backup_info.rs b/src/backup/backup_info.rs index df2349b..d6e9551 100644 --- a/src/backup/backup_info.rs +++ b/src/backup/backup_info.rs @@ -3,18 +3,13 @@ use crate::tools; use anyhow::{bail, format_err, Error}; use regex::Regex; use std::os::unix::io::RawFd; -use nix::dir::Dir; -use std::time::Duration; use chrono::{DateTime, TimeZone, SecondsFormat, Utc}; use std::path::{PathBuf, Path}; use lazy_static::lazy_static; -use proxmox::sys::error::SysError; - use super::manifest::MANIFEST_BLOB_NAME; -use crate::tools::fs::lock_dir_noblock; macro_rules! BACKUP_ID_RE { () => (r"[A-Za-z0-9][A-Za-z0-9_-]+") } macro_rules! BACKUP_TYPE_RE { () => (r"(?:host|vm|ct)") } @@ -41,9 +36,6 @@ lazy_static!{ } -/// Opaque type releasing the corresponding flock when dropped -pub type BackupLockGuard = Dir; - /// BackupGroup is a directory containing a list of BackupDir #[derive(Debug, Eq, PartialEq, Hash, Clone)] pub struct BackupGroup { @@ -95,7 +87,6 @@ impl BackupGroup { list.push(BackupInfo { backup_dir, files, - base_path: base_path.to_owned() }); Ok(()) @@ -270,8 +261,8 @@ pub struct BackupInfo { pub backup_dir: BackupDir, /// List of data files pub files: Vec, - /// Full path to dir containing backup_dir - pub base_path: PathBuf, + // Full path to dir containing backup_dir + //pub base_path: PathBuf, } impl BackupInfo { @@ -282,7 +273,7 @@ impl BackupInfo { let files = list_backup_files(libc::AT_FDCWD, &path)?; - Ok(BackupInfo { backup_dir, files, base_path: base_path.to_owned() }) + Ok(BackupInfo { backup_dir, files }) } /// Finds the latest backup inside a backup group @@ -330,8 +321,7 @@ impl BackupInfo { list.push(BackupInfo { backup_dir, files, - base_path: base_path.to_owned() - }); + }); Ok(()) }) @@ -344,41 +334,6 @@ impl BackupInfo { // backup is considered unfinished if there is no manifest self.files.iter().any(|name| name == super::MANIFEST_BLOB_NAME) } - - pub fn lock(&self) -> Result { - use nix::fcntl::OFlag; - use nix::sys::stat::Mode; - - let mut path = self.base_path.clone(); - let dir = self.backup_dir.relative_path(); - path.push(&dir); - - let mut handle = Dir::open(&path, OFlag::O_RDONLY, Mode::empty()) - .map_err(|err| { - format_err!( - "unable to open snapshot directory {:?} for locking - {}", - &dir, - err, - ) - })?; - - // 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(Duration::from_nanos(0))) - .map_err(|err| { - format_err!( - "unable to acquire lock on snapshot {:?} - {}", - &dir, - if err.would_block() { - String::from("snapshot is running or being used as base") - } else { - err.to_string() - } - ) - })?; - - Ok(handle) - } } fn list_backup_files(dirfd: RawFd, path: &P) -> Result, Error> { diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index dbd42d6..3bed167 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -11,7 +11,7 @@ use serde_json::Value; use proxmox::tools::fs::{replace_file, CreateOptions}; -use super::backup_info::{BackupGroup, BackupDir, BackupInfo}; +use super::backup_info::{BackupGroup, BackupDir}; use super::chunk_store::ChunkStore; use super::dynamic_index::{DynamicIndexReader, DynamicIndexWriter}; use super::fixed_index::{FixedIndexReader, FixedIndexWriter}; @@ -222,7 +222,7 @@ impl DataStore { let _guard; if !force { - _guard = BackupInfo::new(&self.base_path(), backup_dir.clone())?.lock()?; + _guard = tools::fs::lock_dir_noblock(&full_path, "snapshot", "backup is running or snapshot is used as base")?; } log::info!("removing backup snapshot {:?}", full_path); -- 2.20.1