xfs/{263,106}: erase max warnings printout
[xfstests-dev.git] / tests / btrfs / 112
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 112
6 #
7 # Test several cases of cloning inline extents that used to lead to file
8 # corruption or data loss.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
16
17 _cleanup()
18 {
19         cd /
20         rm -f $tmp.*
21 }
22
23 # get standard environment, filters and checks
24 . ./common/rc
25 . ./common/filter
26 . ./common/filter.btrfs
27
28 # real QA test starts here
29 _supported_fs btrfs
30 _supported_os Linux
31 _require_scratch
32 _require_cloner
33 _require_btrfs_fs_feature "no_holes"
34 _require_btrfs_mkfs_feature "no-holes"
35 _require_xfs_io_command "falloc"
36
37 rm -f $seqres.full
38
39 test_cloning_inline_extents()
40 {
41         local mkfs_opts=$1
42         local mount_opts=$2
43
44         _scratch_mkfs $mkfs_opts >>$seqres.full 2>&1
45         _scratch_mount $mount_opts
46
47         # File bar, the source for all the following clone operations, consists
48         # of a single inline extent (50 bytes).
49         $XFS_IO_PROG -f -c "pwrite -S 0xbb 0 50" $SCRATCH_MNT/bar \
50                 | _filter_xfs_io
51
52         # Test cloning into a file with an extent (non-inlined) where the
53         # destination offset overlaps that extent. It should not be possible to
54         # clone the inline extent from file bar into this file.
55         $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 16K" $SCRATCH_MNT/foo \
56                 | _filter_xfs_io
57         $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo \
58                 | _filter_btrfs_cloner_error
59
60         # Doing IO against any range in the first 4K of the file should work.
61         # Due to a past clone ioctl bug which allowed cloning the inline extent,
62         # these operations resulted in EIO errors.
63         echo "File foo data after clone operation:"
64         # All bytes should have the value 0xaa (clone operation failed and did
65         # not modify our file).
66         od -t x1 $SCRATCH_MNT/foo
67         $XFS_IO_PROG -c "pwrite -S 0xcc 0 100" $SCRATCH_MNT/foo | _filter_xfs_io
68
69         # Test cloning the inline extent against a file which has a hole in its
70         # first 4K followed by a non-inlined extent. It should not be possible
71         # as well to clone the inline extent from file bar into this file.
72         $XFS_IO_PROG -f -c "pwrite -S 0xdd 4K 12K" $SCRATCH_MNT/foo2 \
73                 | _filter_xfs_io
74         $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo2 \
75                 | _filter_btrfs_cloner_error
76
77         # Doing IO against any range in the first 4K of the file should work.
78         # Due to a past clone ioctl bug which allowed cloning the inline extent,
79         # these operations resulted in EIO errors.
80         echo "File foo2 data after clone operation:"
81         # All bytes should have the value 0x00 (clone operation failed and did
82         # not modify our file).
83         od -t x1 $SCRATCH_MNT/foo2
84         $XFS_IO_PROG -c "pwrite -S 0xee 0 90" $SCRATCH_MNT/foo2 | _filter_xfs_io
85
86         # Test cloning the inline extent against a file which consists of a
87         # single inline extent that has a size not greater than the size of
88         # bar's inline extent (40 < 50).
89         # It should be possible to do the extent cloning from bar to this file.
90         $XFS_IO_PROG -f -c "pwrite -S 0x01 0 40" $SCRATCH_MNT/foo4 \
91                 | _filter_xfs_io
92         $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo4 \
93                 | _filter_btrfs_cloner_error
94
95         # Doing IO against any range in the first 4K of the file should work.
96         echo "File foo4 data after clone operation:"
97         # Must match file bar's content.
98         od -t x1 $SCRATCH_MNT/foo4
99         $XFS_IO_PROG -c "pwrite -S 0x02 0 90" $SCRATCH_MNT/foo4 | _filter_xfs_io
100
101         # Test cloning the inline extent against a file which consists of a
102         # single inline extent that has a size greater than the size of bar's
103         # inline extent (60 > 50).
104         # It should not be possible to clone the inline extent from file bar
105         # into this file.
106         $XFS_IO_PROG -f -c "pwrite -S 0x03 0 60" $SCRATCH_MNT/foo5 \
107                 | _filter_xfs_io
108         $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo5 \
109                 | _filter_btrfs_cloner_error
110
111         # Reading the file should not fail.
112         echo "File foo5 data after clone operation:"
113         # Must have a size of 60 bytes, with all bytes having a value of 0x03
114         # (the clone operation failed and did not modify our file).
115         od -t x1 $SCRATCH_MNT/foo5
116
117         # Test cloning the inline extent against a file which has no extents but
118         # has a size greater than bar's inline extent (16K > 50).
119         # It should not be possible to clone the inline extent from file bar
120         # into this file.
121         $XFS_IO_PROG -f -c "truncate 16K" $SCRATCH_MNT/foo6 | _filter_xfs_io
122         $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo6 \
123                 | _filter_btrfs_cloner_error
124
125         # Reading the file should not fail.
126         echo "File foo6 data after clone operation:"
127         # Must have a size of 16K, with all bytes having a value of 0x00 (the
128         # clone operation failed and did not modify our file).
129         od -t x1 $SCRATCH_MNT/foo6
130
131         # Test cloning the inline extent against a file which has no extents but
132         # has a size not greater than bar's inline extent (30 < 50).
133         # It should be possible to clone the inline extent from file bar into
134         # this file.
135         $XFS_IO_PROG -f -c "truncate 30" $SCRATCH_MNT/foo7 | _filter_xfs_io
136         $CLONER_PROG -s 0 -d 0 -l 0 $SCRATCH_MNT/bar $SCRATCH_MNT/foo7 \
137                 | _filter_btrfs_cloner_error
138
139         # Reading the file should not fail.
140         echo "File foo7 data after clone operation:"
141         # Must have a size of 50 bytes, with all bytes having a value of 0xbb.
142         od -t x1 $SCRATCH_MNT/foo7
143
144         _scratch_unmount
145 }
146
147 echo -e "\nTesting without compression and without the no-holes feature...\n"
148 test_cloning_inline_extents
149
150 echo -e "\nTesting with compression and without the no-holes feature...\n"
151 test_cloning_inline_extents "" "-o compress"
152
153 echo -e "\nTesting without compression and with the no-holes feature...\n"
154 test_cloning_inline_extents "-O no-holes" ""
155
156 echo -e "\nTesting with compression and with the no-holes feature...\n"
157 test_cloning_inline_extents "-O no-holes" "-o compress"
158
159 status=0
160 exit