mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Fixed TearDown of NFS with root squash.
NFS plugin should not use IsLikelyNotMountPoint(), as it uses lstat() / stat() to determine if the NFS volume is still mounted - NFS server may use root_squash and kubelet may not be allowed to do lstat() / stat() there. It must use slower IsNotMountPoint() instead, including TearDown() function.
This commit is contained in:
parent
51acead084
commit
45d21ee36b
@ -19,6 +19,7 @@ limitations under the License.
|
|||||||
package mount
|
package mount
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -208,6 +209,12 @@ func IsNotMountPoint(mounter Interface, file string) (bool, error) {
|
|||||||
// IsLikelyNotMountPoint provides a quick check
|
// IsLikelyNotMountPoint provides a quick check
|
||||||
// to determine whether file IS A mountpoint
|
// to determine whether file IS A mountpoint
|
||||||
notMnt, notMntErr := mounter.IsLikelyNotMountPoint(file)
|
notMnt, notMntErr := mounter.IsLikelyNotMountPoint(file)
|
||||||
|
if notMntErr != nil && os.IsPermission(notMntErr) {
|
||||||
|
// We were not allowed to do the simple stat() check, e.g. on NFS with
|
||||||
|
// root_squash. Fall back to /proc/mounts check below.
|
||||||
|
notMnt = true
|
||||||
|
notMntErr = nil
|
||||||
|
}
|
||||||
if notMntErr != nil {
|
if notMntErr != nil {
|
||||||
return notMnt, notMntErr
|
return notMnt, notMntErr
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ func (b *nfsMounter) SetUp(fsGroup *int64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *nfsMounter) SetUpAt(dir string, fsGroup *int64) error {
|
func (b *nfsMounter) SetUpAt(dir string, fsGroup *int64) error {
|
||||||
notMnt, err := b.mounter.IsLikelyNotMountPoint(dir)
|
notMnt, err := b.mounter.IsNotMountPoint(dir)
|
||||||
glog.V(4).Infof("NFS mount set up: %s %v %v", dir, !notMnt, err)
|
glog.V(4).Infof("NFS mount set up: %s %v %v", dir, !notMnt, err)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
@ -252,7 +252,7 @@ func (b *nfsMounter) SetUpAt(dir string, fsGroup *int64) error {
|
|||||||
mountOptions := volume.JoinMountOptions(b.mountOptions, options)
|
mountOptions := volume.JoinMountOptions(b.mountOptions, options)
|
||||||
err = b.mounter.Mount(source, dir, "nfs", mountOptions)
|
err = b.mounter.Mount(source, dir, "nfs", mountOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
notMnt, mntErr := b.mounter.IsLikelyNotMountPoint(dir)
|
notMnt, mntErr := b.mounter.IsNotMountPoint(dir)
|
||||||
if mntErr != nil {
|
if mntErr != nil {
|
||||||
glog.Errorf("IsLikelyNotMountPoint check failed: %v", mntErr)
|
glog.Errorf("IsLikelyNotMountPoint check failed: %v", mntErr)
|
||||||
return err
|
return err
|
||||||
@ -262,7 +262,7 @@ func (b *nfsMounter) SetUpAt(dir string, fsGroup *int64) error {
|
|||||||
glog.Errorf("Failed to unmount: %v", mntErr)
|
glog.Errorf("Failed to unmount: %v", mntErr)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
notMnt, mntErr := b.mounter.IsLikelyNotMountPoint(dir)
|
notMnt, mntErr := b.mounter.IsNotMountPoint(dir)
|
||||||
if mntErr != nil {
|
if mntErr != nil {
|
||||||
glog.Errorf("IsLikelyNotMountPoint check failed: %v", mntErr)
|
glog.Errorf("IsLikelyNotMountPoint check failed: %v", mntErr)
|
||||||
return err
|
return err
|
||||||
@ -290,7 +290,10 @@ func (c *nfsUnmounter) TearDown() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *nfsUnmounter) TearDownAt(dir string) error {
|
func (c *nfsUnmounter) TearDownAt(dir string) error {
|
||||||
return util.UnmountPath(dir, c.mounter)
|
// Use extensiveMountPointCheck to consult /proc/mounts. We can't use faster
|
||||||
|
// IsLikelyNotMountPoint (lstat()), since there may be root_squash on the
|
||||||
|
// NFS server and kubelet may not be able to do lstat/stat() there.
|
||||||
|
return util.UnmountMountPoint(dir, c.mounter, true /* extensiveMountPointCheck */)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVolumeSource(spec *volume.Spec) (*v1.NFSVolumeSource, bool, error) {
|
func getVolumeSource(spec *volume.Spec) (*v1.NFSVolumeSource, bool, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user