Make the file lookup faster

This commit is contained in:
Ruihan Li
2024-12-26 21:35:56 +08:00
committed by Tate, Hongliang Tian
parent fb8f493b43
commit b9ce3e64ad
59 changed files with 483 additions and 390 deletions

View File

@ -2,21 +2,16 @@
use super::SyscallReturn;
use crate::{
fs::{file_table::FileDesc, inode_handle::InodeHandle},
fs::file_table::{get_file_fast, FileDesc},
prelude::*,
};
pub fn sys_fsync(fd: FileDesc, ctx: &Context) -> Result<SyscallReturn> {
debug!("fd = {}", fd);
let dentry = {
let file_table = ctx.posix_thread.file_table().lock();
let file = file_table.get_file(fd)?;
let inode_handle = file
.downcast_ref::<InodeHandle>()
.ok_or(Error::with_message(Errno::EINVAL, "not inode"))?;
inode_handle.dentry().clone()
};
let mut file_table = ctx.thread_local.file_table().borrow_mut();
let file = get_file_fast!(&mut file_table, fd);
let dentry = file.as_inode_or_err()?.dentry();
dentry.sync_all()?;
Ok(SyscallReturn::Return(0))
}
@ -24,14 +19,9 @@ pub fn sys_fsync(fd: FileDesc, ctx: &Context) -> Result<SyscallReturn> {
pub fn sys_fdatasync(fd: FileDesc, ctx: &Context) -> Result<SyscallReturn> {
debug!("fd = {}", fd);
let dentry = {
let file_table = ctx.posix_thread.file_table().lock();
let file = file_table.get_file(fd)?;
let inode_handle = file
.downcast_ref::<InodeHandle>()
.ok_or(Error::with_message(Errno::EINVAL, "not inode"))?;
inode_handle.dentry().clone()
};
let mut file_table = ctx.thread_local.file_table().borrow_mut();
let file = get_file_fast!(&mut file_table, fd);
let dentry = file.as_inode_or_err()?.dentry();
dentry.sync_data()?;
Ok(SyscallReturn::Return(0))
}