xref: /freebsd/tests/sys/geom/class/eli/resize_test.sh (revision a2aef24aa3c8458e4036735dd6928b4ef77294e5)
1#!/bin/sh
2# $FreeBSD$
3
4. $(dirname $0)/conf.sh
5
6echo 1..27
7
8BLK=512
9BLKS_PER_MB=2048
10
11md=$(mdconfig -s40m) || exit 1
12unit=${md#md}
13i=1
14
15fsck_md()
16{
17	local is_clean
18
19	out=$(fsck_ffs -Ffy ${md}a.eli)
20	if [ $? -eq 0 -o $? -eq 7 ]; then
21		echo "ok $i - fsck says ${md}a.eli is clean"
22	else
23		echo "not ok $i - fsck says ${md}a.eli is dirty"
24	fi
25	i=$((i + 1))
26}
27
28setsize() {
29    partszMB=$1 unitszMB=$2
30
31    {
32	echo a: $(($partszMB * $BLKS_PER_MB)) 0 4.2BSD 1024 8192
33	echo c: $(($unitszMB * $BLKS_PER_MB)) 0 unused 0 0
34    } | bsdlabel -R $md /dev/stdin
35}
36
37# Initialise
38
39setsize 10 40 || echo -n "not "
40echo ok $i - "Sized ${md}a to 10m"
41i=$((i + 1))
42
43echo secret >tmp.key
44geli init -Bnone -PKtmp.key ${md}a || echo -n "not "
45echo ok $i - "Initialised geli on ${md}a"
46i=$((i + 1))
47geli attach -pk tmp.key ${md}a || echo -n "not "
48echo ok $i - "Attached ${md}a as ${md}a.eli"
49i=$((i + 1))
50
51newfs -U ${md}a.eli >/dev/null || echo -n "not "
52echo ok $i - "Initialised the filesystem on ${md}a.eli"
53i=$((i + 1))
54fsck_md
55
56# Doing a backup, resize & restore must be forced (with -f) as geli
57# verifies that the provider size in the metadata matches the consumer.
58
59geli backup ${md}a tmp.meta || echo -n "not "
60echo ok $i - "Backed up ${md}a metadata"
61i=$((i + 1))
62
63geli detach ${md}a.eli || echo -n "not "
64echo ok $i - "Detached ${md}a.eli"
65i=$((i + 1))
66
67setsize 20 40 || echo -n "not "
68echo ok $i - "Sized ${md}a to 20m"
69i=$((i + 1))
70geli attach -pktmp.key ${md}a && echo -n "not "
71echo ok $i - "Attaching ${md}a fails after resizing the consumer"
72i=$((i + 1))
73
74geli restore tmp.meta ${md}a && echo -n "not "
75echo ok $i - "Restoring metadata on ${md}a.eli fails without -f"
76i=$((i + 1))
77geli restore -f tmp.meta ${md}a || echo -n "not "
78echo ok $i - "Restoring metadata on ${md}a.eli can be forced"
79i=$((i + 1))
80
81geli attach -pktmp.key ${md}a || echo -n "not "
82echo ok $i - "Attaching ${md}a is now possible"
83i=$((i + 1))
84
85growfs -y ${md}a.eli >/dev/null || echo -n "not "
86echo ok $i - "Extended the filesystem on ${md}a.eli"
87i=$((i + 1))
88
89fsck_md
90
91# Now do the resize properly
92
93geli detach ${md}a.eli || echo -n "not "
94echo ok $i - "Detached ${md}a.eli"
95i=$((i + 1))
96
97setsize 30 40 || echo -n "not "
98echo ok $i - "Sized ${md}a to 30m"
99i=$((i + 1))
100
101geli resize -s20m ${md}a || echo -n "not "
102echo ok $i - "Resizing works ok"
103i=$((i + 1))
104geli resize -s20m ${md}a && echo -n "not "
105echo ok $i - "Resizing doesn't work a 2nd time (no old metadata)"
106i=$((i + 1))
107
108geli attach -pktmp.key ${md}a || echo -n "not "
109echo ok $i - "Attaching ${md}a works ok"
110i=$((i + 1))
111
112growfs -y ${md}a.eli >/dev/null || echo -n "not "
113echo ok $i - "Extended the filesystem on ${md}a.eli"
114i=$((i + 1))
115
116fsck_md
117
118geli detach ${md}a.eli
119gpart destroy -F $md >/dev/null
120
121
122# Verify that the man page example works, changing ada0 to $md,
123# 1g to 20m, 2g to 30m and keyfile to tmp.key, and adding -B none
124# to geli init.
125
126gpart create -s GPT $md || echo -n "not "
127echo ok $i - "Installed a GPT on ${md}"
128i=$((i + 1))
129gpart add -s 20m -t freebsd-ufs -i 1 $md || echo -n "not "
130echo ok $i - "Added a 20m partition in slot 1"
131i=$((i + 1))
132geli init -B none -K tmp.key -P ${md}p1 || echo -n "not "
133echo ok $i - "Initialised geli on ${md}p1"
134i=$((i + 1))
135gpart resize -s 30m -i 1 $md || echo -n "not "
136echo ok $i - "Resized partition ${md}p1 to 30m"
137i=$((i + 1))
138geli resize -s 20m ${md}p1 || echo -n "not "
139echo ok $i - "Resized geli on ${md}p1 to 30m"
140i=$((i + 1))
141geli attach -k tmp.key -p ${md}p1 || echo -n "not "
142echo ok $i - "Attached ${md}p1.eli"
143i=$((i + 1))
144
145geli detach ${md}p1.eli
146
147rm tmp.*
148