Skip to content

Commit 45d8a7e

Browse files
authored
Merge pull request #4588 from thaJeztah/remove_redundant_error
mount.isFUSE(): remove unused error return, and extract FUSE unmount to a function
2 parents 822ce4e + 48f64a1 commit 45d8a7e

1 file changed

Lines changed: 25 additions & 14 deletions

File tree

mount/mount_linux.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,37 @@ func Unmount(target string, flags int) error {
106106
return nil
107107
}
108108

109-
func isFUSE(dir string) (bool, error) {
110-
// fuseSuperMagic is defined in statfs(2)
111-
const fuseSuperMagic = 0x65735546
109+
// fuseSuperMagic is defined in statfs(2)
110+
const fuseSuperMagic = 0x65735546
111+
112+
func isFUSE(dir string) bool {
112113
var st unix.Statfs_t
113114
if err := unix.Statfs(dir, &st); err != nil {
114-
return false, err
115+
return false
115116
}
116-
return st.Type == fuseSuperMagic, nil
117+
return st.Type == fuseSuperMagic
118+
}
119+
120+
// unmountFUSE attempts to unmount using fusermount/fusermount3 helper binary.
121+
//
122+
// For FUSE mounts, using these helper binaries is preferred, see:
123+
// https://github.com/containerd/containerd/pull/3765#discussion_r342083514
124+
func unmountFUSE(target string) error {
125+
var err error
126+
for _, helperBinary := range []string{"fusermount3", "fusermount"} {
127+
cmd := exec.Command(helperBinary, "-u", target)
128+
err = cmd.Run()
129+
if err == nil {
130+
return nil
131+
}
132+
}
133+
return err
117134
}
118135

119136
func unmount(target string, flags int) error {
120-
// For FUSE mounts, attempting to execute fusermount helper binary is preferred
121-
// https://github.com/containerd/containerd/pull/3765#discussion_r342083514
122-
if ok, err := isFUSE(target); err == nil && ok {
123-
for _, helperBinary := range []string{"fusermount3", "fusermount"} {
124-
cmd := exec.Command(helperBinary, "-u", target)
125-
if err := cmd.Run(); err == nil {
126-
return nil
127-
}
128-
// ignore error and try unix.Unmount
137+
if isFUSE(target) {
138+
if err := unmountFUSE(target); err == nil {
139+
return nil
129140
}
130141
}
131142
for i := 0; i < 50; i++ {

0 commit comments

Comments
 (0)