resize_test.sh revision 328811
1189251Ssam#!/bin/sh
2214734Srpaulo# $FreeBSD: stable/11/tests/sys/geom/class/eli/resize_test.sh 328811 2018-02-02 21:57:00Z asomers $
3289549Srpaulo
4189251Ssamatf_test_case resize cleanup
5252726Srpauloresize_head()
6252726Srpaulo{
7189251Ssam	atf_set "descr" "geli resize will resize a geli provider"
8189251Ssam	atf_set "require.user" "root"
9189251Ssam}
10189251Ssamresize_body()
11189251Ssam{
12189251Ssam	. $(atf_get_srcdir)/conf.sh
13281806Srpaulo	BLK=512
14189251Ssam	BLKS_PER_MB=2048
15189251Ssam
16189251Ssam	md=$(attach_md -t malloc -s40m)
17281806Srpaulo
18189251Ssam	# Initialise
19189251Ssam	atf_check -s exit:0 -o ignore gpart create -s BSD ${md}
20189251Ssam	atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs -s 10m ${md}
21337817Scy
22189251Ssam	echo secret >tmp.key
23189251Ssam	atf_check geli init -Bnone -PKtmp.key ${md}a
24189251Ssam	atf_check geli attach -pk tmp.key ${md}a
25189251Ssam
26189251Ssam	atf_check -s exit:0 -o ignore newfs -U ${md}a.eli
27289549Srpaulo	atf_check -s exit:7 -o ignore fsck_ffs -Ffy ${md}a.eli
28289549Srpaulo
29289549Srpaulo	# Doing a backup, resize & restore must be forced (with -f) as geli
30289549Srpaulo	# verifies that the provider size in the metadata matches the consumer.
31289549Srpaulo
32289549Srpaulo	atf_check geli backup ${md}a tmp.meta
33189251Ssam	atf_check geli detach ${md}a.eli
34189251Ssam	atf_check -s exit:0 -o match:resized gpart resize -i1 -s 20m ${md}
35214734Srpaulo	atf_check -s not-exit:0 -e ignore geli attach -pktmp.key ${md}a
36289549Srpaulo	atf_check -s not-exit:0 -e ignore geli restore tmp.meta ${md}a
37289549Srpaulo	atf_check geli restore -f tmp.meta ${md}a
38189251Ssam	atf_check geli attach -pktmp.key ${md}a
39337817Scy	atf_check -s exit:0 -o ignore growfs -y ${md}a.eli
40189251Ssam	atf_check -s exit:7 -o ignore fsck_ffs -Ffy ${md}a.eli
41337817Scy
42337817Scy	# Now do the resize properly
43337817Scy
44337817Scy	atf_check geli detach ${md}a.eli
45189251Ssam	atf_check -s exit:0 -o match:resized gpart resize -i1 -s 30m ${md}
46281806Srpaulo	atf_check geli resize -s20m ${md}a
47281806Srpaulo	atf_check -s not-exit:0 -e match:"Inconsistent provider.*metadata" \
48281806Srpaulo		geli resize -s20m ${md}a
49281806Srpaulo	atf_check geli attach -pktmp.key ${md}a
50281806Srpaulo	atf_check -s exit:0 -o ignore growfs -y ${md}a.eli
51281806Srpaulo	atf_check -s exit:7 -o ignore fsck_ffs -Ffy ${md}a.eli
52189251Ssam
53189251Ssam	atf_check geli detach ${md}a.eli
54281806Srpaulo	atf_check -s exit:0 -o ignore gpart destroy -F $md
55281806Srpaulo
56281806Srpaulo
57281806Srpaulo	# Verify that the man page example works, changing ada0 to $md,
58281806Srpaulo	# 1g to 20m, 2g to 30m and keyfile to tmp.key, and adding -B none
59281806Srpaulo	# to geli init.
60281806Srpaulo
61337817Scy	atf_check -s exit:0 -o ignore gpart create -s GPT $md
62346981Scy	atf_check -s exit:0 -o ignore gpart add -s 20m -t freebsd-ufs -i 1 $md
63346981Scy	atf_check geli init -B none -K tmp.key -P ${md}p1
64337817Scy	atf_check -s exit:0 -o match:resized gpart resize -s 30m -i 1 $md
65337817Scy	atf_check geli resize -s 20m ${md}p1
66337817Scy	atf_check geli attach -k tmp.key -p ${md}p1
67337817Scy}
68337817Scyresize_cleanup()
69337817Scy{
70337817Scy	. $(atf_get_srcdir)/conf.sh
71337817Scy
72337817Scy	if [ -f "$TEST_MDS_FILE" ]; then
73337817Scy		while read md; do
74337817Scy			[ -c /dev/${md}a.eli ] && \
75337817Scy				geli detach ${md}a.eli 2>/dev/null
76337817Scy			[ -c /dev/${md}p1.eli ] && \
77337817Scy				geli detach ${md}p1.eli
78337817Scy			[ -c /dev/${md}.eli ] && \
79337817Scy				geli detach ${md}.eli 2>/dev/null
80337817Scy			mdconfig -d -u $md 2>/dev/null
81337817Scy		done < $TEST_MDS_FILE
82337817Scy	fi
83337817Scy}
84337817Scy
85337817Scyatf_init_test_cases()
86337817Scy{
87337817Scy	atf_add_test_case resize
88337817Scy}
89337817Scy