generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
14 _begin_fstest auto quick
15
16 # Override the default cleanup function.
17 _cleanup()
18 {
19     rm -fr $send_files_dir
20     rm -fr $tmp
21 }
22
23 # Import common functions.
24 . ./common/filter
25 . ./common/filter.btrfs
26
27 # real QA test starts here
28 _supported_fs btrfs
29 _require_test
30 _require_scratch
31 _require_btrfs_command "property"
32 _require_btrfs_command inspect-internal dump-super
33
34 send_files_dir=$TEST_DIR/btrfs-test-$seq
35
36 rm -fr $send_files_dir
37 mkdir $send_files_dir
38
39 _scratch_mkfs >/dev/null 2>&1
40 _scratch_mount
41
42 echo "Testing label property"
43 $BTRFS_UTIL_PROG property get $SCRATCH_MNT label
44 echo "***"
45 $BTRFS_UTIL_PROG property set $SCRATCH_MNT label foobar
46 $BTRFS_UTIL_PROG property get $SCRATCH_MNT label
47 echo "***"
48 $BTRFS_UTIL_PROG property get $SCRATCH_MNT
49 echo "***"
50 $BTRFS_UTIL_PROG property set $SCRATCH_MNT label ''
51 $BTRFS_UTIL_PROG property get $SCRATCH_MNT label
52 echo "***"
53 mkdir $SCRATCH_MNT/testdir
54 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir label 2>&1 |
55         _filter_btrfs_prop_error label
56 echo "***"
57
58 echo -e "\nTesting subvolume ro property"
59 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/sv1
60 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 ro
61 echo "***"
62 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro foo 2>&1 |
63         _filter_btrfs_prop_error
64 echo "***"
65 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro true
66 echo "***"
67 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 ro
68 echo "***"
69 touch $SCRATCH_MNT/sv1/foobar 2>&1 | _filter_scratch
70 echo "***"
71 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro false
72 touch $SCRATCH_MNT/sv1/foobar 2>&1 | _filter_scratch
73 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1
74 echo "***"
75
76 echo -e "\nTesting compression property"
77 mkdir $SCRATCH_MNT/testdir/subdir1
78 touch $SCRATCH_MNT/testdir/file1
79 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
80 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
81 echo "***"
82 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression \
83         foo 2>&1 | _filter_scratch |
84         _filter_btrfs_prop_error SCRATCH_MNT/testdir/file1
85 echo "***"
86 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression lzo
87 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
88
89 # Verify property was persisted.
90 _scratch_unmount
91 _check_scratch_fs
92 _scratch_mount
93 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
94 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression zlib
95 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
96 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression ''
97 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
98
99 # Test compression property inheritance.
100 echo "***"
101 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression lzo
102 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
103 echo "***"
104 mkdir $SCRATCH_MNT/testdir/subdir1/subsubdir
105 touch $SCRATCH_MNT/testdir/subdir1/some_file
106 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
107 echo "***"
108 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
109 echo "***"
110 mkdir $SCRATCH_MNT/testdir/subdir1/subsubdir/foo
111 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir/foo \
112         compression
113 echo "***"
114
115 # Verify property was persisted.
116 _scratch_unmount
117 _check_scratch_fs
118 _scratch_mount
119 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
120 echo "***"
121 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir/foo \
122         compression
123 echo "***"
124 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
125 echo "***"
126 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1/subsubdir \
127         compression ''
128 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1/some_file \
129         compression ''
130 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression ''
131 echo "***"
132 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
133 echo "***"
134 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
135 echo "***"
136 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
137 echo "***"
138 touch $SCRATCH_MNT/testdir/subdir1/some_file_2
139 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file_2 \
140         compression
141 echo "***"
142
143 # Verify send is able to replicate properties.
144 echo -e "\nTesting properties with send"
145 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression lzo
146 touch $SCRATCH_MNT/testdir/subdir1/foobar
147 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
148 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/foobar compression
149 echo "***"
150
151 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
152 touch $SCRATCH_MNT/testdir/subdir1/foobar2
153 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
154
155 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
156 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
157         $SCRATCH_MNT/mysnap2
158
159 _scratch_unmount
160 _check_scratch_fs
161 _scratch_mkfs >/dev/null 2>&1
162 _scratch_mount
163
164 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
165 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
166 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1 compression
167 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1/foobar \
168         compression
169 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1/foobar2 \
170         compression
171 echo "***"
172
173 _scratch_unmount
174 _check_scratch_fs
175 _scratch_mkfs >/dev/null 2>&1
176 _scratch_mount
177
178 echo -e "\nTesting subvolume properties"
179 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lzo'
180 $BTRFS_UTIL_PROG property get $SCRATCH_MNT compression
181 echo "***"
182 touch $SCRATCH_MNT/file1
183 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/file1 compression
184 echo "***"
185 mkdir $SCRATCH_MNT/dir1
186 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1 compression
187 echo "***"
188 mkdir $SCRATCH_MNT/dir1/subdir1
189 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1/subdir1 compression
190 echo "***"
191 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/dir1/subdir1 compression 'zlib'
192 touch $SCRATCH_MNT/dir1/subdir1/foo
193 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1/subdir1/foo compression
194
195 echo -e "\nTesting subvolume property inheritance"
196 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/sv1
197 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 compression
198 touch $SCRATCH_MNT/sv1/file2
199 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1/file2 compression
200
201 echo -e "\nTesting argument validation, should fail"
202 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lz' 2>&1 | _filter_scratch
203 echo "***"
204 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zli' 2>&1 | _filter_scratch
205 echo "***"
206 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zst' 2>&1 | _filter_scratch
207
208 echo -e "\nTesting if property is persistent across failed validation"
209 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lzo'
210 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zli' 2>&1 | _filter_scratch
211 $BTRFS_UTIL_PROG property get $SCRATCH_MNT compression
212
213 echo -e "\nTesting generation is unchanged after failed validation"
214 $BTRFS_UTIL_PROG filesystem sync $SCRATCH_MNT
215 gen_before=$($BTRFS_UTIL_PROG inspect-internal dump-super $SCRATCH_DEV | grep '^generation')
216 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lz' 2>&1 | _filter_scratch
217 $BTRFS_UTIL_PROG filesystem sync $SCRATCH_MNT
218 gen_after=$($BTRFS_UTIL_PROG inspect-internal dump-super $SCRATCH_DEV | grep '^generation')
219 [ "$gen_after" == "$gen_before" ] || echo "filesystem generation changed"
220
221 echo -e "\nTesting argument validation with options"
222 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zlib:3'
223 echo "***"
224 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zstd:0'
225 echo "***"
226
227 echo -e "\nTesting invalid argument validation with options, should fail"
228 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zl:9' 2>&1 | _filter_scratch
229 echo "***"
230 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zli:0' 2>&1 | _filter_scratch
231 echo "***"
232 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zst:3' 2>&1 | _filter_scratch
233
234 status=0
235 exit