public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup] api: also update datastore cache on api process
@ 2025-05-12 12:59 Hannes Laimer
  0 siblings, 0 replies; only message in thread
From: Hannes Laimer @ 2025-05-12 12:59 UTC (permalink / raw)
  To: pbs-devel

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-05-12 12:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-12 12:59 [pbs-devel] [PATCH proxmox-backup] api: also update datastore cache on api process Hannes Laimer

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