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 8111871168 for ; Fri, 1 Oct 2021 14:07:10 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6DE672B7CF for ; Fri, 1 Oct 2021 14:06:40 +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 0CD212B7C2 for ; Fri, 1 Oct 2021 14:06:37 +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 C7558453EF for ; Fri, 1 Oct 2021 14:06:36 +0200 (CEST) Date: Fri, 1 Oct 2021 14:06:35 +0200 From: Wolfgang Bumiller To: Hannes Laimer Cc: pbs-devel@lists.proxmox.com, Dominik Csapak Message-ID: <20211001120635.eqr5plsa3fsyigpw@wobu-vie.proxmox.com> References: <20210928100548.4873-1-h.laimer@proxmox.com> <20210928100548.4873-3-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210928100548.4873-3-h.laimer@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.607 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] [PATCH proxmox-backup 2/5] pbs-datastore: add check_maintenence function 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, 01 Oct 2021 12:07:10 -0000 On Tue, Sep 28, 2021 at 12:05:45PM +0200, Hannes Laimer wrote: > This function checks if something is allowed in a specific maintenance > type, it has to be called whenever something depends on maintenance to > be off or less rescrictive than a specific type. > --- > pbs-datastore/src/datastore.rs | 18 +++++++++++++++++- > 1 file changed, 17 insertions(+), 1 deletion(-) > > diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs > index b068a9c9..1014b357 100644 > --- a/pbs-datastore/src/datastore.rs > +++ b/pbs-datastore/src/datastore.rs > @@ -11,7 +11,7 @@ use lazy_static::lazy_static; > > use proxmox::tools::fs::{replace_file, file_read_optional_string, CreateOptions}; > > -use pbs_api_types::{UPID, DataStoreConfig, Authid, GarbageCollectionStatus}; > +use pbs_api_types::{UPID, DataStoreConfig, Authid, GarbageCollectionStatus, MaintenanceType}; > use pbs_tools::format::HumanByte; > use pbs_tools::fs::{lock_dir_noblock, DirLockGuard}; > use pbs_tools::process_locker::ProcessLockSharedGuard; > @@ -98,6 +98,22 @@ impl DataStore { > Ok(()) > } > > + /// checks if the current maintenace mode of the datastore allows something > + pub fn check_maintenance(&self, need_less_than: MaintenanceType) -> Result<(), Error> { I'd very much like the method name itself to suggest the direction of such a check, rather than have only the parameter name tell you this, not even the doc comment ;-) When you read `datastore.check_maintenance(foo)` the parameter name isn't actually visible in code, but the code should speak for itself. And like Dominik said, it's a confusing interface. Plus, I can't think if a really good name for the method that fixes my remark above. So maybe the public facing interface should just be: pub fn can_read(&self) -> bool; pub fn can_write(&self) -> bool; and/or pub fn check_read(&self) -> Result<(), Error>; pub fn check_write(&self) -> Result<(), Error>; with the error including the maintenance message > + let (config, _digest) = pbs_config::datastore::config()?; > + let config: DataStoreConfig = config.lookup("datastore", &self.name())?; > + if let Some(maintenance_type) = config.maintenance_type { > + if maintenance_type >= need_less_than { > + bail!("Datastore '{}' is in maintenance {} mode: {}", > + &self.name(), > + maintenance_type, > + config.maintenance_msg.unwrap_or(String::from("no description")) > + ); > + } > + } > + Ok(()) > + } > + > fn open_with_path(store_name: &str, path: &Path, config: DataStoreConfig) -> Result { > let chunk_store = ChunkStore::open(store_name, path)?; > > -- > 2.30.2