generic/520: Remove sync in clean_dir
[xfstests-dev.git] / tests / generic / 517
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 517
6 #
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.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/reflink
28
29 # real QA test starts here
30 _supported_fs generic
31 _supported_os Linux
32 _require_scratch_dedupe
33
34 rm -f $seqres.full
35
36 _scratch_mkfs >>$seqres.full 2>&1
37 _scratch_mount
38
39 # The first byte with a value of 0xae starts at an offset (512Kb + 100) which is
40 # not a multiple of the block size.
41 $XFS_IO_PROG -f \
42         -c "pwrite -S 0x6b 0 524388" \
43         -c "pwrite -S 0xae 524388 256K" \
44         $SCRATCH_MNT/foo | _filter_xfs_io
45
46 # Create a second file with a length not aligned to the block size (128K + 100),
47 # whose bytes all have the value 0x6b, so that its extent(s) can be deduplicated
48 # with the first file.
49 $XFS_IO_PROG -f -c "pwrite -S 0x6b 0 131172" $SCRATCH_MNT/bar | _filter_xfs_io
50
51 # The file is filled with bytes having the value 0x6b from offset 0 to offset
52 # 524388 (512K + 100) and with the value 0xae from offset 524388 to offset
53 # 786532 (512K + 100 + 256K).
54 echo "File content before first deduplication:"
55 od -A d -t x1 $SCRATCH_MNT/foo
56
57 # Now deduplicate the entire second file into a range of the first file that
58 # also has all bytes with the value 0x6b. The destination range's end offset
59 # must not be aligned to the block size and must be less then the offset of
60 # the first byte with the value 0xae (byte at offset 524388).
61 $XFS_IO_PROG -c "dedupe $SCRATCH_MNT/bar 0 64K 131172" $SCRATCH_MNT/foo \
62         | _filter_xfs_io
63
64 # We should have exactly the same data we had before we asked for deduplication.
65 echo "File content after first deduplication and before unmounting:"
66 od -A d -t x1 $SCRATCH_MNT/foo
67
68 # Unmount the filesystem and mount it again. This guarantees any file data in
69 # the page cache is dropped.
70 _scratch_cycle_mount
71
72 # We should have exactly the same data we had before we asked for deduplication.
73 echo "File content after first unmount:"
74 od -A d -t x1 $SCRATCH_MNT/foo
75
76 # Now do a similar test when trying to dedup just the last (eof) block of a file
77 # into the middle of another file. This triggered a different bug on btrfs.
78 $XFS_IO_PROG -f -c "pwrite -S 0xae 0 100" $SCRATCH_MNT/baz | _filter_xfs_io
79
80 # Unmount the filesystem and mount it again before attempting to dedupe baz's
81 # last block into foo. This is necessary to trigger that btrfs bug mentioned
82 # before.
83 _scratch_cycle_mount
84
85 # Now attempt to dedupe the single block of baz into foo. The destination range,
86 # in file foo, has all bytes with the same value (0xae) as file baz.
87 $XFS_IO_PROG -c "dedupe $SCRATCH_MNT/baz 0 640K 100" $SCRATCH_MNT/foo \
88     | _filter_xfs_io
89
90 # Now attempt to unmount the filesystem before reading from the file. This is
91 # meant to trigger the btrfs bug which caused an infinite loop during inode
92 # eviction.
93 _scratch_cycle_mount
94
95 # We should have exactly the same data we had before we asked for deduplication.
96 echo "File content after second deduplication:"
97 od -A d -t x1 $SCRATCH_MNT/foo
98
99 status=0
100 exit