Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mm): 修复fat文件系统的PageCache同步问题 #1005

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
add9d4b
实现read系统调用读取pagecache
MemoryShore Oct 19, 2024
d2ad608
完善read逻辑
MemoryShore Oct 20, 2024
60e36ca
完善create_pages
MemoryShore Oct 21, 2024
773e36d
添加read_direct
MemoryShore Oct 21, 2024
f99aec5
解决create_pages时的死锁问题
MemoryShore Oct 21, 2024
032db07
修复元数据未更新的问题
MemoryShore Oct 21, 2024
19ea62b
Merge branch 'master' into patch-fix-pagecache
MemoryShore Oct 21, 2024
8365ca3
重构read逻辑
MemoryShore Oct 26, 2024
acc821a
重写write逻辑
MemoryShore Oct 26, 2024
7d13a5b
修正页面回写逻辑
MemoryShore Oct 26, 2024
f97b0b7
Merge branch 'master' into patch-fix-pagecache
MemoryShore Oct 26, 2024
0553021
优化代码
MemoryShore Oct 27, 2024
63bd233
优化代码
MemoryShore Nov 10, 2024
fd59c5b
Merge branch 'master' into patch-fix-pagecache
MemoryShore Nov 10, 2024
1a7e9cc
修复lru链表缩减逻辑
MemoryShore Nov 10, 2024
668a279
修正page_writeback逻辑
MemoryShore Nov 11, 2024
ec98b84
添加write_direct
MemoryShore Nov 11, 2024
74c7059
Merge branch 'master' into patch-fix-pagecache
MemoryShore Nov 12, 2024
7a3608b
完善页面释放逻辑
MemoryShore Nov 12, 2024
0ba9483
完善Page结构体和页面创建流程
MemoryShore Nov 16, 2024
8c8051d
优化PageCache的drop逻辑
MemoryShore Nov 16, 2024
839bef9
PageCache改为HashMap存储页面
MemoryShore Nov 18, 2024
da46956
修正PageCache读写逻辑
MemoryShore Nov 18, 2024
67039ad
完善fat元数据的更新逻辑
MemoryShore Nov 18, 2024
49ab468
允许execve加载文件时缓存到PageCache
MemoryShore Nov 18, 2024
bac195a
优化代码
MemoryShore Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 66 additions & 12 deletions kernel/src/filesystem/fat/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,24 +1384,19 @@ impl FATFsInfo {
}

impl IndexNode for LockedFATInode {
fn read_at(
&self,
offset: usize,
len: usize,
buf: &mut [u8],
_data: SpinLockGuard<FilePrivateData>,
) -> Result<usize, SystemError> {
let mut guard: SpinLockGuard<FATInode> = self.0.lock();
fn read_page_sync(&self, offset: usize, buf: &mut [u8]) -> Result<usize, SystemError> {
let guard: SpinLockGuard<FATInode> = self.0.lock();
let len = buf.len();
match &guard.inode_type {
FATDirEntry::File(f) | FATDirEntry::VolId(f) => {
let r = f.read(
&guard.fs.upgrade().unwrap(),
&mut buf[0..len],
offset as u64,
);
guard.update_metadata();
fslongjin marked this conversation as resolved.
Show resolved Hide resolved
return r;
}

FATDirEntry::Dir(_) => {
return Err(SystemError::EISDIR);
}
Expand All @@ -1412,25 +1407,56 @@ impl IndexNode for LockedFATInode {
}
}

fn read_at(
&self,
offset: usize,
len: usize,
buf: &mut [u8],
data: SpinLockGuard<FilePrivateData>,
) -> Result<usize, SystemError> {
let len = core::cmp::min(len, buf.len());
let buf = &mut buf[0..len];

let page_cache = self.0.lock().page_cache.clone();
if let Some(page_cache) = page_cache {
let r = page_cache.read(offset, &mut buf[0..len]);
return r;
} else {
return self.read_direct(offset, len, buf, data);
}
}

fn write_at(
&self,
offset: usize,
len: usize,
buf: &[u8],
_data: SpinLockGuard<FilePrivateData>,
) -> Result<usize, SystemError> {
let len = core::cmp::min(len, buf.len());
let buf = &buf[0..len];
let mut guard: SpinLockGuard<FATInode> = self.0.lock();
let page_cache = guard.page_cache.clone();
let fs: &Arc<FATFileSystem> = &guard.fs.upgrade().unwrap();

match &mut guard.inode_type {
FATDirEntry::File(f) | FATDirEntry::VolId(f) => {
let r = f.write(fs, &buf[0..len], offset as u64);
guard.update_metadata();
return r;
if let Some(page_cache) = page_cache {
let write_len = page_cache.write(offset, buf)?;
let old_size = guard.metadata.size;
guard.metadata.size = core::cmp::max(old_size, (offset + write_len) as i64);
fslongjin marked this conversation as resolved.
Show resolved Hide resolved
return Ok(write_len);
} else {
let r = f.write(fs, &buf[0..len], offset as u64);
guard.update_metadata();
return r;
}
}

FATDirEntry::Dir(_) => {
return Err(SystemError::EISDIR);
}

FATDirEntry::UnInit => {
error!("FATFS: param: Inode_type uninitialized.");
return Err(SystemError::EROFS);
Expand Down Expand Up @@ -1854,6 +1880,34 @@ impl IndexNode for LockedFATInode {
fn page_cache(&self) -> Option<Arc<PageCache>> {
self.0.lock().page_cache.clone()
}

fn read_direct(
&self,
offset: usize,
len: usize,
buf: &mut [u8],
_data: SpinLockGuard<FilePrivateData>,
) -> Result<usize, SystemError> {
let guard: SpinLockGuard<FATInode> = self.0.lock();
match &guard.inode_type {
FATDirEntry::File(f) | FATDirEntry::VolId(f) => {
let r = f.read(
&guard.fs.upgrade().unwrap(),
&mut buf[0..len],
offset as u64,
);
return r;
}

FATDirEntry::Dir(_) => {
return Err(SystemError::EISDIR);
}
FATDirEntry::UnInit => {
error!("FATFS: param: Inode_type uninitialized.");
return Err(SystemError::EROFS);
}
}
}
}

impl Default for FATFsInfo {
Expand Down
Loading
Loading