mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
mount: properly invalidate kernel node cache entry
fix https://github.com/chrislusf/seaweedfs/issues/1752
This commit is contained in:
parent
c41961d5cc
commit
3a1d3d3413
2
go.mod
2
go.mod
|
@ -56,7 +56,7 @@ require (
|
||||||
github.com/prometheus/client_golang v1.3.0
|
github.com/prometheus/client_golang v1.3.0
|
||||||
github.com/rakyll/statik v0.1.7
|
github.com/rakyll/statik v0.1.7
|
||||||
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563 // indirect
|
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563 // indirect
|
||||||
github.com/seaweedfs/fuse v1.0.9
|
github.com/seaweedfs/fuse v1.1.0
|
||||||
github.com/seaweedfs/goexif v1.0.2
|
github.com/seaweedfs/goexif v1.0.2
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -577,6 +577,8 @@ github.com/seaweedfs/fuse v1.0.8 h1:HBPJTC77OlxwSd2JiTwvLPn8bWTElqQp3xs9vf3C15s=
|
||||||
github.com/seaweedfs/fuse v1.0.8/go.mod h1:W7ubwr1l7KQsMeUpxFFOFOSxUL/ucTRMAlVYs4xdfQ8=
|
github.com/seaweedfs/fuse v1.0.8/go.mod h1:W7ubwr1l7KQsMeUpxFFOFOSxUL/ucTRMAlVYs4xdfQ8=
|
||||||
github.com/seaweedfs/fuse v1.0.9 h1:3JZoGsW7cmmrd/U5KYcIGR2+EqyBvCYCoCpEdZAz/Dc=
|
github.com/seaweedfs/fuse v1.0.9 h1:3JZoGsW7cmmrd/U5KYcIGR2+EqyBvCYCoCpEdZAz/Dc=
|
||||||
github.com/seaweedfs/fuse v1.0.9/go.mod h1:+PP6WlkrRUG6KPE+Th2EX5To/PjHaFsvqg/UgQ39aj8=
|
github.com/seaweedfs/fuse v1.0.9/go.mod h1:+PP6WlkrRUG6KPE+Th2EX5To/PjHaFsvqg/UgQ39aj8=
|
||||||
|
github.com/seaweedfs/fuse v1.1.0 h1:cL1qPHFNtFv0UuJTLjKKgWDzfJ4iZzTa4Y7ipc2acGw=
|
||||||
|
github.com/seaweedfs/fuse v1.1.0/go.mod h1:+PP6WlkrRUG6KPE+Th2EX5To/PjHaFsvqg/UgQ39aj8=
|
||||||
github.com/seaweedfs/goexif v1.0.2 h1:p+rTXYdQ2mgxd+1JaTrQ9N8DvYuw9UH9xgYmJ+Bb29E=
|
github.com/seaweedfs/goexif v1.0.2 h1:p+rTXYdQ2mgxd+1JaTrQ9N8DvYuw9UH9xgYmJ+Bb29E=
|
||||||
github.com/seaweedfs/goexif v1.0.2/go.mod h1:MrKs5LK0HXdffrdCZrW3OIMegL2xXpC6ThLyXMyjdrk=
|
github.com/seaweedfs/goexif v1.0.2/go.mod h1:MrKs5LK0HXdffrdCZrW3OIMegL2xXpC6ThLyXMyjdrk=
|
||||||
github.com/secsy/goftp v0.0.0-20190720192957-f31499d7c79a h1:C6IhVTxNkhlb0tlCB6JfHOUv1f0xHPK7V8X4HlJZEJw=
|
github.com/secsy/goftp v0.0.0-20190720192957-f31499d7c79a h1:C6IhVTxNkhlb0tlCB6JfHOUv1f0xHPK7V8X4HlJZEJw=
|
||||||
|
|
|
@ -208,7 +208,9 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
|
||||||
})
|
})
|
||||||
|
|
||||||
glog.V(0).Infof("mounted %s%s to %s", filer, mountRoot, dir)
|
glog.V(0).Infof("mounted %s%s to %s", filer, mountRoot, dir)
|
||||||
err = fs.Serve(c, seaweedFileSystem)
|
server := fs.New(c, nil)
|
||||||
|
seaweedFileSystem.Server = server
|
||||||
|
err = server.Serve(seaweedFileSystem)
|
||||||
|
|
||||||
// check if the mount process has an error to report
|
// check if the mount process has an error to report
|
||||||
<-c.Ready
|
<-c.Ready
|
||||||
|
|
|
@ -58,7 +58,7 @@ func (dir *Dir) Attr(ctx context.Context, attr *fuse.Attr) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
attr.Inode = util.FullPath(dir.FullPath()).AsInode()
|
// attr.Inode = util.FullPath(dir.FullPath()).AsInode()
|
||||||
attr.Mode = os.FileMode(dir.entry.Attributes.FileMode) | os.ModeDir
|
attr.Mode = os.FileMode(dir.entry.Attributes.FileMode) | os.ModeDir
|
||||||
attr.Mtime = time.Unix(dir.entry.Attributes.Mtime, 0)
|
attr.Mtime = time.Unix(dir.entry.Attributes.Mtime, 0)
|
||||||
attr.Crtime = time.Unix(dir.entry.Attributes.Crtime, 0)
|
attr.Crtime = time.Unix(dir.entry.Attributes.Crtime, 0)
|
||||||
|
@ -82,8 +82,8 @@ func (dir *Dir) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dir *Dir) setRootDirAttributes(attr *fuse.Attr) {
|
func (dir *Dir) setRootDirAttributes(attr *fuse.Attr) {
|
||||||
attr.Inode = 1 // filer2.FullPath(dir.Path).AsInode()
|
// attr.Inode = 1 // filer2.FullPath(dir.Path).AsInode()
|
||||||
attr.Valid = time.Hour
|
attr.Valid = time.Second
|
||||||
attr.Uid = dir.wfs.option.MountUid
|
attr.Uid = dir.wfs.option.MountUid
|
||||||
attr.Gid = dir.wfs.option.MountGid
|
attr.Gid = dir.wfs.option.MountGid
|
||||||
attr.Mode = dir.wfs.option.MountMode
|
attr.Mode = dir.wfs.option.MountMode
|
||||||
|
@ -91,7 +91,7 @@ func (dir *Dir) setRootDirAttributes(attr *fuse.Attr) {
|
||||||
attr.Ctime = dir.wfs.option.MountCtime
|
attr.Ctime = dir.wfs.option.MountCtime
|
||||||
attr.Mtime = dir.wfs.option.MountMtime
|
attr.Mtime = dir.wfs.option.MountMtime
|
||||||
attr.Atime = dir.wfs.option.MountMtime
|
attr.Atime = dir.wfs.option.MountMtime
|
||||||
attr.BlockSize = 1024 * 1024
|
attr.BlockSize = blockSize
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dir *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
|
func (dir *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
|
||||||
|
@ -285,7 +285,7 @@ func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.
|
||||||
}
|
}
|
||||||
|
|
||||||
// resp.EntryValid = time.Second
|
// resp.EntryValid = time.Second
|
||||||
resp.Attr.Inode = fullFilePath.AsInode()
|
// resp.Attr.Inode = fullFilePath.AsInode()
|
||||||
resp.Attr.Valid = time.Second
|
resp.Attr.Valid = time.Second
|
||||||
resp.Attr.Mtime = time.Unix(entry.Attributes.Mtime, 0)
|
resp.Attr.Mtime = time.Unix(entry.Attributes.Mtime, 0)
|
||||||
resp.Attr.Crtime = time.Unix(entry.Attributes.Crtime, 0)
|
resp.Attr.Crtime = time.Unix(entry.Attributes.Crtime, 0)
|
||||||
|
@ -308,13 +308,11 @@ func (dir *Dir) ReadDirAll(ctx context.Context) (ret []fuse.Dirent, err error) {
|
||||||
glog.V(4).Infof("dir ReadDirAll %s", dir.FullPath())
|
glog.V(4).Infof("dir ReadDirAll %s", dir.FullPath())
|
||||||
|
|
||||||
processEachEntryFn := func(entry *filer_pb.Entry, isLast bool) error {
|
processEachEntryFn := func(entry *filer_pb.Entry, isLast bool) error {
|
||||||
fullpath := util.NewFullPath(dir.FullPath(), entry.Name)
|
|
||||||
inode := fullpath.AsInode()
|
|
||||||
if entry.IsDirectory {
|
if entry.IsDirectory {
|
||||||
dirent := fuse.Dirent{Inode: inode, Name: entry.Name, Type: fuse.DT_Dir}
|
dirent := fuse.Dirent{Name: entry.Name, Type: fuse.DT_Dir}
|
||||||
ret = append(ret, dirent)
|
ret = append(ret, dirent)
|
||||||
} else {
|
} else {
|
||||||
dirent := fuse.Dirent{Inode: inode, Name: entry.Name, Type: findFileType(uint16(entry.Attributes.FileMode))}
|
dirent := fuse.Dirent{Name: entry.Name, Type: findFileType(uint16(entry.Attributes.FileMode))}
|
||||||
ret = append(ret, dirent)
|
ret = append(ret, dirent)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (file *File) fullpath() util.FullPath {
|
||||||
|
|
||||||
func (file *File) Attr(ctx context.Context, attr *fuse.Attr) (err error) {
|
func (file *File) Attr(ctx context.Context, attr *fuse.Attr) (err error) {
|
||||||
|
|
||||||
glog.V(4).Infof("file Attr %s, open:%v, existing attr: %+v", file.fullpath(), file.isOpen, attr)
|
glog.V(4).Infof("file Attr %s, open:%v existing:%v", file.fullpath(), file.isOpen, attr)
|
||||||
|
|
||||||
entry := file.entry
|
entry := file.entry
|
||||||
if file.isOpen <= 0 || entry == nil {
|
if file.isOpen <= 0 || entry == nil {
|
||||||
|
@ -54,7 +54,7 @@ func (file *File) Attr(ctx context.Context, attr *fuse.Attr) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
attr.Inode = file.fullpath().AsInode()
|
// attr.Inode = file.fullpath().AsInode()
|
||||||
attr.Valid = time.Second
|
attr.Valid = time.Second
|
||||||
attr.Mode = os.FileMode(entry.Attributes.FileMode)
|
attr.Mode = os.FileMode(entry.Attributes.FileMode)
|
||||||
attr.Size = filer.FileSize(entry)
|
attr.Size = filer.FileSize(entry)
|
||||||
|
@ -91,9 +91,6 @@ func (file *File) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp
|
||||||
func (file *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) {
|
func (file *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) {
|
||||||
|
|
||||||
glog.V(4).Infof("file %v open %+v", file.fullpath(), req)
|
glog.V(4).Infof("file %v open %+v", file.fullpath(), req)
|
||||||
if USE_DIRECT_IO {
|
|
||||||
resp.Flags |= fuse.OpenDirectIO
|
|
||||||
}
|
|
||||||
|
|
||||||
handle := file.wfs.AcquireHandle(file, req.Uid, req.Gid)
|
handle := file.wfs.AcquireHandle(file, req.Uid, req.Gid)
|
||||||
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
//+build darwin
|
|
||||||
|
|
||||||
package filesys
|
|
||||||
|
|
||||||
const (
|
|
||||||
USE_DIRECT_IO = false
|
|
||||||
)
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
//+build !darwin
|
|
||||||
|
|
||||||
package filesys
|
|
||||||
|
|
||||||
const (
|
|
||||||
USE_DIRECT_IO = true
|
|
||||||
)
|
|
|
@ -76,6 +76,7 @@ type WFS struct {
|
||||||
|
|
||||||
// throttle writers
|
// throttle writers
|
||||||
concurrentWriters *util.LimitedConcurrentExecutor
|
concurrentWriters *util.LimitedConcurrentExecutor
|
||||||
|
Server *fs.Server
|
||||||
}
|
}
|
||||||
type statsCache struct {
|
type statsCache struct {
|
||||||
filer_pb.StatisticsResponse
|
filer_pb.StatisticsResponse
|
||||||
|
@ -104,9 +105,22 @@ func NewSeaweedFileSystem(option *Option) *WFS {
|
||||||
fsNode := wfs.fsNodeCache.GetFsNode(filePath)
|
fsNode := wfs.fsNodeCache.GetFsNode(filePath)
|
||||||
if fsNode != nil {
|
if fsNode != nil {
|
||||||
if file, ok := fsNode.(*File); ok {
|
if file, ok := fsNode.(*File); ok {
|
||||||
|
if err := wfs.Server.InvalidateNodeData(file); err != nil {
|
||||||
|
glog.V(4).Infof("InvalidateNodeData %s : %v", filePath, err)
|
||||||
|
}
|
||||||
file.clearEntry()
|
file.clearEntry()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
go meta_cache.SubscribeMetaEvents(wfs.metaCache, wfs.signature, wfs, wfs.option.FilerMountRootPath, startTime.UnixNano())
|
go meta_cache.SubscribeMetaEvents(wfs.metaCache, wfs.signature, wfs, wfs.option.FilerMountRootPath, startTime.UnixNano())
|
||||||
|
|
Loading…
Reference in a new issue