GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — mountinfo.Mounted: add fast path for Linux using openat2 by kolyshkin · Pull Request #29 · moby/sys Conversation
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Looks like https://go-review.googlesource.com/c/sys/+/253057/ was merged (golang/sys@eff7692) (thanks @tklauser!), so this PR can remove the temporary wrapper |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
... to a version that includes openat2 implementation (see https://golang.org/cl/253057). Signed-off-by: Kir Kolyshkin <[email protected]>
... and drop 1.13.x Signed-off-by: Kir Kolyshkin <[email protected]>
2f60725 to
4ec1bfd
Compare
|
v2 changes (thanks to @cyphar for review):
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@cpuguy83 @thaJeztah PTAL. I am mostly interested in any test cases I might be missing. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
v3: add path normalization to mountedByMountinfo |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Aside from the two nits, LGTM. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@cyphar ❤️ for openat2. Love it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Downside is I don't think we can test this in CI without a custom VM. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
A new (as of Linux 5.6) openat2(2) system call can be used to check whether a path is a mount point or not, and it even works for bind mounts! This relies on the fact that openat2() with RESOLVE_NO_XDEV flag won't cross the filesystem boundary (that includes bind mounts). If EXDEV error is received, it means the argument is definitely a mount. If no error is received, it means the argument is definitely not a mount. For all the other errors (most probably ENOSYS or EPERM), fall back to existing methods (mountedByStat, mountedByMountinfo). Add a couple of tests: * TestMountedBy prepares a few mounts, and checks that various mountedBy* functions work as expected. Requires root. * TestMountedByOpenat2VsMountinfo reads the mountinfo and then tries to use mountedByOpenat2() for each mount, ignoring EPERM as the test might not be run as root. AFAIK this is the only way to test the new functionality if one is not root. v2 changes: - drop our own openat2 wrapper; - add O_PATH to openat2 flags; - add O_CLOEXEC to all open* calls; - rm socket and symlink special cases. v3: - drop the stat parameter, remove the dir/file distinction; - use openat2 for dirfd as well, so we can bail out earlier. Signed-off-by: Kir Kolyshkin <[email protected]>
Should be relatively easy to do, @AkihiroSuda did it for runc using vagrant on Travis CI. I might take a look at it later. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The positive side effect from this is we're returning earlier, not falling back on a slow path. The downside is this might not be entirely true, as a mounted path can be overshadowed by another mount, but still present in mountinfo. As the mount is inaccessible anyway, there is nothing that can be done with it, so let's treat it as non-mount. Signed-off-by: Kir Kolyshkin <[email protected]>
Currently, the path provided to mountinfo.Mounted() must be - an absolute path; - with all symlinks resolved; - cleaned. Otherwise, the function may return a false negative (in case this is a bind mount and the kernel is too old to have openat2) -- i.e. it will return "not mounted" while the path is in fact mounted. This commit removes the above limitation by doing a path normalization. This should slow things down but it's not affecting any of the fast paths, so the slowdown will only be seen in the "bind mount and older kernel" case (which is already pretty slow since we have to parse mountinfo). v2: as in mountedByOpenat2 and mountedByStat, treat ENOENT as "not mounted". Signed-off-by: Kir Kolyshkin <[email protected]>
|
v4 changes:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This should make it possible to test the recently added mountedByOpenat2 functionality, which requires Linux kernel 5.6+. Alas, even the latest Ubuntu release available on Travis, Focal (20.04), has a kernel that's not new enough, so we have to setup a vagrant box. The machinery is mostly stolen from the runc repo at https://github.com/opencontainers/runc/ Signed-off-by: Kir Kolyshkin <[email protected]>
Added 🎉 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
aaand it's a pass! https://travis-ci.org/github/moby/sys/builds/727240869#L4099 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return | ||
| } | ||
|
|
||
| func cleanupMounts(t *testing.T, dir string, mounts []string) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
(not for this PR, but just thinking out loud); we should have a look at the testing.Cleanup() option that's now available in Go 1.13+
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| checked := false | ||
| for _, m := range mounts { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
(not a blocker, just thinking out loud as well) We could use subtests for these for easier debugging
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think @cyphar's comments were addressed, so I'll go ahead and merge <3 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Mounted: add path resolution Implement Mounted() optimization using openat2(RESOLVE_NO_XDEV)
There was an error while loading. Please reload this page.