From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id B69641FF13C for ; Thu, 19 Mar 2026 12:03:40 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E38D31B429; Thu, 19 Mar 2026 12:03:55 +0100 (CET) From: =?UTF-8?q?Michael=20K=C3=B6ppl?= To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox-backup v2 1/3] api: move statefile loading into compute_schedule_status Date: Thu, 19 Mar 2026 12:03:16 +0100 Message-ID: <20260319110318.70346-2-m.koeppl@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260319110318.70346-1-m.koeppl@proxmox.com> References: <20260319110318.70346-1-m.koeppl@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1773918157649 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.982 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.408 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.819 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.903 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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: DWKF7AZYHDDW7U74KEHXZSUGP5JGOCSK X-Message-ID-Hash: DWKF7AZYHDDW7U74KEHXZSUGP5JGOCSK X-MailFrom: m.koeppl@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: Centralize loading of the job statefiles in compute_schedule_status, reducing code duplication across the job management API endpoints. Signed-off-by: Michael Köppl --- src/api2/admin/datastore.rs | 13 +++---------- src/api2/admin/prune.rs | 9 +++------ src/api2/admin/sync.rs | 9 +++------ src/api2/admin/verify.rs | 9 +++------ src/api2/tape/backup.rs | 9 +++------ src/server/jobstate.rs | 8 ++++++-- 6 files changed, 21 insertions(+), 36 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index cca340553..4018e0301 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -70,7 +70,7 @@ use proxmox_rest_server::{formatter, worker_is_active, WorkerTask}; use crate::api2::backup::optional_ns_param; use crate::api2::node::rrd::create_value_from_rrd; use crate::backup::{check_ns_privs_full, ListAccessibleBackupGroups, VerifyWorker, NS_PRIVS_OK}; -use crate::server::jobstate::{compute_schedule_status, Job, JobState}; +use crate::server::jobstate::{compute_schedule_status, Job}; use crate::tools::{backup_info_to_snapshot_list_item, get_all_snapshot_files, read_backup_index}; // helper to unify common sequence of checks: @@ -1167,19 +1167,12 @@ pub fn garbage_collection_status( let datastore = DataStore::lookup_datastore(&store, Operation::Read)?; let status_in_memory = datastore.last_gc_status(); - let state_file = JobState::load("garbage_collection", &store) - .map_err(|err| log::error!("could not open GC statefile for {store}: {err}")) - .ok(); let mut last = proxmox_time::epoch_i64(); if let Some(ref upid) = status_in_memory.upid { - let mut computed_schedule: JobScheduleStatus = JobScheduleStatus::default(); - if let Some(state) = state_file { - if let Ok(cs) = compute_schedule_status(&state, Some(upid)) { - computed_schedule = cs; - } - } + let computed_schedule: JobScheduleStatus = + compute_schedule_status("garbage_collection", &store, Some(upid))?; if let Some(endtime) = computed_schedule.last_run_endtime { last = endtime; diff --git a/src/api2/admin/prune.rs b/src/api2/admin/prune.rs index a5ebf2975..1b1d2f1ba 100644 --- a/src/api2/admin/prune.rs +++ b/src/api2/admin/prune.rs @@ -1,6 +1,6 @@ //! Datastore Prune Job Management -use anyhow::{format_err, Error}; +use anyhow::Error; use serde_json::Value; use proxmox_router::{ @@ -18,7 +18,7 @@ use pbs_config::CachedUserInfo; use crate::server::{ do_prune_job, - jobstate::{compute_schedule_status, Job, JobState}, + jobstate::{compute_schedule_status, Job}, }; #[api( @@ -73,10 +73,7 @@ pub fn list_prune_jobs( let mut list = Vec::new(); for job in job_config_iter { - let last_state = JobState::load("prunejob", &job.id) - .map_err(|err| format_err!("could not open statefile for {}: {}", &job.id, err))?; - - let mut status = compute_schedule_status(&last_state, Some(&job.schedule))?; + let mut status = compute_schedule_status("prunejob", &job.id, Some(&job.schedule))?; if job.disable { status.next_run = None; } diff --git a/src/api2/admin/sync.rs b/src/api2/admin/sync.rs index 6722ebea0..2384ede75 100644 --- a/src/api2/admin/sync.rs +++ b/src/api2/admin/sync.rs @@ -1,6 +1,6 @@ //! Datastore Synchronization Job Management -use anyhow::{bail, format_err, Error}; +use anyhow::{bail, Error}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -19,7 +19,7 @@ use pbs_config::CachedUserInfo; use crate::{ api2::config::sync::{check_sync_job_modify_access, check_sync_job_read_access}, - server::jobstate::{compute_schedule_status, Job, JobState}, + server::jobstate::{compute_schedule_status, Job}, server::sync::do_sync_job, }; @@ -112,10 +112,7 @@ pub fn list_config_sync_jobs( continue; } - let last_state = JobState::load("syncjob", &job.id) - .map_err(|err| format_err!("could not open statefile for {}: {}", &job.id, err))?; - - let status = compute_schedule_status(&last_state, job.schedule.as_deref())?; + let status = compute_schedule_status("syncjob", &job.id, job.schedule.as_deref())?; list.push(SyncJobStatus { config: job, diff --git a/src/api2/admin/verify.rs b/src/api2/admin/verify.rs index 66695236c..af5b7fff4 100644 --- a/src/api2/admin/verify.rs +++ b/src/api2/admin/verify.rs @@ -1,6 +1,6 @@ //! Datastore Verify Job Management -use anyhow::{format_err, Error}; +use anyhow::Error; use serde_json::Value; use proxmox_router::{ @@ -19,7 +19,7 @@ use pbs_config::CachedUserInfo; use crate::server::{ do_verification_job, - jobstate::{compute_schedule_status, Job, JobState}, + jobstate::{compute_schedule_status, Job}, }; #[api( @@ -73,10 +73,7 @@ pub fn list_verification_jobs( let mut list = Vec::new(); for job in job_config_iter { - let last_state = JobState::load("verificationjob", &job.id) - .map_err(|err| format_err!("could not open statefile for {}: {}", &job.id, err))?; - - let status = compute_schedule_status(&last_state, job.schedule.as_deref())?; + let status = compute_schedule_status("verificationjob", &job.id, job.schedule.as_deref())?; list.push(VerificationJobStatus { config: job, diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs index 47e8d0209..2c1aa5c0a 100644 --- a/src/api2/tape/backup.rs +++ b/src/api2/tape/backup.rs @@ -1,6 +1,6 @@ use std::sync::{Arc, Mutex}; -use anyhow::{bail, format_err, Error}; +use anyhow::{bail, Error}; use serde_json::Value; use tracing::{info, warn}; @@ -23,7 +23,7 @@ use pbs_datastore::{DataStore, StoreProgress}; use crate::tape::{assert_datastore_type, TapeNotificationMode}; use crate::{ server::{ - jobstate::{compute_schedule_status, Job, JobState}, + jobstate::{compute_schedule_status, Job}, TapeBackupJobSummary, }, tape::{ @@ -97,10 +97,7 @@ pub fn list_tape_backup_jobs( continue; } - let last_state = JobState::load("tape-backup-job", &job.id) - .map_err(|err| format_err!("could not open statefile for {}: {}", &job.id, err))?; - - let status = compute_schedule_status(&last_state, job.schedule.as_deref())?; + let status = compute_schedule_status("tape-backup-job", &job.id, job.schedule.as_deref())?; let next_run = status.next_run.unwrap_or(current_time); diff --git a/src/server/jobstate.rs b/src/server/jobstate.rs index dc9f6c90d..cfb0b8945 100644 --- a/src/server/jobstate.rs +++ b/src/server/jobstate.rs @@ -301,11 +301,15 @@ impl Job { } pub fn compute_schedule_status( - job_state: &JobState, + jobtype: &str, + jobname: &str, schedule: Option<&str>, ) -> Result { + let job_state = JobState::load(jobtype, jobname) + .map_err(|err| format_err!("could not open statefile for {}: {}", jobname, err))?; + let (upid, endtime, state, last) = match job_state { - JobState::Created { time } => (None, None, None, *time), + JobState::Created { time } => (None, None, None, time), JobState::Started { upid } => { let parsed_upid: UPID = upid.parse()?; (Some(upid), None, None, parsed_upid.starttime) -- 2.47.3