From 0eb8d3be58e3221b61e5e9bbb505823cc0bb2628 Mon Sep 17 00:00:00 2001 From: Omer Tuchfeld Date: Fri, 6 Sep 2024 19:12:26 +0200 Subject: [PATCH] cli: wipe_ostree in spawn_blocking An async fn shouldn't block the thread, but write_deployments is a blocking heavy filesystem operation. Using tokio::task::spawn_blocking to avoid blocking async threads. Solves #778 Signed-off-by: Omer Tuchfeld --- lib/src/cli.rs | 3 +-- lib/src/deploy.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/src/cli.rs b/lib/src/cli.rs index c5bf5a1e..76b4b88f 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -21,7 +21,6 @@ use ostree_ext::keyfileext::KeyFileExt; use ostree_ext::ostree; use schemars::schema_for; -use crate::deploy::wipe_ostree; use crate::deploy::RequiredHostSpec; use crate::lints; use crate::spec::Host; @@ -929,7 +928,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> { StateOpts::WipeOstree => { let sysroot = ostree::Sysroot::new_default(); sysroot.load(gio::Cancellable::NONE)?; - wipe_ostree(&sysroot).await?; + crate::deploy::wipe_ostree(sysroot).await?; Ok(()) } }, diff --git a/lib/src/deploy.rs b/lib/src/deploy.rs index 67a5794e..cd1ef419 100644 --- a/lib/src/deploy.rs +++ b/lib/src/deploy.rs @@ -288,10 +288,13 @@ pub(crate) async fn prune_container_store(sysroot: &Storage) -> Result<()> { Ok(()) } -pub(crate) async fn wipe_ostree(sysroot: &Sysroot) -> Result<()> { - sysroot - .write_deployments(&[], gio::Cancellable::NONE) - .context("removing deployments")?; +pub(crate) async fn wipe_ostree(sysroot: Sysroot) -> Result<()> { + tokio::task::spawn_blocking(move || { + sysroot + .write_deployments(&[], gio::Cancellable::NONE) + .context("removing deployments") + }) + .await??; Ok(()) }