From 55acd9a80d024a196885c6a72a570efac4c5bbf3 Mon Sep 17 00:00:00 2001 From: itomsawyer Date: Tue, 11 Apr 2023 17:51:31 +0800 Subject: [PATCH 1/2] add option for lazy unmount --- fuse/api.go | 4 ++++ fuse/mount_linux.go | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fuse/api.go b/fuse/api.go index a0ec84fd7..cf1561547 100644 --- a/fuse/api.go +++ b/fuse/api.go @@ -279,6 +279,10 @@ type MountOptions struct { // directory queries (i.e. 'ls' without '-l') can be faster with // ReadDir, as no per-file stat calls are needed DisableReadDirPlus bool + + // LazyUnmount is used to calling fusermount with -z flag which make unmount + // works even if resource is still busy + LazyUnmount bool } // RawFileSystem is an interface close to the FUSE wire protocol. diff --git a/fuse/mount_linux.go b/fuse/mount_linux.go index 2886a307f..990851339 100644 --- a/fuse/mount_linux.go +++ b/fuse/mount_linux.go @@ -189,7 +189,11 @@ func unmount(mountPoint string, opts *MountOptions) (err error) { return err } errBuf := bytes.Buffer{} - cmd := exec.Command(bin, "-u", mountPoint) + args := []string{"-u", mountPoint} + if opts.LazyUnmount { + args = append(args, "-z") + } + cmd := exec.Command(bin, args...) cmd.Stderr = &errBuf if opts.Debug { log.Printf("unmount: executing %q", cmd.Args) From 2185aa4810df731aafcceab7d6becd801a9ba5b9 Mon Sep 17 00:00:00 2001 From: itomsawyer Date: Tue, 30 Apr 2024 14:55:51 +0800 Subject: [PATCH 2/2] optimize fusermount args slice --- fuse/mount_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fuse/mount_linux.go b/fuse/mount_linux.go index 990851339..5567c2e9a 100644 --- a/fuse/mount_linux.go +++ b/fuse/mount_linux.go @@ -191,7 +191,7 @@ func unmount(mountPoint string, opts *MountOptions) (err error) { errBuf := bytes.Buffer{} args := []string{"-u", mountPoint} if opts.LazyUnmount { - args = append(args, "-z") + args[0] = "-uz" } cmd := exec.Command(bin, args...) cmd.Stderr = &errBuf