Struct Vfs

Source
pub struct Vfs { /* private fields */ }
Expand description

A union fs that combines multiple backend file systems.

Implementations§

Source§

impl Vfs

Source

pub fn save_to_bytes(&self) -> VfsResult<Vec<u8>>

Saves part of the Vfs metadata into a byte array. The upper layer caller can use this method to save and transfer metadata for the reloading in the future.

Note! This function does not save the information of the Backend FileSystem mounted by VFS, which means that when the caller restores VFS, in addition to restoring the information in the byte array returned by this function, it also needs to manually remount each Backend FileSystem according to the Index obtained from the previous mount, the method restore_mount may be help to do this.

§Example

The following example shows how the function is used in conjunction with restore_from_bytes to implement the serialization and deserialization of VFS.

use fuse_backend_rs::api::{Vfs, VfsIndex, VfsOptions};
use fuse_backend_rs::passthrough::{Config, PassthroughFs};

let new_backend_fs = || {
    let fs_cfg = Config::default();
    let fs = PassthroughFs::<()>::new(fs_cfg.clone()).unwrap();
    fs.import().unwrap();
    Box::new(fs)
};

// create new vfs
let vfs = &Vfs::new(VfsOptions::default());
let paths = vec!["/a", "/a/b", "/a/b/c", "/b", "/b/a/c", "/d"];
// record the backend fs and their VfsIndexes
let backend_fs_list: Vec<(&str, VfsIndex)> = paths
    .iter()
    .map(|path| {
        let fs = new_backend_fs();
        let idx = vfs.mount(fs, path).unwrap();

        (path.to_owned(), idx)
    })
    .collect();

// save the vfs state
let mut buf = vfs.save_to_bytes().unwrap();

// restore the vfs state
let restored_vfs = &Vfs::new(VfsOptions::default());
restored_vfs.restore_from_bytes(&mut buf).unwrap();

// mount the backend fs
backend_fs_list.into_iter().for_each(|(path, idx)| {
    let fs = new_backend_fs();
    vfs.restore_mount(fs, idx, path).unwrap();
});
Source

pub fn restore_from_bytes(&self, buf: &mut Vec<u8>) -> VfsResult<()>

Restores part of the Vfs metadata from a byte array. For more information, see the example of save_to_bytes.

Source§

impl Vfs

Source

pub fn new(opts: VfsOptions) -> Self

Create a new vfs instance

Source

pub fn set_remove_pseudo_root(&mut self)

mark remove pseudo root inode when umount

Source

pub fn initialized(&self) -> bool

For sake of live-upgrade, only after negotiation is done, it’s safe to persist state of vfs.

Source

pub fn options(&self) -> VfsOptions

Get a snapshot of the current vfs options.

Source

pub fn mount(&self, fs: BackFileSystem, path: &str) -> VfsResult<VfsIndex>

Mount a backend file system to path

Source

pub fn restore_mount( &self, fs: BackFileSystem, fs_idx: VfsIndex, path: &str, ) -> Result<()>

Restore a backend file system to path

Source

pub fn umount(&self, path: &str) -> VfsResult<(u64, u64)>

Umount a backend file system at path

Source

pub fn get_rootfs(&self, path: &str) -> VfsResult<Option<Arc<BackFileSystem>>>

Get the mounted backend file system alongside the path if there’s one.

Source

pub fn get_root_pseudofs(&self) -> &PseudoFs

Get the root pseudo fs’s reference in vfs

Trait Implementations§

Source§

impl AsyncFileSystem for Vfs

Source§

fn async_lookup<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 Context, parent: <Self as FileSystem>::Inode, name: &'life2 CStr, ) -> Pin<Box<dyn Future<Output = Result<Entry>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Look up a directory entry by name and get its attributes. Read more
Source§

fn async_getattr<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 Context, inode: <Self as FileSystem>::Inode, handle: Option<<Self as FileSystem>::Handle>, ) -> Pin<Box<dyn Future<Output = Result<(stat64, Duration)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get attributes for a file / directory. Read more
Source§

fn async_setattr<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 Context, inode: <Self as FileSystem>::Inode, attr: stat64, handle: Option<<Self as FileSystem>::Handle>, valid: SetattrValid, ) -> Pin<Box<dyn Future<Output = Result<(stat64, Duration)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Set attributes for a file / directory. Read more
Source§

fn async_open<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 Context, inode: <Self as FileSystem>::Inode, flags: u32, fuse_flags: u32, ) -> Pin<Box<dyn Future<Output = Result<(Option<<Self as FileSystem>::Handle>, OpenOptions)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Open a file. Read more
Source§

fn async_create<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 Context, parent: <Self as FileSystem>::Inode, name: &'life2 CStr, args: CreateIn, ) -> Pin<Box<dyn Future<Output = Result<(Entry, Option<<Self as FileSystem>::Handle>, OpenOptions)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Create and open a file. Read more
Source§

fn async_read<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 Context, inode: <Self as FileSystem>::Inode, handle: <Self as FileSystem>::Handle, w: &'life2 mut (dyn AsyncZeroCopyWriter + Send), size: u32, offset: u64, lock_owner: Option<u64>, flags: u32, ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Read data from a file. Read more
Source§

fn async_write<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 Context, inode: <Self as FileSystem>::Inode, handle: <Self as FileSystem>::Handle, r: &'life2 mut (dyn AsyncZeroCopyReader + Send), size: u32, offset: u64, lock_owner: Option<u64>, delayed_write: bool, flags: u32, fuse_flags: u32, ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Write data to a file. Read more
Source§

fn async_fsync<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 Context, inode: <Self as FileSystem>::Inode, datasync: bool, handle: <Self as FileSystem>::Handle, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Synchronize file contents. Read more
Source§

fn async_fallocate<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 Context, inode: <Self as FileSystem>::Inode, handle: <Self as FileSystem>::Handle, mode: u32, offset: u64, length: u64, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Allocate requested space for file data. Read more
Source§

fn async_fsyncdir<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 Context, inode: <Self as FileSystem>::Inode, datasync: bool, handle: <Self as FileSystem>::Handle, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Synchronize the contents of a directory. Read more
Source§

impl Default for Vfs

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl FileSystem for Vfs

Source§

type Inode = VfsInode

Represents a location in the filesystem tree and can be used to perform operations that act on the metadata of a file/directory (e.g., getattr and setattr). Can also be used as the starting point for looking up paths in the filesystem tree. An Inode may support operating directly on the content of the path that to which it points. FileSystem implementations that support this should set the FsOptions::ZERO_MESSAGE_OPEN option in the return value of the init function. On linux based systems, an Inode is equivalent to opening a file or directory with the libc::O_PATH flag. Read more
Source§

type Handle = u64

Represents a file or directory that is open for reading/writing.
Source§

fn init(&self, opts: FsOptions) -> Result<FsOptions>

Initialize the file system. Read more
Source§

fn destroy(&self)

Clean up the file system. Read more
Source§

fn lookup(&self, ctx: &Context, parent: VfsInode, name: &CStr) -> Result<Entry>

Look up a directory entry by name and get its attributes. Read more
Source§

fn forget(&self, ctx: &Context, inode: VfsInode, count: u64)

Forget about an inode. Read more
Source§

fn getattr( &self, ctx: &Context, inode: VfsInode, handle: Option<u64>, ) -> Result<(stat64, Duration)>

Get attributes for a file / directory. Read more
Source§

fn setattr( &self, ctx: &Context, inode: VfsInode, attr: stat64, handle: Option<u64>, valid: SetattrValid, ) -> Result<(stat64, Duration)>

Set attributes for a file / directory. Read more
Read a symbolic link.
Create a symbolic link. Read more
Source§

fn mknod( &self, ctx: &Context, inode: VfsInode, name: &CStr, mode: u32, rdev: u32, umask: u32, ) -> Result<Entry>

Create a file node. Read more
Source§

fn mkdir( &self, ctx: &Context, parent: VfsInode, name: &CStr, mode: u32, umask: u32, ) -> Result<Entry>

Create a directory. Read more
Remove a file. Read more
Source§

fn rmdir(&self, ctx: &Context, parent: VfsInode, name: &CStr) -> Result<()>

Remove a directory. Read more
Source§

fn rename( &self, ctx: &Context, olddir: VfsInode, oldname: &CStr, newdir: VfsInode, newname: &CStr, flags: u32, ) -> Result<()>

Rename a file / directory. Read more
Create a hard link. Read more
Source§

fn open( &self, ctx: &Context, inode: VfsInode, flags: u32, fuse_flags: u32, ) -> Result<(Option<u64>, OpenOptions, Option<u32>)>

Open a file. Read more
Source§

fn create( &self, ctx: &Context, parent: VfsInode, name: &CStr, args: CreateIn, ) -> Result<(Entry, Option<u64>, OpenOptions, Option<u32>)>

Create and open a file. Read more
Source§

fn read( &self, ctx: &Context, inode: VfsInode, handle: u64, w: &mut dyn ZeroCopyWriter, size: u32, offset: u64, lock_owner: Option<u64>, flags: u32, ) -> Result<usize>

Read data from a file. Read more
Source§

fn write( &self, ctx: &Context, inode: VfsInode, handle: u64, r: &mut dyn ZeroCopyReader, size: u32, offset: u64, lock_owner: Option<u64>, delayed_write: bool, flags: u32, fuse_flags: u32, ) -> Result<usize>

Write data to a file. Read more
Source§

fn flush( &self, ctx: &Context, inode: VfsInode, handle: u64, lock_owner: u64, ) -> Result<()>

Flush the contents of a file. Read more
Source§

fn fsync( &self, ctx: &Context, inode: VfsInode, datasync: bool, handle: u64, ) -> Result<()>

Synchronize file contents. Read more
Source§

fn fallocate( &self, ctx: &Context, inode: VfsInode, handle: u64, mode: u32, offset: u64, length: u64, ) -> Result<()>

Allocate requested space for file data. Read more
Source§

fn release( &self, ctx: &Context, inode: VfsInode, flags: u32, handle: u64, flush: bool, flock_release: bool, lock_owner: Option<u64>, ) -> Result<()>

Release an open file. Read more
Source§

fn statfs(&self, ctx: &Context, inode: VfsInode) -> Result<statvfs64>

Get information about the file system.
Source§

fn setxattr( &self, ctx: &Context, inode: VfsInode, name: &CStr, value: &[u8], flags: u32, ) -> Result<()>

Set an extended attribute. Read more
Source§

fn getxattr( &self, ctx: &Context, inode: VfsInode, name: &CStr, size: u32, ) -> Result<GetxattrReply>

Get an extended attribute. Read more
Source§

fn listxattr( &self, ctx: &Context, inode: VfsInode, size: u32, ) -> Result<ListxattrReply>

List extended attribute names. Read more
Source§

fn removexattr(&self, ctx: &Context, inode: VfsInode, name: &CStr) -> Result<()>

Remove an extended attribute. Read more
Source§

fn opendir( &self, ctx: &Context, inode: VfsInode, flags: u32, ) -> Result<(Option<u64>, OpenOptions)>

Open a directory for reading. Read more
Source§

fn readdir( &self, ctx: &Context, inode: VfsInode, handle: u64, size: u32, offset: u64, add_entry: &mut dyn FnMut(DirEntry<'_>) -> Result<usize>, ) -> Result<()>

Read a directory. Read more
Source§

fn readdirplus( &self, ctx: &Context, inode: VfsInode, handle: u64, size: u32, offset: u64, add_entry: &mut dyn FnMut(DirEntry<'_>, Entry) -> Result<usize>, ) -> Result<()>

Read a directory with entry attributes. Read more
Source§

fn fsyncdir( &self, ctx: &Context, inode: VfsInode, datasync: bool, handle: u64, ) -> Result<()>

Synchronize the contents of a directory. Read more
Source§

fn releasedir( &self, ctx: &Context, inode: VfsInode, flags: u32, handle: u64, ) -> Result<()>

Release an open directory. Read more
Source§

fn access(&self, ctx: &Context, inode: VfsInode, mask: u32) -> Result<()>

Check file access permissions. Read more
Source§

fn id_remap(&self, ctx: &mut Context) -> Result<()>

Remap the external IDs in context to internal IDs.
Source§

fn setupmapping( &self, ctx: &Context, inode: VfsInode, handle: u64, foffset: u64, len: u64, flags: u64, moffset: u64, req: &mut dyn FsCacheReqHandler, ) -> Result<()>

Setup a mapping so that guest can access files in DAX style. Read more
Source§

fn removemapping( &self, ctx: &Context, inode: VfsInode, requests: Vec<RemovemappingOne>, req: &mut dyn FsCacheReqHandler, ) -> Result<()>

Teardown a mapping which was setup for guest DAX style access.
Source§

fn batch_forget(&self, ctx: &Context, requests: Vec<(Self::Inode, u64)>)

Forget about multiple inodes. Read more
Source§

fn lseek( &self, ctx: &Context, inode: Self::Inode, handle: Self::Handle, offset: u64, whence: u32, ) -> Result<u64>

Reposition read/write file offset.
Source§

fn getlk( &self, ctx: &Context, inode: Self::Inode, handle: Self::Handle, owner: u64, lock: FileLock, flags: u32, ) -> Result<FileLock>

Query file lock status
Source§

fn setlk( &self, ctx: &Context, inode: Self::Inode, handle: Self::Handle, owner: u64, lock: FileLock, flags: u32, ) -> Result<()>

Grab a file read lock
Source§

fn setlkw( &self, ctx: &Context, inode: Self::Inode, handle: Self::Handle, owner: u64, lock: FileLock, flags: u32, ) -> Result<()>

Grab a file write lock
Source§

fn ioctl( &self, ctx: &Context, inode: Self::Inode, handle: Self::Handle, flags: u32, cmd: u32, data: IoctlData<'_>, out_size: u32, ) -> Result<IoctlData<'_>>

send ioctl to the file
Source§

fn bmap( &self, ctx: &Context, inode: Self::Inode, block: u64, blocksize: u32, ) -> Result<u64>

Query a file’s block mapping info
Source§

fn poll( &self, ctx: &Context, inode: Self::Inode, handle: Self::Handle, khandle: Self::Handle, flags: u32, events: u32, ) -> Result<u32>

Poll a file’s events
Source§

fn notify_reply(&self) -> Result<()>

TODO: support this

Auto Trait Implementations§

§

impl !Freeze for Vfs

§

impl !RefUnwindSafe for Vfs

§

impl Send for Vfs

§

impl Sync for Vfs

§

impl Unpin for Vfs

§

impl !UnwindSafe for Vfs

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.