xfs: Add test for too-small device with stripe geometry
[xfstests-dev.git] / tests / btrfs / 048
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/048
6 #
7 # Btrfs properties test. The btrfs properties feature was introduced in the
8 # linux kernel 3.14.
9 # Fails without the kernel patches:
10 #  btrfs: fix vanished compression property after failed set
11 #  btrfs: fix zstd compression parameter
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19
20 status=1        # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25     rm -fr $send_files_dir
26     rm -fr $tmp
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32 . ./common/filter.btrfs
33
34 # real QA test starts here
35 _supported_fs btrfs
36 _require_test
37 _require_scratch
38 _require_btrfs_command "property"
39 _require_btrfs_command inspect-internal dump-super
40
41 send_files_dir=$TEST_DIR/btrfs-test-$seq
42
43 rm -f $seqres.full
44 rm -fr $send_files_dir
45 mkdir $send_files_dir
46
47 _scratch_mkfs >/dev/null 2>&1
48 _scratch_mount
49
50 echo "Testing label property"
51 $BTRFS_UTIL_PROG property get $SCRATCH_MNT label
52 echo "***"
53 $BTRFS_UTIL_PROG property set $SCRATCH_MNT label foobar
54 $BTRFS_UTIL_PROG property get $SCRATCH_MNT label
55 echo "***"
56 $BTRFS_UTIL_PROG property get $SCRATCH_MNT
57 echo "***"
58 $BTRFS_UTIL_PROG property set $SCRATCH_MNT label ''
59 $BTRFS_UTIL_PROG property get $SCRATCH_MNT label
60 echo "***"
61 mkdir $SCRATCH_MNT/testdir
62 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir label 2>&1 |
63         _filter_btrfs_prop_error label
64 echo "***"
65
66 echo -e "\nTesting subvolume ro property"
67 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/sv1
68 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 ro
69 echo "***"
70 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro foo 2>&1 |
71         _filter_btrfs_prop_error
72 echo "***"
73 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro true
74 echo "***"
75 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 ro
76 echo "***"
77 touch $SCRATCH_MNT/sv1/foobar 2>&1 | _filter_scratch
78 echo "***"
79 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro false
80 touch $SCRATCH_MNT/sv1/foobar 2>&1 | _filter_scratch
81 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1
82 echo "***"
83
84 echo -e "\nTesting compression property"
85 mkdir $SCRATCH_MNT/testdir/subdir1
86 touch $SCRATCH_MNT/testdir/file1
87 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
88 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
89 echo "***"
90 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression \
91         foo 2>&1 | _filter_scratch |
92         _filter_btrfs_prop_error SCRATCH_MNT/testdir/file1
93 echo "***"
94 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression lzo
95 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
96
97 # Verify property was persisted.
98 _scratch_unmount
99 _check_scratch_fs
100 _scratch_mount
101 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
102 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression zlib
103 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
104 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression ''
105 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
106
107 # Test compression property inheritance.
108 echo "***"
109 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression lzo
110 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
111 echo "***"
112 mkdir $SCRATCH_MNT/testdir/subdir1/subsubdir
113 touch $SCRATCH_MNT/testdir/subdir1/some_file
114 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
115 echo "***"
116 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
117 echo "***"
118 mkdir $SCRATCH_MNT/testdir/subdir1/subsubdir/foo
119 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir/foo \
120         compression
121 echo "***"
122
123 # Verify property was persisted.
124 _scratch_unmount
125 _check_scratch_fs
126 _scratch_mount
127 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
128 echo "***"
129 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir/foo \
130         compression
131 echo "***"
132 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
133 echo "***"
134 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1/subsubdir \
135         compression ''
136 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1/some_file \
137         compression ''
138 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression ''
139 echo "***"
140 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
141 echo "***"
142 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
143 echo "***"
144 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
145 echo "***"
146 touch $SCRATCH_MNT/testdir/subdir1/some_file_2
147 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file_2 \
148         compression
149 echo "***"
150
151 # Verify send is able to replicate properties.
152 echo -e "\nTesting properties with send"
153 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression lzo
154 touch $SCRATCH_MNT/testdir/subdir1/foobar
155 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
156 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/foobar compression
157 echo "***"
158
159 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
160 touch $SCRATCH_MNT/testdir/subdir1/foobar2
161 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
162
163 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
164 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
165         $SCRATCH_MNT/mysnap2
166
167 _scratch_unmount
168 _check_scratch_fs
169 _scratch_mkfs >/dev/null 2>&1
170 _scratch_mount
171
172 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
173 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
174 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1 compression
175 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1/foobar \
176         compression
177 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1/foobar2 \
178         compression
179 echo "***"
180
181 _scratch_unmount
182 _check_scratch_fs
183 _scratch_mkfs >/dev/null 2>&1
184 _scratch_mount
185
186 echo -e "\nTesting subvolume properties"
187 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lzo'
188 $BTRFS_UTIL_PROG property get $SCRATCH_MNT compression
189 echo "***"
190 touch $SCRATCH_MNT/file1
191 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/file1 compression
192 echo "***"
193 mkdir $SCRATCH_MNT/dir1
194 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1 compression
195 echo "***"
196 mkdir $SCRATCH_MNT/dir1/subdir1
197 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1/subdir1 compression
198 echo "***"
199 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/dir1/subdir1 compression 'zlib'
200 touch $SCRATCH_MNT/dir1/subdir1/foo
201 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1/subdir1/foo compression
202
203 echo -e "\nTesting subvolume property inheritance"
204 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/sv1
205 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 compression
206 touch $SCRATCH_MNT/sv1/file2
207 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1/file2 compression
208
209 echo -e "\nTesting argument validation, should fail"
210 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lz' 2>&1 | _filter_scratch
211 echo "***"
212 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zli' 2>&1 | _filter_scratch
213 echo "***"
214 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zst' 2>&1 | _filter_scratch
215
216 echo -e "\nTesting if property is persistent across failed validation"
217 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lzo'
218 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zli' 2>&1 | _filter_scratch
219 $BTRFS_UTIL_PROG property get $SCRATCH_MNT compression
220
221 echo -e "\nTesting generation is unchanged after failed validation"
222 $BTRFS_UTIL_PROG filesystem sync $SCRATCH_MNT
223 gen_before=$($BTRFS_UTIL_PROG inspect-internal dump-super $SCRATCH_DEV | grep '^generation')
224 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lz' 2>&1 | _filter_scratch
225 $BTRFS_UTIL_PROG filesystem sync $SCRATCH_MNT
226 gen_after=$($BTRFS_UTIL_PROG inspect-internal dump-super $SCRATCH_DEV | grep '^generation')
227 [ "$gen_after" == "$gen_before" ] || echo "filesystem generation changed"
228
229 echo -e "\nTesting argument validation with options"
230 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zlib:3'
231 echo "***"
232 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zstd:0'
233 echo "***"
234
235 echo -e "\nTesting invalid argument validation with options, should fail"
236 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zl:9' 2>&1 | _filter_scratch
237 echo "***"
238 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zli:0' 2>&1 | _filter_scratch
239 echo "***"
240 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zst:3' 2>&1 | _filter_scratch
241
242 status=0
243 exit