generic/158: test dedupe with destination offset past EOF
authorFilipe Manana <fdmanana@suse.com>
Thu, 18 Feb 2016 23:43:04 +0000 (10:43 +1100)
committerDave Chinner <david@fromorbit.com>
Thu, 18 Feb 2016 23:43:04 +0000 (10:43 +1100)
We were testing when the source file offset starts at EOF or beyond,
but not when the destination offset is beyond EOF or when the
destination offset is smaller than EOF but destination offset plus
dedup length is greater than EOF.

This is motivated by a bug in btrfs' extent_same (dedup) ioctl where
we allowed the destination offset to start at EOF and beyond (and
destination offset + length beyond EOF) for the case where the source
and destination files are the same (was not allowed for different
files used as source and destination). This also made the file's
metadata inconsistent when the dedup operation succeeded, which
happened when the source range corresponded to a file hole, prealloc
extent or a data extent filled with zeroes.

The btrfs issue is fixed by the following patch for the linux kernel:

  "Btrfs: fix extent_same allowing destination offset beyond i_size"

Signed-off-by: Filipe Manana <fdmanana@suse.com>
[darrick.wong@oracle.com: fix merge conflicts with latest reflink patchbomb]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
tests/generic/158
tests/generic/158.out

index 0da5daa956fbf8d0e30901794a97602ad89e6cd2..dd645627f4844a287caf7ec7fb79e2b1e44c8201 100755 (executable)
@@ -97,9 +97,17 @@ _dedupe_range $testdir1/file1 37 $testdir1/file1 59 23
 echo "Try overlapping dedupe"
 _dedupe_range $testdir1/file1 0 $testdir1/file1 1 $((blksz * 2))
 
-echo "Try dedupe past EOF"
+echo "Try dedupe from past EOF"
 _dedupe_range $testdir1/file1 $(( (blks + 10) * blksz)) $testdir1/file1 0 $blksz
 
+echo "Try dedupe to past EOF, destination offset beyond EOF"
+_dedupe_range $testdir1/file1 0 $testdir1/file1 $(( (blks + 10) * blksz)) \
+       $blksz
+
+echo "Try dedupe to past EOF, destination offset behind EOF"
+_dedupe_range $testdir1/file1 0 $testdir1/file1 $(( (blks - 1) * blksz)) \
+       $((blksz * 2))
+
 echo "Try to dedupe a dir"
 _dedupe_range $testdir1/dir1 0 $testdir1/file2 0 $blksz
 
index 7f884034d51a94ce4e6352d926f2c024eef99979..9b82ddf635f11643186292bf4f15ef62848d955b 100644 (file)
@@ -7,7 +7,11 @@ Try unaligned dedupe
 dedupe: Invalid argument
 Try overlapping dedupe
 dedupe: Invalid argument
-Try dedupe past EOF
+Try dedupe from past EOF
+dedupe: Invalid argument
+Try dedupe to past EOF, destination offset beyond EOF
+dedupe: Invalid argument
+Try dedupe to past EOF, destination offset behind EOF
 dedupe: Invalid argument
 Try to dedupe a dir
 XFS_IOC_FILE_EXTENT_SAME: Is a directory