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