kubernetes/pkg/volume/util/subpath
Yubao Liu 834ce75f88 Make sure auto-mounted subpath mount source is already mounted
For example, we have two filesystems, one is embedded into another:

/a/test		# first filesystem with a directory "/a/test/b2"
/a/test/b2	# not auto mounted yet second filesystem, notice "/a/test/b2" is
	        # a new directory on this filesystem after this filesystem is mounted

For subpath mount "/a/test/b2",  `openat("/a/test", "b2")` gets directory "b2" on the first
filesystem, then "mount -c" will use this wrong directory as source directory.

`fstatat("/a/test", "b2/")` forces triggering auto mount of second filesystem, so
`openat("/a/test", "b2")` gets correct source directory for "mount -c".

This fixes issue https://github.com/kubernetes/kubernetes/issues/110818#issuecomment-1175736550

References:

1. https://man7.org/linux/man-pages/man2/openat.2.html

   If pathname refers to an automount point that has not yet
   been triggered, so no other filesystem is mounted on it,
   then the call returns a file descriptor referring to the
   automount directory without triggering a mount.

2. https://man7.org/linux/man-pages/man2/open_by_handle_at.2.html

   name_to_handle_at() does not trigger a mount when the final
   component of the pathname is an automount point.  When a
   filesystem supports both file handles and automount points, a
   name_to_handle_at() call on an automount point will return with
   error EOVERFLOW without having increased handle_bytes.  This can
   happen since Linux 4.13 with NFS when accessing a directory which
   is on a separate filesystem on the server.  In this case, the
   automount can be triggered by adding a "/" to the end of the
   pathname.
2022-07-12 22:09:11 +08:00
..
OWNERS Check in OWNERS modified by update-yamlfmt.sh 2021-12-09 21:31:26 -05:00
subpath_linux_test.go Add tests for checking bind mounts 2021-11-10 11:52:55 -05:00
subpath_linux.go Make sure auto-mounted subpath mount source is already mounted 2022-07-12 22:09:11 +08:00
subpath_unsupported.go generated: Run hack/update-gofmt.sh 2021-08-24 15:47:49 -04:00
subpath_windows_test.go generated: Run hack/update-gofmt.sh 2021-08-24 15:47:49 -04:00
subpath_windows.go generated: Run hack/update-gofmt.sh 2021-08-24 15:47:49 -04:00
subpath.go Refactor subpath out of pkg/util/mount 2019-02-26 19:59:53 -07:00