cleanup: factor out config::datastore::lock_config()
This commit is contained in:
parent
4708f4fc21
commit
b90036dadd
@ -7,7 +7,6 @@ use ::serde::{Deserialize, Serialize};
|
||||
use proxmox::api::{api, Router, RpcEnvironment, Permission};
|
||||
use proxmox::api::section_config::SectionConfigData;
|
||||
use proxmox::api::schema::parse_property_string;
|
||||
use proxmox::tools::fs::open_file_locked;
|
||||
|
||||
use crate::api2::types::*;
|
||||
use crate::backup::*;
|
||||
@ -141,7 +140,7 @@ pub fn create_datastore(
|
||||
rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<String, Error> {
|
||||
|
||||
let lock = open_file_locked(datastore::DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let lock = datastore::lock_config()?;
|
||||
|
||||
let datastore: datastore::DataStoreConfig = serde_json::from_value(param)?;
|
||||
|
||||
@ -315,7 +314,7 @@ pub fn update_datastore(
|
||||
digest: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let _lock = open_file_locked(datastore::DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = datastore::lock_config()?;
|
||||
|
||||
// pass/compare digest
|
||||
let (mut config, expected_digest) = datastore::config()?;
|
||||
@ -424,7 +423,7 @@ pub fn update_datastore(
|
||||
/// Remove a datastore configuration.
|
||||
pub async fn delete_datastore(name: String, digest: Option<String>) -> Result<(), Error> {
|
||||
|
||||
let _lock = open_file_locked(datastore::DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?;
|
||||
let _lock = datastore::lock_config()?;
|
||||
|
||||
let (mut config, expected_digest) = datastore::config()?;
|
||||
|
||||
|
@ -190,7 +190,7 @@ pub fn create_datastore_disk(
|
||||
bail!("datastore '{}' already exists.", datastore.name);
|
||||
}
|
||||
|
||||
crate::api2::config::datastore::create_datastore_impl(lock, config, datastore)?;
|
||||
crate::api2::config::datastore::do_create_datastore(lock, config, datastore)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -14,7 +14,6 @@ use proxmox::api::{
|
||||
},
|
||||
};
|
||||
use proxmox::api::router::Router;
|
||||
use proxmox::tools::fs::open_file_locked;
|
||||
|
||||
use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
|
||||
use crate::tools::disks::{
|
||||
|
@ -13,7 +13,11 @@ use proxmox::api::{
|
||||
}
|
||||
};
|
||||
|
||||
use proxmox::tools::{fs::replace_file, fs::CreateOptions};
|
||||
use proxmox::tools::fs::{
|
||||
open_file_locked,
|
||||
replace_file,
|
||||
CreateOptions,
|
||||
};
|
||||
|
||||
use crate::api2::types::*;
|
||||
|
||||
@ -133,6 +137,11 @@ fn init() -> SectionConfig {
|
||||
pub const DATASTORE_CFG_FILENAME: &str = "/etc/proxmox-backup/datastore.cfg";
|
||||
pub const DATASTORE_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.datastore.lck";
|
||||
|
||||
/// Get exclusive lock
|
||||
pub fn lock_config() -> Result<std::fs::File, Error> {
|
||||
open_file_locked(DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)
|
||||
}
|
||||
|
||||
pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
let content = proxmox::tools::fs::file_read_optional_string(DATASTORE_CFG_FILENAME)?
|
||||
|
Loading…
Reference in New Issue
Block a user