[pbs-devel] [PATCH v2 proxmox-backup 03/15] api2: add support for removable datastore creation
Hannes Laimer
h.laimer at proxmox.com
Mon Aug 30 13:14:53 CEST 2021
---
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<String, Error> {
@@ -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
More information about the pbs-devel
mailing list