-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
feat(namespace) feat some namespace bugs #1033
base: master
Are you sure you want to change the base?
Conversation
codeironman
commented
Nov 7, 2024
- remove contains_of ! Macro
- fix some bugs
主要完善实现了pid_namespace 基本实现了mnt_namespace 开始cgroup的架构设计
1. add overlayfs test 2. fix mount syscall 3. add setns syscall
@codeironman: no appropriate reviewer found, use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
总结一下,这个pr存在几个问题:
- 实例管理混乱:user namespace、pid namespace、 mnt namespace、ucounts里面存储的对象,关联性很差。
- 未经过测试:有些代码一眼就是有问题的。
- 对象的父子关系存储有问题:父级找不到子级。并且关系非常混乱,估计绕几圈之后,指向的都不是同一个实例。
还需要大改哦
pub struct MntNamespace { | ||
/// namespace 共有的部分 | ||
ns_common: Arc<NsCommon>, | ||
/// 关联的用户名字空间 | ||
user_ns: Arc<UserNamespace>, | ||
/// 资源计数器 | ||
ucounts: Arc<UCounts>, | ||
/// 根文件系统 | ||
root: Option<Arc<MountFS>>, | ||
/// 红黑树用于挂载所有挂载点 | ||
mounts: RBTree<InodeId, MountFSInode>, | ||
mounts: Arc<RBTree<InodeId, MountFSInode>>, | ||
/// 等待队列 | ||
poll: WaitQueue, | ||
poll: Arc<WaitQueue>, | ||
/// 挂载序列号 | ||
seq: AtomicU64, | ||
seq: Arc<AtomicU64>, | ||
/// 挂载点的数量 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么每个成员变量都是Arc<>
?这个访存效率低并且浪费内存。直接一个Arc<MntNamespace>
会不会好些。
并且,mounts字段还有poll字段,你确定你测试过能用????这个一眼看过去就知道跑不了。
fn name(&self) -> String; | ||
fn clone_flags(&self) -> CloneFlags; | ||
fn get(&self, pid: Pid) -> Option<Arc<dyn Namespace>>; | ||
fn put(&self); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要put方法吧
} | ||
fn get(&self, pid: crate::process::Pid) -> Option<Arc<dyn Namespace>> { | ||
ProcessManager::find(pid) | ||
.map(|pcb| pcb.get_nsproxy().read().mnt_namespace.clone() as Arc<dyn Namespace>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_nsproxy
方法改名为nsproxy
。这样比较符合rust的命名规范。
return Err(SystemError::EINVAL); | ||
} | ||
nsproxy.mnt_namespace = mnt_ns; | ||
nsproxy.mnt_namespace = Arc::new(self.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1,4 +1,5 @@ | |||
#![allow(dead_code, unused_variables, unused_imports)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删掉全局的这种lint
pub ucount_max: Vec<u32>, //vec![u32; UCOUNT_COUNTS as usize], | ||
pub rlimit_max: Vec<u32>, // vec![u32; UCOUNT_RLIMIT_COUNTS as usize], | ||
pub ucount_max: Vec<u32>, | ||
pub rlimit_max: Vec<u32>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self { | ||
id_alloctor: Arc::new(RwLock::new(IdAllocator::new(1, PID_MAX).unwrap())), | ||
pid_allocated: 1, | ||
level: 0, | ||
child_reaper: Arc::new(RwLock::new(Pid::from(1))), | ||
parent: None, | ||
ucounts: Arc::new(UCounts::default()), | ||
user_ns: Arc::new(UserNamespace::default()), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不应该依赖default方法。并且
Ucounts的Usernamespace和这里的user_ns都不是同一个userNamespace
这个很显然是有问题的。