btrfs/205: Ignore output of chattr command
[xfstests-dev.git] / tests / btrfs / 205
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 205
6 #
7 # Test several scenarios of cloning operations where the source range includes
8 # inline extents. They used to not be supported on btrfs because their
9 # implementation was not straightforward, and therefore these operations used
10 # to fail with errno EOPNOTSUPP on older kernels.
11 #
12 # Support for this was added by a patch with the following subject:
13 #
14 #   "Btrfs: implement full reflink support for inline extents"
15 #
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
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 -f $tmp.*
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 _supported_fs btrfs
36 _supported_os Linux
37 _require_scratch_reflink
38 _require_xfs_io_command "falloc" "-k"
39 _require_command "$CHATTR_PROG" chattr
40 _require_btrfs_fs_feature "no_holes"
41 _require_btrfs_mkfs_feature "no-holes"
42
43 run_tests()
44 {
45     rm -f $SCRATCH_MNT/foo* $SCRATCH_MNT/bar*
46
47     # File foo1 has an inline extent encoding 4K of data followed by a regular
48     # extent. It has a file size of 128K.
49     echo "Creating file foo1"
50     touch $SCRATCH_MNT/foo1
51     $CHATTR_PROG +c $SCRATCH_MNT/foo1 > /dev/null 2>&1
52     $XFS_IO_PROG -c "pwrite -S 0xab 0 4K" \
53                  -c "fsync" \
54                  -c "pwrite -S 0xab 4K 124K" \
55                  $SCRATCH_MNT/foo1 | _filter_xfs_io
56
57     # File bar1 has a single 128K extent, and a file size of 128K.
58     echo "Creating file bar1"
59     $XFS_IO_PROG -f -c "pwrite -S 0xcd 0 128K" $SCRATCH_MNT/bar1 | _filter_xfs_io
60
61     echo "Cloning foo1 into the end of bar1"
62     $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo1 0 128K 128K" $SCRATCH_MNT/bar1 \
63         | _filter_xfs_io
64
65     echo "File bar1 digest = $(_md5_checksum $SCRATCH_MNT/bar1)"
66
67     # File foo2 has an inline extent with 1000 bytes of data and it's followed
68     # by a regular extent of 60K. It has a file size of 64K.
69     echo "Creating file foo2"
70     $XFS_IO_PROG -f -c "pwrite -S 0xab 0 1000" \
71                  -c "fsync" \
72                  -c "falloc 0 4K" \
73                  -c "pwrite -S 0xab 4K 60K" \
74                  $SCRATCH_MNT/foo2 | _filter_xfs_io
75
76     # File bar2 has a regular extent of 64K and a file size of 64K too.
77     echo "Creating file bar2"
78     $XFS_IO_PROG -f -c "pwrite -S 0xcd 0 64K" $SCRATCH_MNT/bar2 | _filter_xfs_io
79
80     echo "Cloning foo2 into the end of bar2"
81     $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo2 0 64K 64K" $SCRATCH_MNT/bar2 \
82         | _filter_xfs_io
83
84     echo "File bar2 digest = $(_md5_checksum $SCRATCH_MNT/bar2)"
85
86     # File bar3 has a regular extent of 128K and a file size of 128K too.
87     echo "Creating file bar3"
88     $XFS_IO_PROG -f -c "pwrite -S 0xcd 0 128K" $SCRATCH_MNT/bar3 \
89         | _filter_xfs_io
90
91     echo "Cloning foo2 into the middle of bar3"
92     $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo2 0 64K 64K" $SCRATCH_MNT/bar3 \
93         | _filter_xfs_io
94
95     echo "File bar3 digest = $(_md5_checksum $SCRATCH_MNT/bar3)"
96
97     # File bar4 has a 64K hole at offset 0 followed by a 64K regular extent, and
98     # a file size of 128K.
99     echo "Creating file bar4"
100     $XFS_IO_PROG -f -c "pwrite -S 0xcd 64K 64K" $SCRATCH_MNT/bar4 | _filter_xfs_io
101
102     echo "Cloning foo1 into bar4"
103     $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo1 0 0 128K" $SCRATCH_MNT/bar4 \
104         | _filter_xfs_io
105
106     echo "File bar4 digest = $(_md5_checksum $SCRATCH_MNT/bar4)"
107
108     # File bar5 has a 1Mb prealloc extent at file offset 0 and a file size of 0.
109     echo "Creating file bar5"
110     $XFS_IO_PROG -f -c "falloc -k 0 1M" $SCRATCH_MNT/bar5
111
112     echo "Cloning foo1 into bar5"
113     $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo1 0 0 128K" $SCRATCH_MNT/bar5 \
114         | _filter_xfs_io
115
116     echo "File bar5 digest = $(_md5_checksum $SCRATCH_MNT/bar5)"
117
118     # File bar6 has an inline extent encoding 500 bytes of data followed by a
119     # prealloc extent of 1Mb at file offset 4K. The file size is 500 bytes.
120     echo "Creating file bar6"
121     $XFS_IO_PROG -f -c "pwrite -S 0xef 0 500" \
122                  -c "falloc -k 4K 1M" \
123                  $SCRATCH_MNT/bar6 | _filter_xfs_io
124
125     echo "Cloning foo1 into bar6"
126     $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo1 0 0 128K" $SCRATCH_MNT/bar6 \
127         | _filter_xfs_io
128
129     echo "File bar6 digest = $(_md5_checksum $SCRATCH_MNT/bar6)"
130
131     # File foo3 a single inline extent of 500 bytes.
132     echo "Creating file foo3"
133     $XFS_IO_PROG -f -c "pwrite -S 0xbf 0 500" $SCRATCH_MNT/foo3 | _filter_xfs_io
134
135     # File bar7 is an empty file, has no extents.
136     touch $SCRATCH_MNT/bar7
137
138     echo "Cloning foo3 into bar7"
139     $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo3" $SCRATCH_MNT/bar7 | _filter_xfs_io
140
141     echo "File bar7 digest = $(_md5_checksum $SCRATCH_MNT/bar7)"
142
143     # Unmount and mount again the filesystem. We want to verify the reflink
144     # operations were durably persisted.
145     _scratch_cycle_mount
146
147     echo "File digests after mounting again the filesystem:"
148     echo "File bar1 digest = $(_md5_checksum $SCRATCH_MNT/bar1)"
149     echo "File bar2 digest = $(_md5_checksum $SCRATCH_MNT/bar2)"
150     echo "File bar3 digest = $(_md5_checksum $SCRATCH_MNT/bar3)"
151     echo "File bar4 digest = $(_md5_checksum $SCRATCH_MNT/bar4)"
152     echo "File bar5 digest = $(_md5_checksum $SCRATCH_MNT/bar5)"
153     echo "File bar6 digest = $(_md5_checksum $SCRATCH_MNT/bar6)"
154     echo "File bar7 digest = $(_md5_checksum $SCRATCH_MNT/bar7)"
155 }
156
157 _scratch_mkfs "-O ^no-holes" >>$seqres.full 2>&1
158 _scratch_mount
159
160 echo
161 echo "Testing with defaults"
162 echo
163 run_tests
164
165 echo
166 echo "Testing with -o compress"
167 echo
168 _scratch_cycle_mount "compress"
169 run_tests
170
171 echo
172 echo "Testing with -o nodatacow"
173 echo
174 _scratch_cycle_mount "nodatacow"
175 run_tests
176
177 echo
178 echo "Testing with -O no-holes"
179 echo
180 _scratch_unmount
181 _scratch_mkfs "-O no-holes" >>$seqres.full 2>&1
182 _scratch_mount
183 run_tests
184
185 status=0
186 exit