Skip to content

fix(starry): provide /sys/fs/cgroup mount point in sysfs#1243

Merged
ZR233 merged 1 commit into
rcore-os:devfrom
programskillforverification:systemd/fix-sysfs-cgroup-mountpoint
Jun 15, 2026
Merged

fix(starry): provide /sys/fs/cgroup mount point in sysfs#1243
ZR233 merged 1 commit into
rcore-os:devfrom
programskillforverification:systemd/fix-sysfs-cgroup-mountpoint

Conversation

@programskillforverification

Copy link
Copy Markdown
Contributor

背景

在 StarryOS 上以 Debian trixie 的 systemd 作为 PID 1 启动时,首次 boot 暴露了若干内核问题。本 PR 修复其中之一:sysfs 缺少 /sys/fs/cgroup 挂载点,导致 systemd 无法建立 cgroup 层级。

现象

systemd 在 /sys/fs/cgroup 上挂载 tmpfs 时失败,mount(2) 返回 ENOENT(挂载点路径不存在):

Failed to mount tmpfs (type tmpfs) on /sys/fs/cgroup (...): No such file or directory

根因

手搓的 sysfs 根目录只暴露 class / bus / devices / dev / kernel没有 fs/ 目录

systemd 早期把 sysfs 挂到 /sys,盖住了 rootfs 里 mkdir 出来的 /sys/fs/cgroup;而 sysfs 自身没有这个目录,挂载时路径解析即 ENOENT。真实 Linux 中 /sys/fs/cgroup 是内核在 sysfs 内提供的空目录。

修复

在 sysfs 中补 fs/cgroup 空目录作为挂载点(仿照已有的 kernel/debug),对齐 Linux 行为。

影响范围

仅向 sysfs 树新增一个空目录节点,不影响现有 class / bus / devices 等 libudev 相关结构。

测试

扩展现有用例 qemu-smp1/system/c-regression-test-sysfs-class,新增对挂载点的检查:/sys/fs/sys/fs/cgroup 均存在且为目录,并验证可在 /sys/fs/cgroup 上挂载 / 卸载 tmpfs。修复前 /sys/fs/cgroup 不存在,相关检查会 FAIL。

cargo xtask starry test qemu --arch aarch64 -c qemu-smp1/system/c-regression-test-sysfs-class

验证

修复后 systemd 成功建立 cgroup 层级并打出欢迎语:

Found cgroup2 on /sys/fs/cgroup/, full unified hierarchy
Unified cgroup hierarchy is located at /sys/fs/cgroup.
Welcome to Debian GNU/Linux 13 (trixie)!

The hand-built sysfs root only exposed class/bus/devices/dev/kernel and
had no `fs/` directory. Once sysfs is mounted over /sys it shadows the
rootfs's own /sys/fs/cgroup, so systemd's `mount("/sys/fs/cgroup")`
failed with ENOENT and it could not set up the cgroup hierarchy.

在 sysfs 中补 `fs/cgroup` 空目录作为挂载点,对齐 Linux 由内核在 sysfs 中
提供该目录的行为。systemd 据此成功在其上挂载 tmpfs + cgroup2。

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR 变更概述

本 PR 修复 sysfs 缺少 /sys/fs/cgroup 挂载点导致 systemd 无法建立 cgroup 层级的问题。改动仅 2 个文件,+26 行:

  1. os/StarryOS/kernel/src/pseudofs/sysfs.rs:在 sysfs 根目录下新增 fs/cgroup 空目录节点,完全仿照已有的 kernel/debug 模式(DirMapping::new())。注释清晰说明了 Linux 内核在 sysfs 中提供此空目录的原因,以及 sysfs 挂载后会遮蔽 rootfs 同名路径的机制。
  2. test-suit/starryos/qemu-smp1/system/c-regression-test-sysfs-class/src/main.c:扩展现有 sysfs-class 测试用例,新增 /sys/fs/sys/fs/cgroupstat 目录验证,以及 tmpfs 挂载/卸载验证。测试覆盖了修复前不存在路径时的 FAIL 行为。

实现逻辑

修复对齐 Linux 内核行为:真实 Linux 在 sysfs 内提供 /sys/fs/cgroup 空目录作为 cgroup v2 的挂载点。systemd 启动时先将 sysfs 挂载到 /sys,遮蔽了 rootfs 中预先 mkdir 的路径,因此挂载点必须在 sysfs 自身的目录树中存在。PR 使用与 kernel/debug 完全相同的 DirMapping::new() 模式创建空目录,无额外依赖,不影响现有 class/bus/devices/dev/kernel 结构。

验证结果

  • cargo fmt --check:✅ 通过
  • cargo clippy --all-features -D warnings(starry-kernel):✅ 通过,无警告
  • 测试用例结构合理:CHECK_RET/CHECK 宏覆盖 stat 和 mount/umount,能可靠检测修复前的 ENOENT

CI 状态

所有 GitHub Actions check runs 状态为 skipped(共 14 个 jobs),属于 fork PR 未触发 CI 的预期行为(run_host / run_container 互斥作业均被跳过)。CI 失败不是 PR 引起的。合并后 CI 将正常运行。

重复/重叠分析

  • base 分支(dev)不包含任何 cgroup 相关的 sysfs 代码,本 PR 为新增内容。
  • PR #1234feat(ax-cgroup): extract cgroup v2 subsystem into standalone crate)将 cgroup 核心逻辑抽取为独立 crate,与本 PR 互补而非冲突:#1234 解决 cgroup 实现的模块化,本 PR 提供 sysfs 中的挂载点。两者可独立合并。
  • 未发现其他重复或冲突的 open PR。

结论

代码简洁、遵循既有模式、注释充分、测试覆盖合理,无阻塞问题。APPROVE。

Powered by mimo-v2.5-pro

@mai-team-app
mai-team-app Bot requested review from luodeb and yfblock June 12, 2026 10:59
@ZR233
ZR233 merged commit c5f6d61 into rcore-os:dev Jun 15, 2026
50 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 15, 2026
fzg-23 pushed a commit to fzg-23/tgoskits that referenced this pull request Jun 16, 2026
The hand-built sysfs root only exposed class/bus/devices/dev/kernel and
had no `fs/` directory. Once sysfs is mounted over /sys it shadows the
rootfs's own /sys/fs/cgroup, so systemd's `mount("/sys/fs/cgroup")`
failed with ENOENT and it could not set up the cgroup hierarchy.

在 sysfs 中补 `fs/cgroup` 空目录作为挂载点,对齐 Linux 由内核在 sysfs 中
提供该目录的行为。systemd 据此成功在其上挂载 tmpfs + cgroup2。
This was referenced Jun 22, 2026
luodeb pushed a commit that referenced this pull request Jun 30, 2026
The hand-built sysfs root only exposed class/bus/devices/dev/kernel and
had no `fs/` directory. Once sysfs is mounted over /sys it shadows the
rootfs's own /sys/fs/cgroup, so systemd's `mount("/sys/fs/cgroup")`
failed with ENOENT and it could not set up the cgroup hierarchy.

在 sysfs 中补 `fs/cgroup` 空目录作为挂载点,对齐 Linux 由内核在 sysfs 中
提供该目录的行为。systemd 据此成功在其上挂载 tmpfs + cgroup2。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants