[pbs-devel] [PATCH proxmox-backup v3 13/24] api: mark removable datastores as unplugged after restart

Hannes Laimer h.laimer at proxmox.com
Tue Apr 9 13:00:01 CEST 2024


... if it is not mounted

Signed-off-by: Hannes Laimer <h.laimer at proxmox.com>
---
 src/bin/proxmox-backup-api.rs | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs
index e46557a0..50f31d4e 100644
--- a/src/bin/proxmox-backup-api.rs
+++ b/src/bin/proxmox-backup-api.rs
@@ -10,6 +10,8 @@ use proxmox_lang::try_block;
 use proxmox_router::RpcEnvironmentType;
 use proxmox_sys::fs::CreateOptions;
 
+use pbs_api_types::{DataStoreConfig, MaintenanceMode, MaintenanceType};
+use pbs_datastore::check_if_available;
 use proxmox_rest_server::{daemon, ApiConfig, RestServer};
 
 use proxmox_backup::auth_helpers::*;
@@ -73,6 +75,8 @@ async fn run() -> Result<(), Error> {
 
     proxmox_backup::auth_helpers::setup_auth_context(true);
 
+    mark_removable_datastores_unplugged()?;
+
     let backup_user = pbs_config::backup_user()?;
     let mut command_sock = proxmox_rest_server::CommandSocket::new(
         proxmox_rest_server::our_ctrl_sock(),
@@ -161,3 +165,17 @@ async fn run() -> Result<(), Error> {
 
     Ok(())
 }
+
+fn mark_removable_datastores_unplugged() -> Result<(), Error> {
+    let (mut config, _digest) = pbs_config::datastore::config()?;
+    let list: Vec<DataStoreConfig> = config.convert_to_typed_array("datastore")?;
+    for mut datastore in list {
+        if check_if_available(&datastore).is_err() {
+            datastore
+                .set_maintenance_mode(Some(MaintenanceMode::new(MaintenanceType::Unplugged, None)));
+            config.set_data(&datastore.name, "datastore", &datastore)?;
+        }
+    }
+    pbs_config::datastore::save_config(&config)?;
+    Ok(())
+}
-- 
2.39.2





More information about the pbs-devel mailing list