Skip to content

Commit 06398e8

Browse files
committed
fusefrontend: Read: use provided buffer
This will allow us to return internal buffers to a pool.
1 parent 2932a28 commit 06398e8

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

internal/fusefrontend/file.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,16 @@ func (f *file) createHeader() (fileID []byte, err error) {
132132
return h.ID, err
133133
}
134134

135-
// doRead - returns "length" plaintext bytes from plaintext offset "off".
135+
// doRead - read "length" plaintext bytes from plaintext offset "off" and append
136+
// to "dst".
136137
// Arguments "length" and "off" do not have to be block-aligned.
137138
//
138139
// doRead reads the corresponding ciphertext blocks from disk, decrypts them and
139140
// returns the requested part of the plaintext.
140141
//
141142
// Called by Read() for normal reading,
142143
// by Write() and Truncate() for Read-Modify-Write
143-
func (f *file) doRead(off uint64, length uint64) ([]byte, fuse.Status) {
144+
func (f *file) doRead(dst []byte, off uint64, length uint64) ([]byte, fuse.Status) {
144145
// Make sure we have the file ID.
145146
f.fileTableEntry.HeaderLock.RLock()
146147
if f.fileTableEntry.ID == nil {
@@ -211,7 +212,7 @@ func (f *file) doRead(off uint64, length uint64) ([]byte, fuse.Status) {
211212
}
212213
// else: out stays empty, file was smaller than the requested offset
213214

214-
return out, fuse.OK
215+
return append(dst, out...), fuse.OK
215216
}
216217

217218
// Read - FUSE call
@@ -225,7 +226,7 @@ func (f *file) Read(buf []byte, off int64) (resultData fuse.ReadResult, code fus
225226
serialize_reads.Wait(off, len(buf))
226227
}
227228

228-
out, status := f.doRead(uint64(off), uint64(len(buf)))
229+
out, status := f.doRead(buf[:0], uint64(off), uint64(len(buf)))
229230

230231
if f.fs.args.SerializeReads {
231232
serialize_reads.Done()
@@ -282,7 +283,7 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) {
282283
// Incomplete block -> Read-Modify-Write
283284
if b.IsPartial() {
284285
// Read
285-
oldData, status := f.doRead(b.BlockPlainOff(), f.contentEnc.PlainBS())
286+
oldData, status := f.doRead(nil, b.BlockPlainOff(), f.contentEnc.PlainBS())
286287
if status != fuse.OK {
287288
tlog.Warn.Printf("ino%d fh%d: RMW read failed: %s", f.qIno.Ino, f.intFd(), status.String())
288289
return 0, status

internal/fusefrontend/file_allocate_truncate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
144144
var data []byte
145145
if lastBlockLen > 0 {
146146
var status fuse.Status
147-
data, status = f.doRead(plainOff, lastBlockLen)
147+
data, status = f.doRead(nil, plainOff, lastBlockLen)
148148
if status != fuse.OK {
149149
tlog.Warn.Printf("Truncate: shrink doRead returned error: %v", err)
150150
return status

0 commit comments

Comments
 (0)