2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that punch-hole steps around reflinked ranges:
8 # - Create three reflink clones of a file
9 # - Punch 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 punch
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 "fpunch"
32 testdir=$TEST_DIR/test-$seq
36 echo "Create the original files"
38 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
39 _pwrite_byte 0x62 $blksz $blksz $testdir/file1 >> $seqres.full
40 _pwrite_byte 0x63 $((blksz * 2)) $blksz $testdir/file1 >> $seqres.full
42 _cp_reflink $testdir/file1 $testdir/file2
43 _cp_reflink $testdir/file1 $testdir/file3
44 _cp_reflink $testdir/file1 $testdir/file4
46 _pwrite_byte 0x00 0 $blksz $testdir/file2.chk >> $seqres.full
47 _pwrite_byte 0x62 $blksz $blksz $testdir/file2.chk >> $seqres.full
48 _pwrite_byte 0x63 $((blksz * 2)) $blksz $testdir/file2.chk >> $seqres.full
50 _pwrite_byte 0x61 0 $blksz $testdir/file3.chk >> $seqres.full
51 _pwrite_byte 0x00 $blksz $blksz $testdir/file3.chk >> $seqres.full
52 _pwrite_byte 0x63 $((blksz * 2)) $blksz $testdir/file3.chk >> $seqres.full
54 _pwrite_byte 0x61 0 $blksz $testdir/file4.chk >> $seqres.full
55 _pwrite_byte 0x62 $blksz $blksz $testdir/file4.chk >> $seqres.full
56 _pwrite_byte 0x00 $((blksz * 2)) $blksz $testdir/file4.chk >> $seqres.full
59 md5sum $testdir/file1 | _filter_test_dir
60 md5sum $testdir/file2 | _filter_test_dir
61 md5sum $testdir/file3 | _filter_test_dir
62 md5sum $testdir/file4 | _filter_test_dir
63 md5sum $testdir/file2.chk | _filter_test_dir
64 md5sum $testdir/file3.chk | _filter_test_dir
65 md5sum $testdir/file4.chk | _filter_test_dir
67 c1=$(_md5_checksum $testdir/file1)
68 c2=$(_md5_checksum $testdir/file2)
69 c3=$(_md5_checksum $testdir/file3)
70 c4=$(_md5_checksum $testdir/file4)
72 test ${c1} = ${c2} || echo "file1 and file2 should match"
73 test ${c1} = ${c3} || echo "file1 and file3 should match"
74 test ${c1} = ${c4} || echo "file1 and file4 should match"
75 test ${c2} = ${c3} || echo "file2 and file3 should match"
76 test ${c2} = ${c4} || echo "file2 and file4 should match"
77 test ${c3} = ${c4} || echo "file3 and file4 should match"
80 $XFS_IO_PROG -f -c "fpunch 0 $blksz" $testdir/file2
81 $XFS_IO_PROG -f -c "fpunch $blksz $blksz" $testdir/file3
82 $XFS_IO_PROG -f -c "fpunch $((blksz * 2)) $blksz" $testdir/file4
86 md5sum $testdir/file1 | _filter_test_dir
87 md5sum $testdir/file2 | _filter_test_dir
88 md5sum $testdir/file3 | _filter_test_dir
89 md5sum $testdir/file4 | _filter_test_dir
90 md5sum $testdir/file2.chk | _filter_test_dir
91 md5sum $testdir/file3.chk | _filter_test_dir
92 md5sum $testdir/file4.chk | _filter_test_dir
94 c1=$(_md5_checksum $testdir/file1)
95 c2=$(_md5_checksum $testdir/file2)
96 c3=$(_md5_checksum $testdir/file3)
97 c4=$(_md5_checksum $testdir/file4)
99 test ${c1} != ${c2} || echo "file1 and file2 should not match"
100 test ${c1} != ${c3} || echo "file1 and file3 should not match"
101 test ${c1} != ${c4} || echo "file1 and file4 should not match"
102 test ${c2} != ${c3} || echo "file2 and file3 should not match"
103 test ${c2} != ${c4} || echo "file2 and file4 should not match"
104 test ${c3} != ${c4} || echo "file3 and file4 should not match"
106 echo "Compare against check files"
107 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk do not match"
108 cmp -s $testdir/file3 $testdir/file3.chk || echo "file3 and file3.chk do not match"
109 cmp -s $testdir/file4 $testdir/file4.chk || echo "file4 and file4.chk do not match"