From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 264901FF125 for ; Mon, 03 Aug 2026 11:08:33 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 24BE521581; Mon, 03 Aug 2026 11:08:10 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox-backup v4 13/14] api: datastore: move prune job and s3 backend logic to create helper Date: Mon, 3 Aug 2026 11:07:46 +0200 Message-ID: <20260803090747.265683-14-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260803090747.265683-1-c.ebner@proxmox.com> References: <20260803090747.265683-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1785748075537 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.132 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 2BRRGTSBG2II3IQHLIN5OVUTRCIXANK6 X-Message-ID-Hash: 2BRRGTSBG2II3IQHLIN5OVUTRCIXANK6 X-MailFrom: c.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Moving the logic to the common datastore create helper will facilitate switching to the datastore create maintenance mode in following changes. The same logic can be used for the directory/zfs datastore creation, as prune job creation and s3 backend logic can be skipped there. No functional changes intended. Signed-off-by: Christian Ebner --- src/api2/config/datastore.rs | 28 ++++++++++++++++++---------- src/api2/node/disks/directory.rs | 15 +++++++++++---- src/api2/node/disks/zfs.rs | 17 ++++++++++++----- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 7505e8c78..5d0aa966a 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -9,6 +9,7 @@ use proxmox_router::{Permission, Router, RpcEnvironment, RpcEnvironmentType, htt use proxmox_schema::{ApiType, api, param_bail}; use proxmox_section_config::SectionConfigData; use proxmox_uuid::Uuid; +use proxmox_worker_task::WorkerTaskContext; use pbs_api_types::{ Authid, DATASTORE_SCHEMA, DataStoreConfig, DataStoreConfigUpdater, DatastoreBackendType, @@ -95,7 +96,10 @@ impl Drop for UnmountGuard { pub(crate) fn do_create_datastore( lock: BackupLockGuard, mut config: SectionConfigData, + worker: &dyn WorkerTaskContext, + backend_type: DatastoreBackendType, mut datastore: DataStoreConfig, + prune_job_config: Option, reuse_datastore: bool, overwrite_in_use: bool, ) -> Result<(), Error> { @@ -118,6 +122,16 @@ pub(crate) fn do_create_datastore( unmount_guard.disable(); + drop(lock); + + if let Some(prune_job_config) = prune_job_config { + do_create_prune_job(prune_job_config)?; + } + + if reuse_datastore && backend_type == DatastoreBackendType::S3 { + crate::api2::admin::datastore::do_s3_refresh(&datastore.name, worker)?; + } + Ok(()) } @@ -214,19 +228,13 @@ pub fn create_datastore( do_create_datastore( lock, section_config, + &worker, + backend, config, + prune_job_config, reuse_datastore, overwrite_in_use, - )?; - - if let Some(prune_job_config) = prune_job_config { - do_create_prune_job(prune_job_config)?; - } - - if reuse_datastore && backend == DatastoreBackendType::S3 { - crate::api2::admin::datastore::do_s3_refresh(&store_name, &worker)?; - } - Ok(()) + ) }, ) } diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs index 9979355e5..7fc7187bf 100644 --- a/src/api2/node/disks/directory.rs +++ b/src/api2/node/disks/directory.rs @@ -11,8 +11,8 @@ use proxmox_schema::api; use proxmox_section_config::SectionConfigData; use pbs_api_types::{ - BLOCKDEVICE_NAME_SCHEMA, DATASTORE_MOUNT_DIR, DATASTORE_SCHEMA, DataStoreConfig, NODE_SCHEMA, - PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, UPID_SCHEMA, + BLOCKDEVICE_NAME_SCHEMA, DATASTORE_MOUNT_DIR, DATASTORE_SCHEMA, DataStoreConfig, + DatastoreBackendType, NODE_SCHEMA, PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, UPID_SCHEMA, }; use crate::tools::disks::{ @@ -214,7 +214,7 @@ pub fn create_datastore_disk( Some(name.clone()), auth_id, to_stdout, - move |_worker| { + move |worker| { info!("create datastore '{name}' on disk {disk}"); let filesystem = filesystem.unwrap_or(FileSystemType::Ext4); @@ -251,7 +251,14 @@ pub fn create_datastore_disk( pbs_config::datastore::validate_new_datastore_config(&datastore, &config, &lock)?; crate::api2::config::datastore::do_create_datastore( - lock, config, datastore, false, false, + lock, + config, + &worker, + DatastoreBackendType::Filesystem, + datastore, + None, + false, + false, )?; } diff --git a/src/api2/node/disks/zfs.rs b/src/api2/node/disks/zfs.rs index 0e8ce75b5..2a44c3d2d 100644 --- a/src/api2/node/disks/zfs.rs +++ b/src/api2/node/disks/zfs.rs @@ -6,9 +6,9 @@ use proxmox_router::{Permission, Router, RpcEnvironment, RpcEnvironmentType}; use proxmox_schema::api; use pbs_api_types::{ - DATASTORE_SCHEMA, DISK_ARRAY_SCHEMA, DISK_LIST_SCHEMA, DataStoreConfig, NODE_SCHEMA, - PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, UPID_SCHEMA, ZFS_ASHIFT_SCHEMA, ZPOOL_NAME_SCHEMA, - ZfsCompressionType, ZfsRaidLevel, ZpoolListItem, + DATASTORE_SCHEMA, DISK_ARRAY_SCHEMA, DISK_LIST_SCHEMA, DataStoreConfig, DatastoreBackendType, + NODE_SCHEMA, PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, UPID_SCHEMA, ZFS_ASHIFT_SCHEMA, + ZPOOL_NAME_SCHEMA, ZfsCompressionType, ZfsRaidLevel, ZpoolListItem, }; use crate::tools::disks::{ @@ -228,7 +228,7 @@ pub fn create_zpool( Some(name.clone()), auth_id, to_stdout, - move |_worker| { + move |worker| { info!("create {raidlevel:?} zpool '{name}' on devices '{devices_text}'"); let mut command = std::process::Command::new("zpool"); @@ -311,7 +311,14 @@ pub fn create_zpool( pbs_config::datastore::validate_new_datastore_config(&datastore, &config, &lock)?; crate::api2::config::datastore::do_create_datastore( - lock, config, datastore, false, false, + lock, + config, + &worker, + DatastoreBackendType::Filesystem, + datastore, + None, + false, + false, )?; } -- 2.47.3