common: Check fs consistency on TEST_DEV only when needed
[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
45 # real QA test starts here
46 _supported_fs btrfs
47 _supported_os Linux
48 _require_test
49 _require_scratch
50 _require_btrfs "property"
51 _need_to_be_root
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
75 echo "***"
76
77 echo -e "\nTesting subvolume ro property"
78 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/sv1
79 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 ro
80 echo "***"
81 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro foo
82 echo "***"
83 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro true
84 echo "***"
85 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 ro
86 echo "***"
87 touch $SCRATCH_MNT/sv1/foobar 2>&1 | _filter_scratch
88 echo "***"
89 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro false
90 touch $SCRATCH_MNT/sv1/foobar 2>&1 | _filter_scratch
91 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1
92 echo "***"
93
94 echo -e "\nTesting compression property"
95 mkdir $SCRATCH_MNT/testdir/subdir1
96 touch $SCRATCH_MNT/testdir/file1
97 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
98 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
99 echo "***"
100 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression \
101         foo 2>&1 | _filter_scratch
102 echo "***"
103 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression lzo
104 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
105
106 # Verify property was persisted.
107 _scratch_unmount
108 _check_scratch_fs
109 _scratch_mount
110 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
111 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression zlib
112 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
113 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression ''
114 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
115
116 # Test compression property inheritance.
117 echo "***"
118 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression lzo
119 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
120 echo "***"
121 mkdir $SCRATCH_MNT/testdir/subdir1/subsubdir
122 touch $SCRATCH_MNT/testdir/subdir1/some_file
123 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
124 echo "***"
125 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
126 echo "***"
127 mkdir $SCRATCH_MNT/testdir/subdir1/subsubdir/foo
128 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir/foo \
129         compression
130 echo "***"
131
132 # Verify property was persisted.
133 _scratch_unmount
134 _check_scratch_fs
135 _scratch_mount
136 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
137 echo "***"
138 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir/foo \
139         compression
140 echo "***"
141 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
142 echo "***"
143 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1/subsubdir \
144         compression ''
145 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1/some_file \
146         compression ''
147 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression ''
148 echo "***"
149 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
150 echo "***"
151 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
152 echo "***"
153 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
154 echo "***"
155 touch $SCRATCH_MNT/testdir/subdir1/some_file_2
156 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file_2 \
157         compression
158 echo "***"
159
160 # Verify send is able to replicate properties.
161 echo -e "\nTesting properties with send"
162 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression lzo
163 touch $SCRATCH_MNT/testdir/subdir1/foobar
164 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
165 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/foobar compression
166 echo "***"
167
168 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
169 touch $SCRATCH_MNT/testdir/subdir1/foobar2
170 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
171
172 _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $send_files_dir/1.snap
173 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
174         -f $send_files_dir/2.snap
175
176 _scratch_unmount
177 _check_scratch_fs
178 _scratch_mkfs >/dev/null 2>&1
179 _scratch_mount
180
181 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
182 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/2.snap
183 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1 compression
184 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1/foobar \
185         compression
186 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1/foobar2 \
187         compression
188 echo "***"
189
190 _scratch_unmount
191 _check_scratch_fs
192 _scratch_mkfs >/dev/null 2>&1
193 _scratch_mount
194
195 echo -e "\nTesting subvolume properties"
196 $BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lzo'
197 $BTRFS_UTIL_PROG property get $SCRATCH_MNT compression
198 echo "***"
199 touch $SCRATCH_MNT/file1
200 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/file1 compression
201 echo "***"
202 mkdir $SCRATCH_MNT/dir1
203 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1 compression
204 echo "***"
205 mkdir $SCRATCH_MNT/dir1/subdir1
206 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1/subdir1 compression
207 echo "***"
208 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/dir1/subdir1 compression 'zlib'
209 touch $SCRATCH_MNT/dir1/subdir1/foo
210 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1/subdir1/foo compression
211
212 echo -e "\nTesting subvolume property inheritance"
213 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/sv1
214 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 compression
215 touch $SCRATCH_MNT/sv1/file2
216 $BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1/file2 compression
217
218 status=0
219 exit