xref: /freebsd/tests/sys/geom/class/eli/resize_test.sh (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
1#!/bin/sh
2# $FreeBSD$
3
4. $(atf_get_srcdir)/conf.sh
5
6atf_test_case resize cleanup
7resize_head()
8{
9	atf_set "descr" "geli resize will resize a geli provider"
10	atf_set "require.user" "root"
11}
12resize_body()
13{
14	geli_test_setup
15
16	BLK=512
17	BLKS_PER_MB=2048
18
19	md=$(attach_md -t malloc -s40m)
20
21	# Initialise
22	atf_check -s exit:0 -o ignore gpart create -s BSD ${md}
23	atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs -s 10m ${md}
24
25	echo secret >tmp.key
26	atf_check geli init -Bnone -PKtmp.key ${md}a
27	atf_check geli attach -pk tmp.key ${md}a
28
29	atf_check -s exit:0 -o ignore newfs -U ${md}a.eli
30	atf_check -s exit:7 -o ignore fsck_ffs -Ffy ${md}a.eli
31
32	# Doing a backup, resize & restore must be forced (with -f) as geli
33	# verifies that the provider size in the metadata matches the consumer.
34
35	atf_check geli backup ${md}a tmp.meta
36	atf_check geli detach ${md}a.eli
37	atf_check -s exit:0 -o match:resized gpart resize -i1 -s 20m ${md}
38	atf_check -s not-exit:0 -e ignore geli attach -pktmp.key ${md}a
39	atf_check -s not-exit:0 -e ignore geli restore tmp.meta ${md}a
40	atf_check geli restore -f tmp.meta ${md}a
41	atf_check geli attach -pktmp.key ${md}a
42	atf_check -s exit:0 -o ignore growfs -y ${md}a.eli
43	atf_check -s exit:7 -o ignore fsck_ffs -Ffy ${md}a.eli
44
45	# Now do the resize properly
46
47	atf_check geli detach ${md}a.eli
48	atf_check -s exit:0 -o match:resized gpart resize -i1 -s 30m ${md}
49	atf_check geli resize -s20m ${md}a
50	atf_check -s not-exit:0 -e match:"Inconsistent provider.*metadata" \
51		geli resize -s20m ${md}a
52	atf_check geli attach -pktmp.key ${md}a
53	atf_check -s exit:0 -o ignore growfs -y ${md}a.eli
54	atf_check -s exit:7 -o ignore fsck_ffs -Ffy ${md}a.eli
55
56	atf_check geli detach ${md}a.eli
57	atf_check -s exit:0 -o ignore gpart destroy -F $md
58
59
60	# Verify that the man page example works, changing ada0 to $md,
61	# 1g to 20m, 2g to 30m and keyfile to tmp.key, and adding -B none
62	# to geli init.
63
64	atf_check -s exit:0 -o ignore gpart create -s GPT $md
65	atf_check -s exit:0 -o ignore gpart add -s 20m -t freebsd-ufs -i 1 $md
66	atf_check geli init -B none -K tmp.key -P ${md}p1
67	atf_check -s exit:0 -o match:resized gpart resize -s 30m -i 1 $md
68	atf_check geli resize -s 20m ${md}p1
69	atf_check geli attach -k tmp.key -p ${md}p1
70}
71resize_cleanup()
72{
73	if [ -f "$TEST_MDS_FILE" ]; then
74		while read md; do
75			[ -c /dev/${md}a.eli ] && \
76				geli detach ${md}a.eli 2>/dev/null
77			[ -c /dev/${md}p1.eli ] && \
78				geli detach ${md}p1.eli
79			[ -c /dev/${md}.eli ] && \
80				geli detach ${md}.eli 2>/dev/null
81			mdconfig -d -u $md 2>/dev/null
82		done < $TEST_MDS_FILE
83	fi
84}
85
86atf_init_test_cases()
87{
88	atf_add_test_case resize
89}
90