cleanup last patch
This commit is contained in:
parent
be614c625f
commit
98161fddb5
|
@ -2,7 +2,7 @@ use anyhow::{bail, Error};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use ::serde::{Deserialize, Serialize};
|
use ::serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use proxmox::api::{api, Permission, RpcEnvironment, RpcEnvironmentType, HttpError};
|
use proxmox::api::{api, Permission, RpcEnvironment, RpcEnvironmentType};
|
||||||
use proxmox::api::section_config::SectionConfigData;
|
use proxmox::api::section_config::SectionConfigData;
|
||||||
use proxmox::api::router::Router;
|
use proxmox::api::router::Router;
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ use crate::tools::systemd::{self, types::*};
|
||||||
use crate::server::WorkerTask;
|
use crate::server::WorkerTask;
|
||||||
|
|
||||||
use crate::api2::types::*;
|
use crate::api2::types::*;
|
||||||
use proxmox::api::error::StatusCode;
|
|
||||||
use crate::config::datastore::DataStoreConfig;
|
use crate::config::datastore::DataStoreConfig;
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
|
@ -194,10 +193,8 @@ pub fn create_datastore_disk(
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// Remove a Filesystem mounted under '/mnt/datastore/<name>'.".
|
/// Remove a Filesystem mounted under '/mnt/datastore/<name>'.".
|
||||||
pub fn delete_datastore_disk(
|
pub fn delete_datastore_disk(name: String) -> Result<(), Error> {
|
||||||
name: String,
|
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let path = format!("/mnt/datastore/{}", name);
|
let path = format!("/mnt/datastore/{}", name);
|
||||||
// path of datastore cannot be changed
|
// path of datastore cannot be changed
|
||||||
let (config, _) = crate::config::datastore::config()?;
|
let (config, _) = crate::config::datastore::config()?;
|
||||||
|
@ -206,27 +203,25 @@ pub fn delete_datastore_disk(
|
||||||
.filter(|ds| ds.path == path)
|
.filter(|ds| ds.path == path)
|
||||||
.next();
|
.next();
|
||||||
|
|
||||||
match conflicting_datastore {
|
if let Some(conflicting_datastore) = conflicting_datastore {
|
||||||
Some(conflicting_datastore) =>
|
bail!("Can't remove '{}' since it's required by datastore '{}'",
|
||||||
Err(Error::from(HttpError::new(StatusCode::CONFLICT,
|
conflicting_datastore.path, conflicting_datastore.name);
|
||||||
format!("Can't remove '{}' since it's required by datastore '{}'",
|
}
|
||||||
conflicting_datastore.path,
|
|
||||||
conflicting_datastore.name)))),
|
|
||||||
None => {
|
|
||||||
// disable systemd mount-unit
|
// disable systemd mount-unit
|
||||||
let mut mount_unit_name = systemd::escape_unit(&path, true);
|
let mut mount_unit_name = systemd::escape_unit(&path, true);
|
||||||
mount_unit_name.push_str(".mount");
|
mount_unit_name.push_str(".mount");
|
||||||
systemd::disable_unit(mount_unit_name.as_str())?;
|
systemd::disable_unit(&mount_unit_name)?;
|
||||||
|
|
||||||
// delete .mount-file
|
// delete .mount-file
|
||||||
let mount_unit_path = format!("/etc/systemd/system/{}", mount_unit_name);
|
let mount_unit_path = format!("/etc/systemd/system/{}", mount_unit_name);
|
||||||
let full_path = std::path::Path::new(mount_unit_path.as_str());
|
let full_path = std::path::Path::new(&mount_unit_path);
|
||||||
log::info!("removing {:?}", full_path);
|
log::info!("removing systemd mount unit {:?}", full_path);
|
||||||
std::fs::remove_file(&full_path)?;
|
std::fs::remove_file(&full_path)?;
|
||||||
|
|
||||||
// try to unmount, if that fails tell the user to reboot or unmount manually
|
// try to unmount, if that fails tell the user to reboot or unmount manually
|
||||||
let mut command = std::process::Command::new("umount");
|
let mut command = std::process::Command::new("umount");
|
||||||
command.arg(path.as_str());
|
command.arg(&path);
|
||||||
match crate::tools::run_command(command, None) {
|
match crate::tools::run_command(command, None) {
|
||||||
Err(_) => bail!(
|
Err(_) => bail!(
|
||||||
"Could not umount '{}' since it is busy. It will stay mounted \
|
"Could not umount '{}' since it is busy. It will stay mounted \
|
||||||
|
@ -236,8 +231,6 @@ pub fn delete_datastore_disk(
|
||||||
Ok(_) => Ok(())
|
Ok(_) => Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const ITEM_ROUTER: Router = Router::new()
|
const ITEM_ROUTER: Router = Router::new()
|
||||||
.delete(&API_METHOD_DELETE_DATASTORE_DISK);
|
.delete(&API_METHOD_DELETE_DATASTORE_DISK);
|
||||||
|
|
Loading…
Reference in New Issue