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