From 922b204280440203d0e5f9d6a06040df64d1e7e5 Mon Sep 17 00:00:00 2001 From: Ruihan Li Date: Tue, 6 Jan 2026 23:51:42 +0800 Subject: [PATCH] Move `Pipe` from `InodeImpl` to `Inode` --- kernel/src/fs/ext2/impl_for_vfs/inode.rs | 6 +++- kernel/src/fs/ext2/inode.rs | 36 ++++++++----------- .../syscall/gvisor/blocklists.ext2/pipe_test | 6 ++-- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/kernel/src/fs/ext2/impl_for_vfs/inode.rs b/kernel/src/fs/ext2/impl_for_vfs/inode.rs index eb39d8e74..96560528d 100644 --- a/kernel/src/fs/ext2/impl_for_vfs/inode.rs +++ b/kernel/src/fs/ext2/impl_for_vfs/inode.rs @@ -148,7 +148,11 @@ impl Inode for Ext2Inode { Some(device.open()) } - InodeType::NamedPipe => Some(self.open_named_pipe(access_mode, status_flags)), + InodeType::NamedPipe => { + let pipe = self.named_pipe().unwrap(); + + Some(pipe.open_named(access_mode, status_flags)) + } _ => None, } } diff --git a/kernel/src/fs/ext2/inode.rs b/kernel/src/fs/ext2/inode.rs index 06f6e132c..1187903f8 100644 --- a/kernel/src/fs/ext2/inode.rs +++ b/kernel/src/fs/ext2/inode.rs @@ -20,12 +20,11 @@ use super::{ }; use crate::{ fs::{ - inode_handle::FileIo, path::{is_dot, is_dot_or_dotdot, is_dotdot}, pipe::Pipe, utils::{ - AccessMode, Extension, FallocMode, Inode as _, InodeMode, Metadata, Permission, - StatusFlags, XattrName, XattrNamespace, XattrSetFlags, + Extension, FallocMode, Inode as _, InodeMode, Metadata, Permission, XattrName, + XattrNamespace, XattrSetFlags, }, }, process::{Gid, Uid, posix_thread::AsPosixThread}, @@ -41,6 +40,9 @@ pub const MAX_FAST_SYMLINK_LEN: usize = MAX_BLOCK_PTRS * BID_SIZE; pub struct Inode { ino: u32, type_: InodeType, + // This corresponds to the `i_pipe` field in `struct inode` in Linux. + // Reference: . + named_pipe: Option>, block_group_idx: usize, inner: RwMutex, fs: Weak, @@ -58,6 +60,11 @@ impl Inode { Arc::new_cyclic(|weak_self| Self { ino, type_: desc.type_, + named_pipe: if desc.type_ == InodeType::NamedPipe { + Some(Box::new(Pipe::new())) + } else { + None + }, block_group_idx, xattr: desc .acl @@ -76,6 +83,10 @@ impl Inode { self.type_ } + pub(super) fn named_pipe(&self) -> Option<&Pipe> { + self.named_pipe.as_deref() + } + pub(super) fn block_group_idx(&self) -> usize { self.block_group_idx } @@ -683,16 +694,6 @@ impl Inode { inner.device_id() } - pub(super) fn open_named_pipe( - &self, - access_mode: AccessMode, - status_flags: StatusFlags, - ) -> Result> { - let inner = self.inner.read(); - let named_pipe = inner.named_pipe.as_ref().unwrap(); - named_pipe.open_named(access_mode, status_flags) - } - pub fn read_at(&self, offset: usize, writer: &mut VmWriter) -> Result { if self.type_ != InodeType::File { return_errno!(Errno::EISDIR); @@ -965,19 +966,11 @@ fn write_lock_multiple_inodes(inodes: Vec<&Inode>) -> Vec. - named_pipe: Option, } impl InodeInner { pub fn new(desc: Dirty, weak_self: Weak, fs: Weak) -> Self { let num_page_bytes = desc.num_page_bytes(); - let named_pipe = if desc.type_ == InodeType::NamedPipe { - Some(Pipe::new()) - } else { - None - }; let inode_impl = InodeImpl::new(desc, weak_self, fs); Self { page_cache: PageCache::with_capacity( @@ -986,7 +979,6 @@ impl InodeInner { ) .unwrap(), inode_impl, - named_pipe, } } diff --git a/test/src/syscall/gvisor/blocklists.ext2/pipe_test b/test/src/syscall/gvisor/blocklists.ext2/pipe_test index 0ebb273bf..3ec200f0e 100644 --- a/test/src/syscall/gvisor/blocklists.ext2/pipe_test +++ b/test/src/syscall/gvisor/blocklists.ext2/pipe_test @@ -1,2 +1,4 @@ -# TODO: Support pipe file in ext2 filesystem. -* \ No newline at end of file +# Nothing here. Pipe files are supported by the ext2 file system. +# +# This file is kept to ensure that the `blocklists.ext2` directory +# is not empty, as it may become useful in the future.