7294f231e4ed0a327cce4c23129275fdc856b328
[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 _supported_os Linux
37 _require_test
38 _require_scratch
39 _require_btrfs_command "property"
40 _require_btrfs_command inspect-internal dump-super
41
42 send_files_dir=$TEST_DIR/btrfs-test-$seq
43
44 rm -f $seqres.full
45 rm -fr $send_files_dir
46 mkdir $send_files_dir
47
48 _scratch_mkfs >/dev/null 2>&1
49 _scratch_mount
50
51 echo "Testing label property"
52 $BTRFS_UTIL_PROG property get $SCRATCH_MNT label
53 echo "***"
54 $BTRFS_UTIL_PROG property set $SCRATCH_MNT label foobar
55 $BTRFS_UTIL_PROG property get $SCRATCH_MNT label
56 echo "***"
57 $BTRFS_UTIL_PROG property get $SCRATCH_MNT
58 echo "***"
59 $BTRFS_UTIL_PROG property set $SCRATCH_MNT label ''
60 $BTRFS_UTIL_PROG property get $SCRATCH_MNT label
61 echo "***"
62 mkdir $SCRATCH_MNT/testdir
63 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir label 2>&1 |
64         _filter_btrfs_prop_error label
65 echo "***"
66
67 echo -e "\nTesting subvolume ro property"
68 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/sv1
69 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 ro
70 echo "***"
71 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro foo 2>&1 |
72         _filter_btrfs_prop_error
73 echo "***"
74 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro true
75 echo "***"
76 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 ro
77 echo "***"
78 touch $SCRATCH_MNT/sv1/foobar 2>&1 | _filter_scratch
79 echo "***"
80 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro false
81 touch $SCRATCH_MNT/sv1/foobar 2>&1 | _filter_scratch
82 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1
83 echo "***"
84
85 echo -e "\nTesting compression property"
86 mkdir $SCRATCH_MNT/testdir/subdir1
87 touch $SCRATCH_MNT/testdir/file1
88 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
89 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
90 echo "***"
91 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression \
92         foo 2>&1 | _filter_scratch |
93         _filter_btrfs_prop_error SCRATCH_MNT/testdir/file1
94 echo "***"
95 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression lzo
96 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
97
98 # Verify property was persisted.
99 _scratch_unmount
100 _check_scratch_fs
101 _scratch_mount
102 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
103 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression zlib
104 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
105 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression ''
106 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
107
108 # Test compression property inheritance.
109 echo "***"
110 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression lzo
111 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
112 echo "***"
113 mkdir $SCRATCH_MNT/testdir/subdir1/subsubdir
114 touch $SCRATCH_MNT/testdir/subdir1/some_file
115 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
116 echo "***"
117 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
118 echo "***"
119 mkdir $SCRATCH_MNT/testdir/subdir1/subsubdir/foo
120 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir/foo \
121         compression
122 echo "***"
123
124 # Verify property was persisted.
125 _scratch_unmount
126 _check_scratch_fs
127 _scratch_mount
128 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
129 echo "***"
130 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir/foo \
131         compression
132 echo "***"
133 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
134 echo "***"
135 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1/subsubdir \
136         compression ''
137 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1/some_file \
138         compression ''
139 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression ''
140 echo "***"
141 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
142 echo "***"
143 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
144 echo "***"
145 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
146 echo "***"
147 touch $SCRATCH_MNT/testdir/subdir1/some_file_2
148 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file_2 \
149         compression
150 echo "***"
151
152 # Verify send is able to replicate properties.
153 echo -e "\nTesting properties with send"
154 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression lzo
155 touch $SCRATCH_MNT/testdir/subdir1/foobar
156 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
157 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/foobar compression
158 echo "***"
159
160 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
161 touch $SCRATCH_MNT/testdir/subdir1/foobar2
162 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
163
164 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
165 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
166         $SCRATCH_MNT/mysnap2
167
168 _scratch_unmount
169 _check_scratch_fs
170 _scratch_mkfs >/dev/null 2>&1
171 _scratch_mount
172
173 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
174 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
175 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1 compression
176 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1/foobar \
177         compression
178 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1/foobar2 \
179         compression
180 echo "***"
181
182 _scratch_unmount
183 _check_scratch_fs
184 _scratch_mkfs >/dev/null 2>&1
185 _scratch_mount
186
187 echo -e "\nTesting subvolume properties"
188 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lzo'
189 $BTRFS_UTIL_PROG property get $SCRATCH_MNT compression
190 echo "***"
191 touch $SCRATCH_MNT/file1
192 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/file1 compression
193 echo "***"
194 mkdir $SCRATCH_MNT/dir1
195 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1 compression
196 echo "***"
197 mkdir $SCRATCH_MNT/dir1/subdir1
198 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1/subdir1 compression
199 echo "***"
200 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/dir1/subdir1 compression 'zlib'
201 touch $SCRATCH_MNT/dir1/subdir1/foo
202 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1/subdir1/foo compression
203
204 echo -e "\nTesting subvolume property inheritance"
205 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/sv1
206 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 compression
207 touch $SCRATCH_MNT/sv1/file2
208 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1/file2 compression
209
210 echo -e "\nTesting argument validation, should fail"
211 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lz' 2>&1 | _filter_scratch
212 echo "***"
213 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zli' 2>&1 | _filter_scratch
214 echo "***"
215 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zst' 2>&1 | _filter_scratch
216
217 echo -e "\nTesting if property is persistent across failed validation"
218 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lzo'
219 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zli' 2>&1 | _filter_scratch
220 $BTRFS_UTIL_PROG property get $SCRATCH_MNT compression
221
222 echo -e "\nTesting generation is unchanged after failed validation"
223 $BTRFS_UTIL_PROG filesystem sync $SCRATCH_MNT
224 $BTRFS_UTIL_PROG inspect-internal dump-super $SCRATCH_DEV | grep '^generation'
225 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lz' 2>&1 | _filter_scratch
226 $BTRFS_UTIL_PROG filesystem sync $SCRATCH_MNT
227 $BTRFS_UTIL_PROG inspect-internal dump-super $SCRATCH_DEV | grep '^generation'
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