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 3D9AB61015 for ; Tue, 8 Feb 2022 10:44:05 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 270E82C96A for ; Tue, 8 Feb 2022 10:43:35 +0100 (CET) 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 872F62C961 for ; Tue, 8 Feb 2022 10:43:34 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 5C4A440B15 for ; Tue, 8 Feb 2022 10:43:34 +0100 (CET) Date: Tue, 8 Feb 2022 10:43:32 +0100 From: Wolfgang Bumiller To: Hannes Laimer Cc: pbs-devel@lists.proxmox.com Message-ID: <20220208094332.xksrhybcrilcer3x@olga.proxmox.com> References: <20220204111729.22107-1-h.laimer@proxmox.com> <20220204111729.22107-3-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220204111729.22107-3-h.laimer@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.395 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 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [restore.rs, datastore.rs, proxmox-backup-proxy.rs, status.rs, mod.rs, pull.rs, backup.rs] Subject: Re: [pbs-devel] [PATCH proxmox-backup v7 2/6] datastore: add check for maintenance in lookup 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: Tue, 08 Feb 2022 09:44:05 -0000 On Fri, Feb 04, 2022 at 11:17:25AM +0000, Hannes Laimer wrote: > Signed-off-by: Hannes Laimer > --- > pbs-datastore/src/datastore.rs | 19 ++++++++--- > pbs-datastore/src/snapshot_reader.rs | 6 +++- > src/api2/admin/datastore.rs | 50 ++++++++++++++-------------- > src/api2/backup/mod.rs | 4 +-- > src/api2/reader/mod.rs | 6 ++-- > src/api2/status.rs | 4 +-- > src/api2/tape/backup.rs | 6 ++-- > src/api2/tape/restore.rs | 6 ++-- > src/bin/proxmox-backup-proxy.rs | 4 +-- > src/server/prune_job.rs | 4 +-- > src/server/pull.rs | 4 +-- > src/server/verify_job.rs | 4 +-- > 12 files changed, 66 insertions(+), 51 deletions(-) > > diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs > index 37ef753e..c65d4574 100644 > --- a/pbs-datastore/src/datastore.rs > +++ b/pbs-datastore/src/datastore.rs > @@ -15,7 +15,9 @@ use proxmox_sys::WorkerTaskContext; > use proxmox_sys::{task_log, task_warn}; > use proxmox_sys::fs::{lock_dir_noblock, DirLockGuard}; > > -use pbs_api_types::{UPID, DataStoreConfig, Authid, GarbageCollectionStatus, HumanByte}; > +use pbs_api_types::{ > + UPID, DataStoreConfig, Authid, MaintenanceType, Operation, GarbageCollectionStatus, HumanByte > +}; > use pbs_config::{open_backup_lockfile, BackupLockGuard}; > > use crate::DataBlob; > @@ -60,13 +62,22 @@ pub struct DataStore { > } > > impl DataStore { > - > - pub fn lookup_datastore(name: &str) -> Result, Error> { > - > + pub fn lookup_datastore( > + name: &str, > + operation: Option, > + ) -> Result, Error> { > let (config, _digest) = pbs_config::datastore::config()?; > let config: DataStoreConfig = config.lookup("datastore", name)?; > let path = PathBuf::from(&config.path); > > + match (&config.maintenance_type, operation) { > + (Some(MaintenanceType::ReadOnly(message)), Some(Operation::Write)) > + | (Some(MaintenanceType::Offline(message)), Some(_)) => { > + bail!("Datastore '{}' is in maintenance mode: {}", name, message); I'd like to see the current-confg vs requested operation check logic as a method of the `MaintenanceType` actually. Even if we only use it once for now, I think the code will be much nicer this way. This could one of: impl MaintenanceType { fn check(current: &Option, other: &Option) -> Result<(), Error>; fn check(&self, other: &Option) -> Result<(), Error>; } resulting in either: MaintenanceType::check(&config.maintenance_type, operation) or if let Some(cur) = config.maintenance_type.clone() { cur.check(&operation)?; } both are also easier on the eyes than a multi-line match pattern ;-)