summaryrefslogtreecommitdiff
path: root/tests/btrfs/048
blob: 7816a9975cbb7f8c2ebcf9ee9a0f923374d837fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
#
# FS QA Test No. btrfs/048
#
# Btrfs properties test. The btrfs properties feature was introduced in the
# linux kernel 3.14.
# Fails without the kernel patches:
#  btrfs: fix vanished compression property after failed set
#  btrfs: fix zstd compression parameter
#
. ./common/preamble
_begin_fstest auto quick compress

# Override the default cleanup function.
_cleanup()
{
    rm -fr $send_files_dir
    rm -fr $tmp
}

# Import common functions.
. ./common/filter
. ./common/filter.btrfs

# real QA test starts here
_supported_fs btrfs
_require_test
_require_scratch
_require_btrfs_command "property"
_require_btrfs_command inspect-internal dump-super

send_files_dir=$TEST_DIR/btrfs-test-$seq

rm -fr $send_files_dir
mkdir $send_files_dir

_scratch_mkfs >/dev/null 2>&1
_scratch_mount

echo "Testing label property"
$BTRFS_UTIL_PROG property get $SCRATCH_MNT label
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT label foobar
$BTRFS_UTIL_PROG property get $SCRATCH_MNT label
echo "***"
$BTRFS_UTIL_PROG property get $SCRATCH_MNT
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT label ''
$BTRFS_UTIL_PROG property get $SCRATCH_MNT label
echo "***"
mkdir $SCRATCH_MNT/testdir
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir label 2>&1 |
	_filter_btrfs_prop_error label
echo "***"

echo -e "\nTesting subvolume ro property"
_run_btrfs_util_prog subvolume create $SCRATCH_MNT/sv1
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 ro
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro foo 2>&1 |
	_filter_btrfs_prop_error
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro true
echo "***"
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 ro
echo "***"
touch $SCRATCH_MNT/sv1/foobar 2>&1 | _filter_scratch
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/sv1 ro false
touch $SCRATCH_MNT/sv1/foobar 2>&1 | _filter_scratch
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1
echo "***"

echo -e "\nTesting compression property"
mkdir $SCRATCH_MNT/testdir/subdir1
touch $SCRATCH_MNT/testdir/file1
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression \
	foo 2>&1 | _filter_scratch |
	_filter_btrfs_prop_error SCRATCH_MNT/testdir/file1
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression lzo
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression

# Verify property was persisted.
_scratch_unmount
_check_scratch_fs
_scratch_mount
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression zlib
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/file1 compression ''
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/file1 compression

# Test compression property inheritance.
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression lzo
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
echo "***"
mkdir $SCRATCH_MNT/testdir/subdir1/subsubdir
touch $SCRATCH_MNT/testdir/subdir1/some_file
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
echo "***"
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
echo "***"
mkdir $SCRATCH_MNT/testdir/subdir1/subsubdir/foo
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir/foo \
	compression
echo "***"

# Verify property was persisted.
_scratch_unmount
_check_scratch_fs
_scratch_mount
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
echo "***"
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir/foo \
	compression
echo "***"
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1/subsubdir \
	compression ''
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1/some_file \
	compression ''
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression ''
echo "***"
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/subsubdir compression
echo "***"
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file compression
echo "***"
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
echo "***"
touch $SCRATCH_MNT/testdir/subdir1/some_file_2
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/some_file_2 \
	compression
echo "***"

# Verify send is able to replicate properties.
echo -e "\nTesting properties with send"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/testdir/subdir1 compression lzo
touch $SCRATCH_MNT/testdir/subdir1/foobar
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1 compression
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/testdir/subdir1/foobar compression
echo "***"

_run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
touch $SCRATCH_MNT/testdir/subdir1/foobar2
_run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2

_run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
_run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
	$SCRATCH_MNT/mysnap2

_scratch_unmount
_check_scratch_fs
_scratch_mkfs >/dev/null 2>&1
_scratch_mount

_run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
_run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1 compression
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1/foobar \
	compression
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/mysnap2/testdir/subdir1/foobar2 \
	compression
echo "***"

_scratch_unmount
_check_scratch_fs
_scratch_mkfs >/dev/null 2>&1
_scratch_mount

echo -e "\nTesting subvolume properties"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lzo'
$BTRFS_UTIL_PROG property get $SCRATCH_MNT compression
echo "***"
touch $SCRATCH_MNT/file1
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/file1 compression
echo "***"
mkdir $SCRATCH_MNT/dir1
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1 compression
echo "***"
mkdir $SCRATCH_MNT/dir1/subdir1
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1/subdir1 compression
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT/dir1/subdir1 compression 'zlib'
touch $SCRATCH_MNT/dir1/subdir1/foo
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/dir1/subdir1/foo compression

echo -e "\nTesting subvolume property inheritance"
_run_btrfs_util_prog subvolume create $SCRATCH_MNT/sv1
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1 compression
touch $SCRATCH_MNT/sv1/file2
$BTRFS_UTIL_PROG property get $SCRATCH_MNT/sv1/file2 compression

echo -e "\nTesting argument validation, should fail"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lz' 2>&1 | _filter_scratch
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zli' 2>&1 | _filter_scratch
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zst' 2>&1 | _filter_scratch

echo -e "\nTesting if property is persistent across failed validation"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lzo'
$BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zli' 2>&1 | _filter_scratch
$BTRFS_UTIL_PROG property get $SCRATCH_MNT compression

echo -e "\nTesting generation is unchanged after failed validation"
$BTRFS_UTIL_PROG filesystem sync $SCRATCH_MNT
gen_before=$($BTRFS_UTIL_PROG inspect-internal dump-super $SCRATCH_DEV | grep '^generation')
$BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'lz' 2>&1 | _filter_scratch
$BTRFS_UTIL_PROG filesystem sync $SCRATCH_MNT
gen_after=$($BTRFS_UTIL_PROG inspect-internal dump-super $SCRATCH_DEV | grep '^generation')
[ "$gen_after" == "$gen_before" ] || echo "filesystem generation changed"

echo -e "\nTesting argument validation with options"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zlib:3'
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zstd:0'
echo "***"

echo -e "\nTesting invalid argument validation with options, should fail"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zl:9' 2>&1 | _filter_scratch
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zli:0' 2>&1 | _filter_scratch
echo "***"
$BTRFS_UTIL_PROG property set $SCRATCH_MNT compression 'zst:3' 2>&1 | _filter_scratch

status=0
exit