From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH proxmox-backup] api: gc: fix mismatched UPID and jobstate in GC status
Date: Fri, 13 Nov 2026 09:16:27 +0100 [thread overview]
Message-ID: <20261113081627.43740-1-c.ebner@proxmox.com> (raw)
garbage_collection_status_unchecked() gathers information from two
locations, the .gc-status as well as the job state file.
The former is written only on successful garbage collection runs,
the latter on every run, including failed ones.
Collecting the status incorrectly mixed the information from both,
leading to comparison of timestamps from two different runs, which
caused incorrect or negative durations. Further, missing a
.gc-status UPID dropped last-run endtimes and states completely.
To fix this, prefer computed_schedule.last_run_upid together with its
matching endtime and state, and guard duration calculation against
negative values. If jobstate has no last_run_upid, fall back to
reading the task status for a non-active .gc-status UPID.
Reported-by: https://forum.proxmox.com/threads/187530/
Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
src/api2/admin/datastore.rs | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 3ba25934f..382c3c965 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -64,7 +64,9 @@ use pbs_datastore::{
ensure_datastore_is_mounted, task_tracking,
};
use pbs_tools::json::required_string_param;
-use proxmox_rest_server::{WorkerTask, formatter, worker_is_active};
+use proxmox_rest_server::{
+ WorkerTask, formatter, upid_read_status, worker_is_active, worker_is_active_local,
+};
use crate::api2::backup::optional_ns_param;
use crate::api2::node::rrd::create_value_from_rrd;
@@ -1267,20 +1269,36 @@ pub(crate) fn garbage_collection_status_unchecked(
};
let datastore = DataStore::lookup_datastore(lookup_with(&store, Operation::Read))?;
- let status_in_memory = datastore.last_gc_status();
+ let mut status_in_memory = datastore.last_gc_status();
let computed_schedule: JobScheduleStatus =
compute_schedule_status("garbage_collection", &store, info.schedule.as_deref())?;
- if let Some(ref upid) = status_in_memory.upid {
- if let Some(endtime) = computed_schedule.last_run_endtime {
- if let Ok(parsed_upid) = upid.parse::<UPID>() {
- info.duration = Some(endtime - parsed_upid.starttime);
- }
+ let calc_duration = |starttime: i64, endtime: i64| -> Option<i64> {
+ endtime.checked_sub(starttime).filter(|&d| d >= 0)
+ };
+
+ if let Some(upid) = &computed_schedule.last_run_upid {
+ if let (Some(endtime), Ok(parsed_upid)) =
+ (computed_schedule.last_run_endtime, upid.parse::<UPID>())
+ {
+ info.duration = calc_duration(parsed_upid.starttime, endtime);
}
info.last_run_endtime = computed_schedule.last_run_endtime;
info.last_run_state = computed_schedule.last_run_state;
+ status_in_memory.upid = Some(upid.clone());
+ } else if let Some(upid) = &status_in_memory.upid {
+ if let Ok(parsed_upid) = upid.parse::<UPID>() {
+ if !worker_is_active_local(&parsed_upid) {
+ if let Ok(task_state) = upid_read_status(&parsed_upid) {
+ let endtime = task_state.endtime();
+ info.duration = calc_duration(parsed_upid.starttime, endtime);
+ info.last_run_endtime = Some(endtime);
+ info.last_run_state = Some(task_state.to_string());
+ }
+ }
+ }
}
info.next_run = computed_schedule.next_run;
--
2.47.3
next reply other threads:[~2026-11-13 8:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 8:16 Christian Ebner [this message]
2026-11-14 21:27 ` applied: [PATCH proxmox-backup] api: gc: fix mismatched UPID and jobstate in GC status Thomas Lamprecht
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=20261113081627.43740-1-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.