Browse Source

Merge pull request #2252 from combineads/sync_isOpen

Synchronize number of open files
pull/2274/head
Chris Lu 3 years ago
committed by GitHub
parent
commit
a51447ffcb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      weed/filesys/filehandle.go
  2. 9
      weed/filesys/wfs.go

2
weed/filesys/filehandle.go

@ -210,7 +210,9 @@ func (fh *FileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) err
fh.Lock()
defer fh.Unlock()
fh.f.wfs.handlesLock.Lock()
fh.f.isOpen--
fh.f.wfs.handlesLock.Unlock()
if fh.f.isOpen <= 0 {
fh.f.entry = nil

9
weed/filesys/wfs.go

@ -157,20 +157,21 @@ func (wfs *WFS) AcquireHandle(file *File, uid, gid uint32, writeOnly bool) (file
wfs.handlesLock.Lock()
existingHandle, found := wfs.handles[inodeId]
wfs.handlesLock.Unlock()
if found && existingHandle != nil {
if found && existingHandle != nil && existingHandle.f.isOpen > 0 {
existingHandle.f.isOpen++
wfs.handlesLock.Unlock()
existingHandle.dirtyPages.SetWriteOnly(writeOnly)
glog.V(4).Infof("Acquired Handle %s open %d", fullpath, existingHandle.f.isOpen)
glog.V(4).Infof("Reuse AcquiredHandle %s open %d", fullpath, existingHandle.f.isOpen)
return existingHandle
}
wfs.handlesLock.Unlock()
entry, _ := file.maybeLoadEntry(context.Background())
file.entry = entry
fileHandle = newFileHandle(file, uid, gid, writeOnly)
file.isOpen++
wfs.handlesLock.Lock()
file.isOpen++
wfs.handles[inodeId] = fileHandle
wfs.handlesLock.Unlock()
fileHandle.handle = inodeId

Loading…
Cancel
Save