xref: /freebsd/tests/sys/geom/class/concat/append2.sh (revision 96950419f15510287080c557174e0d8409f06956)
186461b64SMark Johnston#!/bin/sh
286461b64SMark Johnston
386461b64SMark Johnston# A basic regression test for gconcat append using "gconcat label",
486461b64SMark Johnston# i.e., automatic mode.
586461b64SMark Johnston
686461b64SMark Johnstongconcat_check_size()
786461b64SMark Johnston{
886461b64SMark Johnston    local actual expected name
986461b64SMark Johnston
1086461b64SMark Johnston    name=$1
1186461b64SMark Johnston    expected=$2
1286461b64SMark Johnston
1386461b64SMark Johnston    actual=$(diskinfo /dev/concat/${name} | awk '{print $3}')
1486461b64SMark Johnston    if [ $actual -eq $expected ]; then
1586461b64SMark Johnston        echo "ok - Size is ${actual}"
1686461b64SMark Johnston    else
1786461b64SMark Johnston        echo "not ok - Size is ${actual}"
1886461b64SMark Johnston    fi
1986461b64SMark Johnston}
2086461b64SMark Johnston
2186461b64SMark Johnston. `dirname $0`/conf.sh
2286461b64SMark Johnston
2386461b64SMark Johnstonecho '1..4'
2486461b64SMark Johnston
2586461b64SMark Johnstonss=512
2686461b64SMark Johnston
2786461b64SMark Johnstonf1=$(mktemp) || exit 1
2886461b64SMark Johnstontruncate -s $((1024 * 1024 + $ss)) $f1
2986461b64SMark Johnstonf2=$(mktemp) || exit 1
3086461b64SMark Johnstontruncate -s $((1024 * 1024 + $ss)) $f2
3186461b64SMark Johnstonf3=$(mktemp) || exit 1
3286461b64SMark Johnstontruncate -s $((1024 * 1024 + $ss)) $f3
3386461b64SMark Johnston
34*96950419SGleb Smirnoffattach_md us0 -f $f1 -S $ss || exit 1
35*96950419SGleb Smirnoffattach_md us1 -f $f2 -S $ss || exit 1
36*96950419SGleb Smirnoffattach_md us2 -f $f3 -S $ss || exit 1
3786461b64SMark Johnston
3886461b64SMark Johnstongconcat label $name /dev/$us0 /dev/$us1 || exit 1
3986461b64SMark Johnstondevwait
4086461b64SMark Johnston
4186461b64SMark Johnston# We should have a 2MB device.  Add another disk and verify that the
4286461b64SMark Johnston# reported size of the concat device grows accordingly.  A sector from
4386461b64SMark Johnston# each disk is reserved for the metadata sector.
4486461b64SMark Johnstongconcat_check_size "${name}" $((2 * 1024 * 1024))
4586461b64SMark Johnstongconcat append $name /dev/$us2 || exit 1
4686461b64SMark Johnstongconcat_check_size "${name}" $((3 * 1024 * 1024))
4786461b64SMark Johnston
4886461b64SMark Johnstoncopy=$(mktemp) || exit 1
4986461b64SMark Johnstondd if=/dev/random of=$copy bs=1M count=3 || exit 1
5086461b64SMark Johnstondd if=$copy of=/dev/concat/${name} || exit 1
5186461b64SMark Johnston
5286461b64SMark Johnston# Stop the concat device and destroy the backing providers.
5386461b64SMark Johnstongconcat stop ${name} || exit 1
5486461b64SMark Johnstondetach_md $us0
5586461b64SMark Johnstondetach_md $us1
5686461b64SMark Johnstondetach_md $us2
5786461b64SMark Johnston
5886461b64SMark Johnston# Re-create the providers and verify that the concat device comes
5986461b64SMark Johnston# back and that the data is still there.
60*96950419SGleb Smirnoffattach_md us0 -f $f1 -S $ss || exit 1
61*96950419SGleb Smirnoffattach_md us1 -f $f2 -S $ss || exit 1
62*96950419SGleb Smirnoffattach_md us2 -f $f3 -S $ss || exit 1
6386461b64SMark Johnston
6486461b64SMark Johnstondevwait
6586461b64SMark Johnston
6686461b64SMark Johnston# Make sure that the
6786461b64SMark Johnstonif [ -c /dev/concat/${name} ]; then
6886461b64SMark Johnston    echo "ok - concat device was instantiated"
6986461b64SMark Johnstonelse
7086461b64SMark Johnston    echo "not ok - concat device was instantiated"
7186461b64SMark Johnstonfi
7286461b64SMark Johnston
7386461b64SMark Johnstonif cmp -s $copy /dev/concat/${name}; then
7486461b64SMark Johnston    echo "ok - Data was persisted across gconcat stop"
7586461b64SMark Johnstonelse
7686461b64SMark Johnston    echo "not ok - Data was persisted across gconcat stop"
7786461b64SMark Johnstonfi
78