diff options
author | Jakob Unterwurzacher | 2017-06-30 23:11:38 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2017-06-30 23:11:38 +0200 |
commit | 06398e82d91c81c618bfa6a481c0e9070847c909 (patch) | |
tree | 7179445982d09f79843f035557e8cd8eb8d84c2c /internal | |
parent | 2932a285aa2e8f6ef7cdd8b3c0387438dcb96015 (diff) |
fusefrontend: Read: use provided buffer
This will allow us to return internal buffers to a pool.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/fusefrontend/file.go | 11 | ||||
-rw-r--r-- | internal/fusefrontend/file_allocate_truncate.go | 2 |
2 files changed, 7 insertions, 6 deletions
diff --git a/internal/fusefrontend/file.go b/internal/fusefrontend/file.go index 277a71e..6f963e7 100644 --- a/internal/fusefrontend/file.go +++ b/internal/fusefrontend/file.go @@ -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 diff --git a/internal/fusefrontend/file_allocate_truncate.go b/internal/fusefrontend/file_allocate_truncate.go index 85ed11c..86aee8e 100644 --- a/internal/fusefrontend/file_allocate_truncate.go +++ b/internal/fusefrontend/file_allocate_truncate.go @@ -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 |