Skip to content
Merged
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
13 changes: 13 additions & 0 deletions os/StarryOS/kernel/src/pseudofs/sysfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ fn builder(fs: Arc<SimpleFs>) -> DirMaker {
);
SimpleDir::new_maker(fs.clone(), Arc::new(kernel))
});
// `/sys/fs/cgroup` is the mount point systemd lays its cgroup hierarchy on
// (it mounts tmpfs then cgroup2 here). On Linux the kernel provides this
// empty directory inside sysfs; once sysfs is mounted over /sys it shadows
// the rootfs's own /sys/fs/cgroup, so the mount point must exist here or
// `mount("/sys/fs/cgroup")` fails with ENOENT.
root.add("fs", {
let mut fs_dir = DirMapping::new();
fs_dir.add(
"cgroup",
SimpleDir::new_maker(fs.clone(), Arc::new(DirMapping::new())),
);
SimpleDir::new_maker(fs.clone(), Arc::new(fs_dir))
});
SimpleDir::new_maker(fs.clone(), Arc::new(root))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <limits.h>

Expand Down Expand Up @@ -82,5 +83,17 @@ int main(void)
CHECK(S_ISLNK(st.st_mode),
"/sys/class/graphics/fb0 应是软链");

/* /sys/fs/cgroup 必须由 sysfs 自身提供 —— sysfs 盖在 /sys 上后
* rootfs 里的同名目录不可见,systemd 在这里挂 cgroup 层级 */
CHECK_RET(stat("/sys/fs", &st), 0, "/sys/fs 应可 stat");
CHECK(S_ISDIR(st.st_mode), "/sys/fs 应是目录");
CHECK_RET(stat("/sys/fs/cgroup", &st), 0, "/sys/fs/cgroup 应可 stat");
CHECK(S_ISDIR(st.st_mode), "/sys/fs/cgroup 应是目录");

CHECK_RET(mount("none", "/sys/fs/cgroup", "tmpfs", 0, NULL), 0,
"tmpfs 应能挂载到 /sys/fs/cgroup");
CHECK_RET(umount2("/sys/fs/cgroup", 0), 0,
"应能卸载 /sys/fs/cgroup 上的 tmpfs");

TEST_DONE();
}