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