]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - tests/sys/geom/class/eli/resize_test.sh
MFC r324478:
[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 fsck_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
28 setsize() {
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     } | disklabel -R $md /dev/stdin
35 }
36
37 # Initialise
38
39 setsize 10 40 || echo -n "not "
40 echo ok $i - "Sized ${md}a to 10m"
41 i=$((i + 1))
42
43 echo secret >tmp.key
44 geli init -Bnone -PKtmp.key ${md}a || echo -n "not "
45 echo ok $i - "Initialised geli on ${md}a"
46 i=$((i + 1))
47 geli attach -pk tmp.key ${md}a || echo -n "not "
48 echo ok $i - "Attached ${md}a as ${md}a.eli"
49 i=$((i + 1))
50
51 newfs -U ${md}a.eli >/dev/null || echo -n "not "
52 echo ok $i - "Initialised the filesystem on ${md}a.eli"
53 i=$((i + 1))
54 fsck_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
59 geli backup ${md}a tmp.meta || echo -n "not "
60 echo ok $i - "Backed up ${md}a metadata"
61 i=$((i + 1))
62
63 geli detach ${md}a.eli || echo -n "not "
64 echo ok $i - "Detached ${md}a.eli"
65 i=$((i + 1))
66
67 setsize 20 40 || echo -n "not "
68 echo ok $i - "Sized ${md}a to 20m"
69 i=$((i + 1))
70 geli attach -pktmp.key ${md}a && echo -n "not "
71 echo ok $i - "Attaching ${md}a fails after resizing the consumer"
72 i=$((i + 1))
73
74 geli restore tmp.meta ${md}a && echo -n "not "
75 echo ok $i - "Restoring metadata on ${md}a.eli fails without -f"
76 i=$((i + 1))
77 geli restore -f tmp.meta ${md}a || echo -n "not "
78 echo ok $i - "Restoring metadata on ${md}a.eli can be forced"
79 i=$((i + 1))
80
81 geli attach -pktmp.key ${md}a || echo -n "not "
82 echo ok $i - "Attaching ${md}a is now possible"
83 i=$((i + 1))
84
85 growfs -y ${md}a.eli >/dev/null || echo -n "not "
86 echo ok $i - "Extended the filesystem on ${md}a.eli"
87 i=$((i + 1))
88
89 fsck_md
90
91 # Now do the resize properly
92
93 geli detach ${md}a.eli || echo -n "not "
94 echo ok $i - "Detached ${md}a.eli"
95 i=$((i + 1))
96
97 setsize 30 40 || echo -n "not "
98 echo ok $i - "Sized ${md}a to 30m"
99 i=$((i + 1))
100
101 geli resize -s20m ${md}a || echo -n "not "
102 echo ok $i - "Resizing works ok"
103 i=$((i + 1))
104 geli resize -s20m ${md}a && echo -n "not "
105 echo ok $i - "Resizing doesn't work a 2nd time (no old metadata)"
106 i=$((i + 1))
107
108 geli attach -pktmp.key ${md}a || echo -n "not "
109 echo ok $i - "Attaching ${md}a works ok"
110 i=$((i + 1))
111
112 growfs -y ${md}a.eli >/dev/null || echo -n "not "
113 echo ok $i - "Extended the filesystem on ${md}a.eli"
114 i=$((i + 1))
115
116 fsck_md
117
118 geli detach ${md}a.eli
119 gpart 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
126 gpart create -s GPT $md || echo -n "not "
127 echo ok $i - "Installed a GPT on ${md}"
128 i=$((i + 1))
129 gpart add -s 20m -t freebsd-ufs -i 1 $md || echo -n "not "
130 echo ok $i - "Added a 20m partition in slot 1"
131 i=$((i + 1))
132 geli init -B none -K tmp.key -P ${md}p1 || echo -n "not "
133 echo ok $i - "Initialised geli on ${md}p1"
134 i=$((i + 1))
135 gpart resize -s 30m -i 1 $md || echo -n "not "
136 echo ok $i - "Resized partition ${md}p1 to 30m"
137 i=$((i + 1))
138 geli resize -s 20m ${md}p1 || echo -n "not "
139 echo ok $i - "Resized geli on ${md}p1 to 30m"
140 i=$((i + 1))
141 geli attach -k tmp.key -p ${md}p1 || echo -n "not "
142 echo ok $i - "Attached ${md}p1.eli"
143 i=$((i + 1))
144
145 geli detach ${md}p1.eli
146
147 rm tmp.*