diff options
author | Jakob Unterwurzacher | 2015-10-04 14:21:07 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2015-10-04 14:21:07 +0200 |
commit | 775676ecb82f415874f3c6b83da1436b629166f4 (patch) | |
tree | 7aa81dc0bdc0669630036289c26beb8c36807f32 /pathfs_frontend/file_holes.go | |
parent | 2003ca965d2905e240f2b2f1c596aa02f7786c77 (diff) |
Utilize file hole passtrough capability in Truncate()
Cuts down the runtime of xfstests generic/014
from 1822 seconds to 36 seconds
Diffstat (limited to 'pathfs_frontend/file_holes.go')
-rw-r--r-- | pathfs_frontend/file_holes.go | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/pathfs_frontend/file_holes.go b/pathfs_frontend/file_holes.go index 8c9c83f..db27805 100644 --- a/pathfs_frontend/file_holes.go +++ b/pathfs_frontend/file_holes.go @@ -1,14 +1,12 @@ package pathfs_frontend import ( - "fmt" "github.com/hanwen/go-fuse/fuse" - "github.com/rfjakob/gocryptfs/cryptfs" ) // Will a write to offset "off" create a file hole? -func (f *file) createsHole(cipherSize uint64, off int64) bool { - nextBlock := f.cfs.BlockNoCipherOff(cipherSize) +func (f *file) createsHole(plainSize uint64, off int64) bool { + nextBlock := f.cfs.BlockNoPlainOff(plainSize) targetBlock := f.cfs.BlockNoPlainOff(uint64(off)) if targetBlock > nextBlock { return true @@ -16,20 +14,8 @@ func (f *file) createsHole(cipherSize uint64, off int64) bool { return false } -// Zero-pad the file if a write to "off" creates a file hole -func (f *file) conditionalZeroPad(off int64) fuse.Status { - fi, err := f.fd.Stat() - if err != nil { - cryptfs.Warn.Printf("conditionalZeroPad: Stat: %v\n", err) - return fuse.ToStatus(err) - } - cipherSize := uint64(fi.Size()) - - if f.createsHole(cipherSize, off) == false { - return fuse.OK - } - - plainSize := f.cfs.PlainSize(cipherSize) +// Zero-pad the file of size plainSize to the next block boundary +func (f *file) zeroPad(plainSize uint64) fuse.Status { lastBlockLen := plainSize % f.cfs.PlainBS() missing := f.cfs.PlainBS() - lastBlockLen pad := make([]byte, missing) |