#fuse #virtio #virtio-fs #client-server #daemon #linux #vhost-fs

fuse-backend-rs

A rust library for Fuse(filesystem in userspace) servers and virtio-fs devices

21 releases

0.12.0 Mar 12, 2024
0.11.0 Oct 31, 2023
0.10.5 Aug 3, 2023
0.10.4 Jun 16, 2023
0.1.1 Feb 13, 2021

#38 in Unix APIs

Download history 1505/week @ 2024-01-25 1681/week @ 2024-02-01 1132/week @ 2024-02-08 1104/week @ 2024-02-15 1831/week @ 2024-02-22 1653/week @ 2024-02-29 1563/week @ 2024-03-07 1664/week @ 2024-03-14 1412/week @ 2024-03-21 1282/week @ 2024-03-28 1106/week @ 2024-04-04 1278/week @ 2024-04-11 1542/week @ 2024-04-18 1281/week @ 2024-04-25 1125/week @ 2024-05-02 1133/week @ 2024-05-09

5,329 downloads per month
Used in 7 crates (6 directly)

Apache-2.0 AND BSD-3-Clause

1MB
21K SLoC

Rust FUSE library for server, virtio-fs and vhost-user-fs

Crates.io Crates.io

Design

The fuse-backend-rs crate is an rust library to implement Fuse daemons based on the Linux FUSE device (/dev/fuse) or the virtiofs draft specification.

Linux FUSE is an userspace filesystem framework, and the /dev/fuse device node is the interface for userspace filesystem daemons to communicate with the in-kernel fuse driver.

And the virito-fs specification extends the FUSE framework into the virtualization world, which uses the Virtio protocol to transfer FUSE requests and responses between the Fuse client and server. With virtio-fs, the Fuse client runs within the guest kernel and the Fuse server runs on the host userspace or hardware.

So the fuse-rs crate is a library to communicate with the Linux FUSE clients, which includes:

  • ABI layer, which defines all data structures shared between linux Fuse framework and Fuse daemons.
  • API layer, defines the interfaces for Fuse daemons to implement a userspace file system.
  • Transport layer, which supports both the Linux Fuse device and virtio-fs protocol.
  • VFS/pseudo_fs, an abstraction layer to support multiple file systems by a single virtio-fs device.
  • A sample passthrough file system implementation, which passes through files from daemons to clients.

arch

Examples

Filesystem Drivers

Fuse Servers

Fuse Server and Main Service Loop

A sample fuse server based on the Linux Fuse device (/dev/fuse):

use fuse_backend_rs::api::{server::Server, Vfs, VfsOptions};
use fuse_backend_rs::transport::fusedev::{FuseSession, FuseChannel};

struct FuseServer {
    server: Arc<Server<Arc<Vfs>>>,
    ch: FuseChannel,
}

impl FuseServer {
    fn svc_loop(&self) -> Result<()> {
      // Given error EBADF, it means kernel has shut down this session.
      let _ebadf = std::io::Error::from_raw_os_error(libc::EBADF);
      loop {
        if let Some((reader, writer)) = self
                .ch
                .get_request()
                .map_err(|_| std::io::Error::from_raw_os_error(libc::EINVAL))?
        {
          if let Err(e) = self.server.handle_message(reader, writer, None, None) {
            match e {
              fuse_backend_rs::Error::EncodeMessage(_ebadf) => {
                break;
              }
              _ => {
                error!("Handling fuse message failed");
                continue;
              }
            }
          }
        } else {
          info!("fuse server exits");
          break;
        }
      }
      Ok(())
    }
}

License

This project is licensed under

Dependencies

~3–15MB
~142K SLoC