mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 09:53:24 +00:00
Minor optimizations on both lat-syscall-stat
and lat-syscall-open
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
fc77c474db
commit
f2af6136da
@ -191,7 +191,7 @@ impl<'a> ReadCString for VmReader<'a, Fallible> {
|
||||
|
||||
// Handle the first few bytes to make `cur_addr` aligned with `size_of::<usize>`
|
||||
read_one_byte_at_a_time_while!(
|
||||
(self.cursor() as usize) % mem::size_of::<usize>() != 0 && buffer.len() < max_len
|
||||
!is_addr_aligned(self.cursor() as usize) && buffer.len() < max_len
|
||||
);
|
||||
|
||||
// Handle the rest of the bytes in bulk
|
||||
@ -253,3 +253,8 @@ fn check_vaddr(va: Vaddr) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if the given address is aligned.
|
||||
const fn is_addr_aligned(addr: usize) -> bool {
|
||||
(addr & (mem::size_of::<usize>() - 1)) == 0
|
||||
}
|
||||
|
@ -187,6 +187,7 @@ impl FsResolver {
|
||||
/// If `follow_tail_link` is true and the trailing component is a symlink,
|
||||
/// it will be followed.
|
||||
/// Symlinks in earlier components of the path will always be followed.
|
||||
#[allow(clippy::redundant_closure)]
|
||||
fn lookup_from_parent(
|
||||
&self,
|
||||
parent: &Arc<Dentry>,
|
||||
@ -205,7 +206,7 @@ impl FsResolver {
|
||||
|
||||
// To handle symlinks
|
||||
let follow_tail_link = lookup_ctx.follow_tail_link;
|
||||
let mut link_path = String::new();
|
||||
let mut link_path_opt = None;
|
||||
let mut follows = 0;
|
||||
|
||||
// Initialize the first dentry and the relative path
|
||||
@ -263,9 +264,10 @@ impl FsResolver {
|
||||
if link_path_remain.starts_with('/') {
|
||||
dentry = self.root.clone();
|
||||
}
|
||||
let link_path = link_path_opt.get_or_insert_with(|| String::new());
|
||||
link_path.clear();
|
||||
link_path.push_str(link_path_remain.trim_start_matches('/'));
|
||||
relative_path = &link_path;
|
||||
relative_path = link_path;
|
||||
follows += 1;
|
||||
} else {
|
||||
// If path ends with `/`, the inode must be a directory
|
||||
|
@ -12,11 +12,11 @@ impl InodeHandle<Rights> {
|
||||
access_mode: AccessMode,
|
||||
status_flags: StatusFlags,
|
||||
) -> Result<Self> {
|
||||
let inode = dentry.inode();
|
||||
if access_mode.is_readable() && !inode.mode()?.is_readable() {
|
||||
let inode_mode = dentry.inode().mode()?;
|
||||
if access_mode.is_readable() && !inode_mode.is_readable() {
|
||||
return_errno_with_message!(Errno::EACCES, "file is not readable");
|
||||
}
|
||||
if access_mode.is_writable() && !inode.mode()?.is_writable() {
|
||||
if access_mode.is_writable() && !inode_mode.is_writable() {
|
||||
return_errno_with_message!(Errno::EACCES, "file is not writable");
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ impl InodeHandle<Rights> {
|
||||
status_flags: StatusFlags,
|
||||
) -> Result<Self> {
|
||||
let inode = dentry.inode();
|
||||
if access_mode.is_writable() && inode.type_() == InodeType::Dir {
|
||||
if inode.type_() == InodeType::Dir && access_mode.is_writable() {
|
||||
return_errno_with_message!(Errno::EISDIR, "directory cannot open to write");
|
||||
}
|
||||
|
||||
|
@ -68,10 +68,6 @@ impl RamFS {
|
||||
fn alloc_id(&self) -> u64 {
|
||||
self.inode_allocator.fetch_add(1, Ordering::SeqCst)
|
||||
}
|
||||
|
||||
fn device_id(&self) -> u64 {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl FileSystem for RamFS {
|
||||
@ -783,6 +779,9 @@ impl Inode for RamInode {
|
||||
}
|
||||
|
||||
fn as_device(&self) -> Option<Arc<dyn Device>> {
|
||||
if !self.typ.is_device() {
|
||||
return None;
|
||||
}
|
||||
self.node.read().inner.as_device().cloned()
|
||||
}
|
||||
|
||||
@ -1146,20 +1145,21 @@ impl Inode for RamInode {
|
||||
|
||||
fn metadata(&self) -> Metadata {
|
||||
let self_inode = self.node.read();
|
||||
let inode_metadata = &self_inode.metadata;
|
||||
Metadata {
|
||||
dev: self.fs.upgrade().unwrap().device_id(),
|
||||
dev: 0,
|
||||
ino: self.ino as _,
|
||||
size: self_inode.metadata.size,
|
||||
size: inode_metadata.size,
|
||||
blk_size: BLOCK_SIZE,
|
||||
blocks: self_inode.metadata.blocks,
|
||||
atime: self_inode.metadata.atime,
|
||||
mtime: self_inode.metadata.mtime,
|
||||
ctime: self_inode.metadata.ctime,
|
||||
blocks: inode_metadata.blocks,
|
||||
atime: inode_metadata.atime,
|
||||
mtime: inode_metadata.mtime,
|
||||
ctime: inode_metadata.ctime,
|
||||
type_: self.typ,
|
||||
mode: self_inode.metadata.mode,
|
||||
nlinks: self_inode.metadata.nlinks,
|
||||
uid: self_inode.metadata.uid,
|
||||
gid: self_inode.metadata.gid,
|
||||
mode: inode_metadata.mode,
|
||||
nlinks: inode_metadata.nlinks,
|
||||
uid: inode_metadata.uid,
|
||||
gid: inode_metadata.gid,
|
||||
rdev: {
|
||||
if let Some(device) = self_inode.inner.as_device() {
|
||||
device.id().into()
|
||||
|
@ -6,5 +6,5 @@ set -e
|
||||
|
||||
echo "*** Running the LMbench open latency test ***"
|
||||
|
||||
touch test_file
|
||||
/benchmark/bin/lmbench/lat_syscall -P 1 open test_file
|
||||
touch testfile
|
||||
/benchmark/bin/lmbench/lat_syscall -P 1 -W 1000 -N 1000 open testfile
|
@ -6,5 +6,5 @@ set -e
|
||||
|
||||
echo "*** Running the LMbench stat latency test ***"
|
||||
|
||||
touch test_file
|
||||
/benchmark/bin/lmbench/lat_syscall -P 1 stat test_file
|
||||
touch testfile
|
||||
/benchmark/bin/lmbench/lat_syscall -P 1 -W 1000 -N 1000 stat testfile
|
Reference in New Issue
Block a user