Skip to content

Commit 48f64a1

Browse files
committed
mount: extract FUSE unmounting to a function
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 5b13dcc commit 48f64a1

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

mount/mount_linux.go

Lines changed: 21 additions & 10 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+
// fuseSuperMagic is defined in statfs(2)
110+
const fuseSuperMagic = 0x65735546
111+
109112
func isFUSE(dir string) bool {
110-
// fuseSuperMagic is defined in statfs(2)
111-
const fuseSuperMagic = 0x65735546
112113
var st unix.Statfs_t
113114
if err := unix.Statfs(dir, &st); err != nil {
114115
return false
115116
}
116117
return st.Type == fuseSuperMagic
117118
}
118119

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
134+
}
135+
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
122137
if isFUSE(target) {
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
138+
if err := unmountFUSE(target); err == nil {
139+
return nil
129140
}
130141
}
131142
for i := 0; i < 50; i++ {

0 commit comments

Comments
 (0)