xref: /freebsd/tests/sys/geom/class/eli/kill_test.sh (revision 96950419f15510287080c557174e0d8409f06956)
109d98641SEnji Cooper
2cf551b8aSAlan Somers. $(atf_get_srcdir)/conf.sh
3cf551b8aSAlan Somers
4f397a004SAlan Somersatf_test_case kill cleanup
5f397a004SAlan Somerskill_head()
6f397a004SAlan Somers{
7f397a004SAlan Somers	atf_set "descr" "geli kill will wipe a provider's metadata"
8f397a004SAlan Somers	atf_set "require.user" "root"
9f397a004SAlan Somers}
10f397a004SAlan Somerskill_body()
11f397a004SAlan Somers{
12cf551b8aSAlan Somers	geli_test_setup
1309d98641SEnji Cooper
1409d98641SEnji Cooper	sectors=100
15*96950419SGleb Smirnoff	attach_md md -t malloc -s `expr $sectors + 1`
1609d98641SEnji Cooper
17f397a004SAlan Somers	atf_check dd if=/dev/random of=keyfile1 bs=512 count=16 status=none
18f397a004SAlan Somers	atf_check dd if=/dev/random of=keyfile2 bs=512 count=16 status=none
1909d98641SEnji Cooper
20f397a004SAlan Somers	atf_check geli init -B none -P -K keyfile1 ${md}
21f397a004SAlan Somers	atf_check geli attach -p -k keyfile1 ${md}
22f397a004SAlan Somers	atf_check -s exit:0 -o ignore geli setkey -n 1 -P -K keyfile2 ${md}
2309d98641SEnji Cooper
2409d98641SEnji Cooper	# Kill attached provider.
25f397a004SAlan Somers	atf_check geli kill ${md}
2609d98641SEnji Cooper	sleep 1
2709d98641SEnji Cooper	# Provider should be automatically detached.
28f397a004SAlan Somers	if [ -c /dev/${md}.eli ]; then
29f397a004SAlan Somers		atf_fail "Provider did not detach when killed"
3009d98641SEnji Cooper	fi
3109d98641SEnji Cooper
3209d98641SEnji Cooper	# We cannot use keyfile1 anymore.
33f397a004SAlan Somers	atf_check -s not-exit:0 -e match:"Cannot read metadata" \
34f397a004SAlan Somers		geli attach -p -k keyfile1 ${md}
3509d98641SEnji Cooper
3609d98641SEnji Cooper	# We cannot use keyfile2 anymore.
37f397a004SAlan Somers	atf_check -s not-exit:0 -e match:"Cannot read metadata" \
38f397a004SAlan Somers		geli attach -p -k keyfile2 ${md}
3909d98641SEnji Cooper
40f397a004SAlan Somers	atf_check geli init -B none -P -K keyfile1 ${md}
41f397a004SAlan Somers	atf_check -s exit:0 -o ignore \
42f397a004SAlan Somers		geli setkey -n 1 -p -k keyfile1 -P -K keyfile2 ${md}
4309d98641SEnji Cooper
4409d98641SEnji Cooper	# Should be possible to attach with keyfile1.
45f397a004SAlan Somers	atf_check geli attach -p -k keyfile1 ${md}
46f397a004SAlan Somers	atf_check geli detach ${md}
4709d98641SEnji Cooper
4809d98641SEnji Cooper	# Should be possible to attach with keyfile2.
49f397a004SAlan Somers	atf_check geli attach -p -k keyfile2 ${md}
50f397a004SAlan Somers	atf_check geli detach ${md}
5109d98641SEnji Cooper
5209d98641SEnji Cooper	# Kill detached provider.
53f397a004SAlan Somers	atf_check geli kill ${md}
5409d98641SEnji Cooper
5509d98641SEnji Cooper	# We cannot use keyfile1 anymore.
56f397a004SAlan Somers	atf_check -s not-exit:0 -e match:"Cannot read metadata" \
57f397a004SAlan Somers		geli attach -p -k keyfile1 ${md}
5809d98641SEnji Cooper
5909d98641SEnji Cooper	# We cannot use keyfile2 anymore.
60f397a004SAlan Somers	atf_check -s not-exit:0 -e match:"Cannot read metadata" \
61f397a004SAlan Somers		geli attach -p -k keyfile2 ${md}
62f397a004SAlan Somers}
63f397a004SAlan Somerskill_cleanup()
64f397a004SAlan Somers{
65f397a004SAlan Somers	geli_test_cleanup
66f397a004SAlan Somers}
6709d98641SEnji Cooper
68565a0a2cSAlan Somersatf_test_case kill_readonly cleanup
69565a0a2cSAlan Somerskill_readonly_head()
70565a0a2cSAlan Somers{
71565a0a2cSAlan Somers	atf_set "descr" "geli kill will not destroy the keys of a readonly provider"
72565a0a2cSAlan Somers	atf_set "require.user" "root"
73565a0a2cSAlan Somers}
74565a0a2cSAlan Somerskill_readonly_body()
75565a0a2cSAlan Somers{
76cf551b8aSAlan Somers	geli_test_setup
77565a0a2cSAlan Somers
78565a0a2cSAlan Somers	sectors=100
79*96950419SGleb Smirnoff	attach_md md -t malloc -s `expr $sectors + 1`
80565a0a2cSAlan Somers	atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
81565a0a2cSAlan Somers
82565a0a2cSAlan Somers	atf_check geli init -B none -P -K keyfile ${md}
83565a0a2cSAlan Somers	# Attach read-only
84565a0a2cSAlan Somers	atf_check geli attach -r -p -k keyfile ${md}
85565a0a2cSAlan Somers
86565a0a2cSAlan Somers	atf_check geli kill ${md}
87565a0a2cSAlan Somers	# The provider will be detached
88565a0a2cSAlan Somers	atf_check [ ! -c /dev/${md}.eli ]
89565a0a2cSAlan Somers	# But its keys should not be destroyed
90565a0a2cSAlan Somers	atf_check geli attach -p -k keyfile ${md}
91565a0a2cSAlan Somers}
92565a0a2cSAlan Somerskill_readonly_cleanup()
93565a0a2cSAlan Somers{
94565a0a2cSAlan Somers	geli_test_cleanup
95565a0a2cSAlan Somers}
96565a0a2cSAlan Somers
97f397a004SAlan Somersatf_init_test_cases()
98f397a004SAlan Somers{
99f397a004SAlan Somers	atf_add_test_case kill
100565a0a2cSAlan Somers	atf_add_test_case kill_readonly
101f397a004SAlan Somers}
102