[pbs-devel] [PATCH v2 proxmox-backup 05/15] api2: add 'is_available' to DataStoreConfig

Hannes Laimer h.laimer at proxmox.com
Mon Aug 30 13:14:55 CEST 2021


---
 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<DataStoreStatus, Error> {
+    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<GarbageCollectionStatus>,
-- 
2.30.2






More information about the pbs-devel mailing list