From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 00C731FF164 for ; Fri, 22 Nov 2024 15:47:50 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1F34815A16; Fri, 22 Nov 2024 15:47:54 +0100 (CET) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Fri, 22 Nov 2024 15:47:08 +0100 Message-Id: <20241122144713.299130-22-h.laimer@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241122144713.299130-1-h.laimer@proxmox.com> References: <20241122144713.299130-1-h.laimer@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.026 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 v14 21/25] api: node: allow creation of removable datastore through directory endpoint 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: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Signed-off-by: Hannes Laimer --- changes since v13: * use one worker with few conditionals instead of two src/api2/node/disks/directory.rs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs index 7f5402207..b6006b47c 100644 --- a/src/api2/node/disks/directory.rs +++ b/src/api2/node/disks/directory.rs @@ -123,6 +123,11 @@ pub fn list_datastore_mounts() -> Result, Error> { description: "Configure a datastore using the directory.", type: bool, optional: true, + default: false, + }, + "removable-datastore": { + description: "The added datastore is removable.", + type: bool, }, filesystem: { type: FileSystemType, @@ -141,7 +146,8 @@ pub fn list_datastore_mounts() -> Result, Error> { pub fn create_datastore_disk( name: String, disk: String, - add_datastore: Option, + add_datastore: bool, + removable_datastore: bool, filesystem: Option, rpcenv: &mut dyn RpcEnvironment, ) -> Result { @@ -156,7 +162,6 @@ pub fn create_datastore_disk( } let mount_point = format!("{}{}", BASE_MOUNT_DIR, &name); - // check if the default path exists already. // bail if it is not empty or another filesystem mounted on top let default_path = std::path::PathBuf::from(&mount_point); @@ -183,7 +188,6 @@ pub fn create_datastore_disk( move |_worker| { info!("create datastore '{name}' on disk {disk}"); - let add_datastore = add_datastore.unwrap_or(false); let filesystem = filesystem.unwrap_or(FileSystemType::Ext4); let manager = DiskManage::new(); @@ -196,18 +200,24 @@ pub fn create_datastore_disk( let uuid = get_fs_uuid(&partition)?; let uuid_path = format!("/dev/disk/by-uuid/{}", uuid); - let mount_unit_name = - create_datastore_mount_unit(&name, &mount_point, filesystem, &uuid_path)?; + if !removable_datastore { + let mount_unit_name = + create_datastore_mount_unit(&name, &mount_point, filesystem, &uuid_path)?; - crate::tools::systemd::reload_daemon()?; - crate::tools::systemd::enable_unit(&mount_unit_name)?; - crate::tools::systemd::start_unit(&mount_unit_name)?; + crate::tools::systemd::reload_daemon()?; + crate::tools::systemd::enable_unit(&mount_unit_name)?; + crate::tools::systemd::start_unit(&mount_unit_name)?; + } if add_datastore { let lock = pbs_config::datastore::lock_config()?; - let datastore: DataStoreConfig = - serde_json::from_value(json!({ "name": name, "path": mount_point }))?; - + let datastore: DataStoreConfig = if removable_datastore { + serde_json::from_value( + json!({ "name": name, "path": format!("/{name}"), "backing-device": uuid }), + )? + } else { + serde_json::from_value(json!({ "name": name, "path": mount_point }))? + }; let (config, _digest) = pbs_config::datastore::config()?; if config.sections.contains_key(&datastore.name) { -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel