Skip to content

Commit b3c7496

Browse files
authored
Merge pull request #4393 from fenglixa/fix-mount-failed
Fix "mount failed: File exists" issue when unmount fails
2 parents bf50225 + cfaac81 commit b3c7496

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Diff for: pkg/minikube/cluster/mount.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,15 @@ func mntCmd(source string, target string, c *MountConfig) string {
132132

133133
// umountCmd returns a command for unmounting
134134
func umountCmd(target string, force bool) string {
135-
flag := ""
135+
// Call fuser before unmount, for killing the processes using the mount point. Notes: don't use 'lsof' to avoid the innocents
136+
flag1 := fmt.Sprintf("sudo fuser -km %s;", target)
137+
flag2 := ""
136138
if force {
137-
flag = "-f "
139+
flag1 = ""
140+
flag2 = "-f "
138141
}
139142
// grep because findmnt will also display the parent!
140-
return fmt.Sprintf("findmnt -T %s | grep %s && sudo umount %s%s || true", target, target, flag, target)
143+
return fmt.Sprintf("[ \"x$(findmnt -T %s | grep %s)\" != \"x\" ] && { %s sudo umount %s%s; } || echo ", target, target, flag1, flag2, target)
141144
}
142145

143146
// Unmount unmounts a path

Diff for: pkg/minikube/cluster/mount_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestMount(t *testing.T) {
5454
target: "target",
5555
cfg: &MountConfig{Type: "9p", Mode: os.FileMode(0700)},
5656
want: []string{
57-
"findmnt -T target | grep target && sudo umount target || true",
57+
"[ \"x$(findmnt -T target | grep target)\" != \"x\" ] && { sudo fuser -km target; sudo umount target; } || echo ",
5858
"sudo mkdir -m 700 -p target && sudo mount -t 9p -o dfltgid=0,dfltuid=0 src target",
5959
},
6060
},
@@ -64,7 +64,7 @@ func TestMount(t *testing.T) {
6464
target: "target",
6565
cfg: &MountConfig{Type: "9p", Mode: os.FileMode(0700), UID: "docker", GID: "docker"},
6666
want: []string{
67-
"findmnt -T target | grep target && sudo umount target || true",
67+
"[ \"x$(findmnt -T target | grep target)\" != \"x\" ] && { sudo fuser -km target; sudo umount target; } || echo ",
6868
"sudo mkdir -m 700 -p target && sudo mount -t 9p -o dfltgid=$(grep ^docker: /etc/group | cut -d: -f3),dfltuid=$(id -u docker) src target",
6969
},
7070
},
@@ -77,7 +77,7 @@ func TestMount(t *testing.T) {
7777
"cache": "fscache",
7878
}},
7979
want: []string{
80-
"findmnt -T /target | grep /target && sudo umount /target || true",
80+
"[ \"x$(findmnt -T /target | grep /target)\" != \"x\" ] && { sudo fuser -km /target; sudo umount /target; } || echo ",
8181
"sudo mkdir -m 777 -p /target && sudo mount -t 9p -o cache=fscache,dfltgid=72,dfltuid=82,noextend,version=9p2000.u 10.0.0.1 /target",
8282
},
8383
},
@@ -89,7 +89,7 @@ func TestMount(t *testing.T) {
8989
"version": "9p2000.L",
9090
}},
9191
want: []string{
92-
"findmnt -T tgt | grep tgt && sudo umount tgt || true",
92+
"[ \"x$(findmnt -T tgt | grep tgt)\" != \"x\" ] && { sudo fuser -km tgt; sudo umount tgt; } || echo ",
9393
"sudo mkdir -m 700 -p tgt && sudo mount -t 9p -o dfltgid=0,dfltuid=0,version=9p2000.L src tgt",
9494
},
9595
},
@@ -115,7 +115,7 @@ func TestUnmount(t *testing.T) {
115115
t.Fatalf("Unmount(/mnt): %v", err)
116116
}
117117

118-
want := []string{"findmnt -T /mnt | grep /mnt && sudo umount /mnt || true"}
118+
want := []string{"[ \"x$(findmnt -T /mnt | grep /mnt)\" != \"x\" ] && { sudo fuser -km /mnt; sudo umount /mnt; } || echo "}
119119
if diff := cmp.Diff(r.cmds, want); diff != "" {
120120
t.Errorf("command diff (-want +got): %s", diff)
121121
}

0 commit comments

Comments
 (0)