cberner / fuser

Filesystem in Userspace (FUSE) for Rust
MIT License
835 stars 114 forks source link

How spawn thread for fs `!Send`? #263

Closed kik0908 closed 1 year ago

kik0908 commented 1 year ago

I want spawn a background thread to handle filesystem operations, but spawn_mount2 requires impl Send for filesystem. As I understand from source code, fuser requires Send only to send the file system to a new thread, and not to work directly. This behavior prevents you from using !Send data types(Rc or RefCell for example) in the fs implementation. How can I hack this to use such !Send data types? Also I should have a way to unmount my filesystem from my code like BackgroundSession::join

I could implement a Send wrapper for my filesystem and use the code from BackgroundSession::new but I am limited by the privacy of variables to create a new BackgroundSession.

I admit that there is a solution to my problem in the current version of fuser, but I don't understand how to do it.

kik0908 commented 1 year ago

Sorry for the spam. If someone has the same question, then this problem can be solved using Session:

...
thread::spawn(move || {
    let fs = create_filesystem(); // fs is impl Filesystem
    let mut session = Session::new(fs, mountpoint, options).unwrap();
    let session_end = session.unmount_callable();
    channel.send(session_end);
    session.run()
}
...

and then in main thread:

let mut unmount = channel.recv();
unmount.unmount()