From a577d7d80165497179e6516d5a87dd46de36dec0 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 12 Jul 2022 11:07:55 +0200 Subject: [PATCH] api: move 'list_snapshots' to a blocking thread This is a stop-gap measure to prevent snapshot listing from blocking the main async worker threads as it can potentially do a *lot* of I/O. Ideally we'll move to a proper streaming API, but this will be an API break. Signed-off-by: Wolfgang Bumiller --- src/api2/admin/datastore.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index eb1a4511..a77bde35 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -426,7 +426,7 @@ pub fn delete_snapshot( }, )] /// List backup snapshots. -pub fn list_snapshots( +pub async fn list_snapshots( store: String, ns: Option, backup_type: Option, @@ -437,6 +437,21 @@ pub fn list_snapshots( ) -> Result, Error> { let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; + tokio::task::spawn_blocking(move || unsafe { + list_snapshots_blocking(store, ns, backup_type, backup_id, auth_id) + }) + .await + .map_err(|err| format_err!("failed to await blocking task: {err}"))? +} + +/// This must not run in a main worker thread as it potentially does tons of I/O. +unsafe fn list_snapshots_blocking( + store: String, + ns: Option, + backup_type: Option, + backup_id: Option, + auth_id: Authid, +) -> Result, Error> { let ns = ns.unwrap_or_default(); let list_all = !check_ns_privs_full(