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