pub struct Vfs { /* private fields */ }
Expand description
A union fs that combines multiple backend file systems.
Implementations§
Source§impl Vfs
impl Vfs
Sourcepub fn save_to_bytes(&self) -> VfsResult<Vec<u8>>
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§impl Vfs
impl Vfs
Sourcepub fn new(opts: VfsOptions) -> Self
pub fn new(opts: VfsOptions) -> Self
Create a new vfs instance
Sourcepub fn set_remove_pseudo_root(&mut self)
pub fn set_remove_pseudo_root(&mut self)
mark remove pseudo root inode when umount
Sourcepub fn initialized(&self) -> bool
pub fn initialized(&self) -> bool
For sake of live-upgrade, only after negotiation is done, it’s safe to persist state of vfs.
Sourcepub fn options(&self) -> VfsOptions
pub fn options(&self) -> VfsOptions
Get a snapshot of the current vfs options.
Sourcepub fn mount(&self, fs: BackFileSystem, path: &str) -> VfsResult<VfsIndex>
pub fn mount(&self, fs: BackFileSystem, path: &str) -> VfsResult<VfsIndex>
Mount a backend file system to path
Sourcepub fn restore_mount(
&self,
fs: BackFileSystem,
fs_idx: VfsIndex,
path: &str,
) -> Result<()>
pub fn restore_mount( &self, fs: BackFileSystem, fs_idx: VfsIndex, path: &str, ) -> Result<()>
Restore a backend file system to path
Sourcepub fn get_rootfs(&self, path: &str) -> VfsResult<Option<Arc<BackFileSystem>>>
pub fn get_rootfs(&self, path: &str) -> VfsResult<Option<Arc<BackFileSystem>>>
Get the mounted backend file system alongside the path if there’s one.
Sourcepub fn get_root_pseudofs(&self) -> &PseudoFs
pub fn get_root_pseudofs(&self) -> &PseudoFs
Get the root pseudo fs’s reference in vfs
Trait Implementations§
Source§impl AsyncFileSystem for Vfs
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
Source§impl FileSystem for Vfs
impl FileSystem for Vfs
Source§type Inode = VfsInode
type Inode = VfsInode
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