public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 04/15] backup: add check_if_available function to ds
Date: Thu, 19 Aug 2021 13:03:32 +0200	[thread overview]
Message-ID: <20210819110343.8708-5-h.laimer@proxmox.com> (raw)
In-Reply-To: <20210819110343.8708-1-h.laimer@proxmox.com>

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





  parent reply	other threads:[~2021-08-19 11:04 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-19 11:03 [pbs-devel] [PATCH proxmox-backup 00/15] (partially)close #3156: Add support for removable datastores Hannes Laimer
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 01/15] tools: add disks utility functions Hannes Laimer
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 02/15] config: add uuid+mountpoint to DataStoreConfig Hannes Laimer
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 03/15] api2: add support for removable datastore creation Hannes Laimer
2021-08-19 11:03 ` Hannes Laimer [this message]
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 05/15] api2: add 'is_available' to DataStoreConfig Hannes Laimer
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 06/15] api2: add 'removable' to DataStoreListItem Hannes Laimer
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 07/15] api2: add (un)mount endpoint for removable ds's Hannes Laimer
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 08/15] pbs: add mount-removable command to commandSocket Hannes Laimer
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 09/15] pbs-manager: add 'send-command' command Hannes Laimer
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 10/15] debian: add udev rule for removable datastores Hannes Laimer
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 11/15] ui: show usb icon for removable datastore in list Hannes Laimer
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 12/15] ui: add 'removable' checkbox in datastore creation Hannes Laimer
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 13/15] ui: display row as disabled in ds statistics Hannes Laimer
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 14/15] ui: show backing device UUID in option tab Hannes Laimer
2021-08-19 11:03 ` [pbs-devel] [PATCH proxmox-backup 15/15] ui: add (un)mount button to summary Hannes Laimer
2021-08-27  8:03 ` [pbs-devel] [PATCH proxmox-backup 00/15] (partially)close #3156: Add support for removable datastores Lorenz Stechauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210819110343.8708-5-h.laimer@proxmox.com \
    --to=h.laimer@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal