[pbs-devel] [PATCH proxmox-backup 2/2] disks: unify default datastore creation
Gabriel Goller
g.goller at proxmox.com
Fri May 3 16:29:29 CEST 2024
A datastore created with the "Add: ZFS" and "Add: Directory" button is
not the same as when created manually. The difference is that the
manually created one includes a default prune-job and a gc-job with a
daily schedule.
Use the create_default_datatore function so that every
datastore created will look the same.
Signed-off-by: Gabriel Goller <g.goller at proxmox.com>
---
src/api2/node/disks/directory.rs | 23 ++++++-----------------
src/api2/node/disks/zfs.rs | 28 ++++++++++------------------
2 files changed, 16 insertions(+), 35 deletions(-)
diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs
index 9f1112a9..de5df953 100644
--- a/src/api2/node/disks/directory.rs
+++ b/src/api2/node/disks/directory.rs
@@ -1,6 +1,5 @@
use ::serde::{Deserialize, Serialize};
use anyhow::{bail, Error};
-use serde_json::json;
use std::os::linux::fs::MetadataExt;
use proxmox_router::{Permission, Router, RpcEnvironment, RpcEnvironmentType};
@@ -13,6 +12,7 @@ use pbs_api_types::{
PRIV_SYS_MODIFY, UPID_SCHEMA,
};
+use crate::api2::config::datastore::create_default_datastore;
use crate::tools::disks::{
create_file_system, create_single_linux_partition, get_fs_uuid, DiskManage, DiskUsageQuery,
DiskUsageType, FileSystemType,
@@ -203,22 +203,11 @@ pub fn create_datastore_disk(
crate::tools::systemd::start_unit(&mount_unit_name)?;
if add_datastore {
- let lock = pbs_config::datastore::lock_config()?;
- let datastore: DataStoreConfig =
- serde_json::from_value(json!({ "name": name, "path": mount_point }))?;
-
- let (config, _digest) = pbs_config::datastore::config()?;
-
- if config.sections.get(&datastore.name).is_some() {
- bail!("datastore '{}' already exists.", datastore.name);
- }
-
- crate::api2::config::datastore::do_create_datastore(
- lock,
- config,
- datastore,
- Some(&worker),
- )?;
+ let mut config = DataStoreConfig::new(name, mount_point);
+ config.gc_schedule = Some("daily".to_string());
+ config.prune_schedule = Some("daily".to_string());
+
+ create_default_datastore(config, worker)?;
}
Ok(())
diff --git a/src/api2/node/disks/zfs.rs b/src/api2/node/disks/zfs.rs
index 673dc1bf..6422f6fc 100644
--- a/src/api2/node/disks/zfs.rs
+++ b/src/api2/node/disks/zfs.rs
@@ -1,5 +1,5 @@
use anyhow::{bail, Error};
-use serde_json::{json, Value};
+use serde_json::Value;
use proxmox_router::{Permission, Router, RpcEnvironment, RpcEnvironmentType};
use proxmox_schema::api;
@@ -11,8 +11,11 @@ use pbs_api_types::{
ZFS_ASHIFT_SCHEMA, ZPOOL_NAME_SCHEMA,
};
-use crate::tools::disks::{
- parse_zpool_status_config_tree, vdev_list_to_tree, zpool_list, zpool_status, DiskUsageType,
+use crate::{
+ api2::config::datastore::create_default_datastore,
+ tools::disks::{
+ parse_zpool_status_config_tree, vdev_list_to_tree, zpool_list, zpool_status, DiskUsageType,
+ },
};
use proxmox_rest_server::WorkerTask;
@@ -309,22 +312,11 @@ pub fn create_zpool(
};
if add_datastore {
- let lock = pbs_config::datastore::lock_config()?;
- let datastore: DataStoreConfig =
- serde_json::from_value(json!({ "name": name, "path": mount_point }))?;
-
- let (config, _digest) = pbs_config::datastore::config()?;
-
- if config.sections.get(&datastore.name).is_some() {
- bail!("datastore '{}' already exists.", datastore.name);
- }
+ let mut config = DataStoreConfig::new(name, mount_point);
+ config.gc_schedule = Some("daily".to_string());
+ config.prune_schedule = Some("daily".to_string());
- crate::api2::config::datastore::do_create_datastore(
- lock,
- config,
- datastore,
- Some(&worker),
- )?;
+ create_default_datastore(config, worker)?;
}
Ok(())
--
2.43.0
More information about the pbs-devel
mailing list