btrfs/048: user filter for property error messages
[xfstests-dev.git] / tests / btrfs / 048
1 #! /bin/bash
2 # FS QA Test No. btrfs/048
3 #
4 # Btrfs properties test. The btrfs properties feature was introduced in the
5 # linux kernel 3.14.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     rm -fr $send_files_dir
38     rm -fr $tmp
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44 . ./common/filter.btrfs
45
46 # real QA test starts here
47 _supported_fs btrfs
48 _supported_os Linux
49 _require_test
50 _require_scratch
51 _require_btrfs "property"
52
53 send_files_dir=$TEST_DIR/btrfs-test-$seq
54
55 rm -f $seqres.full
56 rm -fr $send_files_dir
57 mkdir $send_files_dir
58
59 _scratch_mkfs >/dev/null 2>&1
60 _scratch_mount
61
62 echo "Testing label property"
63 $BTRFS_UTIL_PROG property get $SCRATCH_MNT label
64 echo "***"
65 $BTRFS_UTIL_PROG property set $SCRATCH_MNT label foobar
66 $BTRFS_UTIL_PROG property get $SCRATCH_MNT label
67 echo "***"
68 $BTRFS_UTIL_PROG property get $SCRATCH_MNT
69 echo "***"
70 $BTRFS_UTIL_PROG property set $SCRATCH_MNT label ''
71 $BTRFS_UTIL_PROG property get $SCRATCH_MNT label
72 echo "***"
73 mkdir $SCRATCH_MNT/testdir
74 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir label 2>&1 |
75         _filter_btrfs_prop_error label
76 echo "***"
77
78 echo -e "\nTesting subvolume ro property"
79 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/sv1
80 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 ro
81 echo "***"
82 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro foo
83 echo "***"
84 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro true
85 echo "***"
86 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 ro
87 echo "***"
88 touch $SCRATCH_MNT/sv1/foobar 2>&1 | _filter_scratch
89 echo "***"
90 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro false
91 touch $SCRATCH_MNT/sv1/foobar 2>&1 | _filter_scratch
92 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1
93 echo "***"
94
95 echo -e "\nTesting compression property"
96 mkdir $SCRATCH_MNT/testdir/subdir1
97 touch $SCRATCH_MNT/testdir/file1
98 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
99 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
100 echo "***"
101 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression \
102         foo 2>&1 | _filter_scratch
103 echo "***"
104 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression lzo
105 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
106
107 # Verify property was persisted.
108 _scratch_unmount
109 _check_scratch_fs
110 _scratch_mount
111 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
112 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression zlib
113 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
114 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression ''
115 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
116
117 # Test compression property inheritance.
118 echo "***"
119 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression lzo
120 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
121 echo "***"
122 mkdir $SCRATCH_MNT/testdir/subdir1/subsubdir
123 touch $SCRATCH_MNT/testdir/subdir1/some_file
124 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
125 echo "***"
126 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
127 echo "***"
128 mkdir $SCRATCH_MNT/testdir/subdir1/subsubdir/foo
129 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir/foo \
130         compression
131 echo "***"
132
133 # Verify property was persisted.
134 _scratch_unmount
135 _check_scratch_fs
136 _scratch_mount
137 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
138 echo "***"
139 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir/foo \
140         compression
141 echo "***"
142 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
143 echo "***"
144 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1/subsubdir \
145         compression ''
146 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1/some_file \
147         compression ''
148 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression ''
149 echo "***"
150 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
151 echo "***"
152 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
153 echo "***"
154 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
155 echo "***"
156 touch $SCRATCH_MNT/testdir/subdir1/some_file_2
157 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file_2 \
158         compression
159 echo "***"
160
161 # Verify send is able to replicate properties.
162 echo -e "\nTesting properties with send"
163 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression lzo
164 touch $SCRATCH_MNT/testdir/subdir1/foobar
165 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
166 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/foobar compression
167 echo "***"
168
169 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
170 touch $SCRATCH_MNT/testdir/subdir1/foobar2
171 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
172
173 _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $send_files_dir/1.snap
174 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
175         -f $send_files_dir/2.snap
176
177 _scratch_unmount
178 _check_scratch_fs
179 _scratch_mkfs >/dev/null 2>&1
180 _scratch_mount
181
182 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
183 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/2.snap
184 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1 compression
185 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1/foobar \
186         compression
187 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1/foobar2 \
188         compression
189 echo "***"
190
191 _scratch_unmount
192 _check_scratch_fs
193 _scratch_mkfs >/dev/null 2>&1
194 _scratch_mount
195
196 echo -e "\nTesting subvolume properties"
197 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lzo'
198 $BTRFS_UTIL_PROG property get $SCRATCH_MNT compression
199 echo "***"
200 touch $SCRATCH_MNT/file1
201 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/file1 compression
202 echo "***"
203 mkdir $SCRATCH_MNT/dir1
204 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1 compression
205 echo "***"
206 mkdir $SCRATCH_MNT/dir1/subdir1
207 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1/subdir1 compression
208 echo "***"
209 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/dir1/subdir1 compression 'zlib'
210 touch $SCRATCH_MNT/dir1/subdir1/foo
211 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1/subdir1/foo compression
212
213 echo -e "\nTesting subvolume property inheritance"
214 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/sv1
215 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 compression
216 touch $SCRATCH_MNT/sv1/file2
217 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1/file2 compression
218
219 status=0
220 exit