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 00D727084B for ; Mon, 6 Sep 2021 12:25:30 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D2A1DF56B for ; Mon, 6 Sep 2021 12:25:30 +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 2B4B9F560 for ; Mon, 6 Sep 2021 12:25:30 +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 BE3D8445BC for ; Mon, 6 Sep 2021 12:25:29 +0200 (CEST) Date: Mon, 6 Sep 2021 12:25:28 +0200 From: Wolfgang Bumiller To: Dominik Csapak Cc: pbs-devel@lists.proxmox.com Message-ID: <20210906102528.3bp6fotg4zoaqazb@olga.proxmox.com> References: <20210903071752.1225271-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210903071752.1225271-1-d.csapak@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.617 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 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:25:31 -0000 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