xref: /freebsd/tests/sys/geom/class/eli/kill_test.sh (revision 396c556d77189a5c474d35cec6f44a762e310b7d)
1#!/bin/sh
2# $FreeBSD$
3
4. $(dirname $0)/conf.sh
5
6base=`basename $0`
7sectors=100
8keyfile1=`mktemp $base.XXXXXX` || exit 1
9keyfile2=`mktemp $base.XXXXXX` || exit 1
10mdconfig -a -t malloc -s `expr $sectors + 1` -u $no || exit 1
11
12echo "1..9"
13
14dd if=/dev/random of=${keyfile1} bs=512 count=16 >/dev/null 2>&1
15dd if=/dev/random of=${keyfile2} bs=512 count=16 >/dev/null 2>&1
16
17geli init -B none -P -K $keyfile1 md${no}
18geli attach -p -k $keyfile1 md${no}
19geli setkey -n 1 -P -K $keyfile2 md${no}
20
21# Kill attached provider.
22geli kill md${no}
23if [ $? -eq 0 ]; then
24	echo "ok 1"
25else
26	echo "not ok 1"
27fi
28sleep 1
29# Provider should be automatically detached.
30if [ ! -c /dev/md{$no}.eli ]; then
31	echo "ok 2"
32else
33	echo "not ok 2"
34fi
35
36# We cannot use keyfile1 anymore.
37geli attach -p -k $keyfile1 md${no} 2>/dev/null
38if [ $? -ne 0 ]; then
39	echo "ok 3"
40else
41	echo "not ok 3"
42fi
43
44# We cannot use keyfile2 anymore.
45geli attach -p -k $keyfile2 md${no} 2>/dev/null
46if [ $? -ne 0 ]; then
47	echo "ok 4"
48else
49	echo "not ok 4"
50fi
51
52geli init -B none -P -K $keyfile1 md${no}
53geli setkey -n 1 -p -k $keyfile1 -P -K $keyfile2 md${no}
54
55# Should be possible to attach with keyfile1.
56geli attach -p -k $keyfile1 md${no}
57if [ $? -eq 0 ]; then
58	echo "ok 5"
59else
60	echo "not ok 5"
61fi
62geli detach md${no}
63
64# Should be possible to attach with keyfile2.
65geli attach -p -k $keyfile2 md${no}
66if [ $? -eq 0 ]; then
67	echo "ok 6"
68else
69	echo "not ok 6"
70fi
71geli detach md${no}
72
73# Kill detached provider.
74geli kill md${no}
75if [ $? -eq 0 ]; then
76	echo "ok 7"
77else
78	echo "not ok 7"
79fi
80
81# We cannot use keyfile1 anymore.
82geli attach -p -k $keyfile1 md${no} 2>/dev/null
83if [ $? -ne 0 ]; then
84	echo "ok 8"
85else
86	echo "not ok 8"
87fi
88
89# We cannot use keyfile2 anymore.
90geli attach -p -k $keyfile2 md${no} 2>/dev/null
91if [ $? -ne 0 ]; then
92	echo "ok 9"
93else
94	echo "not ok 9"
95fi
96
97rm -f $keyfile1 $keyfile2
98