contentenc: add PReqPool and use it in DecryptBlocks
This gets us a massive speed boost in streaming reads.
This commit is contained in:
parent
e4b5005bcc
commit
12c0101a23
|
@ -60,6 +60,8 @@ type ContentEnc struct {
|
||||||
CReqPool bPool
|
CReqPool bPool
|
||||||
// Plaintext block pool. Always returns plainBS-sized byte slices.
|
// Plaintext block pool. Always returns plainBS-sized byte slices.
|
||||||
pBlockPool bPool
|
pBlockPool bPool
|
||||||
|
// Plaintext request data pool. Slice have size fuse.MAX_KERNEL_WRITE.
|
||||||
|
PReqPool bPool
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns an initialized ContentEnc instance.
|
// New returns an initialized ContentEnc instance.
|
||||||
|
@ -80,6 +82,7 @@ func New(cc *cryptocore.CryptoCore, plainBS uint64, forceDecode bool) *ContentEn
|
||||||
cBlockPool: newBPool(int(cipherBS)),
|
cBlockPool: newBPool(int(cipherBS)),
|
||||||
CReqPool: newBPool(cReqSize),
|
CReqPool: newBPool(cReqSize),
|
||||||
pBlockPool: newBPool(int(plainBS)),
|
pBlockPool: newBPool(int(plainBS)),
|
||||||
|
PReqPool: newBPool(fuse.MAX_KERNEL_WRITE),
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
@ -98,7 +101,7 @@ func (be *ContentEnc) CipherBS() uint64 {
|
||||||
func (be *ContentEnc) DecryptBlocks(ciphertext []byte, firstBlockNo uint64, fileID []byte) ([]byte, error) {
|
func (be *ContentEnc) DecryptBlocks(ciphertext []byte, firstBlockNo uint64, fileID []byte) ([]byte, error) {
|
||||||
cBuf := bytes.NewBuffer(ciphertext)
|
cBuf := bytes.NewBuffer(ciphertext)
|
||||||
var err error
|
var err error
|
||||||
var pBuf bytes.Buffer
|
pBuf := bytes.NewBuffer(be.PReqPool.Get()[:0])
|
||||||
for cBuf.Len() > 0 {
|
for cBuf.Len() > 0 {
|
||||||
cBlock := cBuf.Next(int(be.cipherBS))
|
cBlock := cBuf.Next(int(be.cipherBS))
|
||||||
var pBlock []byte
|
var pBlock []byte
|
||||||
|
|
|
@ -214,7 +214,10 @@ func (f *file) doRead(dst []byte, off uint64, length uint64) ([]byte, fuse.Statu
|
||||||
}
|
}
|
||||||
// else: out stays empty, file was smaller than the requested offset
|
// else: out stays empty, file was smaller than the requested offset
|
||||||
|
|
||||||
return append(dst, out...), fuse.OK
|
out = append(dst, out...)
|
||||||
|
f.fs.contentEnc.PReqPool.Put(plaintext)
|
||||||
|
|
||||||
|
return out, fuse.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read - FUSE call
|
// Read - FUSE call
|
||||||
|
|
Loading…
Reference in New Issue