aboutsummaryrefslogtreecommitdiff
path: root/weed/mount/filehandle_map.go
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-02-13 22:50:44 -0800
committerchrislu <chris.lu@gmail.com>2022-02-13 22:50:44 -0800
commit2b955c171345334a4034888c69547662150ceb91 (patch)
treed2e037582cfc99303b305b81b56b095ada4c9f87 /weed/mount/filehandle_map.go
parentf3c1e0052127a165955013cf7ba6483dcbda3391 (diff)
downloadseaweedfs-2b955c171345334a4034888c69547662150ceb91.tar.xz
seaweedfs-2b955c171345334a4034888c69547662150ceb91.zip
support read
Diffstat (limited to 'weed/mount/filehandle_map.go')
-rw-r--r--weed/mount/filehandle_map.go26
1 files changed, 12 insertions, 14 deletions
diff --git a/weed/mount/filehandle_map.go b/weed/mount/filehandle_map.go
index ca010dabb..50ca6bcea 100644
--- a/weed/mount/filehandle_map.go
+++ b/weed/mount/filehandle_map.go
@@ -5,20 +5,12 @@ import (
"sync"
)
-type FileHandleId uint64
-
type FileHandleToInode struct {
sync.RWMutex
nextFh FileHandleId
inode2fh map[uint64]*FileHandle
fh2inode map[FileHandleId]uint64
}
-type FileHandle struct {
- fh FileHandleId
- counter int64
- entry *filer_pb.Entry
- inode uint64
-}
func NewFileHandleToInode() *FileHandleToInode {
return &FileHandleToInode{
@@ -28,16 +20,22 @@ func NewFileHandleToInode() *FileHandleToInode {
}
}
-func (i *FileHandleToInode) GetFileHandle(inode uint64) *FileHandle {
+func (i *FileHandleToInode) GetFileHandle(fh FileHandleId) *FileHandle {
+ i.RLock()
+ defer i.RUnlock()
+ inode, found := i.fh2inode[fh]
+ if found {
+ return i.inode2fh[inode]
+ }
+ return nil
+}
+
+func (i *FileHandleToInode) AcquireFileHandle(wfs *WFS, inode uint64, entry *filer_pb.Entry) *FileHandle {
i.Lock()
defer i.Unlock()
fh, found := i.inode2fh[inode]
if !found {
- fh = &FileHandle{
- fh: i.nextFh,
- counter: 1,
- inode: inode,
- }
+ fh = newFileHandle(wfs, i.nextFh, inode, entry)
i.nextFh++
i.inode2fh[inode] = fh
i.fh2inode[fh.fh] = inode