mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-27 12:49:41 +08:00
refactor
This commit is contained in:
parent
6063a889ed
commit
a9c9e1bcb3
@ -2,6 +2,7 @@ package mount
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
@ -76,8 +77,8 @@ type WFS struct {
|
||||
signature int32
|
||||
concurrentWriters *util.LimitedConcurrentExecutor
|
||||
inodeToPath *InodeToPath
|
||||
fhmap *FileHandleToInode
|
||||
dhmap *DirectoryHandleToInode
|
||||
fhMap *FileHandleToInode
|
||||
dhMap *DirectoryHandleToInode
|
||||
fuseServer *fuse.Server
|
||||
IsOverQuota bool
|
||||
fhLockTable *util.LockTable[FileHandleId]
|
||||
@ -89,8 +90,8 @@ func NewSeaweedFileSystem(option *Option) *WFS {
|
||||
option: option,
|
||||
signature: util.RandomInt32(),
|
||||
inodeToPath: NewInodeToPath(util.FullPath(option.FilerMountRootPath)),
|
||||
fhmap: NewFileHandleToInode(),
|
||||
dhmap: NewDirectoryHandleToInode(),
|
||||
fhMap: NewFileHandleToInode(),
|
||||
dhMap: NewDirectoryHandleToInode(),
|
||||
fhLockTable: util.NewLockTable[FileHandleId](),
|
||||
}
|
||||
|
||||
@ -108,9 +109,9 @@ func NewSeaweedFileSystem(option *Option) *WFS {
|
||||
return wfs.inodeToPath.IsChildrenCached(path)
|
||||
}, func(filePath util.FullPath, entry *filer_pb.Entry) {
|
||||
// Find inode if it is not a deleted path
|
||||
if inode, inode_found := wfs.inodeToPath.GetInode(filePath); inode_found {
|
||||
if inode, inodeFound := wfs.inodeToPath.GetInode(filePath); inodeFound {
|
||||
// Find open file handle
|
||||
if fh, fh_found := wfs.fhmap.FindFileHandle(inode); fh_found {
|
||||
if fh, fhFound := wfs.fhMap.FindFileHandle(inode); fhFound {
|
||||
fhActiveLock := fh.wfs.fhLockTable.AcquireLock("invalidateFunc", fh.fh, util.ExclusiveLock)
|
||||
defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock)
|
||||
|
||||
@ -119,10 +120,10 @@ func NewSeaweedFileSystem(option *Option) *WFS {
|
||||
fh.dirtyPages = newPageWriter(fh, wfs.option.ChunkSizeLimit)
|
||||
|
||||
// Update handle entry
|
||||
newentry, status := wfs.maybeLoadEntry(filePath)
|
||||
newEntry, status := wfs.maybeLoadEntry(filePath)
|
||||
if status == fuse.OK {
|
||||
if fh.GetEntry().GetEntry() != newentry {
|
||||
fh.SetEntry(newentry)
|
||||
if fh.GetEntry().GetEntry() != newEntry {
|
||||
fh.SetEntry(newEntry)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -160,7 +161,7 @@ func (wfs *WFS) maybeReadEntry(inode uint64) (path util.FullPath, fh *FileHandle
|
||||
return
|
||||
}
|
||||
var found bool
|
||||
if fh, found = wfs.fhmap.FindFileHandle(inode); found {
|
||||
if fh, found = wfs.fhMap.FindFileHandle(inode); found {
|
||||
entry = fh.UpdateEntry(func(entry *filer_pb.Entry) {
|
||||
if entry != nil && fh.entry.Attributes == nil {
|
||||
entry.Attributes = &filer_pb.FuseAttributes{}
|
||||
@ -195,7 +196,7 @@ func (wfs *WFS) maybeLoadEntry(fullpath util.FullPath) (*filer_pb.Entry, fuse.St
|
||||
// read from async meta cache
|
||||
meta_cache.EnsureVisited(wfs.metaCache, wfs, util.FullPath(dir))
|
||||
cachedEntry, cacheErr := wfs.metaCache.FindEntry(context.Background(), fullpath)
|
||||
if cacheErr == filer_pb.ErrNotFound {
|
||||
if errors.Is(cacheErr, filer_pb.ErrNotFound) {
|
||||
return nil, fuse.ENOENT
|
||||
}
|
||||
return cachedEntry.ToProtoEntry(), fuse.OK
|
||||
|
@ -23,7 +23,7 @@ func (wfs *WFS) GetAttr(cancel <-chan struct{}, input *fuse.GetAttrIn, out *fuse
|
||||
wfs.setAttrByPbEntry(&out.Attr, inode, entry, true)
|
||||
return status
|
||||
} else {
|
||||
if fh, found := wfs.fhmap.FindFileHandle(inode); found {
|
||||
if fh, found := wfs.fhMap.FindFileHandle(inode); found {
|
||||
out.AttrValid = 1
|
||||
wfs.setAttrByPbEntry(&out.Attr, inode, fh.entry.GetEntry(), true)
|
||||
out.Nlink = 0
|
||||
|
@ -57,7 +57,7 @@ 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 {
|
||||
if fh, found := wfs.fhMap.FindFileHandle(inode); found {
|
||||
fh.entryLock.RLock()
|
||||
if entry := fh.GetEntry().GetEntry(); entry != nil {
|
||||
glog.V(4).Infof("lookup opened file %s size %d", dirPath.Child(localEntry.Name()), filer.FileSize(entry))
|
||||
|
@ -46,30 +46,30 @@ func NewDirectoryHandleToInode() *DirectoryHandleToInode {
|
||||
func (wfs *WFS) AcquireDirectoryHandle() (DirectoryHandleId, *DirectoryHandle) {
|
||||
fh := FileHandleId(util.RandomUint64())
|
||||
|
||||
wfs.dhmap.Lock()
|
||||
defer wfs.dhmap.Unlock()
|
||||
wfs.dhMap.Lock()
|
||||
defer wfs.dhMap.Unlock()
|
||||
dh := new(DirectoryHandle)
|
||||
dh.reset()
|
||||
wfs.dhmap.dir2inode[DirectoryHandleId(fh)] = dh
|
||||
wfs.dhMap.dir2inode[DirectoryHandleId(fh)] = dh
|
||||
return DirectoryHandleId(fh), dh
|
||||
}
|
||||
|
||||
func (wfs *WFS) GetDirectoryHandle(dhid DirectoryHandleId) *DirectoryHandle {
|
||||
wfs.dhmap.Lock()
|
||||
defer wfs.dhmap.Unlock()
|
||||
if dh, found := wfs.dhmap.dir2inode[dhid]; found {
|
||||
wfs.dhMap.Lock()
|
||||
defer wfs.dhMap.Unlock()
|
||||
if dh, found := wfs.dhMap.dir2inode[dhid]; found {
|
||||
return dh
|
||||
}
|
||||
dh := new(DirectoryHandle)
|
||||
dh.reset()
|
||||
wfs.dhmap.dir2inode[dhid] = dh
|
||||
wfs.dhMap.dir2inode[dhid] = dh
|
||||
return dh
|
||||
}
|
||||
|
||||
func (wfs *WFS) ReleaseDirectoryHandle(dhid DirectoryHandleId) {
|
||||
wfs.dhmap.Lock()
|
||||
defer wfs.dhmap.Unlock()
|
||||
delete(wfs.dhmap.dir2inode, dhid)
|
||||
wfs.dhMap.Lock()
|
||||
defer wfs.dhMap.Unlock()
|
||||
delete(wfs.dhMap.dir2inode, dhid)
|
||||
}
|
||||
|
||||
// Directory handling
|
||||
@ -169,7 +169,7 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPl
|
||||
isEarlyTerminated = true
|
||||
return false
|
||||
}
|
||||
if fh, found := wfs.fhmap.FindFileHandle(inode); found {
|
||||
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().GetEntry())
|
||||
}
|
||||
|
@ -18,15 +18,15 @@ func (wfs *WFS) AcquireHandle(inode uint64, flags, uid, gid uint32) (fileHandle
|
||||
}
|
||||
}
|
||||
// need to AcquireFileHandle again to ensure correct handle counter
|
||||
fileHandle = wfs.fhmap.AcquireFileHandle(wfs, inode, entry)
|
||||
fileHandle = wfs.fhMap.AcquireFileHandle(wfs, inode, entry)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (wfs *WFS) ReleaseHandle(handleId FileHandleId) {
|
||||
wfs.fhmap.ReleaseByHandle(handleId)
|
||||
wfs.fhMap.ReleaseByHandle(handleId)
|
||||
}
|
||||
|
||||
func (wfs *WFS) GetHandle(handleId FileHandleId) *FileHandle {
|
||||
return wfs.fhmap.GetFileHandle(handleId)
|
||||
return wfs.fhMap.GetFileHandle(handleId)
|
||||
}
|
||||
|
@ -65,5 +65,5 @@ func (wfs *WFS) Forget(nodeid, nlookup uint64) {
|
||||
wfs.inodeToPath.Forget(nodeid, nlookup, func(dir util.FullPath) {
|
||||
wfs.metaCache.DeleteFolderChildren(context.Background(), dir)
|
||||
})
|
||||
wfs.fhmap.ReleaseByInode(nodeid)
|
||||
wfs.fhMap.ReleaseByInode(nodeid)
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ func (wfs *WFS) handleRenameResponse(ctx context.Context, resp *filer_pb.StreamR
|
||||
|
||||
sourceInode, targetInode := wfs.inodeToPath.MovePath(oldPath, newPath)
|
||||
if sourceInode != 0 {
|
||||
fh, foundFh := wfs.fhmap.FindFileHandle(sourceInode)
|
||||
fh, foundFh := wfs.fhMap.FindFileHandle(sourceInode)
|
||||
if foundFh {
|
||||
if entry := fh.GetEntry(); entry != nil {
|
||||
entry.Name = newName
|
||||
|
Loading…
Reference in New Issue
Block a user