feat: implement UTS namespace support#936
Closed
fzg-23 wants to merge 1 commit into
Closed
Conversation
fzg-23
commented
May 25, 2026
Contributor
- Add UtNamespace type with nodename/domainname fields
- Add uts_ns field to ProcessData for per-process namespace
- Implement sys_unshare to handle CLONE_NEWUTS
- Implement sys_sethostname to write to process's uts_ns
- Implement sys_uname to read from process's uts_ns
- Add dispatch entries for unshare/sethostname/setdomainname
- Update clone to handle CLONE_NEWUTS namespace inheritance
- Add test case for UTS namespace isolation
- Add UtNamespace type with nodename/domainname fields - Add uts_ns field to ProcessData for per-process namespace - Implement sys_unshare to handle CLONE_NEWUTS - Implement sys_sethostname to write to process's uts_ns - Implement sys_uname to read from process's uts_ns - Add dispatch entries for unshare/sethostname/setdomainname - Update clone to handle CLONE_NEWUTS namespace inheritance - Add test case for UTS namespace isolation
luodeb
self-requested a review
May 25, 2026 08:26
Contributor
There was a problem hiding this comment.
审查总结
本 PR 实现了 UTS namespace 的基本支持,包括:
- 新增
UtNamespace类型,包含nodename/domainname字段 - 在
ProcessData中添加uts_ns字段(SpinNoIrq<Arc<SpinNoIrq<UtNamespace>>>),支持进程间共享 namespace - 实现
sys_unshare(CLONE_NEWUTS)创建独立的 UTS namespace - 实现
sys_sethostname/sys_setdomainname写入进程所属 namespace - 修改
sys_uname从进程 namespace 读取 nodename/domainname - 更新 clone 路径,处理
CLONE_NEWUTS的 namespace 继承/复制逻辑 - 添加
bug-unshare-uts测试用例,覆盖 unshare、sethostname/setdomainname 往返、fork 继承、共享 namespace 传播等场景
代码质量
整体实现结构清晰,遵循项目现有模式:
UtNamespace定义在task/namespace.rs,与ProcessData放在同一模块sys_unshare放在syscall/task/namespace.rs,与其他 syscall 分离sys_uname/sys_sethostname/sys_setdomainname放在syscall/sys.rs,符合现有布局- 使用
Arc实现 namespace 共享,语义正确 SpinNoIrq的锁定顺序一致(先外层后内层),不会死锁sys_uname中将 SpinNoIrq 锁的释放与用户态内存访问分离,避免 IRQ 禁用问题
验证结果
| 检查项 | 结果 |
|---|---|
cargo xtask clippy --package starry-kernel (13 个 feature 组合) |
✅ 全部通过 |
cargo fmt --check |
❌ 3 处格式问题 |
| CI: Check formatting / run_host | ❌ failure |
| CI: Run sync-lint / run_container | |
| CI: 其余检查 |
阻塞问题
格式问题:cargo fmt --check 在 3 处失败:
os/StarryOS/kernel/src/syscall/task/clone.rs:250— 行过长,需换行os/StarryOS/kernel/src/syscall/task/namespace.rs:1—use语句后缺少空行os/StarryOS/kernel/src/task/namespace.rs:6—ROOT_UTS_NS定义行过长
请运行 cargo fmt 修复上述格式问题后重新提交。
非阻塞观察
-
sys_unshare缺少权限检查:Linux 中unshare(CLONE_NEWUTS)需要CAP_SYS_ADMIN,当前实现未检查任何权限。考虑到 StarryOS 的能力系统尚未完全实现,这是一个可接受的简化,但建议后续补充。 -
测试质量良好:
bug-unshare-uts测试覆盖了 6 个场景(unshare 成功、拒绝不支持的 flag、sethostname 往返、setdomainname 往返、fork 继承、共享 namespace 传播),结构清晰,使用syscall()直接调用避免 libc 包装的干扰。 -
与现有代码无重复:base 分支(dev)中不存在 UTS namespace 实现,
CLONE_NEWUTS仅在 clone.rs 的 unsupported flags 集合中出现。与当前其他 open PR(如 #934 axvisor board tests)无功能重叠。 -
clone 路径行为改进:将不支持的 namespace flag 从
warn!(仅警告)改为error!+return EINVAL,更符合 Linux 语义。
结论
请修复格式问题后重新请求审查。修复后(仅需 cargo fmt),代码逻辑上没有其他阻塞问题。
Powered by deepseek-v4-pro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.