挂载命名空间与 fs_context

挂载命名空间与 fs_context

1. Mount tree

内核内部 struct mount 包含公开 vfsmount、父 mount、mountpoint dentry、子树和 propagation 信息。每个 mount namespace 维护自己的拓扑,但 superblock 和 dentry 可被多个 namespace 共享。

2. 旧 mount

1
2
3
4
5
6
mount(2)
-> do_mount()
-> path_mount()
-> do_new_mount()/bind/remount/move
-> filesystem mount/get_tree
-> graft_tree/attach_recursive_mnt

umount2()path_umount(),busy 检查依赖 open file、cwd、子 mount 等引用。

3. 新 mount API

1
2
3
4
5
6
7
8
9
10
fsopen("ext4")
-> fs_context_for_mount()
fsconfig(fsfd, SET_STRING/SET_FD/CREATE, ...)
-> vfs_parse_fs_param()
-> filesystem parse_param
fsmount(fsfd)
-> vfs_get_tree()
-> detached mount fd
move_mount()
-> attach to namespace

新 API 避免把所有参数拼成逗号字符串,并支持 detached mount 和更清晰的错误。

4. fs_context

包含:

  • fs_type
  • ops
  • source;
  • purpose(mount/reconfigure/submount);
  • user/mount namespace;
  • security context;
  • filesystem private state。

fs_parser.c 通过 fs_parameter_spec 校验 string/u32/enum/flag/path/fd 等参数。CONFIG_VALIDATE_FS_PARSER 可在注册时加强描述校验。

5. super 获取

  • block fs:get_tree_bdev()
  • singleton/pseudo:get_tree_single()
  • nodev:get_tree_nodev()
  • key-based reuse:sget_fc() test/set callbacks。

同一设备重复 mount 可能复用 super,但不同 mount 可有不同 mount flags/idmap/path。

6. Propagation

mount 可为:

  • private
  • shared
  • slave
  • unbindable

shared subtree 决定 mount 事件如何传播到 peer/slave。容器 runtime 必须显式管理 propagation,否则可能泄漏 host mount 或看不到期望挂载。

7. idmapped mount

mount 可关联 user namespace/idmap,使 inode uid/gid 在该挂载视图中映射。VFS permission、chown、ACL 和具体文件系统支持均需正确处理,不能等同于递归修改磁盘 owner。

8. Freeze 和 remount

superblock freeze 分阶段阻止写入、page fault、internal write 并同步;用于 snapshot 等。remount/reconfigure 通过 fs_context 修改 super 状态,受 s_umount 和 filesystem 检查保护。

9. 排障

1
2
3
4
findmnt -o TARGET,SOURCE,FSTYPE,OPTIONS,PROPAGATION
cat /proc/self/mountinfo
lsns -t mnt
fuser -vm /mountpoint

“target is busy”应查 open fd、cwd/root、mmap 和子挂载,而不是直接使用 lazy unmount 掩盖生命周期问题。

文章互动

阅读 --

留言

0 条留言

正在加载留言…