From 2d68b06f9dab66b2a0a6c29c8d5450e2b1d43fae Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 1 Jul 2018 19:14:00 +0200 Subject: fsck: handle sparse files efficiently, fix xfstests generic/285 If we encounter a 128KB block of zeros, try to skip to the next data section by calling File.SeekData(). This fixes xfstests generic/285, which creates a 17TB sparse file, and runs fsck afterwards. Without this optimization, fsck would take ages. --- fsck.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'fsck.go') diff --git a/fsck.go b/fsck.go index 37157cb..59bb2f0 100644 --- a/fsck.go +++ b/fsck.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "fmt" "os" "path/filepath" @@ -115,6 +116,7 @@ func (ck *fsckObj) file(path string) { return } defer f.Release() + allZero := make([]byte, fuse.MAX_KERNEL_WRITE) buf := make([]byte, fuse.MAX_KERNEL_WRITE) var off int64 // Read() through the whole file and catch transparently mitigated corruptions @@ -132,6 +134,15 @@ func (ck *fsckObj) file(path string) { return } off += int64(result.Size()) + // If we seem to be in the middle of a file hole, try to skip to the next + // data section. + if bytes.Equal(buf, allZero) { + f2 := f.(*fusefrontend.File) + nextOff, err := f2.SeekData(off) + if err == nil { + off = nextOff + } + } } } -- cgit v1.2.3