xref: /freebsd/tests/sys/geom/class/concat/append2.sh (revision 06c3fb27)
1#!/bin/sh
2
3# A basic regression test for gconcat append using "gconcat label",
4# i.e., automatic mode.
5
6gconcat_check_size()
7{
8    local actual expected name
9
10    name=$1
11    expected=$2
12
13    actual=$(diskinfo /dev/concat/${name} | awk '{print $3}')
14    if [ $actual -eq $expected ]; then
15        echo "ok - Size is ${actual}"
16    else
17        echo "not ok - Size is ${actual}"
18    fi
19}
20
21. `dirname $0`/conf.sh
22
23echo '1..4'
24
25ss=512
26
27f1=$(mktemp) || exit 1
28truncate -s $((1024 * 1024 + $ss)) $f1
29f2=$(mktemp) || exit 1
30truncate -s $((1024 * 1024 + $ss)) $f2
31f3=$(mktemp) || exit 1
32truncate -s $((1024 * 1024 + $ss)) $f3
33
34attach_md us0 -f $f1 -S $ss || exit 1
35attach_md us1 -f $f2 -S $ss || exit 1
36attach_md us2 -f $f3 -S $ss || exit 1
37
38gconcat label $name /dev/$us0 /dev/$us1 || exit 1
39devwait
40
41# We should have a 2MB device.  Add another disk and verify that the
42# reported size of the concat device grows accordingly.  A sector from
43# each disk is reserved for the metadata sector.
44gconcat_check_size "${name}" $((2 * 1024 * 1024))
45gconcat append $name /dev/$us2 || exit 1
46gconcat_check_size "${name}" $((3 * 1024 * 1024))
47
48copy=$(mktemp) || exit 1
49dd if=/dev/random of=$copy bs=1M count=3 || exit 1
50dd if=$copy of=/dev/concat/${name} || exit 1
51
52# Stop the concat device and destroy the backing providers.
53gconcat stop ${name} || exit 1
54detach_md $us0
55detach_md $us1
56detach_md $us2
57
58# Re-create the providers and verify that the concat device comes
59# back and that the data is still there.
60attach_md us0 -f $f1 -S $ss || exit 1
61attach_md us1 -f $f2 -S $ss || exit 1
62attach_md us2 -f $f3 -S $ss || exit 1
63
64devwait
65
66# Make sure that the
67if [ -c /dev/concat/${name} ]; then
68    echo "ok - concat device was instantiated"
69else
70    echo "not ok - concat device was instantiated"
71fi
72
73if cmp -s $copy /dev/concat/${name}; then
74    echo "ok - Data was persisted across gconcat stop"
75else
76    echo "not ok - Data was persisted across gconcat stop"
77fi
78