generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / generic / 148
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 148
6 #
7 # Ensure that truncating the last block in a reflinked file CoWs appropriately:
8 #   - Create a file that doesn't end on a block boundary
9 #   - Create two reflink clones of the file
10 #   - Shorten one of the clones with truncate
11 #   - Lengthen the other clone with truncate
12 #   - Check that the reflinked areas are still there.
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1    # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25     cd /
26     rm -rf $tmp.* $testdir
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32 . ./common/reflink
33
34 # real QA test starts here
35 _require_test_reflink
36 _require_cp_reflink
37 _require_xfs_io_command "truncate"
38
39 rm -f $seqres.full
40
41 testdir=$TEST_DIR/test-$seq
42 rm -rf $testdir
43 mkdir $testdir
44
45 echo "Create the original files"
46 blksz=65536
47 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
48 _pwrite_byte 0x62 $blksz 37 $testdir/file1 >> $seqres.full
49
50 _cp_reflink $testdir/file1 $testdir/file2
51 _cp_reflink $testdir/file1 $testdir/file3
52
53 _pwrite_byte 0x61 0 $blksz $testdir/file2.chk >> $seqres.full
54 _pwrite_byte 0x62 $blksz 34 $testdir/file2.chk >> $seqres.full
55
56 _pwrite_byte 0x61 0 $blksz $testdir/file3.chk >> $seqres.full
57 _pwrite_byte 0x62 $blksz 37 $testdir/file3.chk >> $seqres.full
58 _pwrite_byte 0x00 $((blksz + 37)) 3 $testdir/file3.chk >> $seqres.full
59 _test_cycle_mount
60
61 md5sum $testdir/file1 | _filter_test_dir
62 md5sum $testdir/file2 | _filter_test_dir
63 md5sum $testdir/file3 | _filter_test_dir
64 md5sum $testdir/file2.chk | _filter_test_dir
65 md5sum $testdir/file3.chk | _filter_test_dir
66
67 c1=$(_md5_checksum $testdir/file1)
68 c2=$(_md5_checksum $testdir/file2)
69 c3=$(_md5_checksum $testdir/file3)
70
71 test ${c1} = ${c2} || echo "file1 and file2 should match"
72 test ${c1} = ${c3} || echo "file1 and file3 should match"
73 test ${c2} = ${c3} || echo "file2 and file3 should match"
74
75 echo "truncate files"
76 $XFS_IO_PROG -f -c "truncate $((blksz + 34))" $testdir/file2
77 $XFS_IO_PROG -f -c "truncate $((blksz + 40))" $testdir/file3
78 _test_cycle_mount
79
80 echo "Compare files"
81 md5sum $testdir/file1 | _filter_test_dir
82 md5sum $testdir/file2 | _filter_test_dir
83 md5sum $testdir/file3 | _filter_test_dir
84 md5sum $testdir/file2.chk | _filter_test_dir
85 md5sum $testdir/file3.chk | _filter_test_dir
86
87 c1=$(_md5_checksum $testdir/file1)
88 c2=$(_md5_checksum $testdir/file2)
89 c3=$(_md5_checksum $testdir/file3)
90
91 test ${c1} != ${c2} || echo "file1 and file2 should not match"
92 test ${c1} != ${c3} || echo "file1 and file3 should not match"
93 test ${c2} != ${c3} || echo "file2 and file3 should not match"
94
95 echo "Compare against check files"
96 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk do not match"
97 cmp -s $testdir/file3 $testdir/file3.chk || echo "file3 and file3.chk do not match"
98
99 # success, all done
100 status=0
101 exit