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