all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Gabriel Goller <g.goller@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/2] disks: unify default datastore creation
Date: Fri,  3 May 2024 16:29:29 +0200	[thread overview]
Message-ID: <20240503142933.171798-2-g.goller@proxmox.com> (raw)
In-Reply-To: <20240503142933.171798-1-g.goller@proxmox.com>

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@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



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


  reply	other threads:[~2024-05-03 14:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03 14:29 [pbs-devel] [PATCH proxmox-backup 1/2] config: add default datastore creation function Gabriel Goller
2024-05-03 14:29 ` Gabriel Goller [this message]
2024-05-03 14:32 ` Gabriel Goller
2024-05-03 14:49   ` Christian Ebner
2024-05-03 15:31     ` Christian Ebner
2024-05-13  8:52 ` Christian Ebner
2024-05-13  9:31   ` Gabriel Goller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240503142933.171798-2-g.goller@proxmox.com \
    --to=g.goller@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal