mount: "bind" with recursive propagation (rprivate/rslave/rshared) performs a recursive bind (rbind)
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 1-2 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- go, linux
调研方向
Start in mount/mounter_linux.go and trace how parseOptions separates mount flags before the initial and propagation mount(2) calls. The issue proposes returning separate flag and propagation masks and updating MakeMount and ensureMountedAs; inspect their existing tests and add coverage for bind,rprivate, bind,rslave, and bind,rshared. Done means these options no longer copy submounts, while rbind still does.
由索引模型根据 Issue 内容生成。
描述
mount.Mount(src, dst, "none", "bind,rprivate") performs a recursive bind mount instead of a plain bind mount. The same happens with bind,rslave, bind,rshared, and bind,runbindable.
Cause
parseOptionsORs every option into a singleintmask, so"bind,rprivate"producesMS_BIND|MS_PRIVATE|MS_REC(0x45000).- In
mount()(mount/mounter_linux.go),oflags := flags &^ ptypesstrips the propagation type bits before the firstmount(2)call, but leavesMS_REC(0x4000) set. - The initial
mount(2)call runs withMS_BIND|MS_REC, which the kernel treats asrbind, copying all submounts undersrcintodstbefore the secondmount(2)call appliesrprivate.
We hit this via Moby local volumes (volume/local), which pass o= directly to mount.Mount. A local volume with type=none,device=<dir>,o=bind,rprivate exposes every submount under <dir> inside the container; with o=bind,rshared, docker volume rm also unmounts those submounts on the host because the volume became a shared recursive bind.
Details and dockerd reproduction matrix
Tested on Linux with dockerd built from moby/moby master using local volumes type=none,device=/src,o=<opts>, where /src is a shared tmpfs with a tmpfs submount at /src/sub:
o= |
/src/sub visible in container |
host /src/sub after docker volume rm |
|---|---|---|
bind, bind,private |
no | kept |
bind,rprivate, bind,rslave |
yes (expected: no) | kept |
bind,rshared |
yes (expected: no) | unmounted (expected: kept) |
rbind, rbind,r* |
yes | rbind/rbind,rshared: unmounted; rprivate/rslave: kept |
Minimal standalone Go reproducer (run as root or under unshare -Urm --propagation private):
src, _ := os.MkdirTemp("", "src")
dst, _ := os.MkdirTemp("", "dst")
_ = mount.Mount("tmpfs", src, "tmpfs", "shared")
_ = os.Mkdir(filepath.Join(src, "sub"), 0o755)
_ = mount.Mount("tmpfs", filepath.Join(src, "sub"), "tmpfs", "")
_ = mount.Mount(src, dst, "none", "bind,rprivate")
mounted, _ := mountinfo.Mounted(filepath.Join(dst, "sub"))
fmt.Println("dst/sub mounted:", mounted) // prints true (expected: false)
Proposed fix
Split propagation options out of parseOptions (flag, propFlag, data) so the initial mount(2) call receives flag and the propagation mount(2) call receives propFlag. MakeMount and ensureMountedAs are updated to match, and the exported API stays unchanged.
Callers passing bind,r<prop> that relied on submounts being copied would now get a non-recursive bind (matching mount --bind --make-r<prop>). Callers that want submounts would need rbind,r<prop>.
Does this approach look good to maintainers? Happy to open a PR with unit and root mount tests if so.
AI disclosure: Used Antigravity (Gemini) to help trace the MS_REC bitmask interaction, build the dockerd reproducer, and draft this issue; reviewed and verified by the author.
- 主要语言
- Go
- 星标
- 104
- 派生
- 64
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 11
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
moby/sys 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 74/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 68/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
VictoriaMetrics/VictoriaLogs#1965 ·
维护者通常 1 天内回复
-
Sign-off cards drift between formats; write down one card format可能已有人在做 @keyxmakerx 今天认领。 未关闭documentation
难度 2/5 1-3 小时 新手友好度 65/100
keyxmakerx/Chronicle#2795 ·
维护者通常 1 天内回复
-
bug ElasticSearch
难度 2/5 1-3 小时 新手友好度 72/100
aliyun/terraform-provider-alicloud#11614 · 1 条评论 ·
维护者通常 1 天内回复
-
bug enhancement
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复