public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>,
	pbs-devel@lists.proxmox.com
Subject: Re: [pbs-devel] [PATCH proxmox-backup 3/3] GC: mark cond_sweep_chunk helper as unafe
Date: Wed, 15 Oct 2025 11:13:08 +0200	[thread overview]
Message-ID: <e40e1711-b83d-4d71-85e3-0cf2ce6ea0b4@proxmox.com> (raw)
In-Reply-To: <20251015083840.569025-4-f.gruenbichler@proxmox.com>

On 10/15/25 10:38 AM, Fabian Grünbichler wrote:
> it's only allowed to be called in GC context with all the prerequisites like
> locking, ensuring proper atime calculation, etc.
> 
> ideally, this should be internal to the chunk store, but with S3 the boundaries
> between datastore, chunk cache and chunk store became rather blurry, and that
> probably requires more refactoring of the interactions..
> 
> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
> ---
> best viewed with -w
> 
>   pbs-datastore/src/chunk_store.rs | 39 +++++++++++++++++++-------------
>   pbs-datastore/src/datastore.rs   | 34 +++++++++++++++-------------
>   2 files changed, 41 insertions(+), 32 deletions(-)
> 
> diff --git a/pbs-datastore/src/chunk_store.rs b/pbs-datastore/src/chunk_store.rs
> index f81603971..94ff53b86 100644
> --- a/pbs-datastore/src/chunk_store.rs
> +++ b/pbs-datastore/src/chunk_store.rs
> @@ -408,22 +408,26 @@ impl ChunkStore {
>   
>                   chunk_count += 1;
>   
> -                self.cond_sweep_chunk(
> -                    stat.st_atime,
> -                    min_atime,
> -                    oldest_writer,
> -                    stat.st_size as u64,
> -                    bad,
> -                    status,
> -                    || {
> -                        unlinkat(Some(dirfd), filename, UnlinkatFlags::NoRemoveDir).map_err(|err| {
> -                            format_err!(
> -                                "unlinking chunk {filename:?} failed on store '{}' - {err}",
> -                                self.name,
> +                unsafe {
> +                    self.cond_sweep_chunk(
> +                        stat.st_atime,
> +                        min_atime,
> +                        oldest_writer,
> +                        stat.st_size as u64,
> +                        bad,
> +                        status,
> +                        || {
> +                            unlinkat(Some(dirfd), filename, UnlinkatFlags::NoRemoveDir).map_err(
> +                                |err| {
> +                                    format_err!(
> +                                        "unlinking chunk {filename:?} failed on store '{}' - {err}",
> +                                        self.name,
> +                                    )
> +                                },
>                               )
> -                        })
> -                    },
> -                )?;
> +                        },
> +                    )?;
> +                }
>               }
>               drop(lock);
>           }
> @@ -435,7 +439,10 @@ impl ChunkStore {
>       /// status accordingly.
>       ///
>       /// If the chunk should be removed, the [`remove_callback`] is executed.
> -    pub(super) fn cond_sweep_chunk<T: FnOnce() -> Result<(), Error>>(
> +    ///
> +    /// Unsafe: requires locking and GC checks to be called
> +    /// FIXME: make this internal with further refactoring
> +    pub(super) unsafe fn cond_sweep_chunk<T: FnOnce() -> Result<(), Error>>(
>           &self,
>           atime: i64,
>           min_atime: i64,
> diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
> index f1237af32..038306166 100644
> --- a/pbs-datastore/src/datastore.rs
> +++ b/pbs-datastore/src/datastore.rs
> @@ -1664,22 +1664,24 @@ impl DataStore {
>                           .extension()
>                           .is_some_and(|ext| ext == "bad");
>   
> -                    self.inner.chunk_store.cond_sweep_chunk(
> -                        atime,
> -                        min_atime,
> -                        oldest_writer,
> -                        content.size,
> -                        bad,
> -                        &mut gc_status,
> -                        || {
> -                            if let Some(cache) = self.cache() {
> -                                // ignore errors, phase 3 will retry cleanup anyways
> -                                let _ = unsafe { cache.remove(&digest) };
> -                            }
> -                            delete_list.push(content.key);
> -                            Ok(())
> -                        },
> -                    )?;
> +                    unsafe {
> +                        self.inner.chunk_store.cond_sweep_chunk(
> +                            atime,
> +                            min_atime,
> +                            oldest_writer,
> +                            content.size,
> +                            bad,
> +                            &mut gc_status,
> +                            || {
> +                                if let Some(cache) = self.cache() {
> +                                    // ignore errors, phase 3 will retry cleanup anyways
> +                                    let _ = cache.remove(&digest);
> +                                }
> +                                delete_list.push(content.key);
> +                                Ok(())
> +                            },
> +                        )?;
> +                    }
>   
>                       chunk_count += 1;
>                   }

LGTM!

Reviewed-by: Christian Ebner <c.ebner@proxmox.com>


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

  reply	other threads:[~2025-10-15  9:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15  8:38 [pbs-devel] [PATCH proxmox-backup 0/3] GC refactor follow-ups Fabian Grünbichler
2025-10-15  8:38 ` [pbs-devel] [PATCH proxmox-backup 1/3] GC: refactor chunk removal helper Fabian Grünbichler
2025-10-15  9:10   ` Christian Ebner
2025-10-15  9:46     ` Fabian Grünbichler
2025-10-15  9:56       ` Christian Ebner
2025-10-15 10:04         ` Fabian Grünbichler
2025-10-15  8:38 ` [pbs-devel] [PATCH proxmox-backup 2/3] GC: rename helper to cond_sweep_chunk Fabian Grünbichler
2025-10-15  9:12   ` Christian Ebner
2025-10-15  8:38 ` [pbs-devel] [PATCH proxmox-backup 3/3] GC: mark cond_sweep_chunk helper as unafe Fabian Grünbichler
2025-10-15  9:13   ` Christian Ebner [this message]
2025-10-15 10:14 ` [pbs-devel] superseded: [PATCH proxmox-backup 0/3] GC refactor follow-ups 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=e40e1711-b83d-4d71-85e3-0cf2ce6ea0b4@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=f.gruenbichler@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal