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 7F4EE6F628 for ; Mon, 30 Aug 2021 13:15:15 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5758D1A036 for ; Mon, 30 Aug 2021 13:15:15 +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 2286119FF6 for ; Mon, 30 Aug 2021 13:15:11 +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 E267E44255 for ; Mon, 30 Aug 2021 13:15:10 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Mon, 30 Aug 2021 13:14:53 +0200 Message-Id: <20210830111505.38694-4-h.laimer@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210830111505.38694-1-h.laimer@proxmox.com> References: <20210830111505.38694-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.188 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 v2 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: Mon, 30 Aug 2021 11:15:15 -0000 --- src/api2/config/datastore.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index b0a5b0d2..742a298f 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, DataStoreConfigUpdater}; 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,18 @@ 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)?; + if mount_path == "/" { + bail!("The device for a removable datastore cannot have '/' as its mountpoint."); + } + 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