[24.0 backport] c8d: Use reference counting while mounting a snapshot #45780
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.
--read-only
with containerd-integration enabled #46074- What I did
Some snapshotters (like overlayfs or zfs) can't mount the same directories twice. For example if the same directroy is used as an upper directory in two mounts the kernel will output this warning:
And indeed accessing the files from both mounts will result in an "No such file or directory" error.
This change introduces reference counts for the mounts, if a directory is already mounted the mount interface will only increment the mount counter and return the mount target effectively making sure that the filesystem doesn't end up in an undefined behavior.
This PR replaces #45383
- How I did it
Created a
refCountMounter
that makes sure things aren't mounted twice.- How to verify it
You can use this script:
Note: Using this script you will see the kernel warning you that upperdir or workdir is already in-use by another mount. This is because unmounting happens async (MNT_DETACH is used, more info here), this happens during the last block of
docker cp
commands. This happens because cp does two calls:HEAD /v1.43/containers/<containerID>/archive?path=<patHh
PUT /v1.43/containers/<containerID>/archive?noOverwriteDirNonDir=true&path=<path>
The daemon calls Mount/Unmount for both of these calls, between the first Unmount and the second Mount the kernel didn't have the time to finish unmounting.
In this case this warning can be safely ignored. The same warning can be seen with graph drivers when running the script above.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)