From 2f67681e3b6113710343c396cb24c43930062f43 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 28 Jan 2021 18:17:47 +0000 Subject: [PATCH] cmount: don't attempt to unmount if fs has been destroyed already #4957 --- cmd/cmount/fs.go | 13 ++++++++----- cmd/cmount/mount.go | 6 +++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cmd/cmount/fs.go b/cmd/cmount/fs.go index 34b5b7f66..32a6b8c21 100644 --- a/cmd/cmount/fs.go +++ b/cmd/cmount/fs.go @@ -9,6 +9,7 @@ import ( "os" "path" "sync" + "sync/atomic" "time" "github.com/billziss-gh/cgofuse/fuse" @@ -23,11 +24,12 @@ const fhUnset = ^uint64(0) // FS represents the top level filing system type FS struct { - VFS *vfs.VFS - f fs.Fs - ready chan (struct{}) - mu sync.Mutex // to protect the below - handles []vfs.Handle + VFS *vfs.VFS + f fs.Fs + ready chan (struct{}) + mu sync.Mutex // to protect the below + handles []vfs.Handle + destroyed int32 // read/write with sync/atomic } // NewFS makes a new FS @@ -187,6 +189,7 @@ func (fsys *FS) Init() { // Destroy call). func (fsys *FS) Destroy() { defer log.Trace(fsys.f, "")("") + atomic.StoreInt32(&fsys.destroyed, 1) } // Getattr reads the attributes for path diff --git a/cmd/cmount/mount.go b/cmd/cmount/mount.go index ecfabe3f4..de5691399 100644 --- a/cmd/cmount/mount.go +++ b/cmd/cmount/mount.go @@ -12,6 +12,7 @@ import ( "fmt" "os" "runtime" + "sync/atomic" "time" "github.com/billziss-gh/cgofuse/fuse" @@ -168,7 +169,10 @@ func mount(VFS *vfs.VFS, mountPath string, opt *mountlib.Options) (<-chan error, // Shutdown the VFS fsys.VFS.Shutdown() var umountOK bool - if atexit.Signalled() { + if atomic.LoadInt32(&fsys.destroyed) != 0 { + fs.Debugf(nil, "Not calling host.Unmount as mount already Destroyed") + umountOK = true + } else if atexit.Signalled() { // If we have received a signal then FUSE will be shutting down already fs.Debugf(nil, "Not calling host.Unmount as signal received") umountOK = true