-
Notifications
You must be signed in to change notification settings - Fork 40k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local storage teardown fix #48402
Local storage teardown fix #48402
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,8 +44,21 @@ type Interface interface { | |
// it could change between chunked reads). This is guaranteed to be | ||
// consistent. | ||
List() ([]MountPoint, error) | ||
// IsLikelyNotMountPoint determines if a directory is a mountpoint. | ||
// IsMountPointMatch determines if the mountpoint matches the dir | ||
IsMountPointMatch(mp MountPoint, dir string) bool | ||
// IsNotMountPoint determines if a directory is a mountpoint. | ||
// It should return ErrNotExist when the directory does not exist. | ||
// IsNotMountPoint is more expensive than IsLikelyNotMountPoint. | ||
// IsNotMountPoint detects bind mounts in linux. | ||
// IsNotMountPoint enumerates all the mountpoints using List() and | ||
// the list of mountpoints may be large, then it uses | ||
// IsMountPointMatch to evaluate whether the directory is a mountpoint | ||
IsNotMountPoint(file string) (bool, error) | ||
// IsLikelyNotMountPoint uses heuristics to determine if a directory | ||
// is a mountpoint. | ||
// It should return ErrNotExist when the directory does not exist. | ||
// IsLikelyNotMountPoint does NOT properly detect all mountpoint types | ||
// most notably linux bind mounts. | ||
IsLikelyNotMountPoint(file string) (bool, error) | ||
// DeviceOpened determines if the device is in use elsewhere | ||
// on the system, i.e. still mounted. | ||
|
@@ -199,3 +212,34 @@ func getDeviceNameFromMount(mounter Interface, mountPath, pluginDir string) (str | |
|
||
return path.Base(mountPath), nil | ||
} | ||
|
||
// IsNotMountPoint determines if a directory is a mountpoint. | ||
// It should return ErrNotExist when the directory does not exist. | ||
// This method uses the List() of all mountpoints | ||
// It is more extensive than IsLikelyNotMountPoint | ||
// and it detects bind mounts in linux | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add a comment indicating that compared to |
||
func IsNotMountPoint(mounter Interface, file string) (bool, error) { | ||
// IsLikelyNotMountPoint provides a quick check | ||
// to determine whether file IS A mountpoint | ||
notMnt, notMntErr := mounter.IsLikelyNotMountPoint(file) | ||
if notMntErr != nil { | ||
return notMnt, notMntErr | ||
} | ||
// identified as mountpoint, so return this fact | ||
if notMnt == false { | ||
return notMnt, nil | ||
} | ||
// check all mountpoints since IsLikelyNotMountPoint | ||
// is not reliable for some mountpoint types | ||
mountPoints, mountPointsErr := mounter.List() | ||
if mountPointsErr != nil { | ||
return notMnt, mountPointsErr | ||
} | ||
for _, mp := range mountPoints { | ||
if mounter.IsMountPointMatch(mp, file) { | ||
notMnt = false | ||
break | ||
} | ||
} | ||
return notMnt, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,7 +198,7 @@ func (m *localVolumeMounter) SetUpAt(dir string, fsGroup *int64) error { | |
return fmt.Errorf("invalid path: %s %v", m.globalPath, err) | ||
} | ||
|
||
notMnt, err := m.mounter.IsLikelyNotMountPoint(dir) | ||
notMnt, err := m.mounter.IsNotMountPoint(dir) | ||
glog.V(4).Infof("LocalVolume mount setup: PodDir(%s) VolDir(%s) Mounted(%t) Error(%v), ReadOnly(%t)", dir, m.globalPath, !notMnt, err, m.readOnly) | ||
if err != nil && !os.IsNotExist(err) { | ||
glog.Errorf("cannot validate mount point: %s %v", dir, err) | ||
|
@@ -223,19 +223,19 @@ func (m *localVolumeMounter) SetUpAt(dir string, fsGroup *int64) error { | |
err = m.mounter.Mount(m.globalPath, dir, "", options) | ||
if err != nil { | ||
glog.Errorf("Mount of volume %s failed: %v", dir, err) | ||
notMnt, mntErr := m.mounter.IsLikelyNotMountPoint(dir) | ||
notMnt, mntErr := m.mounter.IsNotMountPoint(dir) | ||
if mntErr != nil { | ||
glog.Errorf("IsLikelyNotMountPoint check failed: %v", mntErr) | ||
glog.Errorf("IsNotMountPoint check failed: %v", mntErr) | ||
return err | ||
} | ||
if !notMnt { | ||
if mntErr = m.mounter.Unmount(dir); mntErr != nil { | ||
glog.Errorf("Failed to unmount: %v", mntErr) | ||
return err | ||
} | ||
notMnt, mntErr = m.mounter.IsLikelyNotMountPoint(dir) | ||
notMnt, mntErr = m.mounter.IsNotMountPoint(dir) | ||
if mntErr != nil { | ||
glog.Errorf("IsLikelyNotMountPoint check failed: %v", mntErr) | ||
glog.Errorf("IsNotMountPoint check failed: %v", mntErr) | ||
return err | ||
} | ||
if !notMnt { | ||
|
@@ -269,5 +269,5 @@ func (u *localVolumeUnmounter) TearDown() error { | |
// TearDownAt unmounts the bind mount | ||
func (u *localVolumeUnmounter) TearDownAt(dir string) error { | ||
glog.V(4).Infof("Unmounting volume %q at path %q\n", u.volName, dir) | ||
return util.UnmountPath(dir, u.mounter) | ||
return util.UnmountMountPoint(dir, u.mounter, true) /* extensiveMountPointCheck = true */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During mount we also call IsLikelyNotMountPoint. Need to also evaluate if that call needs to be updated too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I modified all references of IsLikelyNotMountPoint to use IsNotMountPoint inside local.go. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,23 +75,42 @@ func SetReady(dir string) { | |
// UnmountPath is a common unmount routine that unmounts the given path and | ||
// deletes the remaining directory if successful. | ||
func UnmountPath(mountPath string, mounter mount.Interface) error { | ||
return UnmountMountPoint(mountPath, mounter, false /* extensiveMountPointCheck */) | ||
} | ||
|
||
// UnmountMountPoint is a common unmount routine that unmounts the given path and | ||
// deletes the remaining directory if successful. | ||
// if extensiveMountPointCheck is true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also please add comment about perf implications about enabling this option. |
||
// IsNotMountPoint will be called instead of IsLikelyNotMountPoint. | ||
// IsNotMountPoint is more expensive but properly handles bind mounts. | ||
func UnmountMountPoint(mountPath string, mounter mount.Interface, extensiveMountPointCheck bool) error { | ||
if pathExists, pathErr := PathExists(mountPath); pathErr != nil { | ||
return fmt.Errorf("Error checking if path exists: %v", pathErr) | ||
} else if !pathExists { | ||
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", mountPath) | ||
return nil | ||
} | ||
|
||
notMnt, err := mounter.IsLikelyNotMountPoint(mountPath) | ||
var notMnt bool | ||
var err error | ||
|
||
if extensiveMountPointCheck { | ||
notMnt, err = mount.IsNotMountPoint(mounter, mountPath) | ||
} else { | ||
notMnt, err = mounter.IsLikelyNotMountPoint(mountPath) | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
if notMnt { | ||
glog.Warningf("Warning: %q is not a mountpoint, deleting", mountPath) | ||
return os.Remove(mountPath) | ||
} | ||
|
||
// Unmount the mount path | ||
glog.V(4).Infof("%q is a mountpoint, unmounting", mountPath) | ||
if err := mounter.Unmount(mountPath); err != nil { | ||
return err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment that in particular this is can detect bind mounts of directories.