Merge pull request #4588 from thaJeztah/remove_redundant_error
mount.isFUSE(): remove unused error return, and extract FUSE unmount to a function
This commit is contained in:
commit
45d8a7e4a2
@ -106,26 +106,37 @@ func Unmount(target string, flags int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func isFUSE(dir string) (bool, error) {
|
// fuseSuperMagic is defined in statfs(2)
|
||||||
// fuseSuperMagic is defined in statfs(2)
|
const fuseSuperMagic = 0x65735546
|
||||||
const fuseSuperMagic = 0x65735546
|
|
||||||
|
func isFUSE(dir string) bool {
|
||||||
var st unix.Statfs_t
|
var st unix.Statfs_t
|
||||||
if err := unix.Statfs(dir, &st); err != nil {
|
if err := unix.Statfs(dir, &st); err != nil {
|
||||||
return false, err
|
return false
|
||||||
}
|
}
|
||||||
return st.Type == fuseSuperMagic, nil
|
return st.Type == fuseSuperMagic
|
||||||
|
}
|
||||||
|
|
||||||
|
// unmountFUSE attempts to unmount using fusermount/fusermount3 helper binary.
|
||||||
|
//
|
||||||
|
// For FUSE mounts, using these helper binaries is preferred, see:
|
||||||
|
// https://github.com/containerd/containerd/pull/3765#discussion_r342083514
|
||||||
|
func unmountFUSE(target string) error {
|
||||||
|
var err error
|
||||||
|
for _, helperBinary := range []string{"fusermount3", "fusermount"} {
|
||||||
|
cmd := exec.Command(helperBinary, "-u", target)
|
||||||
|
err = cmd.Run()
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmount(target string, flags int) error {
|
func unmount(target string, flags int) error {
|
||||||
// For FUSE mounts, attempting to execute fusermount helper binary is preferred
|
if isFUSE(target) {
|
||||||
// https://github.com/containerd/containerd/pull/3765#discussion_r342083514
|
if err := unmountFUSE(target); err == nil {
|
||||||
if ok, err := isFUSE(target); err == nil && ok {
|
return nil
|
||||||
for _, helperBinary := range []string{"fusermount3", "fusermount"} {
|
|
||||||
cmd := exec.Command(helperBinary, "-u", target)
|
|
||||||
if err := cmd.Run(); err == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// ignore error and try unix.Unmount
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := 0; i < 50; i++ {
|
for i := 0; i < 50; i++ {
|
||||||
|
Loading…
Reference in New Issue
Block a user