src/api2/node/disks/directory.rs: add early check if disk is unused

This commit is contained in:
Dietmar Maurer 2020-06-17 08:31:11 +02:00
parent 1aef491e24
commit 3f851d1321
1 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,4 @@
use anyhow::{Error}; use anyhow::{bail, Error};
use serde_json::json; use serde_json::json;
use ::serde::{Deserialize, Serialize}; 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::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
use crate::tools::disks::{ use crate::tools::disks::{
DiskManage, FileSystemType, DiskManage, FileSystemType, DiskUsageType,
create_file_system, create_single_linux_partition, get_fs_uuid, create_file_system, create_single_linux_partition, get_fs_uuid, get_disk_usage_info,
}; };
use crate::tools::systemd::{self, types::*}; use crate::tools::systemd::{self, types::*};
@ -135,6 +135,12 @@ pub fn create_datastore_disk(
let username = rpcenv.get_user().unwrap(); 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( let upid_str = WorkerTask::new_thread(
"dircreate", Some(name.clone()), &username.clone(), to_stdout, move |worker| "dircreate", Some(name.clone()), &username.clone(), to_stdout, move |worker|
{ {