]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - tests/sys/geom/class/eli/resize_test.sh
MFC r294973:
[FreeBSD/stable/10.git] / tests / sys / geom / class / eli / resize_test.sh
1 #!/bin/sh
2 # $FreeBSD$
3
4 . $(dirname $0)/conf.sh
5
6 echo 1..27
7
8 BLK=512
9 BLKS_PER_MB=2048
10
11 md=$(mdconfig -s40m) || exit 1
12 unit=${md#md}
13 i=1
14
15 setsize() {
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
26 setsize 10 40 || echo -n "not "
27 echo ok $i - "Sized ${md}a to 10m"
28 i=$((i + 1))
29
30 echo secret >tmp.key
31 geli init -Bnone -PKtmp.key ${md}a || echo -n "not "
32 echo ok $i - "Initialised geli on ${md}a"
33 i=$((i + 1))
34 geli attach -pk tmp.key ${md}a || echo -n "not "
35 echo ok $i - "Attached ${md}a as ${md}a.eli"
36 i=$((i + 1))
37
38 newfs -U ${md}a.eli >/dev/null || echo -n "not "
39 echo ok $i - "Initialised the filesystem on ${md}a.eli"
40 i=$((i + 1))
41 out=$(fsck -tufs -y ${md}a.eli)
42 echo "$out" | fgrep -q MODIFIED && echo -n "not "
43 echo ok $i - "fsck says ${md}a.eli is clean," $(echo $(echo "$out" | wc -l)) \
44     "lines of output"
45 i=$((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
51 geli backup ${md}a tmp.meta || echo -n "not "
52 echo ok $i - "Backed up ${md}a metadata"
53 i=$((i + 1))
54
55 geli detach ${md}a.eli || echo -n "not "
56 echo ok $i - "Detached ${md}a.eli"
57 i=$((i + 1))
58
59 setsize 20 40 || echo -n "not "
60 echo ok $i - "Sized ${md}a to 20m"
61 i=$((i + 1))
62 geli attach -pktmp.key ${md}a && echo -n "not "
63 echo ok $i - "Attaching ${md}a fails after resizing the consumer"
64 i=$((i + 1))
65
66 geli restore tmp.meta ${md}a && echo -n "not "
67 echo ok $i - "Restoring metadata on ${md}a.eli fails without -f"
68 i=$((i + 1))
69 geli restore -f tmp.meta ${md}a || echo -n "not "
70 echo ok $i - "Restoring metadata on ${md}a.eli can be forced"
71 i=$((i + 1))
72
73 geli attach -pktmp.key ${md}a || echo -n "not "
74 echo ok $i - "Attaching ${md}a is now possible"
75 i=$((i + 1))
76
77 growfs -y ${md}a.eli >/dev/null || echo -n "not "
78 echo ok $i - "Extended the filesystem on ${md}a.eli"
79 i=$((i + 1))
80
81 out=$(fsck -tufs -y ${md}a.eli)
82 echo "$out" | fgrep -q MODIFIED && echo -n "not "
83 echo ok $i - "fsck says ${md}a.eli is clean," $(echo $(echo "$out" | wc -l)) \
84     "lines of output"
85 i=$((i + 1))
86
87
88 # Now do the resize properly
89
90 geli detach ${md}a.eli || echo -n "not "
91 echo ok $i - "Detached ${md}a.eli"
92 i=$((i + 1))
93
94 setsize 30 40 || echo -n "not "
95 echo ok $i - "Sized ${md}a to 30m"
96 i=$((i + 1))
97
98 geli resize -s20m ${md}a || echo -n "not "
99 echo ok $i - "Resizing works ok"
100 i=$((i + 1))
101 geli resize -s20m ${md}a && echo -n "not "
102 echo ok $i - "Resizing doesn't work a 2nd time (no old metadata)"
103 i=$((i + 1))
104
105 geli attach -pktmp.key ${md}a || echo -n "not "
106 echo ok $i - "Attaching ${md}a works ok"
107 i=$((i + 1))
108
109 growfs -y ${md}a.eli >/dev/null || echo -n "not "
110 echo ok $i - "Extended the filesystem on ${md}a.eli"
111 i=$((i + 1))
112
113 out=$(fsck -tufs -y ${md}a.eli)
114 echo "$out" | fgrep -q MODIFIED && echo -n "not "
115 echo ok $i - "fsck says ${md}a.eli is clean," $(echo $(echo "$out" | wc -l)) \
116     "lines of output"
117 i=$((i + 1))
118
119 geli detach ${md}a.eli
120 gpart 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
127 gpart create -s GPT $md || echo -n "not "
128 echo ok $i - "Installed a GPT on ${md}"
129 i=$((i + 1))
130 gpart add -s 20m -t freebsd-ufs -i 1 $md || echo -n "not "
131 echo ok $i - "Added a 20m partition in slot 1"
132 i=$((i + 1))
133 geli init -B none -K tmp.key -P ${md}p1 || echo -n "not "
134 echo ok $i - "Initialised geli on ${md}p1"
135 i=$((i + 1))
136 gpart resize -s 30m -i 1 $md || echo -n "not "
137 echo ok $i - "Resized partition ${md}p1 to 30m"
138 i=$((i + 1))
139 geli resize -s 20m ${md}p1 || echo -n "not "
140 echo ok $i - "Resized geli on ${md}p1 to 30m"
141 i=$((i + 1))
142 geli attach -k tmp.key -p ${md}p1 || echo -n "not "
143 echo ok $i - "Attached ${md}p1.eli"
144 i=$((i + 1))
145
146 geli detach ${md}p1.eli
147
148 rm tmp.*