From 9ef5bb20f6cea962e2e521f183c1d2fa692a4a2b Mon Sep 17 00:00:00 2001 From: chrislu Date: Sun, 27 Feb 2022 00:00:23 -0800 Subject: [PATCH] mount2: invalidate fuse cache for replaced inode --- weed/mount/inode_to_path.go | 3 ++- weed/mount/weedfs.go | 5 +++++ weed/mount/weedfs_rename.go | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/weed/mount/inode_to_path.go b/weed/mount/inode_to_path.go index 156797b72..1e914dccd 100644 --- a/weed/mount/inode_to_path.go +++ b/weed/mount/inode_to_path.go @@ -138,7 +138,7 @@ func (i *InodeToPath) RemovePath(path util.FullPath) { } } -func (i *InodeToPath) MovePath(sourcePath, targetPath util.FullPath) { +func (i *InodeToPath) MovePath(sourcePath, targetPath util.FullPath) (replacedInode uint64) { i.Lock() defer i.Unlock() sourceInode, sourceFound := i.path2inode[sourcePath] @@ -157,6 +157,7 @@ func (i *InodeToPath) MovePath(sourcePath, targetPath util.FullPath) { } else { i.inode2path[sourceInode].nlookup++ } + return targetInode } func (i *InodeToPath) Forget(inode, nlookup uint64, onForgetDir func(dir util.FullPath)) { diff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.go index 1e6d1a856..157d385c7 100644 --- a/weed/mount/weedfs.go +++ b/weed/mount/weedfs.go @@ -65,6 +65,7 @@ type WFS struct { inodeToPath *InodeToPath fhmap *FileHandleToInode dhmap *DirectoryHandleToInode + fuseServer *fuse.Server } func NewSeaweedFileSystem(option *Option) *WFS { @@ -109,6 +110,10 @@ func (wfs *WFS) String() string { return "seaweedfs" } +func (wfs *WFS) Init(server *fuse.Server) { + wfs.fuseServer = server +} + func (wfs *WFS) maybeReadEntry(inode uint64) (path util.FullPath, fh *FileHandle, entry *filer_pb.Entry, status fuse.Status) { path, status = wfs.inodeToPath.GetPath(inode) if status != fuse.OK { diff --git a/weed/mount/weedfs_rename.go b/weed/mount/weedfs_rename.go index 44f3c910c..5446c7ed1 100644 --- a/weed/mount/weedfs_rename.go +++ b/weed/mount/weedfs_rename.go @@ -214,6 +214,8 @@ func (wfs *WFS) Rename(cancel <-chan struct{}, in *fuse.RenameIn, oldName string func (wfs *WFS) handleRenameResponse(ctx context.Context, resp *filer_pb.StreamRenameEntryResponse) error { // comes from filer StreamRenameEntry, can only be create or delete entry + glog.V(4).Infof("dir Rename %+v", resp.EventNotification) + if resp.EventNotification.NewEntry != nil { // with new entry, the old entry name also exists. This is the first step to create new entry newEntry := filer.FromPbEntry(resp.EventNotification.NewParentPath, resp.EventNotification.NewEntry) @@ -227,7 +229,11 @@ func (wfs *WFS) handleRenameResponse(ctx context.Context, resp *filer_pb.StreamR oldPath := oldParent.Child(oldName) newPath := newParent.Child(newName) - wfs.inodeToPath.MovePath(oldPath, newPath) + replacedInode := wfs.inodeToPath.MovePath(oldPath, newPath) + // invalidate attr and data + if replacedInode > 0 { + wfs.fuseServer.InodeNotify(replacedInode, 0, -1) + } } else if resp.EventNotification.OldEntry != nil { // without new entry, only old entry name exists. This is the second step to delete old entry