Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/tests/sys/geom/class/eli/attach_test.sh
39635 views
1
2
. $(atf_get_srcdir)/conf.sh
3
4
atf_test_case attach_d cleanup
5
attach_d_head()
6
{
7
atf_set "descr" "geli attach -d will cause the provider to detach on last close"
8
atf_set "require.user" "root"
9
}
10
attach_d_body()
11
{
12
geli_test_setup
13
14
sectors=100
15
attach_md md -t malloc -s `expr $sectors + 1`
16
17
atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
18
19
atf_check geli init -B none -P -K keyfile ${md}
20
atf_check geli attach -d -p -k keyfile ${md}
21
22
# Be sure it doesn't detach on read.
23
atf_check dd if=/dev/${md}.eli of=/dev/null status=none
24
sleep 1
25
if [ ! -c /dev/${md}.eli ]; then
26
atf_fail "Detached on last close of a reader"
27
fi
28
29
# It should detach on last close of a writer
30
true > /dev/${md}.eli
31
sleep 1
32
if [ -c /dev/${md}.eli ]; then
33
atf_fail "Did not detach on last close of a writer"
34
fi
35
36
}
37
attach_d_cleanup()
38
{
39
geli_test_cleanup
40
}
41
42
atf_test_case atach_multiple_fails cleanup
43
attach_multiple_fails_head()
44
{
45
atf_set "descr" "test multiple failed attach of geli provider"
46
atf_set "require.user" "root"
47
}
48
attach_multiple_fails_body()
49
{
50
geli_test_setup
51
52
sectors=1000
53
attach_md md -t malloc -s `expr $sectors + 1`
54
atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
55
56
atf_check geli init -B none -P -K keyfile ${md}
57
atf_check geli attach -d -p -k keyfile ${md}
58
59
for i in $(jot 100); do
60
atf_check -s not-exit:0 -e ignore -- geli attach -d -p -k keyfile ${md}
61
done
62
atf_check -o ignore -- newfs ${md}.eli
63
}
64
attach_multiple_fails_cleanup()
65
{
66
geli_test_cleanup
67
}
68
69
70
atf_test_case attach_r cleanup
71
attach_r_head()
72
{
73
atf_set "descr" "geli attach -r will create a readonly provider"
74
atf_set "require.user" "root"
75
}
76
attach_r_body()
77
{
78
geli_test_setup
79
80
sectors=100
81
attach_md md -t malloc -s `expr $sectors + 1`
82
atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
83
84
atf_check geli init -B none -P -K keyfile ${md}
85
atf_check geli attach -r -p -k keyfile ${md}
86
87
atf_check -o match:"^Flags: .*READ-ONLY" geli list ${md}.eli
88
89
# Verify that writes are verbotten
90
atf_check -s not-exit:0 -e match:"Read-only" \
91
dd if=/dev/zero of=/dev/${md}.eli count=1
92
}
93
attach_r_cleanup()
94
{
95
geli_test_cleanup
96
}
97
98
atf_test_case attach_multiple cleanup
99
attach_multiple_head()
100
{
101
atf_set "descr" "geli attach can attach multiple providers"
102
atf_set "require.user" "root"
103
}
104
attach_multiple_body()
105
{
106
geli_test_setup
107
108
sectors=100
109
attach_md md0 -t malloc -s `expr $sectors + 1`
110
attach_md md1 -t malloc -s `expr $sectors + 1`
111
attach_md md2 -t malloc -s `expr $sectors + 1`
112
atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
113
114
atf_check geli init -B none -P -K keyfile ${md0}
115
atf_check geli init -B none -P -K keyfile ${md1}
116
atf_check geli init -B none -P -K keyfile ${md2}
117
atf_check geli attach -p -k keyfile ${md0} ${md1} ${md2}
118
# verify that it did create all 3 geli devices
119
atf_check -s exit:0 test -c /dev/${md0}.eli
120
atf_check -s exit:0 test -c /dev/${md1}.eli
121
atf_check -s exit:0 test -c /dev/${md2}.eli
122
}
123
attach_multiple_cleanup()
124
{
125
geli_test_cleanup
126
}
127
128
atf_test_case nokey cleanup
129
nokey_head()
130
{
131
atf_set "descr" "geli attach fails if called with no key component"
132
atf_set "require.user" "root"
133
}
134
nokey_body()
135
{
136
geli_test_setup
137
138
sectors=100
139
attach_md md -t malloc -s `expr $sectors + 1`
140
atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
141
142
atf_check geli init -B none -P -K keyfile ${md}
143
atf_check -s not-exit:0 -e match:"No key components given" \
144
geli attach -p ${md} 2>/dev/null
145
}
146
nokey_cleanup()
147
{
148
geli_test_cleanup
149
}
150
151
atf_init_test_cases()
152
{
153
atf_add_test_case attach_d
154
atf_add_test_case attach_r
155
atf_add_test_case attach_multiple
156
atf_add_test_case attach_multiple_fails
157
atf_add_test_case nokey
158
}
159
160