2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that deduplication of an entire file that has a size that is not aligned
8 # to the filesystem's block size into the middle of a different file does not
9 # corrupt the destination's file data by reflinking the last (eof) block.
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
29 # real QA test starts here
32 _require_scratch_dedupe
36 _scratch_mkfs >>$seqres.full 2>&1
39 # The first byte with a value of 0xae starts at an offset (2518890) which is not
40 # a multiple of the block size.
42 -c "pwrite -S 0x6b 0 2518890" \
43 -c "pwrite -S 0xae 2518890 102398" \
44 $SCRATCH_MNT/foo | _filter_xfs_io
46 # Create a second file with a length not aligned to the block size, whose bytes
47 # all have the value 0x6b, so that its extent(s) can be deduplicated with the
49 $XFS_IO_PROG -f -c "pwrite -S 0x6b 0 557771" $SCRATCH_MNT/bar | _filter_xfs_io
51 # The file is filled with bytes having the value 0x6b from offset 0 to offset
52 # 2518889 and with the value 0xae from offset 2518890 to offset 2621287.
53 echo "File content before first deduplication:"
54 od -t x1 $SCRATCH_MNT/foo
56 # Now deduplicate the entire second file into a range of the first file that
57 # also has all bytes with the value 0x6b. The destination range's end offset
58 # must not be aligned to the block size and must be less then the offset of
59 # the first byte with the value 0xae (byte at offset 2518890).
60 $XFS_IO_PROG -c "dedupe $SCRATCH_MNT/bar 0 1957888 557771" $SCRATCH_MNT/foo \
63 # We should have exactly the same data we had before we asked for deduplication.
64 echo "File content after first deduplication and before unmounting:"
65 od -A d -t x1 $SCRATCH_MNT/foo
67 # Unmount the filesystem and mount it again. This guarantees any file data in
68 # the page cache is dropped.
71 # We should have exactly the same data we had before we asked for deduplication.
72 echo "File content after first unmount:"
73 od -A d -t x1 $SCRATCH_MNT/foo
75 # Now do a similar test when trying to dedup just the last (eof) block of a file
76 # into the middle of another file. This triggered a different bug on btrfs.
77 $XFS_IO_PROG -f -c "pwrite -S 0xae 0 100" $SCRATCH_MNT/baz | _filter_xfs_io
79 # Unmount the filesystem and mount it again before attempting to dedupe baz's
80 # last block into foo. This is necessary to trigger that btrfs bug mentioned
84 # Now attempt to dedupe the single block of baz into foo.
85 $XFS_IO_PROG -c "dedupe $SCRATCH_MNT/baz 0 2519040 100" $SCRATCH_MNT/foo \
88 # Now attempt to unmount the filesystem before reading from the file. This is
89 # meant to trigger the btrfs bug which caused an infinite loop during inode
93 # We should have exactly the same data we had before we asked for deduplication.
94 echo "File content after second deduplication:"
95 od -A d -t x1 $SCRATCH_MNT/foo