From 6eeec7989faf443485bb7116a878a39edff8a826 Mon Sep 17 00:00:00 2001 From: Khanh Tran Date: Fri, 19 Jun 2026 10:39:48 +0700 Subject: [PATCH] feat: add async unmount facilities --- src/lib.rs | 1 + src/session.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 6fb6cb12..06c7241c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,6 +75,7 @@ pub use crate::reply::ReplyWrite; pub use crate::reply::ReplyXattr; pub use crate::request_param::Request; pub use crate::session::BackgroundSession; +pub use crate::session::BackgroundUnmount; use crate::session::MAX_WRITE_SIZE; pub use crate::session::Session; pub use crate::session::SessionACL; diff --git a/src/session.rs b/src/session.rs index 76261db3..3fad3133 100644 --- a/src/session.rs +++ b/src/session.rs @@ -566,6 +566,15 @@ pub struct BackgroundSession { mount: Option, } +/// A set of relevant threads during an asynchronous unmounting process. +#[derive(Debug)] +pub struct BackgroundUnmount { + /// The unmounting thread + pub unmount_thread: JoinHandle>, + /// The session thread that hosts the filesystem + pub session_thread: JoinHandle>, +} + impl BackgroundSession { /// Unmount the filesystem and join the background thread. pub fn umount_and_join(mut self) -> io::Result<()> { @@ -591,4 +600,26 @@ impl BackgroundSession { ) })? } + + /// Unmount the filesystem and return the background thread for manual joining. This is useful for asynchronous daemons that coordinate access to multiple filesystems. + pub fn umount_no_join(mut self) -> io::Result>> { + if let Some(mount) = self.mount.take() { + mount.umount()?; + } + Ok(self.guard) + } + + /// Unmount the filesystem from a separate thread and return the background thread for manual joining. This allows the main thread to continue doing useful work while reporting errors in the background, and for implementing structured concurrency by giving the filesystem threads an opportunity to be joined. + pub fn umount_background(mut self) -> BackgroundUnmount { + let unmount_thread = thread::spawn(move || { + if let Some(mount) = self.mount.take() { + mount.umount()?; + } + Ok(()) + }); + BackgroundUnmount { + unmount_thread, + session_thread: self.guard, + } + } }