generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 149
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. 813
6 #
7 # Ensure that zero-range steps around reflinked ranges:
8 #   - Create three reflink clones of a file
9 #   - Zero-range 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 zero
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 "fzero"
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 $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
41
42 _cp_reflink $testdir/file1 $testdir/file2
43 _cp_reflink $testdir/file1 $testdir/file3
44 _cp_reflink $testdir/file1 $testdir/file4
45
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
49
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
53
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
57 _test_cycle_mount
58
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
66
67 c1=$(_md5_checksum $testdir/file1)
68 c2=$(_md5_checksum $testdir/file2)
69 c3=$(_md5_checksum $testdir/file3)
70 c4=$(_md5_checksum $testdir/file4)
71
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"
78
79 echo "fzero files"
80 $XFS_IO_PROG -f -c "fzero 0 $blksz" $testdir/file2
81 $XFS_IO_PROG -f -c "fzero $blksz $blksz" $testdir/file3
82 $XFS_IO_PROG -f -c "fzero $((blksz * 2)) $blksz" $testdir/file4
83 _test_cycle_mount
84
85 echo "Compare files"
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
93
94 c1=$(_md5_checksum $testdir/file1)
95 c2=$(_md5_checksum $testdir/file2)
96 c3=$(_md5_checksum $testdir/file3)
97 c4=$(_md5_checksum $testdir/file4)
98
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"
105
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"
110
111 # success, all done
112 status=0
113 exit