public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Shannon Sterz" <s.sterz@proxmox.com>
To: "Hannes Laimer" <h.laimer@proxmox.com>, <pbs-devel@lists.proxmox.com>
Subject: Re: [PATCH proxmox-backup v2 2/3] api: datastore: add option to run garbage collection before unmount
Date: Mon, 20 Apr 2026 10:52:00 +0200	[thread overview]
Message-ID: <DHXURMQFJ0LP.FZR9LGNAK7G0@proxmox.com> (raw)
In-Reply-To: <41889dc0-da67-4316-86dd-8facc5e23405@proxmox.com>

On Mon Apr 20, 2026 at 10:45 AM CEST, Hannes Laimer wrote:
> On 2026-04-20 10:31, Shannon Sterz wrote:
>> On Mon Apr 20, 2026 at 9:42 AM CEST, Hannes Laimer wrote:

-->8 snip 8<--

>>> +    // Setting gc-on-unmount requires Datastore.Modify (or Datastore.Allocate at creation), the
>>> +    // same level needed to start GC directly, so no privilege escalation from triggering it here.
>>> +    if datastore.gc_on_unmount.unwrap_or(false) {
>>> +        let client = crate::client_helpers::connect_to_localhost()
>>> +            .context("failed to connect to localhost for starting GC")?;
>>> +        match client
>>> +            .post(&format!("api2/json/admin/datastore/{store}/gc"), None)
>>> +            .await
>>> +        {
>>> +            Ok(_) => info!("started garbage collection, unmount will wait for it to finish"),
>>> +            Err(err) => warn!("unable to start garbage collection before unmount: {err}"),
>>
>> small question, any reason to do a round trip across the api here
>> instead of factoring out the logic needed here from the
>> `start_garbage_collection` function below and calling that directly?
>> something like this should to the trick:
>>
>> ```
>>
>> fn init_garbage_collection_job(
>>     store: String,
>>     auth_id: &Authid,
>>     to_stdout: bool,
>> ) -> Result<Value, Error> {
>>     let datastore = DataStore::lookup_datastore(lookup_with(&store, Operation::Write))?;
>>
>>     let job = Job::new("garbage_collection", &store)
>>         .map_err(|_| format_err!("garbage collection already running"))?;
>>
>>     let upid_str =
>>         crate::server::do_garbage_collection_job(job, datastore, &auth_id, None, to_stdout)
>>             .map_err(|err| {
>>                 format_err!("unable to start garbage collection job on datastore {store} - {err:#}")
>>             })?;
>>
>>     Ok(json!(upid_str))
>> }
>>
>> you can then call that in `do_unmount` and `start_garbage_collection`.
>> or am i missing something? would also associate the gc task with user
>> starting the unmount operation instead of root@pam if im not mistaken?
>>
>
> the reason is that the unmounting is running in the api process, so as
> root. if we don't go through the api we would have the gc also running
> in the privileged process. general datastore operations, like gc, do
> assume they run as the `backup` user
>
> hitting the (proxy) api endpoint is the simplest way to have the gc run
> with the correct permissions

ah yeah makes sense, thanks for clearing that up.




  reply	other threads:[~2026-04-20  8:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20  7:42 [PATCH proxmox{,-backup} v2 0/3] fixes #7465: add gc-on-unmount flag Hannes Laimer
2026-04-20  7:42 ` [PATCH proxmox v2 1/3] pbs-api-types: add gc-on-unmount flag for removable datastores Hannes Laimer
2026-04-21 22:17   ` applied: " Thomas Lamprecht
2026-04-20  7:42 ` [PATCH proxmox-backup v2 2/3] api: datastore: add option to run garbage collection before unmount Hannes Laimer
2026-04-20  8:32   ` Shannon Sterz
2026-04-20  8:45     ` Hannes Laimer
2026-04-20  8:52       ` Shannon Sterz [this message]
2026-04-20  7:42 ` [PATCH proxmox-backup v2 3/3] ui: datastore: expose gc-on-unmount setting Hannes Laimer
2026-04-21 11:34 ` [PATCH proxmox{,-backup} v2 0/3] fixes #7465: add gc-on-unmount flag 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=DHXURMQFJ0LP.FZR9LGNAK7G0@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=h.laimer@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