From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 7F0E46DD62 for ; Thu, 19 Aug 2021 13:04:43 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1681F14CB7 for ; Thu, 19 Aug 2021 13:04:12 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 7DB3814617 for ; Thu, 19 Aug 2021 13:04:07 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4F8A043457 for ; Thu, 19 Aug 2021 13:04:07 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Thu, 19 Aug 2021 13:03:36 +0200 Message-Id: <20210819110343.8708-9-h.laimer@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210819110343.8708-1-h.laimer@proxmox.com> References: <20210819110343.8708-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.218 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 08/15] pbs: add mount-removable command to commandSocket X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Aug 2021 11:04:43 -0000 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::( + "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