1#!/bin/sh
2# $FreeBSD$
3
4. $(atf_get_srcdir)/conf.sh
5
6atf_test_case online_resize cleanup
7online_resize_head()
8{
9	atf_set "descr" "online resize of geli providers"
10	atf_set "require.user" "root"
11}
12online_resize_body()
13{
14	geli_test_setup
15
16	(
17		echo "m 512 none 10485248 1 1 20971008 1 1 31456768 1 1"
18		echo "m 4096 none 10481664 1 1 20967424 1 1 31453184 1 1"
19		echo "m 512 HMAC/SHA256 5242368 1 1 10485248 1 1 15728128 1 1"
20		echo "m 4096 HMAC/SHA256 9318400 1 1 18640896 1 1 27959296 1 1"
21		echo "p 512 none 11258999068425728 [0-9] 20971520 22517998136851968 [0-9] 41943040 33776997205278208 [0-9] 62914560"
22		echo "p 4096 none 11258999068422144 [0-9] 2621440 22517998136848384 [0-9] 5242880 33776997205274624 [0-9] 7864320"
23		echo "p 512 HMAC/SHA256 5629499534212608 [0-9] 20971520 11258999068425728 [0-9] 41943040 16888498602638848 [0-9] 62914560"
24		echo "p 4096 HMAC/SHA256 10007999171932160 [0-9] 20971520 20015998343868416 [0-9] 41943040 30023997515800576 [0-9] 62914560"
25	) | while read prefix sector auth esize10 ka10 kt10 esize20 ka20 kt20 esize30 ka30 kt30; do
26		if [ "${auth}" = "none" ]; then
27			aalgo=""
28			eflags="0x200"
29			dflags="0x0"
30		else
31			aalgo="-a ${auth}"
32			eflags="0x210"
33			dflags="0x10"
34		fi
35
36		if [ "${prefix}" = "m" ]; then
37			psize10="10485760"
38			psize20="20971520"
39			psize30="31457280"
40		else
41			psize10="11258999068426240"
42			psize20="22517998136852480"
43			psize30="33776997205278720"
44		fi
45
46		md=$(attach_md -t malloc -s40${prefix})
47
48		# Initialise
49		atf_check -s exit:0 -o ignore gpart create -s GPT ${md}
50		atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs -s 10${prefix} ${md}
51
52		echo secret >tmp.key
53
54		atf_check geli init ${aalgo} -s ${sector} -Bnone -PKtmp.key ${md}p1
55		# Autoresize is set by default.
56		atf_check -s exit:0 -o match:"flags: ${eflags}$" geli dump ${md}p1
57
58		atf_check geli configure -R ${md}p1
59		atf_check -s exit:0 -o match:"flags: ${dflags}$" geli dump ${md}p1
60		atf_check geli configure -r ${md}p1
61		atf_check -s exit:0 -o match:"flags: ${eflags}$" geli dump ${md}p1
62
63		atf_check geli init -R ${aalgo} -s ${sector} -Bnone -PKtmp.key ${md}p1
64		atf_check -s exit:0 -o match:"flags: ${dflags}$" geli dump ${md}p1
65
66		atf_check geli configure -r ${md}p1
67		atf_check -s exit:0 -o match:"flags: ${eflags}$" geli dump ${md}p1
68		atf_check geli configure -R ${md}p1
69		atf_check -s exit:0 -o match:"flags: ${dflags}$" geli dump ${md}p1
70
71		atf_check geli init ${aalgo} -s ${sector} -Bnone -PKtmp.key ${md}p1
72		atf_check geli attach -pk tmp.key ${md}p1
73		atf_check -s exit:0 -o match:'^Flags: .*AUTORESIZE' geli list ${md}p1.eli
74		atf_check geli configure -R ${md}p1
75		atf_check -s exit:0 -o match:"flags: ${dflags}$" geli dump ${md}p1
76		atf_check -o not-match:'^Flags: .*AUTORESIZE' geli list ${md}p1.eli
77		atf_check geli configure -r ${md}p1
78		atf_check -s exit:0 -o match:"flags: ${eflags}$" geli dump ${md}p1
79		atf_check -s exit:0 -o match:'^Flags: .*AUTORESIZE' geli list ${md}p1.eli
80
81		atf_check geli configure -R ${md}p1
82		atf_check -s exit:0 -o match:"provsize: ${psize10}$" geli dump ${md}p1
83		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 20${prefix} ${md}
84		# Autoresize turned off - we lose metadata.
85		atf_check -s exit:1 -o empty -e ignore geli dump ${md}p1
86		atf_check geli detach ${md}p1.eli
87		# When we recover previous size, the metadata should be there.
88		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 10${prefix} ${md}
89		atf_check -s exit:0 -o match:"flags: ${dflags}$" geli dump ${md}p1
90
91		atf_check geli configure -r ${md}p1
92		atf_check geli attach -pk tmp.key ${md}p1
93		atf_check -s exit:0 -o match:"^[[:space:]]${esize10}[[:space:]]+# mediasize in bytes" diskinfo -v ${md}p1.eli
94		atf_check -s exit:0 -o match:"^KeysAllocated: ${ka10}$" geli list ${md}p1.eli
95		atf_check -s exit:0 -o match:"^KeysTotal: ${kt10}$" geli list ${md}p1.eli
96
97		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 20${prefix} ${md}
98		atf_check -s exit:0 -o match:"provsize: ${psize20}$" geli dump ${md}p1
99		atf_check -s exit:0 -o match:"^[[:space:]]${esize20}[[:space:]]+# mediasize in bytes" diskinfo -v ${md}p1.eli
100		atf_check -s exit:0 -o match:"^KeysAllocated: ${ka20}$" geli list ${md}p1.eli
101		atf_check -s exit:0 -o match:"^KeysTotal: ${kt20}$" geli list ${md}p1.eli
102		atf_check -s exit:0 -o match:"flags: ${eflags}$" geli dump ${md}p1
103		atf_check -s exit:0 -o match:'^Flags: .*AUTORESIZE' geli list ${md}p1.eli
104		if [ "${prefix}" = "m" ]; then
105			atf_check -s exit:1 -o empty -e match:"^${esize20} bytes transferred " dd if=/dev/random of=/dev/${md}p1.eli bs=1m
106			atf_check -s exit:0 -o empty -e match:"^${esize20} bytes transferred " dd if=/dev/${md}p1.eli of=/dev/null bs=1m
107		fi
108
109		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 30${prefix} ${md}
110		atf_check -s exit:0 -o match:"provsize: ${psize30}$" geli dump ${md}p1
111		atf_check -s exit:0 -o match:"^[[:space:]]${esize30}[[:space:]]+# mediasize in bytes" diskinfo -v ${md}p1.eli
112		atf_check -s exit:0 -o match:"^KeysAllocated: ${ka30}$" geli list ${md}p1.eli
113		atf_check -s exit:0 -o match:"^KeysTotal: ${kt30}$" geli list ${md}p1.eli
114		atf_check -s exit:0 -o match:"flags: ${eflags}$" geli dump ${md}p1
115		atf_check -s exit:0 -o match:'^Flags: .*AUTORESIZE' geli list ${md}p1.eli
116		if [ "${prefix}" = "m" ]; then
117			atf_check -s exit:1 -o empty -e match:"^${esize30} bytes transferred " dd if=/dev/random of=/dev/${md}p1.eli bs=1m
118			atf_check -s exit:0 -o empty -e match:"^${esize30} bytes transferred " dd if=/dev/${md}p1.eli of=/dev/null bs=1m
119		fi
120
121		atf_check geli detach ${md}p1.eli
122
123		# Make sure that the old metadata is removed.
124		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 20${prefix} ${md}
125		atf_check -s exit:1 -o empty -e ignore geli dump ${md}p1
126		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 10${prefix} ${md}
127		atf_check -s exit:1 -o empty -e ignore geli dump ${md}p1
128
129		# Test geli with onetime keys.
130		if [ "${auth}" = "none" ]; then
131			osize10="${psize10}"
132			osize20="${psize20}"
133			osize30="${psize30}"
134		else
135			osize10="${esize10}"
136			osize20="${esize20}"
137			osize30="${esize30}"
138			if [ "${sector}" -eq 512 ]; then
139				osize10=$((osize10+sector))
140				osize20=$((osize20+sector))
141				osize30=$((osize30+sector))
142			fi
143		fi
144		atf_check geli onetime ${aalgo} -s ${sector} ${md}p1
145		atf_check -s exit:0 -o match:"^[[:space:]]${osize10}[[:space:]]+# mediasize in bytes" diskinfo -v ${md}p1.eli
146		atf_check -s exit:0 -o match:'^Flags: .*AUTORESIZE' geli list ${md}p1.eli
147		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 20${prefix} ${md}
148		atf_check -s exit:0 -o match:"^[[:space:]]${osize20}[[:space:]]+# mediasize in bytes" diskinfo -v ${md}p1.eli
149		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 30${prefix} ${md}
150		atf_check -s exit:0 -o match:"^[[:space:]]${osize30}[[:space:]]+# mediasize in bytes" diskinfo -v ${md}p1.eli
151		atf_check geli detach ${md}p1.eli
152
153		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 10${prefix} ${md}
154		atf_check geli onetime -R ${aalgo} -s ${sector} ${md}p1
155		atf_check -s exit:0 -o match:"^[[:space:]]${osize10}[[:space:]]+# mediasize in bytes" diskinfo -v ${md}p1.eli
156		atf_check -o not-match:'^Flags: .*AUTORESIZE' geli list ${md}p1.eli
157		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 20${prefix} ${md}
158		atf_check -s exit:0 -o match:"^[[:space:]]${osize10}[[:space:]]+# mediasize in bytes" diskinfo -v ${md}p1.eli
159		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 30${prefix} ${md}
160		atf_check -s exit:0 -o match:"^[[:space:]]${osize10}[[:space:]]+# mediasize in bytes" diskinfo -v ${md}p1.eli
161		atf_check geli detach ${md}p1.eli
162
163		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 10${prefix} ${md}
164		atf_check geli onetime ${aalgo} -s ${sector} ${md}p1
165		atf_check -s exit:0 -o match:"^[[:space:]]${osize10}[[:space:]]+# mediasize in bytes" diskinfo -v ${md}p1.eli
166		atf_check -s exit:0 -o match:'^Flags: .*AUTORESIZE' geli list ${md}p1.eli
167		atf_check geli configure -R ${md}p1
168		atf_check -o not-match:'^Flags: .*AUTORESIZE' geli list ${md}p1.eli
169		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 20${prefix} ${md}
170		atf_check -s exit:0 -o match:"^[[:space:]]${osize10}[[:space:]]+# mediasize in bytes" diskinfo -v ${md}p1.eli
171		atf_check geli configure -r ${md}p1
172		atf_check -s exit:0 -o match:'^Flags: .*AUTORESIZE' geli list ${md}p1.eli
173		atf_check -s exit:0 -o match:resized gpart resize -i 1 -s 30${prefix} ${md}
174		atf_check -s exit:0 -o match:"^[[:space:]]${osize30}[[:space:]]+# mediasize in bytes" diskinfo -v ${md}p1.eli
175	done
176}
177online_resize_cleanup()
178{
179	if [ -f "$TEST_MDS_FILE" ]; then
180		while read md; do
181			atf_check -s ignore -e ignore -o ignore geli detach ${md}p1.eli
182			atf_check -s ignore -e ignore -o ignore gpart delete -i 1 ${md}
183			atf_check -s ignore -e ignore -o ignore gpart destroy ${md}
184		done < $TEST_MDS_FILE
185	fi
186	geli_test_cleanup
187}
188
189atf_init_test_cases()
190{
191	atf_add_test_case online_resize
192}
193