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 3/3] api: backup: avoid holding mutex and inline backup cleanup method
Date: Mon, 29 Sep 2025 10:04:07 +0200	[thread overview]
Message-ID: <20250929080407.124362-4-c.ebner@proxmox.com> (raw)
In-Reply-To: <20250929080407.124362-1-c.ebner@proxmox.com>

The method to cleanup backups due to failure (or because a benchmark)
currently acquires a mutex guard before removing the backup directory.

Since the S3 backend however needs to execute code in async context,
it is not deadlock save to hold the guard. However, the guard was
only acquired to set the state to finished, which is however not
necessary since the request handling future is already executed to
completion, so this has no further effect.

Therefore, drop the mutex locking altoghether and inline the now
trivial simple function call to the respective callsides.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
changes since version 2:
- not present in previous version

 src/api2/backup/environment.rs | 14 --------------
 src/api2/backup/mod.rs         | 24 +++++++++++++++++++++---
 2 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/api2/backup/environment.rs b/src/api2/backup/environment.rs
index de6ce3c89..ace305d7e 100644
--- a/src/api2/backup/environment.rs
+++ b/src/api2/backup/environment.rs
@@ -833,20 +833,6 @@ impl BackupEnvironment {
         state.finished == BackupState::Finished
     }
 
-    /// Remove complete backup
-    pub fn remove_backup(&self) -> Result<(), Error> {
-        let mut state = self.state.lock().unwrap();
-        state.finished = BackupState::Finished;
-
-        self.datastore.remove_backup_dir(
-            self.backup_dir.backup_ns(),
-            self.backup_dir.as_ref(),
-            true,
-        )?;
-
-        Ok(())
-    }
-
     fn s3_upload_index(&self, s3_client: &S3Client, name: &str) -> Result<(), Error> {
         let object_key =
             pbs_datastore::s3::object_key_from_path(&self.backup_dir.relative_path(), name)
diff --git a/src/api2/backup/mod.rs b/src/api2/backup/mod.rs
index ae61ff697..8a076a2b0 100644
--- a/src/api2/backup/mod.rs
+++ b/src/api2/backup/mod.rs
@@ -282,7 +282,13 @@ fn upgrade_to_backup_protocol(
                 };
                 if benchmark {
                     env.log("benchmark finished successfully");
-                    proxmox_async::runtime::block_in_place(|| env.remove_backup())?;
+                    proxmox_async::runtime::block_in_place(|| {
+                        env.datastore.remove_backup_dir(
+                            env.backup_dir.backup_ns(),
+                            env.backup_dir.as_ref(),
+                            true,
+                        )
+                    })?;
                     return Ok(());
                 }
 
@@ -310,13 +316,25 @@ fn upgrade_to_backup_protocol(
                     (Ok(_), Err(err)) => {
                         env.log(format!("backup ended and finish failed: {}", err));
                         env.log("removing unfinished backup");
-                        proxmox_async::runtime::block_in_place(|| env.remove_backup())?;
+                        proxmox_async::runtime::block_in_place(|| {
+                            env.datastore.remove_backup_dir(
+                                env.backup_dir.backup_ns(),
+                                env.backup_dir.as_ref(),
+                                true,
+                            )
+                        })?;
                         Err(err)
                     }
                     (Err(err), Err(_)) => {
                         env.log(format!("backup failed: {}", err));
                         env.log("removing failed backup");
-                        proxmox_async::runtime::block_in_place(|| env.remove_backup())?;
+                        proxmox_async::runtime::block_in_place(|| {
+                            env.datastore.remove_backup_dir(
+                                env.backup_dir.backup_ns(),
+                                env.backup_dir.as_ref(),
+                                true,
+                            )
+                        })?;
                         Err(err)
                     }
                 }
-- 
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-09-29  8:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-29  8:04 [pbs-devel] [PATCH proxmox-backup v3 0/3] fix #6750: fix possible deadlock for s3 backed datastore backups Christian Ebner
2025-09-29  8:04 ` [pbs-devel] [PATCH proxmox-backup v3 1/3] fix #6750: api: avoid possible deadlock on datastores with s3 backend Christian Ebner
2025-09-29  8:04 ` [pbs-devel] [PATCH proxmox-backup v3 2/3] api: backup: never hold mutex guard when doing manifest update Christian Ebner
2025-09-29  8:04 ` Christian Ebner [this message]
2025-09-29  9:41 ` [pbs-devel] applied-series: [PATCH proxmox-backup v3 0/3] fix #6750: fix possible deadlock for s3 backed datastore backups 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=20250929080407.124362-4-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