Uh oh!
There was an error while loading. Please reload this page.
Let a filesystem operation name a container, and report the bytes a trim discarded - #859
Closed
MayCXC wants to merge 1 commit into
Closed
Let a filesystem operation name a container, and report the bytes a trim discarded#859MayCXC wants to merge 1 commit into
MayCXC wants to merge 1 commit into
Conversation
4 tasks
A filesystem operation takes a path in the init namespace, and a container's root filesystem is not there: the container mounts it in a namespace of its own, and after the pivot nothing in the init namespace names it. The operations that matter for a root filesystem, trim above all, were out of reach for exactly the filesystems that grow. A request that names a container reaches its root filesystem through the init process's proc entry: the kernel resolves /proc/<pid>/root through that process's namespace, and the trailing dot component keeps the opened target a directory rather than the magic link itself, which the handler's O_NOFOLLOW refuses. The agent surface takes the container id and returns the bytes the filesystem reported trimmed, from the machine's one agent, for a single container and for a pod's members alike.
MayCXCforce-pushed
the
trim-container-rootfs
branch
from
August 27, 2026 20:47
869df3b to
43c6070Compare
This was referenced Aug 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A filesystem operation takes a path in the init namespace, and a container's root filesystem is not there: the container mounts it in a namespace of its own, and after the pivot nothing in the init namespace names it. The operations that matter for a root filesystem, trim above all, were out of reach for exactly the filesystems that grow.
A request that names a container reaches its root filesystem through the init process's proc entry: the kernel resolves
/proc/<pid>/rootthrough that process's namespace, and the trailing dot component keeps the opened target a directory rather than the magic link itself, which the handler'sO_NOFOLLOWrefuses. The agent surface takes the container id and answers with the bytes the filesystem reported trimmed, for a single container and for a pod's members alike.Closes#858. Addresses the requirement described in apple/container#2105.
Relationship to #838
This supersedes #838, which asks for the same thing from issue apple/container#2105. Both add
containerIDtoFilesystemOperationRequestso the operation runs against the intended container. The differences:FiTrimResult.trimmed_bytesis populated here. The field arrived with the trim operation in [vminitd]: api for trim filesystem operations #700 and has never been set:trimFilesystem(fd:)throws away the count thatFITRIMwrites back into the range, andfilesystemOperationreturns a bare.init(), so the oneof is never set and callers decode the default. [vminitd]: update filesystem operation to run in new namespace #838 keepsreturn .init(), so the field stays dead after it. Reporting is the whole reason the field exists, and a caller that loops until a trim returns nothing cannot work without it.containerIDstays optional.[vminitd]: update filesystem operation to run in new namespace #838 rejects a request that does not carry one, which breaks the existing path-addressed callers. Here a request names either a path or a container, so existing callers keep working.LinuxContainer.trimRootfs()andLinuxPod.trimContainer(_:)return the bytes discarded, rather than leaving each caller to assemble the request.testContainerTrimReportsBytesboots a container, trims, and asserts the answer is not zero, which is what fails today.One thing #838 does that this does not: it enters the container's mount namespace with
setns(CLONE_NEWNS)on a dedicated thread afterunshare(CLONE_FS). That is a correct way to do it, and it generalises to any path inside the container. Resolving through/proc/<pid>/rootreaches the same filesystem through the same namespace without moving a thread between namespaces. If maintainers prefer thesetnsapproach, the reporting fix and the host-side API here apply on top of it unchanged.Testing
swift buildandmake checkclean.swift test: 603 tests in 83 suites passed.make vminitdbuilds the guest with the change../bin/containerization-integration --filter trimrunscontainer trim reports bytesand the existingcontainer trim ext4 clone, both passing. The new test fails before the reporting fix withtrim reported 0 bytes.