filesystem: make Unmount robust further
@@ -86,6 +86,7 @@ func Mount(device, target, fsType, opts string, readonly bool) error {
// Unmount unmounts the device if it is mounted.
func Unmount(device, target string) error {
+ for i := 0; i < 10; i++ {
switch mounted, err := isMounted(device, target); {
case err != nil:
return err
@@ -93,17 +94,15 @@ func Unmount(device, target string) error {
return nil
}
- for i := 0; i < 10; i++ {
switch err := unix.Unmount(target, unix.UMOUNT_NOFOLLOW); err {
- case nil:
- return nil
- case unix.EBUSY:
+ case nil, unix.EBUSY:
+ // umount(2) can lie that it could have unmounted, so recheck.
time.Sleep(500 * time.Millisecond)
default:
return err
}
}
- return unix.Unmount(target, unix.UMOUNT_NOFOLLOW)
+ return unix.EBUSY
}
// DetectFilesystem returns filesystem type if device has a filesystem.
