Skip to content

Commit

Permalink
mount.Umount: EBUSY: try at most 50 times
Browse files Browse the repository at this point in the history
The function is being used in a number of places, notably container
removal and cleanup.  While container removal already loops over EBUSY,
cleanup does not.

To make sure that all callers of Unmount get a fair chance of unmounting
cleanly, also loop there.  I used the same values as containerd: 50
loops with 50ms sleeps.

Context: containers/podman/issues/11594
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
  • Loading branch information
vrothberg committed Oct 13, 2022
1 parent b0b712a commit 0f21fdf
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions pkg/mount/unmount_unix.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
//go:build !windows
// +build !windows

package mount

import "golang.org/x/sys/unix"
import (
"time"

"golang.org/x/sys/unix"
)

func unmount(target string, flags int) error {
err := unix.Unmount(target, flags)
if err == nil || err == unix.EINVAL {
// Ignore "not mounted" error here. Note the same error
// can be returned if flags are invalid, so this code
// assumes that the flags value is always correct.
return nil
var err error
for i := 0; i < 50; i++ {
err = unix.Unmount(target, flags)
switch err {
case unix.EBUSY:
time.Sleep(50 * time.Millisecond)
continue
case unix.EINVAL, nil:
// Ignore "not mounted" error here. Note the same error
// can be returned if flags are invalid, so this code
// assumes that the flags value is always correct.
return nil
default:
break
}
}

return &mountError{
Expand Down

0 comments on commit 0f21fdf

Please sign in to comment.