generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 136
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. 136
6 #
7 # Ensure that we can dedupe the last block of a file whose size isn't
8 # block-aligned.
9 #   - Create two 'a' files file whose size isn't block-aligned.
10 #   - Create two 'b' files file whose size isn't block-aligned.
11 #   - Dedupe the last block of file1 to the last block in file2 and file3.
12 #   - Check that files 1-2 match, and that 3-4 match.
13 #   - Check that the ends of 1-2 and 3-4 match, and that 1-3 don't match.
14 #
15 . ./common/preamble
16 _begin_fstest auto quick clone dedupe
17
18 # Override the default cleanup function.
19 _cleanup()
20 {
21     cd /
22     rm -rf $tmp.* $testdir
23 }
24
25 # Import common functions.
26 . ./common/filter
27 . ./common/reflink
28
29 # real QA test starts here
30 _require_test_dedupe
31
32 testdir=$TEST_DIR/test-$seq
33 rm -rf $testdir
34 mkdir $testdir
35
36 echo "Create the original files"
37 blksz=65536
38 _pwrite_byte 0x61 0 $((blksz + 37)) $testdir/file1 >> $seqres.full
39 _pwrite_byte 0x61 0 $((blksz + 37)) $testdir/file2 >> $seqres.full
40 _pwrite_byte 0x62 0 $((blksz + 37)) $testdir/file3 >> $seqres.full
41 _pwrite_byte 0x62 0 $((blksz + 37)) $testdir/file4 >> $seqres.full
42 _test_cycle_mount
43
44 md5sum $testdir/file1 | _filter_test_dir
45 md5sum $testdir/file2 | _filter_test_dir
46 md5sum $testdir/file3 | _filter_test_dir
47 md5sum $testdir/file4 | _filter_test_dir
48
49 c1="$(_md5_checksum $testdir/file1)"
50 c2="$(_md5_checksum $testdir/file2)"
51 c3="$(_md5_checksum $testdir/file3)"
52 c4="$(_md5_checksum $testdir/file4)"
53
54 test ${c1} = ${c2} || echo "file1 and file2 should match"
55 test ${c1} != ${c3} || echo "file1 and file3 should not match"
56 test ${c1} != ${c4} || echo "file1 and file4 should not match"
57 test ${c2} != ${c3} || echo "file2 and file3 should not match"
58 test ${c2} != ${c4} || echo "file2 and file4 should not match"
59 test ${c3} = ${c4} || echo "file3 and file4 should match"
60
61 echo "Dedupe the last blocks together"
62 echo "1->2"
63 _dedupe_range $testdir/file1 $blksz $testdir/file2 $blksz 37 >> $seqres.full
64 echo "1->3"
65 _dedupe_range $testdir/file1 $blksz $testdir/file3 $blksz 37 2>&1 | _filter_dedupe_error
66 _test_cycle_mount
67
68 md5sum $testdir/file1 | _filter_test_dir
69 md5sum $testdir/file2 | _filter_test_dir
70 md5sum $testdir/file3 | _filter_test_dir
71 md5sum $testdir/file4 | _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 echo "Compare files"
79 test ${c1} = ${c2} || echo "file1 and file2 should match"
80 test ${c1} != ${c3} || echo "file1 and file3 should not match"
81 test ${c1} != ${c4} || echo "file1 and file4 should not match"
82 test ${c2} != ${c3} || echo "file2 and file3 should not match"
83 test ${c2} != ${c4} || echo "file2 and file4 should not match"
84 test ${c3} = ${c4} || echo "file3 and file4 should match"
85
86 echo "Compare sections"
87 _compare_range $testdir/file1 $blksz $testdir/file2 $blksz 37 \
88        || echo "End sections of files 1-2 do not match"
89
90 _compare_range $testdir/file1 $blksz $testdir/file3 $blksz 37 \
91        || echo "End sections of files 1-3 do not match (intentional)"
92
93 _compare_range $testdir/file1 $blksz $testdir/file4 $blksz 37 \
94        || echo "End sections of files 1-4 do not match (intentional)"
95
96 _compare_range $testdir/file2 $blksz $testdir/file3 $blksz 37 \
97        || echo "End sections of files 2-3 do not match (intentional)"
98
99 _compare_range $testdir/file2 $blksz $testdir/file4 $blksz 37 \
100        || echo "End sections of files 2-4 do not match (intentional)"
101
102 _compare_range $testdir/file3 $blksz $testdir/file4 $blksz 37 \
103        || echo "End sections of files 3-4 do not match"
104
105 # success, all done
106 status=0
107 exit