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 B9E626DC72 for ; Thu, 19 Aug 2021 13:04:36 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A55F514576 for ; Thu, 19 Aug 2021 13:04:06 +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 488B11441F for ; Thu, 19 Aug 2021 13:04:02 +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 17AB6434AE for ; Thu, 19 Aug 2021 13:04:02 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Thu, 19 Aug 2021 13:03:31 +0200 Message-Id: <20210819110343.8708-4-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.248 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 03/15] api2: add support for removable datastore creation 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:36 -0000 --- src/api2/config/datastore.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 7edc43d8..4ee52880 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -22,6 +22,7 @@ use crate::config::cached_user_info::CachedUserInfo; use crate::config::datastore::{self, DataStoreConfig}; use crate::config::acl::{PRIV_DATASTORE_ALLOCATE, PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_MODIFY}; use crate::server::{jobstate, WorkerTask}; +use crate::tools::disks::{get_fs_uuid_by_path, get_mount_point_by_uuid}; #[api( input: { @@ -83,6 +84,12 @@ pub(crate) fn do_create_datastore( protected: true, input: { properties: { + "removable": { + description: "The device to which the data is written is removable.", + type: bool, + optional: true, + default: false, + }, config: { type: DataStoreConfig, flatten: true, @@ -95,7 +102,8 @@ pub(crate) fn do_create_datastore( )] /// Create new datastore config. pub fn create_datastore( - config: DataStoreConfig, + mut config: DataStoreConfig, + removable: bool, rpcenv: &mut dyn RpcEnvironment, ) -> Result { @@ -107,6 +115,15 @@ pub fn create_datastore( bail!("datastore '{}' already exists.", config.name); } + if removable { + let path = std::path::Path::new(&config.path); + std::fs::create_dir_all(&path)?; + let uuid = get_fs_uuid_by_path(&path)?; + let mount_path = get_mount_point_by_uuid(&uuid)?; + config.backing_device_mount_point = Some(mount_path); + config.backing_device = Some(uuid); + }; + let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; WorkerTask::new_thread( -- 2.30.2