From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 6C1B11FF0B7 for ; Fri, 13 Nov 2026 09:16:50 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 7A76D217A7; Fri, 13 Nov 2026 09:16:49 +0100 (CET) From: Christian Ebner 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 Message-ID: <20261113081627.43740-1-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794557803122 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.399 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: SCVDQXAV5VX67VHSTFPGOVFLH2UPYVMN X-Message-ID-Hash: SCVDQXAV5VX67VHSTFPGOVFLH2UPYVMN X-MailFrom: c.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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::() { - info.duration = Some(endtime - parsed_upid.starttime); - } + let calc_duration = |starttime: i64, endtime: i64| -> Option { + 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::()) + { + 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::() { + 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