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 2961D7019E for ; Fri, 3 Sep 2021 09:18:24 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1F29C188ED for ; Fri, 3 Sep 2021 09:17:54 +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 8C91E188E3 for ; Fri, 3 Sep 2021 09:17:53 +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 5F6B7444AF for ; Fri, 3 Sep 2021 09:17:53 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Fri, 3 Sep 2021 09:17:51 +0200 Message-Id: <20210903071752.1225271-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.447 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lib.rs] Subject: [pbs-devel] [RFC PATCH proxmox-backup 1/2] pbs-config: use trait object for the backup lock guard 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, 03 Sep 2021 07:18:24 -0000 instead of a fixed type. The old implementation is now BackupLockGuardImpl and implements the trait. At the same time, introduce a type alias with the same name as the previous struct, so that the users of it do not have to change anything. This makes it possible for us to have a different lock implementation for e.g. tests (where we do not actually want to lock) Signed-off-by: Dominik Csapak --- pbs-config/src/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pbs-config/src/lib.rs b/pbs-config/src/lib.rs index 9d8c730d..604fe9d7 100644 --- a/pbs-config/src/lib.rs +++ b/pbs-config/src/lib.rs @@ -16,7 +16,14 @@ pub fn backup_group() -> Result { pbs_tools::sys::query_group(BACKUP_GROUP_NAME)? .ok_or_else(|| format_err!("Unable to lookup '{}' group.", BACKUP_GROUP_NAME)) } -pub struct BackupLockGuard(std::fs::File); + +pub trait BackupLockGuardTrait: Send + Sync + Unpin + std::panic::UnwindSafe + std::panic::RefUnwindSafe { } + +struct BackupLockGuardImpl(std::fs::File); + +impl BackupLockGuardTrait for BackupLockGuardImpl {} + +pub type BackupLockGuard = Box; /// Open or create a lock file owned by user "backup" and lock it. /// @@ -39,7 +46,7 @@ pub fn open_backup_lockfile>( let timeout = timeout.unwrap_or(std::time::Duration::new(10, 0)); let file = proxmox::tools::fs::open_file_locked(&path, timeout, exclusive, options)?; - Ok(BackupLockGuard(file)) + Ok(Box::new(BackupLockGuardImpl(file))) } /// Atomically write data to file owned by "root:backup" with permission "0640" -- 2.30.2