Skip to content

libct: switch to new mount api #5378

Open
lifubang wants to merge 7 commits into
opencontainers:mainfrom
lifubang:feat-new-mount-api
Open

libct: switch to new mount api #5378
lifubang wants to merge 7 commits into
opencontainers:mainfrom
lifubang:feat-new-mount-api

Conversation

@lifubang

@lifubang lifubang commented Jul 21, 2026

Copy link
Copy Markdown
Member

Since the new mount API, such as open_tree, fsopen, fsmount, and move_mount, has matured over the years, it's time to embrace it fully.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

libcontainer/rootfs_linux.go:1366

  • sharedMaskSrc is always created as mountSourcePlain from sharedMaskFile, but when maskDir() returns a non-nil fd it is a detached mount fd (open_tree/fsmount). Detached mount fds cannot be used as a bind-mount source via mount(2) (/proc/.../fd/N), so later mountViaFds(..., sharedMaskSrc, ..., MS_BIND, ...) can fail or bind the wrong thing. To keep shared masking working, always reopen the mounted directory (reopenAfterMount) to get an O_PATH handle suitable for mountSourcePlain, and close any detached mount fd returned by maskDir().
					sharedMaskSrc = &mountSource{Type: mountSourcePlain, file: sharedMaskFile}

Comment on lines +367 to +371
fd, err := unix.OpenTree(-int(unix.EBADF), "/", unix.OPEN_TREE_CLOEXEC)
if err != nil {
return false
}
_ = unix.Close(fd)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This function is copied from github.com/cyphar/filepath-securejoin:
https://github.com/cyphar/filepath-securejoin/blob/main/pathrs-lite/internal/linux/mount_linux.go#L23-L47

@kolyshkin kolyshkin 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.

For the first commit, I'd like to add the following into the commit message (assuming it's true).

No functional change, just moving the code around.

Comment thread libcontainer/rootfs_linux.go Outdated
Comment on lines +721 to +725
func checkProcMount(rootfs, dest string, m mountEntry) error {
func checkProcMount(rootfs, dest string, m *mountEntry) error {

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.

What is the reason for this change? Just unification?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it's not necessary to make this change, so reverted it now.

Comment thread libcontainer/rootfs_linux.go Outdated
Comment thread libcontainer/rootfs_linux.go
lifubang added 2 commits July 22, 2026 01:22
mount_entry has become complex and requires further refactoring.
Extract it into a separate file to improve modularity and maintainability.

No functional change, just moving the code around.

Signed-off-by: lifubang <lifubang@acmcoder.com>
This change avoids duplicate fd closing and lays the groundwork for migrating
to the new mount API by centralizing resource cleanup logic.

Signed-off-by: lifubang <lifubang@acmcoder.com>
@lifubang
lifubang force-pushed the feat-new-mount-api branch 6 times, most recently from 354f77f to 0024b4b Compare July 24, 2026 11:34
lifubang added 5 commits July 26, 2026 04:39
Adds a regression test to guarantee mount labels are respected
for all supported mount types.

Signed-off-by: lifubang <lifubang@acmcoder.com>
As documented in mount(2): if MS_BIND is included in mountflags,
the filesystem type and mount data arguments are ignored.
Therefore, keep mountLabel empty for bind mounts.
Note: mount data is also blocked in the config validator:
https://github.com/opencontainers/runc/blob/main/libcontainer/configs/validate/validator.go#L373-L375

Signed-off-by: lifubang <lifubang@acmcoder.com>
Signed-off-by: lifubang <lifubang@acmcoder.com>
Signed-off-by: lifubang <lifubang@acmcoder.com>
Signed-off-by: lifubang <lifubang@acmcoder.com>
@lifubang
lifubang force-pushed the feat-new-mount-api branch from 0024b4b to 69bb33b Compare July 26, 2026 05:12
@lifubang

Copy link
Copy Markdown
Member Author

Add a commit libct: always ignore mount label for bind mounts to align the legacy mount(2) behavior with the new mount API for bind mounts.

// file descriptor fsfd using fsconfig(2). The options are expected to be a
// comma-separated list of key=value pairs or flags.
func fsconfigApplyOptions(fsfd int, opts string) error {
fields := strings.SplitSeq(opts, ",")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

On another note, since unix.FsconfigSet(String/Flag) requires individual calls, we need to re-parse back the value of m.Data. It might be better to pass the original array directly instead of joining it here:
https://github.com/opencontainers/runc/blob/main/libcontainer/specconv/spec_linux.go#L1181-L1185

However, configs.Mount is widely used by other projects, so changing m.Data from string to []string might break compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants