From 6f67dc1197649ebffaed81cbd3bac524359540f3 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 13 Jul 2022 13:52:38 +0200 Subject: [PATCH] api: wrap delete_group in spawn_blocking Signed-off-by: Wolfgang Bumiller --- src/api2/admin/datastore.rs | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index a77bde35..b1e353de 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -273,31 +273,34 @@ pub fn list_groups( }, )] /// Delete backup group including all snapshots. -pub fn delete_group( +pub async fn delete_group( store: String, ns: Option, group: pbs_api_types::BackupGroup, - _info: &ApiMethod, rpcenv: &mut dyn RpcEnvironment, ) -> Result { let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; - let ns = ns.unwrap_or_default(); - let datastore = check_privs_and_load_store( - &store, - &ns, - &auth_id, - PRIV_DATASTORE_MODIFY, - PRIV_DATASTORE_PRUNE, - Some(Operation::Write), - &group, - )?; + tokio::task::spawn_blocking(move || { + let ns = ns.unwrap_or_default(); - if !datastore.remove_backup_group(&ns, &group)? { - bail!("group only partially deleted due to protected snapshots"); - } + let datastore = check_privs_and_load_store( + &store, + &ns, + &auth_id, + PRIV_DATASTORE_MODIFY, + PRIV_DATASTORE_PRUNE, + Some(Operation::Write), + &group, + )?; - Ok(Value::Null) + if !datastore.remove_backup_group(&ns, &group)? { + bail!("group only partially deleted due to protected snapshots"); + } + + Ok(Value::Null) + }) + .await? } #[api(