xref: /freebsd/tests/sys/geom/class/eli/resize_test.sh (revision 96950419f15510287080c557174e0d8409f06956)
109d98641SEnji Cooper#!/bin/sh
209d98641SEnji Cooper
3cf551b8aSAlan Somers. $(atf_get_srcdir)/conf.sh
4cf551b8aSAlan Somers
5f397a004SAlan Somersatf_test_case resize cleanup
6f397a004SAlan Somersresize_head()
7f397a004SAlan Somers{
8f397a004SAlan Somers	atf_set "descr" "geli resize will resize a geli provider"
9f397a004SAlan Somers	atf_set "require.user" "root"
10f397a004SAlan Somers}
11f397a004SAlan Somersresize_body()
12f397a004SAlan Somers{
13cf551b8aSAlan Somers	geli_test_setup
14cf551b8aSAlan Somers
1509d98641SEnji Cooper	BLK=512
1609d98641SEnji Cooper	BLKS_PER_MB=2048
1709d98641SEnji Cooper
18*96950419SGleb Smirnoff	attach_md md -t malloc -s40m
1909d98641SEnji Cooper
2009d98641SEnji Cooper	# Initialise
21f397a004SAlan Somers	atf_check -s exit:0 -o ignore gpart create -s BSD ${md}
22f397a004SAlan Somers	atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs -s 10m ${md}
2309d98641SEnji Cooper
2409d98641SEnji Cooper	echo secret >tmp.key
25f397a004SAlan Somers	atf_check geli init -Bnone -PKtmp.key ${md}a
26f397a004SAlan Somers	atf_check geli attach -pk tmp.key ${md}a
2709d98641SEnji Cooper
28f397a004SAlan Somers	atf_check -s exit:0 -o ignore newfs -U ${md}a.eli
29f397a004SAlan Somers	atf_check -s exit:7 -o ignore fsck_ffs -Ffy ${md}a.eli
3009d98641SEnji Cooper
3109d98641SEnji Cooper	# Doing a backup, resize & restore must be forced (with -f) as geli
3209d98641SEnji Cooper	# verifies that the provider size in the metadata matches the consumer.
3309d98641SEnji Cooper
34f397a004SAlan Somers	atf_check geli backup ${md}a tmp.meta
35f397a004SAlan Somers	atf_check geli detach ${md}a.eli
36f397a004SAlan Somers	atf_check -s exit:0 -o match:resized gpart resize -i1 -s 20m ${md}
37f397a004SAlan Somers	atf_check -s not-exit:0 -e ignore geli attach -pktmp.key ${md}a
38f397a004SAlan Somers	atf_check -s not-exit:0 -e ignore geli restore tmp.meta ${md}a
39f397a004SAlan Somers	atf_check geli restore -f tmp.meta ${md}a
40f397a004SAlan Somers	atf_check geli attach -pktmp.key ${md}a
41f397a004SAlan Somers	atf_check -s exit:0 -o ignore growfs -y ${md}a.eli
42f397a004SAlan Somers	atf_check -s exit:7 -o ignore fsck_ffs -Ffy ${md}a.eli
4309d98641SEnji Cooper
4409d98641SEnji Cooper	# Now do the resize properly
4509d98641SEnji Cooper
46f397a004SAlan Somers	atf_check geli detach ${md}a.eli
47f397a004SAlan Somers	atf_check -s exit:0 -o match:resized gpart resize -i1 -s 30m ${md}
48f397a004SAlan Somers	atf_check geli resize -s20m ${md}a
49f397a004SAlan Somers	atf_check -s not-exit:0 -e match:"Inconsistent provider.*metadata" \
50f397a004SAlan Somers		geli resize -s20m ${md}a
51f397a004SAlan Somers	atf_check geli attach -pktmp.key ${md}a
52f397a004SAlan Somers	atf_check -s exit:0 -o ignore growfs -y ${md}a.eli
53f397a004SAlan Somers	atf_check -s exit:7 -o ignore fsck_ffs -Ffy ${md}a.eli
5409d98641SEnji Cooper
55f397a004SAlan Somers	atf_check geli detach ${md}a.eli
56f397a004SAlan Somers	atf_check -s exit:0 -o ignore gpart destroy -F $md
5709d98641SEnji Cooper
5809d98641SEnji Cooper
5909d98641SEnji Cooper	# Verify that the man page example works, changing ada0 to $md,
6009d98641SEnji Cooper	# 1g to 20m, 2g to 30m and keyfile to tmp.key, and adding -B none
6109d98641SEnji Cooper	# to geli init.
6209d98641SEnji Cooper
63f397a004SAlan Somers	atf_check -s exit:0 -o ignore gpart create -s GPT $md
64f397a004SAlan Somers	atf_check -s exit:0 -o ignore gpart add -s 20m -t freebsd-ufs -i 1 $md
65f397a004SAlan Somers	atf_check geli init -B none -K tmp.key -P ${md}p1
66f397a004SAlan Somers	atf_check -s exit:0 -o match:resized gpart resize -s 30m -i 1 $md
67f397a004SAlan Somers	atf_check geli resize -s 20m ${md}p1
68f397a004SAlan Somers	atf_check geli attach -k tmp.key -p ${md}p1
69f397a004SAlan Somers}
70f397a004SAlan Somersresize_cleanup()
71f397a004SAlan Somers{
72f397a004SAlan Somers	if [ -f "$TEST_MDS_FILE" ]; then
73f397a004SAlan Somers		while read md; do
74f397a004SAlan Somers			[ -c /dev/${md}a.eli ] && \
75f397a004SAlan Somers				geli detach ${md}a.eli 2>/dev/null
76f397a004SAlan Somers			[ -c /dev/${md}p1.eli ] && \
7709d98641SEnji Cooper				geli detach ${md}p1.eli
78f397a004SAlan Somers			[ -c /dev/${md}.eli ] && \
79f397a004SAlan Somers				geli detach ${md}.eli 2>/dev/null
80f397a004SAlan Somers			mdconfig -d -u $md 2>/dev/null
81f397a004SAlan Somers		done < $TEST_MDS_FILE
82f397a004SAlan Somers	fi
83f397a004SAlan Somers}
8409d98641SEnji Cooper
85f397a004SAlan Somersatf_init_test_cases()
86f397a004SAlan Somers{
87f397a004SAlan Somers	atf_add_test_case resize
88f397a004SAlan Somers}
89