diff --git a/weed/mount/filehandle.go b/weed/mount/filehandle.go index 2e08432c0..f47d4a877 100644 --- a/weed/mount/filehandle.go +++ b/weed/mount/filehandle.go @@ -66,8 +66,8 @@ func (fh *FileHandle) FullPath() util.FullPath { return fp } -func (fh *FileHandle) GetEntry() *filer_pb.Entry { - return fh.entry.GetEntry() +func (fh *FileHandle) GetEntry() *LockedEntry { + return fh.entry } func (fh *FileHandle) SetEntry(entry *filer_pb.Entry) { @@ -90,13 +90,6 @@ func (fh *FileHandle) UpdateEntry(fn func(entry *filer_pb.Entry)) *filer_pb.Entr } func (fh *FileHandle) AddChunks(chunks []*filer_pb.FileChunk) { - fh.entryLock.Lock() - defer fh.entryLock.Unlock() - - if fh.entry == nil { - return - } - fh.entry.AppendChunks(chunks) } @@ -105,9 +98,6 @@ func (fh *FileHandle) ReleaseHandle() { fhActiveLock := fh.wfs.fhLockTable.AcquireLock("ReleaseHandle", fh.fh, util.ExclusiveLock) defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock) - fh.entryLock.Lock() - defer fh.entryLock.Unlock() - fh.dirtyPages.Destroy() if IsDebugFileReadWrite { fh.mirrorFile.Close() diff --git a/weed/mount/filehandle_map.go b/weed/mount/filehandle_map.go index f0051f061..bb78d0b14 100644 --- a/weed/mount/filehandle_map.go +++ b/weed/mount/filehandle_map.go @@ -50,7 +50,7 @@ func (i *FileHandleToInode) AcquireFileHandle(wfs *WFS, inode uint64, entry *fil } else { fh.counter++ } - if fh.GetEntry() != entry { + if fh.GetEntry().GetEntry() != entry { fh.SetEntry(entry) } return fh diff --git a/weed/mount/filehandle_read.go b/weed/mount/filehandle_read.go index 7b2629c13..3c315b1c4 100644 --- a/weed/mount/filehandle_read.go +++ b/weed/mount/filehandle_read.go @@ -29,23 +29,19 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, int64, e fileFullPath := fh.FullPath() entry := fh.GetEntry() - if entry == nil { - return 0, 0, io.EOF - } if entry.IsInRemoteOnly() { glog.V(4).Infof("download remote entry %s", fileFullPath) - newEntry, err := fh.downloadRemoteEntry(entry) + err := fh.downloadRemoteEntry(entry) if err != nil { glog.V(1).Infof("download remote entry %s: %v", fileFullPath, err) return 0, 0, err } - entry = newEntry } fileSize := int64(entry.Attributes.FileSize) if fileSize == 0 { - fileSize = int64(filer.FileSize(entry)) + fileSize = int64(filer.FileSize(entry.GetEntry())) } if fileSize == 0 { @@ -70,7 +66,7 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, int64, e return int64(totalRead), ts, err } -func (fh *FileHandle) downloadRemoteEntry(entry *filer_pb.Entry) (*filer_pb.Entry, error) { +func (fh *FileHandle) downloadRemoteEntry(entry *LockedEntry) (error) { fileFullPath := fh.FullPath() dir, _ := fileFullPath.DirAndName() @@ -88,12 +84,12 @@ func (fh *FileHandle) downloadRemoteEntry(entry *filer_pb.Entry) (*filer_pb.Entr return fmt.Errorf("CacheRemoteObjectToLocalCluster file %s: %v", fileFullPath, err) } - entry = resp.Entry + entry.SetEntry(resp.Entry) fh.wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(request.Directory, resp.Entry)) return nil }) - return entry, err + return err } diff --git a/weed/mount/locked_entry.go b/weed/mount/locked_entry.go index f3b4bf484..c5fbaee91 100644 --- a/weed/mount/locked_entry.go +++ b/weed/mount/locked_entry.go @@ -16,6 +16,8 @@ func (le *LockedEntry) GetEntry() *filer_pb.Entry { return le.Entry } +// SetEntry sets the entry of the LockedEntry +// entry should never be nil func (le *LockedEntry) SetEntry(entry *filer_pb.Entry) { le.Lock() defer le.Unlock() diff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.go index c5a1d2755..a9fbd9380 100644 --- a/weed/mount/weedfs.go +++ b/weed/mount/weedfs.go @@ -112,9 +112,6 @@ func NewSeaweedFileSystem(option *Option) *WFS { fhActiveLock := fh.wfs.fhLockTable.AcquireLock("invalidateFunc", fh.fh, util.ExclusiveLock) defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock) - fh.entryLock.Lock() - defer fh.entryLock.Unlock() - // Recreate dirty pages fh.dirtyPages.Destroy() fh.dirtyPages = newPageWriter(fh, wfs.option.ChunkSizeLimit) @@ -122,7 +119,7 @@ func NewSeaweedFileSystem(option *Option) *WFS { // Update handle entry newentry, status := wfs.maybeLoadEntry(filePath) if status == fuse.OK { - if fh.GetEntry() != newentry { + if fh.GetEntry().GetEntry() != newentry { fh.SetEntry(newentry) } } diff --git a/weed/mount/weedfs_dir_lookup.go b/weed/mount/weedfs_dir_lookup.go index e646b06a9..f3ba0cc85 100644 --- a/weed/mount/weedfs_dir_lookup.go +++ b/weed/mount/weedfs_dir_lookup.go @@ -59,7 +59,7 @@ func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name strin if fh, found := wfs.fhmap.FindFileHandle(inode); found { fh.entryLock.RLock() - if entry := fh.GetEntry(); entry != nil { + if entry := fh.GetEntry().GetEntry(); entry != nil { glog.V(4).Infof("lookup opened file %s size %d", dirPath.Child(localEntry.Name()), filer.FileSize(entry)) localEntry = filer.FromPbEntry(string(dirPath), entry) } diff --git a/weed/mount/weedfs_dir_read.go b/weed/mount/weedfs_dir_read.go index f140fd86f..02ed72431 100644 --- a/weed/mount/weedfs_dir_read.go +++ b/weed/mount/weedfs_dir_read.go @@ -173,7 +173,7 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPl } if fh, found := wfs.fhmap.FindFileHandle(inode); found { glog.V(4).Infof("readdir opened file %s", dirPath.Child(dirEntry.Name)) - entry = filer.FromPbEntry(string(dirPath), fh.GetEntry()) + entry = filer.FromPbEntry(string(dirPath), fh.GetEntry().GetEntry()) } wfs.outputFilerEntry(entryOut, inode, entry) } diff --git a/weed/mount/weedfs_file_lseek.go b/weed/mount/weedfs_file_lseek.go index 35157d993..0cf7ef43b 100644 --- a/weed/mount/weedfs_file_lseek.go +++ b/weed/mount/weedfs_file_lseek.go @@ -38,10 +38,8 @@ func (wfs *WFS) Lseek(cancel <-chan struct{}, in *fuse.LseekIn, out *fuse.LseekO // lock the file until the proper offset was calculated fhActiveLock := fh.wfs.fhLockTable.AcquireLock("Lseek", fh.fh, util.SharedLock) defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock) - fh.entryLock.RLock() - defer fh.entryLock.RUnlock() - fileSize := int64(filer.FileSize(fh.GetEntry())) + fileSize := int64(filer.FileSize(fh.GetEntry().GetEntry())) offset := max(int64(in.Offset), 0) glog.V(4).Infof( diff --git a/weed/mount/weedfs_file_sync.go b/weed/mount/weedfs_file_sync.go index 762a9b8de..d857606bd 100644 --- a/weed/mount/weedfs_file_sync.go +++ b/weed/mount/weedfs_file_sync.go @@ -116,13 +116,8 @@ func (wfs *WFS) doFlush(fh *FileHandle, uid, gid uint32) fuse.Status { defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock) err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error { - fh.entryLock.Lock() - defer fh.entryLock.Unlock() entry := fh.GetEntry() - if entry == nil { - return nil - } entry.Name = name // this flush may be just after a rename operation if entry.Attributes != nil { @@ -141,7 +136,7 @@ func (wfs *WFS) doFlush(fh *FileHandle, uid, gid uint32) fuse.Status { request := &filer_pb.CreateEntryRequest{ Directory: string(dir), - Entry: entry, + Entry: entry.GetEntry(), Signatures: []int32{wfs.signature}, SkipCheckParentDirectory: true, }