c8d: Use reference counting while mounting a snapshot#45698
Merged
cpuguy83 merged 1 commit intomoby:masterfrom Jun 8, 2023
Merged
c8d: Use reference counting while mounting a snapshot#45698cpuguy83 merged 1 commit intomoby:masterfrom
cpuguy83 merged 1 commit intomoby:masterfrom
Conversation
22ae7eb to
93b6646
Compare
cpuguy83
reviewed
Jun 5, 2023
|
|
||
| // inSlice tests whether a string is contained in a slice of strings or not. | ||
| // Comparison is case sensitive | ||
| func inSlice(slice []string, s string) bool { |
Member
There was a problem hiding this comment.
Member
Author
There was a problem hiding this comment.
We do have 5 implementations of this same function in the code, I could switch all of them with slices.Contains if we don't mind a new dependency
Member
There was a problem hiding this comment.
The benefit of this particular dep is that it's core stdlib in 1.20+ 👀
vvoland
reviewed
Jun 7, 2023
|
|
||
| import ( | ||
| "github.com/containerd/containerd/mount" | ||
| "github.com/docker/docker/daemon/graphdriver" |
Contributor
There was a problem hiding this comment.
Feels a bit weird to make daemon/snapshotter depend on the daemon/graphdriver.
How cumbersome would it be to extract the common bits out of the daemon/graphdriver?
Member
Author
There was a problem hiding this comment.
Yeah I wanted to keep this PR small-ish, I can add a commit to move it or in a followup
2ca294f to
efedc07
Compare
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:
overlayfs: upperdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.
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.
Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
efedc07 to
32d5814
Compare
vvoland
approved these changes
Jun 7, 2023
cpuguy83
approved these changes
Jun 8, 2023
cpuguy83
approved these changes
Jun 8, 2023
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 free
to 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.
--read-onlywith 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
refCountMounterthat 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 cpcommands. This happens because cp does two calls:HEAD /v1.43/containers/<containerID>/archive?path=<patHhPUT /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)
