[pbs-devel] [PATCH proxmox-backup] api: also update datastore cache on api process
Hannes Laimer
h.laimer at proxmox.com
Mon May 12 14:59:33 CEST 2025
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 at 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
More information about the pbs-devel
mailing list