2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that collapse range steps around reflinked ranges:
8 # - Create three reflink clones of a file
9 # - Collapse the start, middle, and end of the reflink range of each
10 # of the three files, respectively
11 # - Check that the reflinked areas are still there.
14 _begin_fstest auto quick clone collapse
16 # Override the default cleanup function.
20 rm -rf $tmp.* $testdir
23 # Import common functions.
27 # real QA test starts here
30 _require_xfs_io_command "falloc"
31 _require_xfs_io_command "fcollapse"
33 testdir=$TEST_DIR/test-$seq
37 echo "Create the original files"
39 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
40 _pwrite_byte 0x62 $blksz $blksz $testdir/file1 >> $seqres.full
41 _pwrite_byte 0x63 $((blksz * 2)) $blksz $testdir/file1 >> $seqres.full
43 _cp_reflink $testdir/file1 $testdir/file2
44 _cp_reflink $testdir/file1 $testdir/file3
45 _cp_reflink $testdir/file1 $testdir/file4
47 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 4))" $testdir/file1
48 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 4))" $testdir/file2
49 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 4))" $testdir/file3
50 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 4))" $testdir/file4
52 _pwrite_byte 0x62 0 $blksz $testdir/file2.chk >> $seqres.full
53 _pwrite_byte 0x63 $blksz $blksz $testdir/file2.chk >> $seqres.full
54 _pwrite_byte 0x00 $((blksz * 2)) $blksz $testdir/file2.chk >> $seqres.full
56 _pwrite_byte 0x61 0 $blksz $testdir/file3.chk >> $seqres.full
57 _pwrite_byte 0x63 $blksz $blksz $testdir/file3.chk >> $seqres.full
58 _pwrite_byte 0x00 $((blksz * 2)) $blksz $testdir/file3.chk >> $seqres.full
60 _pwrite_byte 0x61 0 $blksz $testdir/file4.chk >> $seqres.full
61 _pwrite_byte 0x62 $blksz $blksz $testdir/file4.chk >> $seqres.full
62 _pwrite_byte 0x00 $((blksz * 2)) $blksz $testdir/file4.chk >> $seqres.full
65 md5sum $testdir/file1 | _filter_test_dir
66 md5sum $testdir/file2 | _filter_test_dir
67 md5sum $testdir/file3 | _filter_test_dir
68 md5sum $testdir/file4 | _filter_test_dir
69 md5sum $testdir/file2.chk | _filter_test_dir
70 md5sum $testdir/file3.chk | _filter_test_dir
71 md5sum $testdir/file4.chk | _filter_test_dir
73 c1=$(_md5_checksum $testdir/file1)
74 c2=$(_md5_checksum $testdir/file2)
75 c3=$(_md5_checksum $testdir/file3)
76 c4=$(_md5_checksum $testdir/file4)
78 test ${c1} = ${c2} || echo "file1 and file2 should match"
79 test ${c1} = ${c3} || echo "file1 and file3 should match"
80 test ${c1} = ${c4} || echo "file1 and file4 should match"
81 test ${c2} = ${c3} || echo "file2 and file3 should match"
82 test ${c2} = ${c4} || echo "file2 and file4 should match"
83 test ${c3} = ${c4} || echo "file3 and file4 should match"
85 echo "fcollapse files"
86 $XFS_IO_PROG -f -c "fcollapse 0 $blksz" $testdir/file2
87 $XFS_IO_PROG -f -c "fcollapse $blksz $blksz" $testdir/file3
88 $XFS_IO_PROG -f -c "fcollapse $((blksz * 2)) $blksz" $testdir/file4
92 md5sum $testdir/file1 | _filter_test_dir
93 md5sum $testdir/file2 | _filter_test_dir
94 md5sum $testdir/file3 | _filter_test_dir
95 md5sum $testdir/file4 | _filter_test_dir
96 md5sum $testdir/file2.chk | _filter_test_dir
97 md5sum $testdir/file3.chk | _filter_test_dir
98 md5sum $testdir/file4.chk | _filter_test_dir
100 c1=$(_md5_checksum $testdir/file1)
101 c2=$(_md5_checksum $testdir/file2)
102 c3=$(_md5_checksum $testdir/file3)
103 c4=$(_md5_checksum $testdir/file4)
105 test ${c1} != ${c2} || echo "file1 and file2 should not match"
106 test ${c1} != ${c3} || echo "file1 and file3 should not match"
107 test ${c1} != ${c4} || echo "file1 and file4 should not match"
108 test ${c2} != ${c3} || echo "file2 and file3 should not match"
109 test ${c2} != ${c4} || echo "file2 and file4 should not match"
110 test ${c3} != ${c4} || echo "file3 and file4 should not match"
112 echo "Compare against check files"
113 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk do not match"
114 cmp -s $testdir/file3 $testdir/file3.chk || echo "file3 and file3.chk do not match"
115 cmp -s $testdir/file4 $testdir/file4.chk || echo "file4 and file4.chk do not match"