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 7E6DA7085D for ; Mon, 6 Sep 2021 12:41:55 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 72826F765 for ; Mon, 6 Sep 2021 12:41:25 +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 E74DDF757 for ; Mon, 6 Sep 2021 12:41:24 +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 A9759445BB; Mon, 6 Sep 2021 12:41:24 +0200 (CEST) Message-ID: <645015c1-6a9e-a744-a931-234e4ba1027c@proxmox.com> Date: Mon, 6 Sep 2021 12:41:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Thunderbird/92.0 Content-Language: en-US To: Wolfgang Bumiller Cc: pbs-devel@lists.proxmox.com References: <20210903071752.1225271-1-d.csapak@proxmox.com> <20210906102528.3bp6fotg4zoaqazb@olga.proxmox.com> From: Dominik Csapak In-Reply-To: <20210906102528.3bp6fotg4zoaqazb@olga.proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 1.611 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 NICE_REPLY_A -2.332 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [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: Mon, 06 Sep 2021 10:41:55 -0000 On 9/6/21 12:25, Wolfgang Bumiller wrote: > On Fri, Sep 03, 2021 at 09:17:51AM +0200, Dominik Csapak wrote: >> 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; > > Since the File is abstracted away in a custom type, 2 more possibilities > come to mind: > > pub struct BackupLockGuard(Option); > > and cfg(test) would just use `None` > > or turn the File into our `Fd` type from the proxmox crate and use > `Fd::from_raw_fd(-1)` when no lock is used > > That way we don't even need the trait > sound ok in general, but then we have to make the field public no ? and then we could also open a bug file too, no change in the type needed at all... but i thought we want to avoid making the underlying field public...