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 E8D716DD82 for ; Thu, 19 Aug 2021 13:04:41 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8232014CB4 for ; Thu, 19 Aug 2021 13:04:11 +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 B50D01457E for ; Thu, 19 Aug 2021 13:04:06 +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 8FF3843479 for ; Thu, 19 Aug 2021 13:04:06 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Thu, 19 Aug 2021 13:03:33 +0200 Message-Id: <20210819110343.8708-6-h.laimer@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210819110343.8708-1-h.laimer@proxmox.com> References: <20210819110343.8708-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.237 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: [pbs-devel] [PATCH proxmox-backup 05/15] api2: add 'is_available' to DataStoreConfig 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: Thu, 19 Aug 2021 11:04:41 -0000 --- src/api2/admin/datastore.rs | 14 ++++++++++++++ src/api2/status.rs | 19 ++++++++++++++++++- src/api2/types/mod.rs | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index f3c52413..16559678 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -606,6 +606,19 @@ pub fn status( _info: &ApiMethod, rpcenv: &mut dyn RpcEnvironment, ) -> Result { + let (config, _digest) = datastore::config()?; + let store_config = config.lookup("datastore", &store)?; + if !check_if_available(&store_config).is_ok() { + return Ok(DataStoreStatus { + total: 0, + used: 0, + avail: 0, + is_available: false, + gc_status: None, + counts: None, + }); + } + let datastore = DataStore::lookup_datastore(&store)?; let storage = crate::tools::disks::disk_usage(&datastore.base_path())?; let (counts, gc_status) = if verbose { @@ -631,6 +644,7 @@ pub fn status( total: storage.total, used: storage.used, avail: storage.avail, + is_available: true, gc_status, counts, }) diff --git a/src/api2/status.rs b/src/api2/status.rs index 3aff91e7..06990743 100644 --- a/src/api2/status.rs +++ b/src/api2/status.rs @@ -21,7 +21,7 @@ use crate::api2::types::{ Authid, }; -use crate::backup::DataStore; +use crate::backup::{check_if_available, DataStore}; use crate::config::datastore; use crate::tools::statistics::{linear_regression}; use crate::config::cached_user_info::CachedUserInfo; @@ -53,6 +53,10 @@ use crate::config::acl::{ type: Integer, description: "The available bytes of the underlying storage", }, + "is-available": { + type: bool, + description: "The datastore is available, relevent if it is removable", + }, history: { type: Array, optional: true, @@ -103,6 +107,18 @@ pub fn datastore_status( continue; } + let store_config = config.lookup("datastore", &store)?; + if !check_if_available(&store_config).is_ok() { + list.push(json!({ + "store": store, + "total": -1, + "used": -1, + "avail": -1, + "is-available": false, + })); + continue; + } + let datastore = match DataStore::lookup_datastore(&store) { Ok(datastore) => datastore, Err(err) => { @@ -123,6 +139,7 @@ pub fn datastore_status( "total": status.total, "used": status.used, "avail": status.avail, + "is-available": true, "gc-status": datastore.last_gc_status(), }); diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs index bd3c7ac5..4d9ed691 100644 --- a/src/api2/types/mod.rs +++ b/src/api2/types/mod.rs @@ -371,6 +371,8 @@ pub struct DataStoreStatus { pub used: u64, /// Available space (bytes). pub avail: u64, + /// Datastore is available, relevant if it is removable + pub is_available: bool, /// Status of last GC #[serde(skip_serializing_if="Option::is_none")] pub gc_status: Option, -- 2.30.2