[pbs-devel] [PATCH proxmox-backup 04/15] backup: add check_if_available function to ds
Hannes Laimer
h.laimer at proxmox.com
Thu Aug 19 13:03:32 CEST 2021
Makes sure a removable datastore is available, meaning it is plugged in
and mounted correctly. For not removable datastores the function will
never result in an Error, since they're always available.
---
src/backup/datastore.rs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs
index 848459e8..ef3400d7 100644
--- a/src/backup/datastore.rs
+++ b/src/backup/datastore.rs
@@ -52,6 +52,24 @@ pub fn check_backup_owner(
Ok(())
}
+pub fn check_if_available(config: &datastore::DataStoreConfig) -> Result<(), Error> {
+ if let (Some(uuid), Some(config_mount_point)) = (
+ config.backing_device.clone(),
+ config.backing_device_mount_point.clone(),
+ ) {
+ match tools::disks::get_mount_point_by_uuid(&uuid) {
+ Ok(mount_point) if mount_point.eq(&config_mount_point) => Ok(()),
+ _ => Err(format_err!(
+ "The removale device for datastore '{}' has to be mounted at '{}'!",
+ config.name,
+ config_mount_point
+ )),
+ }
+ } else {
+ Ok(())
+ }
+}
+
/// Datastore Management
///
/// A Datastore can store severals backups, and provides the
@@ -69,6 +87,9 @@ impl DataStore {
let (config, _digest) = datastore::config()?;
let config: datastore::DataStoreConfig = config.lookup("datastore", name)?;
+
+ check_if_available(&config)?;
+
let path = PathBuf::from(&config.path);
let mut map = DATASTORE_MAP.lock().unwrap();
@@ -103,6 +124,8 @@ impl DataStore {
}
fn open_with_path(store_name: &str, path: &Path, config: DataStoreConfig) -> Result<Self, Error> {
+ check_if_available(&config)?;
+
let chunk_store = ChunkStore::open(store_name, path)?;
let mut gc_status_path = chunk_store.base_path();
--
2.30.2
More information about the pbs-devel
mailing list