From 12b350b51833d74fba70dfdac88d8a04a6d141c4 Mon Sep 17 00:00:00 2001 From: fenglixa Date: Fri, 31 May 2019 10:27:02 +0800 Subject: [PATCH 1/2] fix issue 4239 --- pkg/minikube/cluster/mount.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/minikube/cluster/mount.go b/pkg/minikube/cluster/mount.go index 1610b214bc89..c657a8f99646 100644 --- a/pkg/minikube/cluster/mount.go +++ b/pkg/minikube/cluster/mount.go @@ -132,12 +132,15 @@ func mntCmd(source string, target string, c *MountConfig) string { // umountCmd returns a command for unmounting func umountCmd(target string, force bool) string { - flag := "" + // Call fuser before unmount, for killing the processes using the mount point. Notes: don't use 'lsof' to avoid the innocents + flag1 := fmt.Sprintf("sudo fuser -km %s;", target) + flag2 := "" if force { - flag = "-f " + flag1 = "" + flag2 = "-f " } // grep because findmnt will also display the parent! - return fmt.Sprintf("findmnt -T %s | grep %s && sudo umount %s%s || true", target, target, flag, target) + return fmt.Sprintf("[ \"x$(findmnt -T %s | grep %s)\" != \"x\" ] && { %s sudo umount %s%s; } || echo ", target, target, flag1, flag2, target) } // Unmount unmounts a path From cfaac81707684f35c314330e31311063aad762d7 Mon Sep 17 00:00:00 2001 From: fenglixa Date: Sun, 2 Jun 2019 21:11:20 +0800 Subject: [PATCH 2/2] update cases to ensure make test PASS --- pkg/minikube/cluster/mount_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/minikube/cluster/mount_test.go b/pkg/minikube/cluster/mount_test.go index 749f631edab5..efa76adec412 100644 --- a/pkg/minikube/cluster/mount_test.go +++ b/pkg/minikube/cluster/mount_test.go @@ -54,7 +54,7 @@ func TestMount(t *testing.T) { target: "target", cfg: &MountConfig{Type: "9p", Mode: os.FileMode(0700)}, want: []string{ - "findmnt -T target | grep target && sudo umount target || true", + "[ \"x$(findmnt -T target | grep target)\" != \"x\" ] && { sudo fuser -km target; sudo umount target; } || echo ", "sudo mkdir -m 700 -p target && sudo mount -t 9p -o dfltgid=0,dfltuid=0 src target", }, }, @@ -64,7 +64,7 @@ func TestMount(t *testing.T) { target: "target", cfg: &MountConfig{Type: "9p", Mode: os.FileMode(0700), UID: "docker", GID: "docker"}, want: []string{ - "findmnt -T target | grep target && sudo umount target || true", + "[ \"x$(findmnt -T target | grep target)\" != \"x\" ] && { sudo fuser -km target; sudo umount target; } || echo ", "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", }, }, @@ -77,7 +77,7 @@ func TestMount(t *testing.T) { "cache": "fscache", }}, want: []string{ - "findmnt -T /target | grep /target && sudo umount /target || true", + "[ \"x$(findmnt -T /target | grep /target)\" != \"x\" ] && { sudo fuser -km /target; sudo umount /target; } || echo ", "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", }, }, @@ -89,7 +89,7 @@ func TestMount(t *testing.T) { "version": "9p2000.L", }}, want: []string{ - "findmnt -T tgt | grep tgt && sudo umount tgt || true", + "[ \"x$(findmnt -T tgt | grep tgt)\" != \"x\" ] && { sudo fuser -km tgt; sudo umount tgt; } || echo ", "sudo mkdir -m 700 -p tgt && sudo mount -t 9p -o dfltgid=0,dfltuid=0,version=9p2000.L src tgt", }, }, @@ -115,7 +115,7 @@ func TestUnmount(t *testing.T) { t.Fatalf("Unmount(/mnt): %v", err) } - want := []string{"findmnt -T /mnt | grep /mnt && sudo umount /mnt || true"} + want := []string{"[ \"x$(findmnt -T /mnt | grep /mnt)\" != \"x\" ] && { sudo fuser -km /mnt; sudo umount /mnt; } || echo "} if diff := cmp.Diff(r.cmds, want); diff != "" { t.Errorf("command diff (-want +got): %s", diff) }