[libos] Change ROOT_INODE to ROOT_FS
Filesystem should be the owner of its root inode
This commit is contained in:
parent
6353817af8
commit
b40408cb91
2
deps/sefs
vendored
2
deps/sefs
vendored
@ -1 +1 @@
|
|||||||
Subproject commit d26132ca7b5a3338046e4b644cb75953981f0feb
|
Subproject commit d20c9e40853b59162baff3bc82070a8fa5f28537
|
@ -301,7 +301,7 @@ fn do_exec_thread(libos_tid: pid_t, host_tid: pid_t) -> Result<i32> {
|
|||||||
// sync file system
|
// sync file system
|
||||||
// TODO: only sync when all processes exit
|
// TODO: only sync when all processes exit
|
||||||
use rcore_fs::vfs::FileSystem;
|
use rcore_fs::vfs::FileSystem;
|
||||||
crate::fs::ROOT_INODE.read().unwrap().fs().sync()?;
|
crate::fs::ROOT_FS.read().unwrap().sync()?;
|
||||||
|
|
||||||
// Not to be confused with the return value of a main function.
|
// Not to be confused with the return value of a main function.
|
||||||
// The exact meaning of status is described in wait(2) man page.
|
// The exact meaning of status is described in wait(2) man page.
|
||||||
|
@ -22,15 +22,12 @@ pub fn do_mount_rootfs(
|
|||||||
if MOUNT_ONCE.is_completed() {
|
if MOUNT_ONCE.is_completed() {
|
||||||
return_errno!(EPERM, "rootfs cannot be mounted more than once");
|
return_errno!(EPERM, "rootfs cannot be mounted more than once");
|
||||||
}
|
}
|
||||||
let new_root_inode = {
|
let new_rootfs = open_root_fs_according_to(&user_config.mount, user_key)?;
|
||||||
let rootfs = open_root_fs_according_to(&user_config.mount, user_key)?;
|
mount_nonroot_fs_according_to(&new_rootfs.root_inode(), &user_config.mount, user_key, true)?;
|
||||||
rootfs.root_inode()
|
|
||||||
};
|
|
||||||
mount_nonroot_fs_according_to(&new_root_inode, &user_config.mount, user_key, true)?;
|
|
||||||
MOUNT_ONCE.call_once(|| {
|
MOUNT_ONCE.call_once(|| {
|
||||||
let mut root_inode = ROOT_INODE.write().unwrap();
|
let mut rootfs = ROOT_FS.write().unwrap();
|
||||||
root_inode.fs().sync().expect("failed to sync old rootfs");
|
rootfs.sync().expect("failed to sync old rootfs");
|
||||||
*root_inode = new_root_inode;
|
*rootfs = new_rootfs;
|
||||||
*ENTRY_POINTS.write().unwrap() = user_config.entry_points.to_owned();
|
*ENTRY_POINTS.write().unwrap() = user_config.entry_points.to_owned();
|
||||||
});
|
});
|
||||||
// Write resolv.conf file into mounted file system
|
// Write resolv.conf file into mounted file system
|
||||||
@ -132,11 +129,16 @@ pub fn do_mount(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut root_inode = ROOT_INODE.write().unwrap();
|
let mut rootfs = ROOT_FS.write().unwrap();
|
||||||
// Should we sync the fs before mount?
|
// Should we sync the fs before mount?
|
||||||
root_inode.fs().sync()?;
|
rootfs.sync()?;
|
||||||
let follow_symlink = !flags.contains(MountFlags::MS_NOSYMFOLLOW);
|
let follow_symlink = !flags.contains(MountFlags::MS_NOSYMFOLLOW);
|
||||||
mount_nonroot_fs_according_to(&*root_inode, &mount_configs, &user_key, follow_symlink)?;
|
mount_nonroot_fs_according_to(
|
||||||
|
&rootfs.root_inode(),
|
||||||
|
&mount_configs,
|
||||||
|
&user_key,
|
||||||
|
follow_symlink,
|
||||||
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,11 +155,11 @@ pub fn do_umount(target: &str, flags: UmountFlags) -> Result<()> {
|
|||||||
fs.convert_to_abs_path(target)
|
fs.convert_to_abs_path(target)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut root_inode = ROOT_INODE.write().unwrap();
|
let mut rootfs = ROOT_FS.write().unwrap();
|
||||||
// Should we sync the fs before umount?
|
// Should we sync the fs before umount?
|
||||||
root_inode.fs().sync()?;
|
rootfs.sync()?;
|
||||||
let follow_symlink = !flags.contains(UmountFlags::UMOUNT_NOFOLLOW);
|
let follow_symlink = !flags.contains(UmountFlags::UMOUNT_NOFOLLOW);
|
||||||
umount_nonroot_fs(&*root_inode, &target, follow_symlink)?;
|
umount_nonroot_fs(&rootfs.root_inode(), &target, follow_symlink)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,6 @@ use super::*;
|
|||||||
|
|
||||||
pub fn do_sync() -> Result<()> {
|
pub fn do_sync() -> Result<()> {
|
||||||
debug!("sync:");
|
debug!("sync:");
|
||||||
ROOT_INODE.read().unwrap().fs().sync()?;
|
ROOT_FS.read().unwrap().sync()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -165,17 +165,19 @@ impl FsView {
|
|||||||
if path.len() > 0 && path.as_bytes()[0] == b'/' {
|
if path.len() > 0 && path.as_bytes()[0] == b'/' {
|
||||||
// absolute path
|
// absolute path
|
||||||
let abs_path = path.trim_start_matches('/');
|
let abs_path = path.trim_start_matches('/');
|
||||||
let inode = ROOT_INODE
|
let inode = ROOT_FS
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
.root_inode()
|
||||||
.lookup_follow(abs_path, MAX_SYMLINKS)?;
|
.lookup_follow(abs_path, MAX_SYMLINKS)?;
|
||||||
Ok(inode)
|
Ok(inode)
|
||||||
} else {
|
} else {
|
||||||
// relative path
|
// relative path
|
||||||
let cwd = self.cwd().trim_start_matches('/');
|
let cwd = self.cwd().trim_start_matches('/');
|
||||||
let inode = ROOT_INODE
|
let inode = ROOT_FS
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
.root_inode()
|
||||||
.lookup_follow(cwd, MAX_SYMLINKS)?
|
.lookup_follow(cwd, MAX_SYMLINKS)?
|
||||||
.lookup_follow(path, MAX_SYMLINKS)?;
|
.lookup_follow(path, MAX_SYMLINKS)?;
|
||||||
Ok(inode)
|
Ok(inode)
|
||||||
|
@ -31,7 +31,7 @@ pub use self::fs_view::FsView;
|
|||||||
pub use self::host_fd::HostFd;
|
pub use self::host_fd::HostFd;
|
||||||
pub use self::inode_file::{AsINodeFile, INodeExt, INodeFile};
|
pub use self::inode_file::{AsINodeFile, INodeExt, INodeFile};
|
||||||
pub use self::pipe::PipeType;
|
pub use self::pipe::PipeType;
|
||||||
pub use self::rootfs::ROOT_INODE;
|
pub use self::rootfs::ROOT_FS;
|
||||||
pub use self::stdio::{HostStdioFds, StdinFile, StdoutFile};
|
pub use self::stdio::{HostStdioFds, StdinFile, StdoutFile};
|
||||||
pub use self::syscalls::*;
|
pub use self::syscalls::*;
|
||||||
pub use self::timer_file::{AsTimer, TimerCreationFlags, TimerFile};
|
pub use self::timer_file::{AsTimer, TimerCreationFlags, TimerFile};
|
||||||
|
@ -15,29 +15,26 @@ use rcore_fs_unionfs::UnionFS;
|
|||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
/// The root of file system
|
/// The root of file system
|
||||||
pub static ref ROOT_INODE: RwLock<Arc<dyn INode>> = {
|
pub static ref ROOT_FS: RwLock<Arc<dyn FileSystem>> = {
|
||||||
fn init_root_inode() -> Result<Arc<dyn INode>> {
|
fn init_root_fs() -> Result<Arc<dyn FileSystem>> {
|
||||||
let mount_config = &config::LIBOS_CONFIG.mount;
|
let mount_config = &config::LIBOS_CONFIG.mount;
|
||||||
let root_inode = {
|
|
||||||
let rootfs = open_root_fs_according_to(mount_config, &None)?;
|
let rootfs = open_root_fs_according_to(mount_config, &None)?;
|
||||||
rootfs.root_inode()
|
mount_nonroot_fs_according_to(&rootfs.root_inode(), mount_config, &None, true)?;
|
||||||
};
|
Ok(rootfs)
|
||||||
mount_nonroot_fs_according_to(&root_inode, mount_config, &None, true)?;
|
|
||||||
Ok(root_inode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let root_inode = init_root_inode().unwrap_or_else(|e| {
|
let rootfs = init_root_fs().unwrap_or_else(|e| {
|
||||||
error!("failed to init root inode: {}", e.backtrace());
|
error!("failed to init root fs: {}", e.backtrace());
|
||||||
panic!();
|
panic!();
|
||||||
});
|
});
|
||||||
RwLock::new(root_inode)
|
RwLock::new(rootfs)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_root_fs_according_to(
|
pub fn open_root_fs_according_to(
|
||||||
mount_configs: &Vec<ConfigMount>,
|
mount_configs: &Vec<ConfigMount>,
|
||||||
user_key: &Option<sgx_key_128bit_t>,
|
user_key: &Option<sgx_key_128bit_t>,
|
||||||
) -> Result<Arc<MountFS>> {
|
) -> Result<Arc<dyn FileSystem>> {
|
||||||
let root_mount_config = mount_configs
|
let root_mount_config = mount_configs
|
||||||
.iter()
|
.iter()
|
||||||
.find(|m| m.target == Path::new("/") && m.type_ == ConfigMountFsType::TYPE_UNIONFS)
|
.find(|m| m.target == Path::new("/") && m.type_ == ConfigMountFsType::TYPE_UNIONFS)
|
||||||
|
Loading…
Reference in New Issue
Block a user