public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v2 proxmox-backup 03/15] api2: add support for removable datastore creation
Date: Mon, 30 Aug 2021 13:14:53 +0200	[thread overview]
Message-ID: <20210830111505.38694-4-h.laimer@proxmox.com> (raw)
In-Reply-To: <20210830111505.38694-1-h.laimer@proxmox.com>

---
 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





  parent reply	other threads:[~2021-08-30 11:15 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-30 11:14 [pbs-devel] [PATCH v2 proxmox-backup 00/15] (partially)close #3156: Add support for removable datastores Hannes Laimer
2021-08-30 11:14 ` [pbs-devel] [PATCH v2 proxmox-backup 01/15] tools: add disks utility functions Hannes Laimer
2021-09-01 14:48   ` Dominik Csapak
2021-08-30 11:14 ` [pbs-devel] [PATCH v2 proxmox-backup 02/15] config: add uuid+mountpoint to DataStoreConfig Hannes Laimer
2021-08-30 11:14 ` Hannes Laimer [this message]
2021-08-30 11:14 ` [pbs-devel] [PATCH v2 proxmox-backup 04/15] backup: add check_if_available function to ds Hannes Laimer
2021-08-30 11:14 ` [pbs-devel] [PATCH v2 proxmox-backup 05/15] api2: add 'is_available' to DataStoreConfig Hannes Laimer
2021-09-01 14:48   ` Dominik Csapak
2021-08-30 11:14 ` [pbs-devel] [PATCH v2 proxmox-backup 06/15] api2: add 'removable' to DataStoreListItem Hannes Laimer
2021-09-01 14:48   ` Dominik Csapak
2021-08-30 11:14 ` [pbs-devel] [PATCH v2 proxmox-backup 07/15] api2: add (un)mount endpoint for removable ds's Hannes Laimer
2021-09-01 14:48   ` Dominik Csapak
2021-08-30 11:14 ` [pbs-devel] [PATCH v2 proxmox-backup 08/15] pbs: add mount-removable command to commandSocket Hannes Laimer
2021-08-30 11:14 ` [pbs-devel] [PATCH v2 proxmox-backup 09/15] pbs-manager: add 'send-command' command Hannes Laimer
2021-08-30 11:15 ` [pbs-devel] [PATCH v2 proxmox-backup 10/15] debian: add udev rule for removable datastores Hannes Laimer
2021-08-30 11:15 ` [pbs-devel] [PATCH v2 proxmox-backup 11/15] ui: show usb icon for removable datastore in list Hannes Laimer
2021-08-30 11:15 ` [pbs-devel] [PATCH v2 proxmox-backup 12/15] ui: add 'removable' checkbox in datastore creation Hannes Laimer
2021-08-30 11:15 ` [pbs-devel] [PATCH v2 proxmox-backup 13/15] ui: display row as disabled in ds statistics Hannes Laimer
2021-08-30 11:15 ` [pbs-devel] [PATCH v2 proxmox-backup 14/15] ui: show backing device UUID and mount-point in option tab Hannes Laimer
2021-08-30 11:15 ` [pbs-devel] [PATCH v2 proxmox-backup 15/15] ui: add (un)mount button to summary Hannes Laimer
2021-09-01 14:48   ` Dominik Csapak
2021-09-01 14:48 ` [pbs-devel] [PATCH v2 proxmox-backup 00/15] (partially)close #3156: Add support for removable datastores Dominik Csapak
2021-09-02  6:09   ` Thomas Lamprecht
2021-09-02  6:18     ` Dominik Csapak
2021-09-02  6:28       ` Thomas Lamprecht
2021-09-03  9:27   ` Hannes Laimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210830111505.38694-4-h.laimer@proxmox.com \
    --to=h.laimer@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal