xref: /freebsd/tests/sys/geom/class/eli/reentrancy_test.sh (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1# $FreeBSD$
2
3# Test various operations for geli-on-geli providers, to ensure that geli is
4# reentrant.
5
6. $(atf_get_srcdir)/conf.sh
7
8init_test()
9{
10	cipher=$1
11	aalgo=$2
12	secsize=$3
13	ealgo=${cipher%%:*}
14	keylen=${cipher##*:}
15
16	atf_check dd if=/dev/random of=testdata bs=$secsize count=1 status=none
17	atf_check dd if=/dev/random of=keyfile bs=$secsize count=16 status=none
18
19	# Create the lower geli device
20	atf_check -s exit:0 -e ignore \
21		geli init -B none -a $aalgo -e $ealgo -l $keylen -P -K keyfile \
22		-s $secsize ${md}
23	atf_check geli attach -p -k keyfile ${md}
24	# Create the upper geli device
25	atf_check -s exit:0 -e ignore \
26		geli init -B none -a $aalgo -e $ealgo -l $keylen -P -K keyfile \
27		-s $secsize ${md}.eli
28	atf_check geli attach -p -k keyfile ${md}.eli
29	echo ${md} > layered_md_device
30
31	# Ensure we can read and write.
32	atf_check dd if=testdata of=/dev/${md}.eli.eli bs=$secsize count=1 \
33		status=none
34	atf_check dd if=/dev/${md}.eli.eli of=cmpdata bs=$secsize count=1 \
35		status=none
36	atf_check cmp -s testdata cmpdata
37
38	geli detach ${md}.eli 2>/dev/null
39}
40
41atf_test_case init cleanup
42init_head()
43{
44	atf_set "descr" "Initialize a geli provider on top of another"
45	atf_set "require.user" "root"
46	atf_set "timeout" 600
47}
48init_body()
49{
50	sectors=2
51	geli_test_setup
52
53	for_each_geli_config init_test
54}
55init_cleanup()
56{
57	if [ -f layered_md_device ]; then
58		while read provider; do
59			[ -c /dev/${md}.eli.eli ] && \
60				geli detach $md.eli.eli 2>/dev/null
61		done < layered_md_device
62	fi
63	geli_test_cleanup
64}
65
66atf_init_test_cases()
67{
68	atf_add_test_case init
69}
70