Fix xfstests generic/030 failure

The actual fix is

	oldSize := f.cfs.PlainSize(uint64(fi.Size()))

the rest is logging improvements
This commit is contained in:
Jakob Unterwurzacher 2015-10-04 00:26:20 +02:00
parent 0802175328
commit 40448db909
3 changed files with 11 additions and 5 deletions

View File

@ -79,6 +79,7 @@ func (be *CryptFS) DecryptBlock(ciphertext []byte) ([]byte, error) {
if err != nil { if err != nil {
Warn.Printf("DecryptBlock: %s, len=%d, md5=%s\n", err.Error(), len(ciphertextOrig), Warn.Md5sum(ciphertextOrig)) Warn.Printf("DecryptBlock: %s, len=%d, md5=%s\n", err.Error(), len(ciphertextOrig), Warn.Md5sum(ciphertextOrig))
Debug.Println(hex.Dump(ciphertextOrig))
return nil, err return nil, err
} }

View File

@ -34,7 +34,7 @@ func (l *logChannel) Enable() {
// CPU cycles // CPU cycles
func (l *logChannel) Md5sum(buf []byte) string { func (l *logChannel) Md5sum(buf []byte) string {
if l.enabled == false { if l.enabled == false {
return "" return "disabled"
} }
return md5sum(buf) return md5sum(buf)
} }

View File

@ -164,7 +164,7 @@ func (f *file) Write(data []byte, off int64) (uint32, fuse.Status) {
blockData = f.cfs.EncryptBlock(blockData) blockData = f.cfs.EncryptBlock(blockData)
cryptfs.Debug.Printf("ino%d: Writing %d bytes to block #%d, md5=%s\n", f.ino, len(blockData), b.BlockNo, cryptfs.Debug.Md5sum(blockData)) cryptfs.Debug.Printf("ino%d: Writing %d bytes to block #%d, md5=%s\n", f.ino, len(blockData), b.BlockNo, cryptfs.Debug.Md5sum(blockData))
if len(blockData) != int(f.cfs.CipherBS()) { if len(blockData) != int(f.cfs.CipherBS()) {
cryptfs.Debug.Printf("ino%d: Writing partial block #%d (%d bytes)\n", b.BlockNo, len(blockData)) cryptfs.Debug.Printf("ino%d: Writing partial block #%d (%d bytes)\n", f.ino, b.BlockNo, len(blockData))
} }
f.lock.Lock() f.lock.Lock()
_, err := f.fd.WriteAt(blockData, int64(blockOffset)) _, err := f.fd.WriteAt(blockData, int64(blockOffset))
@ -230,8 +230,12 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
cryptfs.Warn.Printf("Truncate: fstat failed: %v\n", err) cryptfs.Warn.Printf("Truncate: fstat failed: %v\n", err)
return fuse.ToStatus(err) return fuse.ToStatus(err)
} }
oldSize := uint64(fi.Size()) oldSize := f.cfs.PlainSize(uint64(fi.Size()))
{
oldB := (oldSize + f.cfs.PlainBS() - 1) / f.cfs.PlainBS()
newB := (newSize + f.cfs.PlainBS() - 1) / f.cfs.PlainBS()
cryptfs.Debug.Printf("ino%d: truncate from %d to %d blocks (%d to %d bytes)\n", f.ino, oldB, newB, oldSize, newSize)
}
// Grow file by appending zeros // Grow file by appending zeros
if newSize > oldSize { if newSize > oldSize {
remaining := newSize - oldSize remaining := newSize - oldSize
@ -259,7 +263,7 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
} }
return fuse.OK return fuse.OK
} }
// else:
// Shrink file by truncating // Shrink file by truncating
newBlockLen := int(newSize % f.cfs.PlainBS()) newBlockLen := int(newSize % f.cfs.PlainBS())
// New file size is aligned to block size - just truncate // New file size is aligned to block size - just truncate
@ -271,6 +275,7 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
return fuse.ToStatus(err) return fuse.ToStatus(err)
} }
// New file size is not aligned - need to do RMW on the last block // New file size is not aligned - need to do RMW on the last block
cryptfs.Debug.Printf("Truncate: Shrink RMW\n")
var blockOffset, blockLen uint64 var blockOffset, blockLen uint64
{ {
// Get the block the last byte belongs to. // Get the block the last byte belongs to.