all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Robert Obkircher <r.obkircher@proxmox.com>
To: Christian Ebner <c.ebner@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: Re: [PATCH proxmox-backup v3 07/10] datastore: create lockdir with correct mode for backup user access
Date: Thu, 23 Jul 2026 13:52:10 +0200	[thread overview]
Message-ID: <178480753020.88450.17561424625137931984.b4-review@b4> (raw)
In-Reply-To: <20260721103643.333028-8-c.ebner@proxmox.com>

> Instead of locking the whole config, which causes also unrelated
> datastores to not be available, use a per-datastore maintenance-mode
> lock to protect against changes during potentially longer running
> operations such as s3-refresh or removable datastore mount/unmount.
> 
> However keep the current semantic of first setting the maintenance
> mode, allow to still opt out from the mode while waiting for active
> operations to finish, and only then enforce the maintenance mode
> during the s3 refresh or removable datastore mount operation.
> 
> unset_maintenance() is adapted to also check for the expected
> maintenance type and acquire the maintenance-mode lock if not provided
> by the caller.
> 
> Fixes: https://forum.proxmox.com/threads/183244/
> Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
>
> diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
> index 99adfde8a..3550f0963 100644
> --- a/pbs-datastore/src/datastore.rs
> +++ b/pbs-datastore/src/datastore.rs
> @@ -3162,6 +3162,7 @@ impl DataStore {
>          let (mut config, _digest) = pbs_config::datastore::config()?;
>          let mut datastore_config: DataStoreConfig = config.lookup("datastore", name)?;
>  
> +        let maintenance_mode_lock = crate::maintenance_mode_lock(name, &config_lock)?;
>          datastore_config.set_maintenance_mode(Some(MaintenanceMode {
>              ty: MaintenanceType::Delete,
>              message: None,
> @@ -3169,6 +3170,7 @@ impl DataStore {
>  
>          config.set_data(name, "datastore", &datastore_config)?;
>          pbs_config::datastore::save_config(&config)?;
> +        drop(maintenance_mode_lock);
>          drop(config_lock);
>  
>          let (operations, _lock) = task_tracking::get_active_operations_locked(name)?;
> diff --git a/pbs-datastore/src/lib.rs b/pbs-datastore/src/lib.rs
> index 187de23f6..99f954f19 100644
> --- a/pbs-datastore/src/lib.rs
> +++ b/pbs-datastore/src/lib.rs
> @@ -159,8 +159,9 @@
>  
>  use std::os::unix::io::AsRawFd;
>  use std::path::Path;
> +use std::time::Duration;
>  
> -use anyhow::{Error, bail};
> +use anyhow::{Context, Error, bail};
>  
>  use proxmox_sys::fs::CreateOptions;
>  
> @@ -282,3 +283,21 @@ where
>  
>      Ok(lock)
>  }
> +
> +/// Acquire an exclusive lock for the datastore's maintenance-mode. The datastore config lock
> +/// must be acquired beforehand to avoid races.
> +pub fn maintenance_mode_lock(
> +    store: &str,
> +    _datastore_config_lock: &BackupLockGuard,
> +) -> Result<BackupLockGuard, Error> {
> +    let mut lock_path = Path::new(DATASTORE_LOCKS_DIR).join(store);
> +    lock_path.push("maintenance-mode.lck");
> +
> +    lock_helper(store, &lock_path, |p| {
> +        // never wait for the lock here: this is only acquired by long running operations
> +        // and the datastore config lock must be held anyways. Blocking the it longer than
> +        // necessary is not acceptable.
> +        pbs_config::open_backup_lockfile(p, Some(Duration::from_secs(0)), true)
> +            .context("unable to acquire exclusive datastore's maintenance-mode lock")
> +    })
> +}
Since those locks are used together it would be nicer to turn this into
a MaintenanceModeLock(BackupLockGuard) wrapper for some additional type
safety.

-- 
Robert Obkircher <r.obkircher@proxmox.com>




  reply	other threads:[~2026-07-23 11:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21 10:36 [PATCH proxmox{,-backup} v3 00/10] keep datastore config unlocked during long running operations Christian Ebner
2026-07-21 10:36 ` [PATCH proxmox v3 01/10] pbs-api-types: add datastore create maintenance-mode type Christian Ebner
2026-07-21 10:36 ` [PATCH proxmox-backup v3 02/10] api: config: rearrange independent code block for datastore creation Christian Ebner
2026-07-21 10:36 ` [PATCH proxmox-backup v3 03/10] api/datastore: refactor datastore creation helper logic Christian Ebner
2026-07-21 10:36 ` [PATCH proxmox-backup v3 04/10] datastore: restrict chunk store scope to pbs-datastore crate Christian Ebner
2026-07-23 11:52   ` Robert Obkircher
2026-07-21 10:36 ` [PATCH proxmox-backup v3 05/10] datastore: move lock files base path constant to central location Christian Ebner
2026-07-23 11:52   ` Robert Obkircher
2026-07-21 10:36 ` [PATCH proxmox-backup v3 06/10] datastore: move file lock helper to centralized place Christian Ebner
2026-07-21 10:36 ` [PATCH proxmox-backup v3 07/10] datastore: create lockdir with correct mode for backup user access Christian Ebner
2026-07-23 11:52   ` Robert Obkircher [this message]
2026-07-21 10:36 ` [PATCH proxmox-backup v3 08/10] api/datastore: use maintenance-mode lock to protect against changes Christian Ebner
2026-07-23 11:52   ` Robert Obkircher
2026-07-21 10:36 ` [PATCH proxmox-backup v3 09/10] api: config: unlocked s3 bucket access check for datastore creation Christian Ebner
2026-07-23 11:52   ` Robert Obkircher
2026-07-23 14:31     ` Christian Ebner
2026-07-21 10:36 ` [PATCH proxmox-backup v3 10/10] datastore: protect datastore creation by maintenance-mode Christian Ebner

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=178480753020.88450.17561424625137931984.b4-review@b4 \
    --to=r.obkircher@proxmox.com \
    --cc=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