Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose file-descriptor and read-one-request/write-one-reply functions for use in event loops #74

Open
sp3d opened this issue Sep 26, 2016 · 2 comments

Comments

@sp3d
Copy link

sp3d commented Sep 26, 2016

Right now, rust-fuse expects either mount or spawn_mount to be called, and these run an event loop, doing blocking reads to the FUSE fd and then dispatching the events read from it to user-implemented callbacks.

In most filesystems of some complexity, IPC, disk IO, or network IO will be performed in response to FUSE events, and it would be nice to be able to perform these asynchronously, e.g. with MIO. But because rust-fuse runs the eventloop itself and hides the FUSE fd, it isn't possible to implement MIO's Evented trait for fuse::Channel (which isn't even exposed in the crate's public API). Asnychronous operation enables higher throughput, so it's desirable to overlap not just multiple requests to the filesystem, but also those requests with IO operations to other OS resources, and it shouldn't be necessary to spawn multiple threads to do so.

If rust-fuse provided a way to get the fd so it can be added to an epoll-based event-loop, as well functions to read a request from the FUSE fd and write a reply to it, this integration would be easy to implement.

@zargony
Copy link
Owner

zargony commented Apr 5, 2017

I like the idea, but I'm not sure if this is actually possible. It might not be able to asynchronously use the file descriptor to the kernel driver (see #80), I'm not sure about that.
On the other hand, rust-fuse is meant to encapsulate the kernel communication. I'm not sure how we could expose the fd and still keep a reasonable encapsulation of talking to the kernel driver.

@roblabla
Copy link

roblabla commented Jul 6, 2017

Instead of exposing the Fd, it might be possible to expose an opaque object implementing mio::Evented. This would allow it to be used in mio as such :

let FUSE: Token = Token(0);
let poll = Poll::new()?;
let fuse_handle = fuse::mount_evented(fs, mountpoint, &[])?;
// Start listening for incoming connections
poll.register(&fuse_handle, FUSE, Ready::readable(),
              PollOpt::edge())?;
// Other potential registers here

// Create storage for events
let mut events = Events::with_capacity(1024);
loop {
    poll.poll(&mut events, None)?;

    for event in events.iter() {
        match event.token() {
            FUSE => {
                fuse_handle.handle_one_request();
            }
            // Handle other registers
            _ => unreachable!(),
        }
    }
}

It's also possible to use it with tokio with tokio-core::reactor::PollEvented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants