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 5E36F6D5F6 for ; Tue, 28 Sep 2021 12:05:57 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5A1FEC2B3 for ; Tue, 28 Sep 2021 12:05:57 +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 CED2EC289 for ; Tue, 28 Sep 2021 12:05:55 +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 A23884247C for ; Tue, 28 Sep 2021 12:05:55 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Tue, 28 Sep 2021 12:05:45 +0200 Message-Id: <20210928100548.4873-3-h.laimer@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210928100548.4873-1-h.laimer@proxmox.com> References: <20210928100548.4873-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.093 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. [datastore.rs] Subject: [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: Tue, 28 Sep 2021 10:05:57 -0000 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> { + 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