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