From 3f851d13210168a0d608c3cf70bc91e17e994b84 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 17 Jun 2020 08:31:11 +0200 Subject: [PATCH] src/api2/node/disks/directory.rs: add early check if disk is unused --- src/api2/node/disks/directory.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs index e63c4caf..f243e8f9 100644 --- a/src/api2/node/disks/directory.rs +++ b/src/api2/node/disks/directory.rs @@ -1,4 +1,4 @@ -use anyhow::{Error}; +use anyhow::{bail, Error}; use serde_json::json; use ::serde::{Deserialize, Serialize}; @@ -8,8 +8,8 @@ use proxmox::api::router::Router; use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY}; use crate::tools::disks::{ - DiskManage, FileSystemType, - create_file_system, create_single_linux_partition, get_fs_uuid, + DiskManage, FileSystemType, DiskUsageType, + create_file_system, create_single_linux_partition, get_fs_uuid, get_disk_usage_info, }; use crate::tools::systemd::{self, types::*}; @@ -135,6 +135,12 @@ pub fn create_datastore_disk( let username = rpcenv.get_user().unwrap(); + let info = get_disk_usage_info(&disk, true)?; + + if info.used != DiskUsageType::Unused { + bail!("disk '{}' is already in use.", disk); + } + let upid_str = WorkerTask::new_thread( "dircreate", Some(name.clone()), &username.clone(), to_stdout, move |worker| {