aboutsummaryrefslogtreecommitdiff
path: root/weed/mount
diff options
context:
space:
mode:
Diffstat (limited to 'weed/mount')
-rw-r--r--weed/mount/filehandle.go14
-rw-r--r--weed/mount/filehandle_map.go7
-rw-r--r--weed/mount/weedfs.go9
-rw-r--r--weed/mount/weedfs_dir_lookup.go12
4 files changed, 31 insertions, 11 deletions
diff --git a/weed/mount/filehandle.go b/weed/mount/filehandle.go
index 8175c61f4..4595764ee 100644
--- a/weed/mount/filehandle.go
+++ b/weed/mount/filehandle.go
@@ -1,12 +1,14 @@
package mount
import (
+ "sync"
+
+ "golang.org/x/exp/slices"
+
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/util"
- "golang.org/x/exp/slices"
- "sync"
)
type FileHandleId uint64
@@ -57,12 +59,20 @@ func (fh *FileHandle) GetEntry() *filer_pb.Entry {
defer fh.entryLock.Unlock()
return fh.entry
}
+
func (fh *FileHandle) SetEntry(entry *filer_pb.Entry) {
fh.entryLock.Lock()
defer fh.entryLock.Unlock()
fh.entry = entry
}
+func (fh *FileHandle) UpdateEntry(fn func(entry *filer_pb.Entry)) *filer_pb.Entry {
+ fh.entryLock.Lock()
+ defer fh.entryLock.Unlock()
+ fn(fh.entry)
+ return fh.entry
+}
+
func (fh *FileHandle) AddChunks(chunks []*filer_pb.FileChunk) {
fh.entryLock.Lock()
defer fh.entryLock.Unlock()
diff --git a/weed/mount/filehandle_map.go b/weed/mount/filehandle_map.go
index a5e1016ca..4cf674166 100644
--- a/weed/mount/filehandle_map.go
+++ b/weed/mount/filehandle_map.go
@@ -1,8 +1,9 @@
package mount
import (
- "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"sync"
+
+ "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
)
type FileHandleToInode struct {
@@ -49,7 +50,9 @@ func (i *FileHandleToInode) AcquireFileHandle(wfs *WFS, inode uint64, entry *fil
} else {
fh.counter++
}
- fh.entry = entry
+ if fh.entry != entry {
+ fh.SetEntry(entry)
+ }
return fh
}
diff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.go
index 9f1d85ab5..7cff71c52 100644
--- a/weed/mount/weedfs.go
+++ b/weed/mount/weedfs.go
@@ -135,10 +135,11 @@ func (wfs *WFS) maybeReadEntry(inode uint64) (path util.FullPath, fh *FileHandle
}
var found bool
if fh, found = wfs.fhmap.FindFileHandle(inode); found {
- entry = fh.GetEntry()
- if entry != nil && fh.entry.Attributes == nil {
- entry.Attributes = &filer_pb.FuseAttributes{}
- }
+ entry = fh.UpdateEntry(func(entry *filer_pb.Entry) {
+ if entry != nil && fh.entry.Attributes == nil {
+ entry.Attributes = &filer_pb.FuseAttributes{}
+ }
+ })
} else {
entry, status = wfs.maybeLoadEntry(path)
}
diff --git a/weed/mount/weedfs_dir_lookup.go b/weed/mount/weedfs_dir_lookup.go
index 7a9b7fecc..49e4b1b56 100644
--- a/weed/mount/weedfs_dir_lookup.go
+++ b/weed/mount/weedfs_dir_lookup.go
@@ -2,7 +2,9 @@ package mount
import (
"context"
+
"github.com/hanwen/go-fuse/v2/fuse"
+
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/mount/meta_cache"
@@ -55,9 +57,13 @@ func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name strin
inode := wfs.inodeToPath.Lookup(fullFilePath, localEntry.Crtime.Unix(), localEntry.IsDirectory(), len(localEntry.HardLinkId) > 0, localEntry.Inode, true)
- if fh, found := wfs.fhmap.FindFileHandle(inode); found && fh.entry != nil {
- glog.V(4).Infof("lookup opened file %s size %d", dirPath.Child(localEntry.Name()), filer.FileSize(fh.entry))
- localEntry = filer.FromPbEntry(string(dirPath), fh.entry)
+ if fh, found := wfs.fhmap.FindFileHandle(inode); found {
+ fh.entryLock.Lock()
+ if fh.entry != nil {
+ glog.V(4).Infof("lookup opened file %s size %d", dirPath.Child(localEntry.Name()), filer.FileSize(fh.entry))
+ localEntry = filer.FromPbEntry(string(dirPath), fh.entry)
+ }
+ fh.entryLock.Unlock()
}
wfs.outputFilerEntry(out, inode, localEntry)