public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH FOLLOW-UP proxmox-backup 3/4] task tracking: refactor code
Date: Thu, 20 Nov 2025 10:01:38 +0100	[thread overview]
Message-ID: <20251120090342.195791-2-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20251120090342.195791-1-f.gruenbichler@proxmox.com>

no semantic changes intended, but make the code a little more readable and
slightly faster, by only initializing the new entry when needed.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
 pbs-datastore/src/task_tracking.rs | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/pbs-datastore/src/task_tracking.rs b/pbs-datastore/src/task_tracking.rs
index 755d88fdf..b7e569efb 100644
--- a/pbs-datastore/src/task_tracking.rs
+++ b/pbs-datastore/src/task_tracking.rs
@@ -101,10 +101,7 @@ pub fn update_active_operations(
     let (_lock, options) = open_lock_file(name)?;
 
     let pid = std::process::id();
-    let starttime = procfs::PidStat::read_from_pid(Pid::from_raw(pid as pid_t))?.starttime;
-
-    let mut updated_active_operations = ActiveOperationStats::default();
-    let mut found_entry = false;
+    let mut current_pid_operations = None;
     let mut updated_tasks: Vec<TaskOperations> = match file_read_optional_string(&path)? {
         Some(data) => serde_json::from_str::<Vec<TaskOperations>>(&data)?
             .into_iter()
@@ -112,13 +109,12 @@ pub fn update_active_operations(
                 match procfs::check_process_running_pstart(task.pid as pid_t, task.starttime) {
                     // update entry for current PID
                     Some(_stat) if pid == task.pid => {
-                        found_entry = true;
                         match operation {
                             Operation::Read => task.active_operations.read += count,
                             Operation::Write => task.active_operations.write += count,
                             Operation::Lookup => (), // no IO must happen there
                         };
-                        updated_active_operations = task.active_operations;
+                        current_pid_operations = Some(task.active_operations);
                         Some(task)
                     }
                     // keep other entries
@@ -131,7 +127,9 @@ pub fn update_active_operations(
         None => Vec::new(),
     };
 
-    if !found_entry {
+    let active_operations = if let Some(current) = current_pid_operations {
+        current
+    } else {
         if count < 0 {
             // if we don't have any operations at the moment, decrementing is not possible..
             log::warn!(
@@ -140,22 +138,27 @@ to decrement by {count}!"
             );
             count = 0;
         };
+        let starttime = procfs::PidStat::read_from_pid(Pid::from_raw(pid as pid_t))?.starttime;
+
+        let mut active_operations = ActiveOperationStats::default();
         match operation {
-            Operation::Read => updated_active_operations.read = count,
-            Operation::Write => updated_active_operations.write = count,
+            Operation::Read => active_operations.read = count,
+            Operation::Write => active_operations.write = count,
             Operation::Lookup => (),
         };
         updated_tasks.push(TaskOperations {
             pid,
             starttime,
-            active_operations: updated_active_operations,
+            active_operations,
         });
-    }
+        active_operations
+    };
     replace_file(
         &path,
         serde_json::to_string(&updated_tasks)?.as_bytes(),
         options,
         false,
-    )
-    .map(|_| updated_active_operations)
+    )?;
+
+    Ok(active_operations)
 }
-- 
2.47.3



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel

  reply	other threads:[~2025-11-20  9:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-20  6:02 [pbs-devel] [PATCH proxmox-backup v2] task tracking: improve pruning and fix accounting for missing entries Hannes Laimer
2025-11-20  9:01 ` [pbs-devel] [PATCH FOLLOW-UP proxmox-backup 2/4] task tracking: actually reset entry if desynced Fabian Grünbichler
2025-11-20  9:01   ` Fabian Grünbichler [this message]
2025-11-20  9:01   ` [pbs-devel] [RFC FOLLOW-UP proxmox-backup 4/4] task tracking: simplify public interface Fabian Grünbichler
2025-11-20  9:37   ` [pbs-devel] [PATCH FOLLOW-UP proxmox-backup 2/4] task tracking: actually reset entry if desynced Hannes Laimer
2025-11-20 10:22     ` Fabian Grünbichler

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=20251120090342.195791-2-f.gruenbichler@proxmox.com \
    --to=f.gruenbichler@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal