generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 145
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. 145
6 #
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.
12 #
13 . ./common/preamble
14 _begin_fstest auto quick clone collapse
15
16 # Override the default cleanup function.
17 _cleanup()
18 {
19     cd /
20     rm -rf $tmp.* $testdir
21 }
22
23 # Import common functions.
24 . ./common/filter
25 . ./common/reflink
26
27 # real QA test starts here
28 _require_test_reflink
29 _require_cp_reflink
30 _require_xfs_io_command "falloc"
31 _require_xfs_io_command "fcollapse"
32
33 testdir=$TEST_DIR/test-$seq
34 rm -rf $testdir
35 mkdir $testdir
36
37 echo "Create the original files"
38 blksz=65536
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
42
43 _cp_reflink $testdir/file1 $testdir/file2
44 _cp_reflink $testdir/file1 $testdir/file3
45 _cp_reflink $testdir/file1 $testdir/file4
46
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
51
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
55
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
59
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
63 _test_cycle_mount
64
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
72
73 c1=$(_md5_checksum $testdir/file1)
74 c2=$(_md5_checksum $testdir/file2)
75 c3=$(_md5_checksum $testdir/file3)
76 c4=$(_md5_checksum $testdir/file4)
77
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"
84
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
89 _test_cycle_mount
90
91 echo "Compare files"
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
99
100 c1=$(_md5_checksum $testdir/file1)
101 c2=$(_md5_checksum $testdir/file2)
102 c3=$(_md5_checksum $testdir/file3)
103 c4=$(_md5_checksum $testdir/file4)
104
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"
111
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"
116
117 # success, all done
118 status=0
119 exit