[pbs-devel] [RFC FOLLOW-UP proxmox-backup 4/4] task tracking: simplify public interface

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Nov 20 10:01:39 CET 2025


instead of an update fn that is always called with 1 or -1, use add/remove_
wrappers.

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---

Notes:
    we could go one step further, and make remove_ return whether it was the last
    one, since that is basically the only thing we are interested in when calling
    either helper..

 pbs-datastore/src/datastore.rs     | 12 ++++++------
 pbs-datastore/src/task_tracking.rs | 16 +++++++++++++++-
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index 0a5179230..8bc58dcbb 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -43,7 +43,7 @@ use crate::fixed_index::{FixedIndexReader, FixedIndexWriter};
 use crate::hierarchy::{ListGroups, ListGroupsType, ListNamespaces, ListNamespacesRecursive};
 use crate::index::IndexFile;
 use crate::s3::S3_CONTENT_PREFIX;
-use crate::task_tracking::{self, update_active_operations};
+use crate::task_tracking::{self, add_active_operation, remove_active_operation};
 use crate::{DataBlob, LocalDatastoreLruCache};
 
 static DATASTORE_MAP: LazyLock<Mutex<HashMap<String, Arc<DataStoreImpl>>>> =
@@ -175,7 +175,7 @@ impl Clone for DataStore {
     fn clone(&self) -> Self {
         let mut new_operation = self.operation;
         if let Some(operation) = self.operation {
-            if let Err(e) = update_active_operations(self.name(), operation, 1) {
+            if let Err(e) = add_active_operation(self.name(), operation) {
                 log::error!("could not update active operations - {}", e);
                 new_operation = None;
             }
@@ -192,7 +192,7 @@ impl Drop for DataStore {
     fn drop(&mut self) {
         if let Some(operation) = self.operation {
             let mut last_task = false;
-            match update_active_operations(self.name(), operation, -1) {
+            match remove_active_operation(self.name(), operation) {
                 Err(e) => log::error!("could not update active operations - {}", e),
                 Ok(updated_operations) => {
                     last_task = updated_operations.read + updated_operations.write == 0;
@@ -356,7 +356,7 @@ impl DataStore {
             let last_digest = datastore.last_digest.as_ref();
             if let Some(true) = last_digest.map(|last_digest| last_digest == &digest) {
                 if let Some(operation) = operation {
-                    update_active_operations(name, operation, 1)?;
+                    add_active_operation(name, operation)?;
                 }
                 return Ok(Arc::new(Self {
                     inner: Arc::clone(datastore),
@@ -382,7 +382,7 @@ impl DataStore {
         datastore_cache.insert(name.to_string(), datastore.clone());
 
         if let Some(operation) = operation {
-            update_active_operations(name, operation, 1)?;
+            add_active_operation(name, operation)?;
         }
 
         Ok(Arc::new(Self {
@@ -469,7 +469,7 @@ impl DataStore {
         )?);
 
         if let Some(operation) = operation {
-            update_active_operations(&name, operation, 1)?;
+            add_active_operation(&name, operation)?;
         }
 
         Ok(Arc::new(Self { inner, operation }))
diff --git a/pbs-datastore/src/task_tracking.rs b/pbs-datastore/src/task_tracking.rs
index b7e569efb..f4f6c57e7 100644
--- a/pbs-datastore/src/task_tracking.rs
+++ b/pbs-datastore/src/task_tracking.rs
@@ -91,7 +91,21 @@ pub fn get_active_operations_locked(
     Ok((data, lock.unwrap()))
 }
 
-pub fn update_active_operations(
+pub fn add_active_operation(
+    name: &str,
+    operation: Operation,
+) -> Result<ActiveOperationStats, Error> {
+    update_active_operations(name, operation, 1)
+}
+
+pub fn remove_active_operation(
+    name: &str,
+    operation: Operation,
+) -> Result<ActiveOperationStats, Error> {
+    update_active_operations(name, operation, -1)
+}
+
+fn update_active_operations(
     name: &str,
     operation: Operation,
     mut count: i64,
-- 
2.47.3





More information about the pbs-devel mailing list