From 3a86d4dbfded2fb34f0d9cb696a6c5ba9415be4f Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 30 Apr 2021 22:51:06 -0700 Subject: [PATCH] mount: fix directory invalidation fix https://github.com/chrislusf/seaweedfs/issues/2038 --- weed/filesys/dir.go | 12 ++++++++---- weed/filesys/meta_cache/meta_cache.go | 4 ---- weed/filesys/wfs.go | 5 ++++- weed/util/bounded_tree/bounded_tree.go | 3 --- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/weed/filesys/dir.go b/weed/filesys/dir.go index 6ee20974b..79fc10442 100644 --- a/weed/filesys/dir.go +++ b/weed/filesys/dir.go @@ -29,7 +29,7 @@ type Dir struct { var _ = fs.Node(&Dir{}) -//var _ = fs.NodeIdentifier(&Dir{}) +var _ = fs.NodeIdentifier(&Dir{}) var _ = fs.NodeCreater(&Dir{}) var _ = fs.NodeMknoder(&Dir{}) var _ = fs.NodeMkdirer(&Dir{}) @@ -45,7 +45,10 @@ var _ = fs.NodeRemovexattrer(&Dir{}) var _ = fs.NodeListxattrer(&Dir{}) var _ = fs.NodeForgetter(&Dir{}) -func (dir *Dir) xId() uint64 { +func (dir *Dir) Id() uint64 { + if dir.parent == nil { + return 1 + } return dir.id } @@ -66,7 +69,7 @@ func (dir *Dir) Attr(ctx context.Context, attr *fuse.Attr) error { return err } - // attr.Inode = dir.Id() + attr.Inode = dir.Id() attr.Mode = os.FileMode(entry.Attributes.FileMode) | os.ModeDir attr.Mtime = time.Unix(entry.Attributes.Mtime, 0) attr.Crtime = time.Unix(entry.Attributes.Crtime, 0) @@ -93,7 +96,7 @@ func (dir *Dir) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *f func (dir *Dir) setRootDirAttributes(attr *fuse.Attr) { // attr.Inode = 1 // filer2.FullPath(dir.Path).AsInode() attr.Valid = time.Second - attr.Inode = 1 // dir.Id() + attr.Inode = dir.Id() attr.Uid = dir.wfs.option.MountUid attr.Gid = dir.wfs.option.MountGid attr.Mode = dir.wfs.option.MountMode @@ -328,6 +331,7 @@ func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse. // resp.EntryValid = time.Second resp.Attr.Inode = fullFilePath.AsInode() resp.Attr.Valid = time.Second + resp.Attr.Size = localEntry.FileSize resp.Attr.Mtime = localEntry.Attr.Mtime resp.Attr.Crtime = localEntry.Attr.Crtime resp.Attr.Mode = localEntry.Attr.Mode diff --git a/weed/filesys/meta_cache/meta_cache.go b/weed/filesys/meta_cache/meta_cache.go index b9d4724c9..3a64df018 100644 --- a/weed/filesys/meta_cache/meta_cache.go +++ b/weed/filesys/meta_cache/meta_cache.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "os" - "strings" "sync" "github.com/chrislusf/seaweedfs/weed/filer" @@ -31,9 +30,6 @@ func NewMetaCache(dbFolder string, baseDir util.FullPath, uidGidMapper *UidGidMa visitedBoundary: bounded_tree.NewBoundedTree(baseDir), uidGidMapper: uidGidMapper, invalidateFunc: func(fullpath util.FullPath) { - if baseDir != "/" && strings.HasPrefix(string(fullpath), string(baseDir)) { - fullpath = fullpath[len(baseDir):] - } invalidateFunc(fullpath) }, } diff --git a/weed/filesys/wfs.go b/weed/filesys/wfs.go index 42816d23d..832925bc1 100644 --- a/weed/filesys/wfs.go +++ b/weed/filesys/wfs.go @@ -111,6 +111,9 @@ func NewSeaweedFileSystem(option *Option) *WFS { dir, name := filePath.DirAndName() parent := NodeWithId(util.FullPath(dir).AsInode()) + if dir == option.FilerMountRootPath { + parent = NodeWithId(1) + } if err := wfs.Server.InvalidateEntry(parent, name); err != nil { glog.V(4).Infof("InvalidateEntry %s : %v", filePath, err) } @@ -121,7 +124,7 @@ func NewSeaweedFileSystem(option *Option) *WFS { wfs.metaCache.Shutdown() }) - wfs.root = &Dir{name: wfs.option.FilerMountRootPath, wfs: wfs} + wfs.root = &Dir{name: wfs.option.FilerMountRootPath, wfs: wfs, id: 1} wfs.fsNodeCache = newFsCache(wfs.root) if wfs.option.ConcurrentWriters > 0 { diff --git a/weed/util/bounded_tree/bounded_tree.go b/weed/util/bounded_tree/bounded_tree.go index 3a8a22a9c..137f690b8 100644 --- a/weed/util/bounded_tree/bounded_tree.go +++ b/weed/util/bounded_tree/bounded_tree.go @@ -41,9 +41,6 @@ func (t *BoundedTree) EnsureVisited(p util.FullPath, visitFn VisitNodeFunc) (vis if t.root == nil { return } - if t.baseDir != "/" { - p = p[len(t.baseDir):] - } components := p.Split() // fmt.Printf("components %v %d\n", components, len(components)) canDelete, err := t.ensureVisited(t.root, t.baseDir, components, 0, visitFn)