From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: Christian Ebner <c.ebner@proxmox.com>, pbs-devel@lists.proxmox.com
Subject: Re: [PATCH proxmox-backup 3/5] bin: proxy: periodically schedule fstrim on datastore's filesystems
Date: Tue, 24 Mar 2026 15:02:00 +0100 [thread overview]
Message-ID: <1774360858.6m2qiiimp7.astroid@yuna.none> (raw)
In-Reply-To: <f41a44ee-9ac1-4301-bfb8-8b7bdd4387bf@proxmox.com>
On March 19, 2026 4:02 pm, Christian Ebner wrote:
> On 3/19/26 3:36 PM, Christian Ebner wrote:
>> Run the fstrim command as scheduled job on datastores having a
>> schedule defined in the config.
>>
>> This is done since by default the systemd service to execute fstrim
>> invokes the command with:
>>
>> `/sbin/fstrim --listed-in /etc/fstab:/proc/self/mountinfo ...`
>>
>> which however does not cover datastores created on top of a disk,
>> since these are mounted via systemd mount units. fstrim however only
>> evaluates the given list above up to the first non-empty file as
>> stated in the man page [0].
>>
>> [0] https://www.man7.org/linux/man-pages/man8/fstrim.8.html
>>
>> Fixes: https://forum.proxmox.com/threads/181764/
>> Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
>> ---
>> src/bin/proxmox-backup-proxy.rs | 59 +++++++++++++++++++++++++++++++++
>> 1 file changed, 59 insertions(+)
>>
>> diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
>> index c1fe3ac15..1d375e69d 100644
>> --- a/src/bin/proxmox-backup-proxy.rs
>> +++ b/src/bin/proxmox-backup-proxy.rs
>> @@ -508,6 +508,7 @@ async fn schedule_tasks() -> Result<(), Error> {
>> schedule_datastore_verify_jobs().await;
>> schedule_tape_backup_jobs().await;
>> schedule_task_log_rotate().await;
>> + schedule_fstrim().await;
>>
>> Ok(())
>> }
>> @@ -879,6 +880,64 @@ async fn schedule_task_log_rotate() {
>> }
>> }
>>
>> +async fn schedule_fstrim() {
>> + let config = match pbs_config::datastore::config() {
>> + Err(err) => {
>> + eprintln!("unable to read datastore config - {err}");
>> + return;
>> + }
>> + Ok((config, _digest)) => config,
>> + };
>> +
>> + for (store, (_, store_config)) in config.sections {
>> + let store_config: DataStoreConfig = match serde_json::from_value(store_config) {
>> + Ok(c) => c,
>> + Err(err) => {
>> + eprintln!("datastore config from_value failed - {err}");
>> + continue;
>> + }
>> + };
>> +
>> + let event_schedule = match &store_config.fstrim_schedule {
>> + Some(event_schedule) => event_schedule,
>> + None => continue,
>> + };
>> +
>> + let worker_type = "fstrim";
>> + if check_schedule(worker_type, event_schedule, &store) {
>> + let mut job = match Job::new(worker_type, &store) {
>> + Ok(job) => job,
>> + Err(_) => continue, // could not get lock
>> + };
>> +
>> + if let Err(err) = WorkerTask::new_thread(
>> + worker_type,
>> + None,
>> + Authid::root_auth_id().to_string(),
>> + false,
>> + move |worker| {
>> + job.start(&worker.upid().to_string())?;
>> + info!("executing fstrim on filesystem for {store}");
>> +
>> + let path = store_config.absolute_path();
>> + let result = proxmox_backup::tools::disks::fstrim(Path::new(&path))
>> + .map(|output| log::info!("{output}"));
>
> Only realized now that this does not work since unprivileged, but this
> needs to be run as root. So this needs additional rework...
>
> Other open questions still remain though.
it would also need to do a lookup_datastore, since we want to register
fstrim as operation that blocks things like unmounting? which likely
means it should be implemented on top of Datastore, and not called
directly..
>
>> +
>> + let status = worker.create_state(&result);
>> +
>> + if let Err(err) = job.finish(status) {
>> + eprintln!("could not finish job state for {worker_type}: {err}");
>> + }
>> +
>> + result
>> + },
>> + ) {
>> + eprintln!("unable to start fstrim task: {err}");
>> + }
>> + }
>> + }
>> +}
>> +
>> async fn command_reopen_access_logfiles() -> Result<(), Error> {
>> // only care about the most recent daemon instance for each, proxy & api, as other older ones
>> // should not respond to new requests anyway, but only finish their current one and then exit.
>
>
>
>
>
>
next prev parent reply other threads:[~2026-03-24 14:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-19 14:36 [RFC proxmox{,-backup} 0/6] add scheduled fstrim job for datastore's backing filesystems Christian Ebner
2026-03-19 14:36 ` [PATCH proxmox 1/1] pbs-api-types: define fstrim schedule on datastore config Christian Ebner
2026-03-19 14:36 ` [PATCH proxmox-backup 1/5] tools: add helper to run fstrim command on path or mountpoint Christian Ebner
2026-03-19 14:36 ` [PATCH proxmox-backup 2/5] api: config: expose fstrim schedule for datastores Christian Ebner
2026-03-19 14:36 ` [PATCH proxmox-backup 3/5] bin: proxy: periodically schedule fstrim on datastore's filesystems Christian Ebner
2026-03-19 15:02 ` Christian Ebner
2026-03-24 14:02 ` Fabian Grünbichler [this message]
2026-03-19 14:36 ` [PATCH proxmox-backup 4/5] ui: expose per-datastore fstrim job schedule Christian Ebner
2026-03-19 14:36 ` [PATCH proxmox-backup 5/5] api: set default fstrim schedule on datastore create Christian Ebner
2026-03-25 7:09 ` [RFC proxmox{,-backup} 0/6] add scheduled fstrim job for datastore's backing filesystems Thomas Lamprecht
2026-03-25 8:22 ` 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=1774360858.6m2qiiimp7.astroid@yuna.none \
--to=f.gruenbichler@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox