public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] api: also update datastore cache on api process
Date: Mon, 12 May 2025 14:59:33 +0200	[thread overview]
Message-ID: <20250512125933.156192-1-h.laimer@proxmox.com> (raw)

Until now we only told the proxy through the command socket that it
should check if it has to update its cache. We never did that for the
cache the api process holds, this wasn't really a problem because we
never actually used any chunks store refs that would have been cached in
the first place, still, if we should ever have the api process do
anything that involves a `datastore_lookup` it will also be in the
cache on the api process.

This also updates the process-local cache whenever we tell the proxy
process to update its cache. And since this is the same logic in a few
places I moved it into a new helper function that does both,
- tell the proxy to update its cache
- and, update its own

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 src/api2/admin/datastore.rs  | 30 ++++++++++++++++++------------
 src/api2/config/datastore.rs | 32 +++++---------------------------
 2 files changed, 23 insertions(+), 39 deletions(-)

diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index a3ba82e21..02a53a932 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -164,6 +164,23 @@ fn get_all_snapshot_files(
     Ok((manifest, files))
 }
 
+/// Triggers a cache update (if needed) on both the api and proxy process
+pub async fn update_datastore_cache(name: &str) -> Result<(), Error> {
+    if let Ok(proxy_pid) = proxmox_rest_server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)
+    {
+        let sock = proxmox_daemon::command_socket::path_from_pid(proxy_pid);
+        let _ = proxmox_daemon::command_socket::send_raw(
+            sock,
+            &format!(
+                "{{\"command\":\"update-datastore-cache\",\"args\":\"{}\"}}\n",
+                name
+            ),
+        )
+        .await;
+    };
+    DataStore::update_datastore_cache(name)
+}
+
 #[api(
     input: {
         properties: {
@@ -2752,18 +2769,7 @@ pub async fn unmount(store: String, rpcenv: &mut dyn RpcEnvironment) -> Result<V
     let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
     let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
 
-    if let Ok(proxy_pid) = proxmox_rest_server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)
-    {
-        let sock = proxmox_daemon::command_socket::path_from_pid(proxy_pid);
-        let _ = proxmox_daemon::command_socket::send_raw(
-            sock,
-            &format!(
-                "{{\"command\":\"update-datastore-cache\",\"args\":\"{}\"}}\n",
-                &store
-            ),
-        )
-        .await;
-    }
+    let _ = update_datastore_cache(&store).await;
 
     let upid = WorkerTask::new_thread(
         "unmount-device",
diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs
index b133be707..8233ec1a1 100644
--- a/src/api2/config/datastore.rs
+++ b/src/api2/config/datastore.rs
@@ -21,8 +21,8 @@ use pbs_config::BackupLockGuard;
 use pbs_datastore::chunk_store::ChunkStore;
 
 use crate::api2::admin::{
-    datastore::do_mount_device, prune::list_prune_jobs, sync::list_config_sync_jobs,
-    verify::list_verification_jobs,
+    datastore::do_mount_device, datastore::update_datastore_cache, prune::list_prune_jobs,
+    sync::list_config_sync_jobs, verify::list_verification_jobs,
 };
 use crate::api2::config::prune::{delete_prune_job, do_create_prune_job, has_prune_job};
 use crate::api2::config::sync::delete_sync_job;
@@ -533,19 +533,7 @@ pub fn update_datastore(
     // tell the proxy it might have to clear a cache entry
     if maintenance_mode_changed {
         tokio::spawn(async move {
-            if let Ok(proxy_pid) =
-                proxmox_rest_server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)
-            {
-                let sock = proxmox_daemon::command_socket::path_from_pid(proxy_pid);
-                let _ = proxmox_daemon::command_socket::send_raw(
-                    sock,
-                    &format!(
-                        "{{\"command\":\"update-datastore-cache\",\"args\":\"{}\"}}\n",
-                        &name
-                    ),
-                )
-                .await;
-            }
+            let _ = update_datastore_cache(&name).await;
         });
     }
 
@@ -647,18 +635,8 @@ pub async fn delete_datastore(
 
     let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
     let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
-    if let Ok(proxy_pid) = proxmox_rest_server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)
-    {
-        let sock = proxmox_daemon::command_socket::path_from_pid(proxy_pid);
-        let _ = proxmox_daemon::command_socket::send_raw(
-            sock,
-            &format!(
-                "{{\"command\":\"update-datastore-cache\",\"args\":\"{}\"}}\n",
-                name.clone()
-            ),
-        )
-        .await;
-    };
+
+    let _ = update_datastore_cache(&name).await;
 
     let upid = WorkerTask::new_thread(
         "delete-datastore",
-- 
2.39.5



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


                 reply	other threads:[~2025-05-12 12:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250512125933.156192-1-h.laimer@proxmox.com \
    --to=h.laimer@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