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 A2469CEA3 for ; Wed, 13 Apr 2022 11:11:57 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8B58620774 for ; Wed, 13 Apr 2022 11:11:57 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 89EC620757 for ; Wed, 13 Apr 2022 11:11:56 +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 5A299414B1 for ; Wed, 13 Apr 2022 11:11:56 +0200 (CEST) From: Stefan Sterz To: pbs-devel@lists.proxmox.com Date: Wed, 13 Apr 2022 11:11:50 +0200 Message-Id: <20220413091151.150019-4-s.sterz@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220413091151.150019-1-s.sterz@proxmox.com> References: <20220413091151.150019-1-s.sterz@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.023 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH proxmox-backup v2 3/4] fix #3935: datastore: move manifest locking to new locking method 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, 13 Apr 2022 09:11:57 -0000 adds double stat'ing and removes directory hierarchy to bring manifest locking in-line with other locks used by the datastore trait. Signed-off-by: Stefan Sterz --- pbs-datastore/src/datastore.rs | 56 +++++++++++++--------------------- 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs index 92d544e5..803dcef1 100644 --- a/pbs-datastore/src/datastore.rs +++ b/pbs-datastore/src/datastore.rs @@ -32,9 +32,7 @@ use crate::dynamic_index::{DynamicIndexReader, DynamicIndexWriter}; use crate::fixed_index::{FixedIndexReader, FixedIndexWriter}; use crate::index::IndexFile; use crate::manifest::{ - MANIFEST_BLOB_NAME, MANIFEST_LOCK_NAME, CLIENT_LOG_BLOB_NAME, - ArchiveType, BackupManifest, - archive_type, + archive_type, ArchiveType, BackupManifest, CLIENT_LOG_BLOB_NAME, MANIFEST_BLOB_NAME, }; use crate::task_tracking::update_active_operations; @@ -403,10 +401,7 @@ impl DataStore { })?; // the manifest does not exists anymore, we do not need to keep the lock - if let Ok(path) = self.manifest_lock_path(backup_dir) { - // ignore errors - let _ = std::fs::remove_file(path); - } + let _ = std::fs::remove_file(self.manifest_lock_path(backup_dir)); let _ = std::fs::remove_file(self.snapshot_lock_path(backup_dir)); @@ -858,41 +853,32 @@ impl DataStore { )) } - /// Returns the filename to lock a manifest + /// Returns the filename to lock a manifest. /// - /// Also creates the basedir. The lockfile is located in - /// '/run/proxmox-backup/locks/{datastore}/{type}/{id}/{timestamp}.index.json.lck' - fn manifest_lock_path( - &self, - backup_dir: &BackupDir, - ) -> Result { - let mut path = format!( - "/run/proxmox-backup/locks/{}/{}/{}", - self.name(), + /// The lock file will be located in: + /// `${DATASTORE_LOCKS_DIR}/${datastore name}/${lock_file_name_helper(rpath)}` + /// where rpath is the relative path of the snapshot appended with "manifest". + fn manifest_lock_path(&self, backup_dir: &BackupDir) -> PathBuf { + let path = Path::new(DATASTORE_LOCKS_DIR).join(self.name()); + + let rpath = format!( + "{}/{}/{}-manifest", backup_dir.group().backup_type(), backup_dir.group().backup_id(), + backup_dir.backup_time_string(), ); - std::fs::create_dir_all(&path)?; - use std::fmt::Write; - write!(path, "/{}{}", backup_dir.backup_time_string(), &MANIFEST_LOCK_NAME)?; - Ok(path) + path.join(self.lock_file_name_helper(&rpath)) } - fn lock_manifest( - &self, - backup_dir: &BackupDir, - ) -> Result { - let path = self.manifest_lock_path(backup_dir)?; - - // update_manifest should never take a long time, so if someone else has - // the lock we can simply block a bit and should get it soon - open_backup_lockfile(&path, Some(Duration::from_secs(5)), true) - .map_err(|err| { - format_err!( - "unable to acquire manifest lock {:?} - {}", &path, err - ) - }) + fn lock_manifest(&self, backup_dir: &BackupDir) -> Result { + self.lock_helper(&self.manifest_lock_path(backup_dir), |p| { + // update_manifest should never take a long time, so if + // someone else has the lock we can simply block a bit + // and should get it soon + open_backup_lockfile(&p, Some(Duration::from_secs(5)), true) + .map_err(|err| format_err!("unable to acquire manifest lock {:?} - {}", &p, err)) + }) } /// Load the manifest without a lock. Must not be written back. -- 2.30.2