Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,15 @@ pub struct BackgroundSession {
mount: Option<Mount>,
}

/// A set of relevant threads during an asynchronous unmounting process.
#[derive(Debug)]
pub struct BackgroundUnmount {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Re-export the background unmount type

Because this new public return type lives inside the private session module while src/lib.rs only re-exports BackgroundSession, downstream crates can receive the value by inference but cannot name it in their own function signatures, struct fields, or imports. Since umount_background is a public API intended for batching/structured concurrency, re-export BackgroundUnmount from the crate root alongside BackgroundSession.

Useful? React with 👍 / 👎.

/// The unmounting thread
pub unmount_thread: JoinHandle<io::Result<()>>,
/// The session thread that hosts the filesystem
pub session_thread: JoinHandle<io::Result<()>>,
}

impl BackgroundSession {
/// Unmount the filesystem and join the background thread.
pub fn umount_and_join(mut self) -> io::Result<()> {
Expand All @@ -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<JoinHandle<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 || {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Surface unmount thread spawn errors

In processes that have exhausted their thread quota or hit OS limits, std::thread::spawn panics on failure; unlike Session::spawn above, which uses thread::Builder::spawn(...)?, this makes the new cleanup path able to panic a daemon while it is trying to unmount. Please return an io::Result<BackgroundUnmount> or otherwise surface the spawn error so callers can handle this failure mode.

Useful? React with 👍 / 👎.

if let Some(mount) = self.mount.take() {
mount.umount()?;
}
Ok(())
});
BackgroundUnmount {
unmount_thread,
session_thread: self.guard,
}
}
}
Loading