fusefrontend: Read: use provided buffer

This will allow us to return internal buffers to a pool.
This commit is contained in:
Jakob Unterwurzacher 2017-06-30 23:11:38 +02:00
parent 2932a285aa
commit 06398e82d9
2 changed files with 7 additions and 6 deletions

View File

@ -132,7 +132,8 @@ func (f *file) createHeader() (fileID []byte, err error) {
return h.ID, err
}
// doRead - returns "length" plaintext bytes from plaintext offset "off".
// doRead - read "length" plaintext bytes from plaintext offset "off" and append
// to "dst".
// Arguments "length" and "off" do not have to be block-aligned.
//
// doRead reads the corresponding ciphertext blocks from disk, decrypts them and
@ -140,7 +141,7 @@ func (f *file) createHeader() (fileID []byte, err error) {
//
// Called by Read() for normal reading,
// by Write() and Truncate() for Read-Modify-Write
func (f *file) doRead(off uint64, length uint64) ([]byte, fuse.Status) {
func (f *file) doRead(dst []byte, off uint64, length uint64) ([]byte, fuse.Status) {
// Make sure we have the file ID.
f.fileTableEntry.HeaderLock.RLock()
if f.fileTableEntry.ID == nil {
@ -211,7 +212,7 @@ func (f *file) doRead(off uint64, length uint64) ([]byte, fuse.Status) {
}
// else: out stays empty, file was smaller than the requested offset
return out, fuse.OK
return append(dst, out...), fuse.OK
}
// Read - FUSE call
@ -225,7 +226,7 @@ func (f *file) Read(buf []byte, off int64) (resultData fuse.ReadResult, code fus
serialize_reads.Wait(off, len(buf))
}
out, status := f.doRead(uint64(off), uint64(len(buf)))
out, status := f.doRead(buf[:0], uint64(off), uint64(len(buf)))
if f.fs.args.SerializeReads {
serialize_reads.Done()
@ -282,7 +283,7 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) {
// Incomplete block -> Read-Modify-Write
if b.IsPartial() {
// Read
oldData, status := f.doRead(b.BlockPlainOff(), f.contentEnc.PlainBS())
oldData, status := f.doRead(nil, b.BlockPlainOff(), f.contentEnc.PlainBS())
if status != fuse.OK {
tlog.Warn.Printf("ino%d fh%d: RMW read failed: %s", f.qIno.Ino, f.intFd(), status.String())
return 0, status

View File

@ -144,7 +144,7 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
var data []byte
if lastBlockLen > 0 {
var status fuse.Status
data, status = f.doRead(plainOff, lastBlockLen)
data, status = f.doRead(nil, plainOff, lastBlockLen)
if status != fuse.OK {
tlog.Warn.Printf("Truncate: shrink doRead returned error: %v", err)
return status