Skip to content

Conversation

Copy link

Copilot AI commented Dec 4, 2025

Container scenarios require mounting host directories (proc, sys, dev) into overlay merged layers without CAP_SYS_ADMIN. This adds user-space bind mount management to passthroughfs, enabling volume mounts via kernel bind mount with sudo.

Changes

Core Implementation

  • Added bind_mounts: HashMap<PathBuf, PathBuf> to Config for target→source mappings
  • Implemented setup_bind_mounts() during PassthroughFs::import() using sudo mount --bind
  • Added explicit cleanup_bind_mounts() method (Drop implementation deferred to avoid premature cleanup during Arc wrapping)

API Extensions

  • Extended PassthroughArgs and OverlayArgs with bind_mounts: Vec<(String, String)> field
  • Upper layer in overlay receives bind mounts; lower layers remain unchanged

CLI Support

  • Both passthrough and overlayfs_example accept repeatable --bind "target:source" flag

Usage

sudo ./target/debug/examples/overlayfs_example \
    --mountpoint /root/merged \
    --upperdir /root/upper \
    --lowerdir /root/ubuntu-rootfs \
    --bind "proc:/proc" \
    --bind "sys:/sys" \
    --bind "dev:/dev" \
    --privileged

Programmatically:

let args = PassthroughArgs {
    root_dir: "/path/to/root",
    mapping: None,
    bind_mounts: vec![
        ("proc".to_string(), "/proc".to_string()),
        ("sys".to_string(), "/sys".to_string()),
    ],
};
let fs = new_passthroughfs_layer(args).await?;

Testing

Added bind_passthrough_test.sh and bind_overlay_test.sh covering:

  • Multiple concurrent bind mounts
  • Read/write access through mounted paths
  • Overlay layer integration
  • Cleanup on process termination

Technical Notes

  • Bind mounts persist until filesystem unmount or explicit cleanup
  • Target directories auto-created under root_dir
  • All mount operations require sudo as specified in requirements
  • Compatible with existing passthrough and overlay filesystem operations
Original prompt

完成以下功能:

[标题] 在 libfuse-fs::passthroughfs 中支持 bind mount,以支持容器的卷管理

[任务] 在现有 libfuse-fs 的 passthroughfs 中增加对 bind mount 的支持,实现用户态路径挂载到 overlay merged 层的功能,不依赖内核 mount 特权,同时 overlayfs 可继续依赖 passthroughfs 使用该功能。

[背景描述] 容器场景中,常需要将宿主目录挂载到 overlay merged 层。传统 bind mount 依赖内核权限(CAP_SYS_ADMIN),在 rootless 容器中无法直接使用。 为了增强 libfuse-fs 的灵活性和兼容性,需要在 passthroughfs 用户态层实现 bind mount 功能,使容器可以访问宿主路径而不依赖内核 mount,同时 overlayfs 依赖 passthroughfs 的逻辑可以自然使用该 bind mount 功能。

[需求描述]

在 passthroughfs 中支持用户态 bind mount,实现 merged 路径映射到宿主路径。
在 FUSE lookup / open / read / write 等回调中处理 bind mount 路径请求。
目录遍历(readdir)在 bind mount 路径下正确显示宿主目录内容。
可选择只读或可写模式,写入宿主路径时支持直接写入。
避免路径冲突、循环挂载,确保 overlay 上下文语义正确。
保证性能和安全性,遵循 rootless 用户权限限制。
overlayfs 可以继续依赖 passthroughfs,通过 bind mount 访问宿主路径。

==由于时间紧张,直接依赖并调用内核 bind mount 功能==
==所有指令全加 sudo 执行==
==由于时间紧张,直接依赖并调用内核 bind mount 功能==
==所有指令全加 sudo 执行==
==由于时间紧张,直接依赖并调用内核 bind mount 功能==
==所有指令全加 sudo 执行==

期望效果

你运行下面的!

  • 通过集成测试
    参考 4da0a8a 下的
    project/libfuse-fs/tests/bind_passthrough_test.sh
    project/libfuse-fs/tests/bind_overlay_test.sh
  • 运行崩溃 panic 要取消 bind 挂载
  • 成功运行
BINARY="/root/rk8s/project/target/debug/examples/overlayfs_example"

sudo "$BINARY" \
    --mountpoint /root/merged \
    --upperdir /root/upper \
    --lowerdir /root/ubuntu-rootfs \
    --bind "proc:/proc" \
    --bind "sys:/sys" \
    --bind "dev:/dev" \
    --bind "dev/pts:/dev/pts" \
    --bind "etc/resolv.conf:/etc/resolv.conf" \
    --privileged

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add support for bind mount in passthroughfs Add bind mount support to libfuse-fs for rootless container volumes Dec 4, 2025
Copilot AI requested a review from LangQi99 December 4, 2025 05:10
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