From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 86C601FF179 for ; Wed, 12 Nov 2025 13:04:38 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EA7A915AC; Wed, 12 Nov 2025 13:05:24 +0100 (CET) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Wed, 12 Nov 2025 13:05:13 +0100 Message-ID: <20251112120515.145480-4-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251112120515.145480-1-h.laimer@proxmox.com> References: <20251112120515.145480-1-h.laimer@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1762949097185 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.048 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup v3 2/4] api: datastore: auto-unmount after mount-triggered sync X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" When a datastore mount triggers sync jobs, unmount the datastore afterwards if any such job has unmount_on_done=true. This applies only to mount-triggered runs. Manual and scheduled syncs run in the proxy and cannot perform the privileged unmount. Signed-off-by: Hannes Laimer --- src/api2/admin/datastore.rs | 96 ++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 39 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 6e269ef9..911378d7 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -2454,6 +2454,7 @@ async fn do_sync_jobs( } } } + Ok(()) } @@ -2515,30 +2516,44 @@ pub fn mount(store: String, rpcenv: &mut dyn RpcEnvironment) -> Result = list - .into_iter() - .filter(|job: &SyncJobConfig| { - // add job iff (running on mount is enabled and) any of these apply - // - the jobs is local and we are source or target - // - we are the source of a push to a remote - // - we are the target of a pull from a remote - // - // `job.store == datastore.name` iff we are the target for pull from remote or we - // are the source for push to remote, therefore we don't have to check for the - // direction of the job. - job.run_on_mount.unwrap_or(false) - && (job.remote.is_none() && job.remote_store == name || job.store == name) - }) - .collect(); + let (unmount_on_done, mut jobs_to_run): (bool, Vec) = + list.into_iter().fold( + (false, Vec::new()), + |(mut unmount, mut jobs), job: SyncJobConfig| { + // add job iff (running on mount is enabled and) any of these apply + // - the jobs is local and we are source or target + // - we are the source of a push to a remote + // - we are the target of a pull from a remote + // + // `job.store == datastore.name` iff we are the target for pull from remote or we + // are the source for push to remote, therefore we don't have to check for the + // direction of the job. + let should_run = job.run_on_mount.unwrap_or(false) + && (job.remote.is_none() && job.remote_store == name + || job.store == name); + if should_run { + unmount |= job.unmount_on_done.unwrap_or_default(); + jobs.push(job); + }; + (unmount, jobs) + }, + ); jobs_to_run.sort_by(|j1, j2| j1.id.cmp(&j2.id)); if !jobs_to_run.is_empty() { info!("starting {} sync jobs", jobs_to_run.len()); let _ = WorkerTask::spawn( "mount-sync-jobs", - Some(store), + Some(store.clone()), auth_id.to_string(), false, - move |worker| async move { do_sync_jobs(jobs_to_run, worker).await }, + move |worker| async move { + let res = do_sync_jobs(jobs_to_run, worker).await; + if unmount_on_done { + info!("start unmounting..."); + do_unmount(store, auth_id, false).await?; + } + res + }, ); } Ok(()) @@ -2624,25 +2639,7 @@ fn do_unmount_device( Ok(()) } -#[api( - protected: true, - input: { - properties: { - store: { schema: DATASTORE_SCHEMA }, - }, - }, - returns: { - schema: UPID_SCHEMA, - }, - access: { - permission: &Permission::And(&[ - &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_MODIFY, true), - &Permission::Privilege(&["system", "disks"], PRIV_SYS_MODIFY, false) - ]), - } -)] -/// Unmount a removable device that is associated with the datastore -pub async fn unmount(store: String, rpcenv: &mut dyn RpcEnvironment) -> Result { +async fn do_unmount(store: String, auth_id: Authid, to_stdout: bool) -> Result { let _lock = pbs_config::datastore::lock_config()?; let (mut section_config, _digest) = pbs_config::datastore::config()?; let mut datastore: DataStoreConfig = section_config.lookup("datastore", &store)?; @@ -2662,9 +2659,6 @@ pub async fn unmount(store: String, rpcenv: &mut dyn RpcEnvironment) -> Result Result Result { + let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; + let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI; + do_unmount(store, auth_id, to_stdout).await +} + #[api( protected: true, input: { -- 2.47.3 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel