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 08/15] pbs: add mount-removable command to commandSocket
Date: Thu, 19 Aug 2021 13:03:36 +0200	[thread overview]
Message-ID: <20210819110343.8708-9-h.laimer@proxmox.com> (raw)
In-Reply-To: <20210819110343.8708-1-h.laimer@proxmox.com>

Adds 'mount-removable' command to superuser commandSocket, this command
is needed for automatic mountntig of removable datastores. When udev
rules are executed, the process and whatever is forked from it will be
killed almost immediately, therefore the mounting has to done
asynchronously.
---
 src/backup/mod.rs             |  2 +-
 src/bin/proxmox-backup-api.rs | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/backup/mod.rs b/src/backup/mod.rs
index c0ab041c..1c489471 100644
--- a/src/backup/mod.rs
+++ b/src/backup/mod.rs
@@ -86,7 +86,7 @@ pub use pbs_datastore::read_chunk::*;
 mod read_chunk;
 pub use read_chunk::*;
 
-mod datastore;
+pub mod datastore;
 pub use datastore::*;
 
 mod verify;
diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs
index 75104205..fa6b6398 100644
--- a/src/bin/proxmox-backup-api.rs
+++ b/src/bin/proxmox-backup-api.rs
@@ -6,6 +6,7 @@ use proxmox::api::RpcEnvironmentType;
 
 use pbs_tools::auth::private_auth_key;
 
+use proxmox_backup::api2::types::Authid;
 use proxmox_backup::server::{
     self,
     auth::default_api_auth,
@@ -66,6 +67,32 @@ async fn run() -> Result<(), Error> {
 
     let mut commando_sock = server::CommandoSocket::new(server::our_ctrl_sock());
 
+    commando_sock.register_command("mount-removable".to_string(), |value| {
+        if let Some(serde_json::Value::String(uuid)) = value {
+            let (config, _digest) = proxmox_backup::config::datastore::config()?;
+            if let Some(store) = &config
+                .sections
+                .iter()
+                .filter_map(|(store, (_, _))| {
+                    config
+                        .lookup::<proxmox_backup::config::datastore::DataStoreConfig>(
+                            "datastore",
+                            &store,
+                        )
+                        .map_or(None, |config| match config.backing_device {
+                            Some(ref config_uuid) if config_uuid.eq(uuid) => Some(config.name),
+                            _ => None,
+                        })
+                })
+                .next()
+            {
+                let auth_id = Authid::root_auth_id().clone();
+                proxmox_backup::api2::admin::datastore::do_mount(String::from(store), &auth_id)?;
+            }
+        };
+        Ok(serde_json::Value::Null)
+    })?;
+
     config.enable_file_log(pbs_buildcfg::API_ACCESS_LOG_FN, &mut commando_sock)?;
 
     let rest_server = RestServer::new(config);
-- 
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 ` [pbs-devel] [PATCH proxmox-backup 04/15] backup: add check_if_available function to ds Hannes Laimer
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 ` Hannes Laimer [this message]
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-9-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