all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v3 5/7] api: datastore: wait for active operations to clear before s3 refresh
Date: Thu, 13 Nov 2025 15:22:12 +0100	[thread overview]
Message-ID: <20251113142214.719217-6-c.ebner@proxmox.com> (raw)
In-Reply-To: <20251113142214.719217-1-c.ebner@proxmox.com>

Currently, the s3 refresh does not take into consideration already
ongoing active operations, only blocking new ones.

This will however lead to inconsistencies if there are ongoing read
or write operations. Therefore, actively wait for ongoing operatioins
to complete before running the actual refresh and keep the datastore
config locked so the maintenance mode cannot be altered.If an abort
was requested while waiting, clear the maintenance mode as well.

By adding this as helper, it can be reuse for datastore recreation as
well.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
changes since version 1:
- use dedicated helper which can be reused also for datastore recreation

 src/api2/admin/datastore.rs | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 7bd7c9f72..8fc5efe41 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -2674,7 +2674,6 @@ pub async fn unmount(store: String, rpcenv: &mut dyn RpcEnvironment) -> Result<V
 )]
 /// Refresh datastore contents from S3 to local cache store.
 pub fn s3_refresh(store: String, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
-    let datastore = DataStore::lookup_datastore(&store, Some(Operation::Lookup))?;
     let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
     let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
 
@@ -2696,17 +2695,21 @@ pub fn s3_refresh(store: String, rpcenv: &mut dyn RpcEnvironment) -> Result<Valu
         Some(store.clone()),
         auth_id.to_string(),
         to_stdout,
-        move |_worker| {
-            proxmox_async::runtime::block_on(datastore.s3_refresh())?;
-
-            let (_lock, config) = expect_maintenance_type(&store, MaintenanceType::S3Refresh)?;
-            unset_maintenance(_lock, config).context("failed to clear maintenance mode")
-        },
+        move |worker| do_s3_refresh(&store, &worker),
     )?;
 
     Ok(json!(upid))
 }
 
+/// Performs an s3 refresh for given datastore. Expects the store to already be in maintenance mode
+/// s3-refresh.
+pub(crate) fn do_s3_refresh(store: &str, worker: &dyn WorkerTaskContext) -> Result<(), Error> {
+    let datastore = DataStore::lookup_datastore(&store, Some(Operation::Lookup))?;
+    run_maintenance_locked(&store, MaintenanceType::S3Refresh, worker, || {
+        proxmox_async::runtime::block_on(datastore.s3_refresh())
+    })
+}
+
 /// Wait for no more active operations on the given datastore and run the provided callback in
 /// a datastore locked context, protecting against maintenance mode changes.
 fn run_maintenance_locked(
-- 
2.47.3



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


  parent reply	other threads:[~2025-11-13 14:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13 14:22 [pbs-devel] [PATCH proxmox-backup v3 0/7] wait for active operations to finish " Christian Ebner
2025-11-13 14:22 ` [pbs-devel] [PATCH proxmox-backup v3 1/7] api: admin: drop useless option for do_unmount_device() parameter Christian Ebner
2025-11-13 14:22 ` [pbs-devel] [PATCH proxmox-backup v3 2/7] api: admin: rework waiting on active operations and maintenance locking Christian Ebner
2025-11-13 14:22 ` [pbs-devel] [PATCH proxmox-backup v3 3/7] api: admin: make s3 refresh handler sync Christian Ebner
2025-11-13 14:22 ` [pbs-devel] [PATCH proxmox-backup v3 4/7] datastore: s3 refresh: set/unset maintenance mode in api handler Christian Ebner
2025-11-13 14:22 ` Christian Ebner [this message]
2025-11-13 14:22 ` [pbs-devel] [PATCH proxmox-backup v3 6/7] api: config: avoid unneeded backend instance on s3 store recreation Christian Ebner
2025-11-13 14:22 ` [pbs-devel] [PATCH proxmox-backup v3 7/7] api: config: guard s3-refresh on datastore recreation Christian Ebner
2025-11-14  8:48 ` [pbs-devel] applied-series: [PATCH proxmox-backup v3 0/7] wait for active operations to finish before s3 refresh Fabian Grünbichler

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=20251113142214.719217-6-c.ebner@proxmox.com \
    --to=c.ebner@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