aboutsummaryrefslogtreecommitdiff
path: root/weed
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2021-04-16 02:55:09 -0700
committerChris Lu <chris.lu@gmail.com>2021-04-18 13:06:38 -0700
commitd9a2a7f1c4593c20ec9a92b98b726af7b32baff3 (patch)
tree2ce7aa6c2c28a8af76b75e0342af8f157f0d78fb /weed
parent54410ca955cf4078684bca17b4363dc33ef433ed (diff)
downloadseaweedfs-d9a2a7f1c4593c20ec9a92b98b726af7b32baff3.tar.xz
seaweedfs-d9a2a7f1c4593c20ec9a92b98b726af7b32baff3.zip
WIP
no memory issue if some directory is removed, it may have this error $ rm -Rf ~/tmp/m2/s1 rm: fts_read: Device not configured
Diffstat (limited to 'weed')
-rw-r--r--weed/filesys/dir.go38
-rw-r--r--weed/filesys/dir_rename.go8
-rw-r--r--weed/filesys/file.go6
-rw-r--r--weed/filesys/wfs.go31
4 files changed, 35 insertions, 48 deletions
diff --git a/weed/filesys/dir.go b/weed/filesys/dir.go
index 9eba4066d..b3577dcf0 100644
--- a/weed/filesys/dir.go
+++ b/weed/filesys/dir.go
@@ -27,6 +27,7 @@ type Dir struct {
}
var _ = fs.Node(&Dir{})
+var _ = fs.NodeIdentifier(&Dir{})
var _ = fs.NodeCreater(&Dir{})
var _ = fs.NodeMknoder(&Dir{})
var _ = fs.NodeMkdirer(&Dir{})
@@ -42,6 +43,10 @@ var _ = fs.NodeRemovexattrer(&Dir{})
var _ = fs.NodeListxattrer(&Dir{})
var _ = fs.NodeForgetter(&Dir{})
+func (dir *Dir) Id() uint64 {
+ return util.FullPath(dir.FullPath()).AsInode()
+}
+
func (dir *Dir) Attr(ctx context.Context, attr *fuse.Attr) error {
// https://github.com/bazil/fuse/issues/196
@@ -105,24 +110,17 @@ func (dir *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
}
func (dir *Dir) newFile(name string) fs.Node {
- f := dir.wfs.fsNodeCache.EnsureFsNode(util.NewFullPath(dir.FullPath(), name), func() fs.Node {
- return &File{
- Name: name,
- dir: dir,
- wfs: dir.wfs,
- }
- })
- f.(*File).dir = dir // in case dir node was created later
- return f
+ return &File{
+ Name: name,
+ dir: dir,
+ wfs: dir.wfs,
+ }
}
func (dir *Dir) newDirectory(fullpath util.FullPath) fs.Node {
- d := dir.wfs.fsNodeCache.EnsureFsNode(fullpath, func() fs.Node {
- return &Dir{name: fullpath.Name(), wfs: dir.wfs, parent: dir}
- })
- d.(*Dir).parent = dir // in case dir node was created later
- return d
+ return &Dir{name: fullpath.Name(), wfs: dir.wfs, parent: dir}
+
}
func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest,
@@ -396,15 +394,6 @@ func (dir *Dir) removeOneFile(req *fuse.RemoveRequest) error {
return fuse.ESTALE
}
- // clear entry inside the file
- fsNode := dir.wfs.fsNodeCache.GetFsNode(filePath)
- dir.wfs.fsNodeCache.DeleteFsNode(filePath)
- if fsNode != nil {
- if file, ok := fsNode.(*File); ok {
- file.entry = nil
- }
- }
-
// remove current file handle if any
dir.wfs.handlesLock.Lock()
defer dir.wfs.handlesLock.Unlock()
@@ -431,7 +420,6 @@ func (dir *Dir) removeFolder(req *fuse.RemoveRequest) error {
t := util.NewFullPath(dirFullPath, req.Name)
dir.wfs.metaCache.DeleteEntry(context.Background(), t)
- dir.wfs.fsNodeCache.DeleteFsNode(t)
return nil
@@ -519,8 +507,6 @@ func (dir *Dir) Listxattr(ctx context.Context, req *fuse.ListxattrRequest, resp
func (dir *Dir) Forget() {
glog.V(4).Infof("Forget dir %s", dir.FullPath())
-
- dir.wfs.fsNodeCache.DeleteFsNode(util.FullPath(dir.FullPath()))
}
func (dir *Dir) maybeLoadEntry() (*filer_pb.Entry, error) {
diff --git a/weed/filesys/dir_rename.go b/weed/filesys/dir_rename.go
index d2acad4b2..7bc705102 100644
--- a/weed/filesys/dir_rename.go
+++ b/weed/filesys/dir_rename.go
@@ -64,19 +64,17 @@ func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirector
return fuse.EIO
}
- // fmt.Printf("rename path: %v => %v\n", oldPath, newPath)
- dir.wfs.fsNodeCache.Move(oldPath, newPath)
-
// change file handle
dir.wfs.handlesLock.Lock()
defer dir.wfs.handlesLock.Unlock()
inodeId := oldPath.AsInode()
existingHandle, found := dir.wfs.handles[inodeId]
if !found || existingHandle == nil {
- return err
+ return nil
}
+ glog.V(4).Infof("opened filehandle %s => %s", oldPath, newPath)
delete(dir.wfs.handles, inodeId)
dir.wfs.handles[newPath.AsInode()] = existingHandle
- return err
+ return nil
}
diff --git a/weed/filesys/file.go b/weed/filesys/file.go
index 2a991d7db..b3e5cc72d 100644
--- a/weed/filesys/file.go
+++ b/weed/filesys/file.go
@@ -18,6 +18,7 @@ import (
const blockSize = 512
var _ = fs.Node(&File{})
+var _ = fs.NodeIdentifier(&File{})
var _ = fs.NodeOpener(&File{})
var _ = fs.NodeFsyncer(&File{})
var _ = fs.NodeSetattrer(&File{})
@@ -40,6 +41,10 @@ func (file *File) fullpath() util.FullPath {
return util.NewFullPath(file.dir.FullPath(), file.Name)
}
+func (file *File) Id() uint64 {
+ return file.fullpath().AsInode()
+}
+
func (file *File) Attr(ctx context.Context, attr *fuse.Attr) (err error) {
glog.V(4).Infof("file Attr %s, open:%v existing:%v", file.fullpath(), file.isOpen, attr)
@@ -253,7 +258,6 @@ func (file *File) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
func (file *File) Forget() {
t := util.NewFullPath(file.dir.FullPath(), file.Name)
glog.V(4).Infof("Forget file %s", t)
- file.wfs.fsNodeCache.DeleteFsNode(t)
file.wfs.ReleaseHandle(t, 0)
}
diff --git a/weed/filesys/wfs.go b/weed/filesys/wfs.go
index 2034354f5..7019a464b 100644
--- a/weed/filesys/wfs.go
+++ b/weed/filesys/wfs.go
@@ -103,24 +103,15 @@ func NewSeaweedFileSystem(option *Option) *WFS {
}
wfs.metaCache = meta_cache.NewMetaCache(path.Join(cacheDir, "meta"), util.FullPath(option.FilerMountRootPath), option.UidGidMapper, func(filePath util.FullPath) {
- fsNode := wfs.fsNodeCache.GetFsNode(filePath)
- if fsNode != nil {
- if file, ok := fsNode.(*File); ok {
- if err := wfs.Server.InvalidateNodeData(file); err != nil {
- glog.V(4).Infof("InvalidateNodeData %s : %v", filePath, err)
- }
- file.entry = nil
- }
+ fsNode := NodeWithId(filePath.AsInode())
+ if err := wfs.Server.InvalidateNodeData(fsNode); err != nil {
+ glog.V(4).Infof("InvalidateNodeData %s : %v", filePath, err)
}
+
dir, name := filePath.DirAndName()
- parent := wfs.root
- if dir != "/" {
- parent = wfs.fsNodeCache.GetFsNode(util.FullPath(dir))
- }
- if parent != nil {
- if err := wfs.Server.InvalidateEntry(parent, name); err != nil {
- glog.V(4).Infof("InvalidateEntry %s : %v", filePath, err)
- }
+ parent := NodeWithId(util.FullPath(dir).AsInode())
+ if err := wfs.Server.InvalidateEntry(parent, name); err != nil {
+ glog.V(4).Infof("InvalidateEntry %s : %v", filePath, err)
}
})
startTime := time.Now()
@@ -267,3 +258,11 @@ func (wfs *WFS) LookupFn() wdclient.LookupFileIdFunctionType {
return filer.LookupFn(wfs)
}
+
+type NodeWithId uint64
+func (n NodeWithId) Id() uint64 {
+ return uint64(n)
+}
+func (n NodeWithId) Attr(ctx context.Context, attr *fuse.Attr) error {
+ return nil
+}