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(net): Unix 资源释放 #1087

Draft
wants to merge 4 commits into
base: feat-network-rebuild
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 25 additions & 2 deletions kernel/src/net/socket/unix/seqpacket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,34 @@ impl Socket for SeqpacketSocket {
if path.is_empty() {
return Ok(());
}
// TODO: 释放INODE_MAP相关资源

// 尝试释放相关抽象地址资源
//释放INODE_MAP相关资源
match self.get_name()? {
Endpoint::Unixpath((inode_id, _)) => {
// 从 INODE_MAP 中移除对应的 inode
let mut inode_guard = INODE_MAP.write_irqsave();
inode_guard.remove(&inode_id);
},
Endpoint::Abspath((abshandle, _)) => {
// 从 ABS_INODE_MAP 中移除对应的地址
let mut abs_inode_map = ABS_INODE_MAP.lock_irqsave();
abs_inode_map.remove(&abshandle.name());
},
_ => {
log::error!("Invalid endpoint in close");
return Err(SystemError::EINVAL);
}
};

//将socket状态置为Init
*self.inner.write() = Inner::Init(Init::new());
//唤醒等待队列
self.wait_queue.wakeup(None);
//抽象地址空间的资源回收
let _ = remove_abs_addr(&path);

return Ok(());

}

fn get_peer_name(&self) -> Result<Endpoint, SystemError> {
Expand Down
22 changes: 22 additions & 0 deletions kernel/src/net/socket/unix/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,28 @@ impl Socket for StreamSocket {
return Ok(());
}
// TODO: 释放INODE_MAP相关资源
match self.get_name()? {
Endpoint::Unixpath((inode_id, _)) => {
// 从 INODE_MAP 中移除对应的 inode
let mut inode_guard = INODE_MAP.write_irqsave();
inode_guard.remove(&inode_id);
}
Endpoint::Abspath((abshandle, _)) => {
// 从 ABS_INODE_MAP 中移除对应的地址
let mut abs_inode_map = ABS_INODE_MAP.lock_irqsave();
abs_inode_map.remove(&abshandle.name());
}
_ => {
log::error!("Invalid endpoint in close");
return Err(SystemError::EINVAL);
}
}

// 重置内部状态为初始状态
*self.inner.write() = Inner::Init(Init::new());

// 唤醒等待队列中的等待者,防止阻塞
self.wait_queue.wakeup(None);

// 尝试释放相关抽象地址资源
let _ = remove_abs_addr(&path);
Expand Down