From 055374a50bc3cfe78be6d73514182decb8531666 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 15 Jun 2021 12:45:20 -0700 Subject: [PATCH] FUSE: skip flushing if file is deleted related to https://github.com/chrislusf/seaweedfs/issues/2110 --- weed/filesys/dir.go | 5 ++++- weed/filesys/filehandle.go | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/weed/filesys/dir.go b/weed/filesys/dir.go index 904999c43..1af868d58 100644 --- a/weed/filesys/dir.go +++ b/weed/filesys/dir.go @@ -443,7 +443,10 @@ func (dir *Dir) removeOneFile(req *fuse.RemoveRequest) error { dir.wfs.handlesLock.Lock() defer dir.wfs.handlesLock.Unlock() inodeId := filePath.AsInode() - delete(dir.wfs.handles, inodeId) + if fh, ok := dir.wfs.handles[inodeId]; ok { + delete(dir.wfs.handles, inodeId) + fh.isDeleted = true + } return nil diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go index 88cfe45f0..f95051f65 100644 --- a/weed/filesys/filehandle.go +++ b/weed/filesys/filehandle.go @@ -33,11 +33,12 @@ type FileHandle struct { Uid uint32 // user ID of process making request Gid uint32 // group ID of process making request writeOnly bool + isDeleted bool } func newFileHandle(file *File, uid, gid uint32, writeOnly bool) *FileHandle { fh := &FileHandle{ - f: file, + f: file, // dirtyPages: newContinuousDirtyPages(file, writeOnly), dirtyPages: newTempFileDirtyPages(file, writeOnly), Uid: uid, @@ -222,6 +223,11 @@ func (fh *FileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) error { glog.V(4).Infof("Flush %v fh %d", fh.f.fullpath(), fh.handle) + if fh.isDeleted { + glog.V(4).Infof("Flush %v fh %d skip deleted", fh.f.fullpath(), fh.handle) + return nil + } + fh.Lock() defer fh.Unlock()