Reuse readDataByFileHandle in Read call (#3482)

This commit is contained in:
Patrick Schmidt
2022-08-22 17:24:06 +02:00
committed by GitHub
parent bdba3da2e4
commit f875031f06
2 changed files with 23 additions and 33 deletions

View File

@@ -43,18 +43,7 @@ func (wfs *WFS) Read(cancel <-chan struct{}, in *fuse.ReadIn, buff []byte) (fuse
defer fh.entryLock.Unlock()
offset := int64(in.Offset)
fh.lockForRead(offset, len(buff))
defer fh.unlockForRead(offset, len(buff))
totalRead, err := fh.readFromChunks(buff, offset)
if err == nil || err == io.EOF {
maxStop := fh.readFromDirtyPages(buff, offset)
totalRead = max(maxStop-offset, totalRead)
}
if err == io.EOF {
err = nil
}
totalRead, err := readDataByFileHandle(buff, fh, offset)
if err != nil {
glog.Warningf("file handle read %s %d: %v", fh.FullPath(), totalRead, err)
return nil, fuse.EIO
@@ -62,3 +51,20 @@ func (wfs *WFS) Read(cancel <-chan struct{}, in *fuse.ReadIn, buff []byte) (fuse
return fuse.ReadResultData(buff[:totalRead]), fuse.OK
}
func readDataByFileHandle(buff []byte, fhIn *FileHandle, offset int64) (int64, error) {
// read data from source file
size := len(buff)
fhIn.lockForRead(offset, size)
defer fhIn.unlockForRead(offset, size)
n, err := fhIn.readFromChunks(buff, offset)
if err == nil || err == io.EOF {
maxStop := fhIn.readFromDirtyPages(buff, offset)
n = max(maxStop-offset, n)
}
if err == io.EOF {
err = nil
}
return n, err
}