19a1fe327SAlan SomersPIDFILE=ggated.pid 29a1fe327SAlan SomersPLAINFILES=plainfiles 39a1fe327SAlan SomersCONF=gg.exports 49a1fe327SAlan Somers 5f5c6c43dSAlan Somersatf_test_case ggatec_trim cleanup 6f5c6c43dSAlan Somersggatec_trim_head() 7f5c6c43dSAlan Somers{ 8f5c6c43dSAlan Somers atf_set "descr" "ggatec survives a trim" 9f5c6c43dSAlan Somers atf_set "require.progs" "ggatec" 10f5c6c43dSAlan Somers atf_set "require.user" "root" 11f5c6c43dSAlan Somers atf_set "timeout" 60 12f5c6c43dSAlan Somers} 13f5c6c43dSAlan Somers 14f5c6c43dSAlan Somersggatec_trim_body() 15f5c6c43dSAlan Somers{ 16f5c6c43dSAlan Somers load_ggate 17f5c6c43dSAlan Somers 18*b5d3f825SMark Johnston port=33080 19f5c6c43dSAlan Somers us=$(alloc_ggate_dev) 20f5c6c43dSAlan Somers work=$(alloc_md) 21f5c6c43dSAlan Somers atf_check -e ignore -o ignore dd if=/dev/random of=/dev/$work bs=1m count=1 conv=notrunc 22f5c6c43dSAlan Somers echo $CONF >> $PLAINFILES 23f5c6c43dSAlan Somers echo "localhost RW /dev/$work" > $CONF 24*b5d3f825SMark Johnston atf_check ggated -p $port -F $PIDFILE $CONF 25*b5d3f825SMark Johnston atf_check ggatec create -p $port -u $us localhost /dev/$work 26f5c6c43dSAlan Somers ggate_dev=/dev/ggate${us} 27f5c6c43dSAlan Somers wait_for_ggate_device ${ggate_dev} 28f5c6c43dSAlan Somers 29f5c6c43dSAlan Somers # ggatec only supports read or write. 30f5c6c43dSAlan Somers atf_check -s not-exit:0 -e ignore -o ignore trim -q -f ${ggate_dev} 31f5c6c43dSAlan Somers} 32f5c6c43dSAlan Somers 33f5c6c43dSAlan Somersggatec_trim_cleanup() 34f5c6c43dSAlan Somers{ 35f5c6c43dSAlan Somers common_cleanup 36f5c6c43dSAlan Somers} 37f5c6c43dSAlan Somers 38f5c6c43dSAlan Somers 399a1fe327SAlan Somersatf_test_case ggated cleanup 409a1fe327SAlan Somersggated_head() 419a1fe327SAlan Somers{ 429a1fe327SAlan Somers atf_set "descr" "ggated can proxy geoms" 439a1fe327SAlan Somers atf_set "require.progs" "ggatec ggated" 449a1fe327SAlan Somers atf_set "require.user" "root" 459a1fe327SAlan Somers atf_set "timeout" 60 469a1fe327SAlan Somers} 479a1fe327SAlan Somers 489a1fe327SAlan Somersggated_body() 499a1fe327SAlan Somers{ 50f29bf91aSLi-Wen Hsu if [ "$(atf_config_get ci false)" = "true" ] && \ 51f29bf91aSLi-Wen Hsu [ "$(uname -p)" = "i386" ]; then 52f29bf91aSLi-Wen Hsu atf_skip "https://bugs.freebsd.org/244737" 53f29bf91aSLi-Wen Hsu fi 54f29bf91aSLi-Wen Hsu 55b8891d7cSEnji Cooper load_ggate 56b8891d7cSEnji Cooper 57*b5d3f825SMark Johnston port=33081 589a1fe327SAlan Somers us=$(alloc_ggate_dev) 599a1fe327SAlan Somers work=$(alloc_md) 609a1fe327SAlan Somers src=$(alloc_md) 619a1fe327SAlan Somers 62b42fffb4SEnji Cooper atf_check -e ignore -o ignore \ 639a1fe327SAlan Somers dd if=/dev/random of=/dev/$work bs=1m count=1 conv=notrunc 64b42fffb4SEnji Cooper atf_check -e ignore -o ignore \ 659a1fe327SAlan Somers dd if=/dev/random of=/dev/$src bs=1m count=1 conv=notrunc 669a1fe327SAlan Somers 679a1fe327SAlan Somers echo $CONF >> $PLAINFILES 689a1fe327SAlan Somers echo "127.0.0.1 RW /dev/$work" > $CONF 699a1fe327SAlan Somers 70*b5d3f825SMark Johnston atf_check ggated -p $port -F $PIDFILE $CONF 71*b5d3f825SMark Johnston atf_check ggatec create -p $port -u $us 127.0.0.1 /dev/$work 729a1fe327SAlan Somers 73b42fffb4SEnji Cooper ggate_dev=/dev/ggate${us} 74b42fffb4SEnji Cooper 75b42fffb4SEnji Cooper wait_for_ggate_device ${ggate_dev} 76b42fffb4SEnji Cooper 77b42fffb4SEnji Cooper atf_check -e ignore -o ignore \ 78b42fffb4SEnji Cooper dd if=/dev/${src} of=${ggate_dev} bs=1m count=1 conv=notrunc 799a1fe327SAlan Somers 809a1fe327SAlan Somers checksum /dev/$src /dev/$work 819a1fe327SAlan Somers} 829a1fe327SAlan Somers 839a1fe327SAlan Somersggated_cleanup() 849a1fe327SAlan Somers{ 859a1fe327SAlan Somers common_cleanup 869a1fe327SAlan Somers} 879a1fe327SAlan Somers 889a1fe327SAlan Somersatf_test_case ggatel_file cleanup 899a1fe327SAlan Somersggatel_file_head() 909a1fe327SAlan Somers{ 919a1fe327SAlan Somers atf_set "descr" "ggatel can proxy files" 929a1fe327SAlan Somers atf_set "require.progs" "ggatel" 939a1fe327SAlan Somers atf_set "require.user" "root" 949a1fe327SAlan Somers atf_set "timeout" 15 959a1fe327SAlan Somers} 969a1fe327SAlan Somers 979a1fe327SAlan Somersggatel_file_body() 989a1fe327SAlan Somers{ 99b8891d7cSEnji Cooper load_ggate 100b8891d7cSEnji Cooper 1019a1fe327SAlan Somers us=$(alloc_ggate_dev) 1029a1fe327SAlan Somers 1039a1fe327SAlan Somers echo src work >> ${PLAINFILES} 1049a1fe327SAlan Somers dd if=/dev/random of=work bs=1m count=1 1059a1fe327SAlan Somers dd if=/dev/random of=src bs=1m count=1 1069a1fe327SAlan Somers 1079a1fe327SAlan Somers atf_check ggatel create -u $us work 1089a1fe327SAlan Somers 10915b69ab2SEnji Cooper ggate_dev=/dev/ggate${us} 11015b69ab2SEnji Cooper 11115b69ab2SEnji Cooper wait_for_ggate_device ${ggate_dev} 11215b69ab2SEnji Cooper 113b42fffb4SEnji Cooper atf_check -e ignore -o ignore \ 11415b69ab2SEnji Cooper dd if=src of=${ggate_dev} bs=1m count=1 conv=notrunc 1159a1fe327SAlan Somers 1169a1fe327SAlan Somers checksum src work 1179a1fe327SAlan Somers} 1189a1fe327SAlan Somers 1199a1fe327SAlan Somersggatel_file_cleanup() 1209a1fe327SAlan Somers{ 1219a1fe327SAlan Somers common_cleanup 1229a1fe327SAlan Somers} 1239a1fe327SAlan Somers 1249a1fe327SAlan Somersatf_test_case ggatel_md cleanup 1259a1fe327SAlan Somersggatel_md_head() 1269a1fe327SAlan Somers{ 1279a1fe327SAlan Somers atf_set "descr" "ggatel can proxy files" 1289a1fe327SAlan Somers atf_set "require.progs" "ggatel" 1299a1fe327SAlan Somers atf_set "require.user" "root" 1309a1fe327SAlan Somers atf_set "timeout" 15 1319a1fe327SAlan Somers} 1329a1fe327SAlan Somers 1339a1fe327SAlan Somersggatel_md_body() 1349a1fe327SAlan Somers{ 135b8891d7cSEnji Cooper load_ggate 136b8891d7cSEnji Cooper 1379a1fe327SAlan Somers us=$(alloc_ggate_dev) 1389a1fe327SAlan Somers work=$(alloc_md) 1399a1fe327SAlan Somers src=$(alloc_md) 1409a1fe327SAlan Somers 141b42fffb4SEnji Cooper atf_check -e ignore -o ignore \ 1429a1fe327SAlan Somers dd if=/dev/random of=$work bs=1m count=1 conv=notrunc 143b42fffb4SEnji Cooper atf_check -e ignore -o ignore \ 1449a1fe327SAlan Somers dd if=/dev/random of=$src bs=1m count=1 conv=notrunc 1459a1fe327SAlan Somers 1469a1fe327SAlan Somers atf_check ggatel create -u $us /dev/$work 1479a1fe327SAlan Somers 14815b69ab2SEnji Cooper ggate_dev=/dev/ggate${us} 14915b69ab2SEnji Cooper 15015b69ab2SEnji Cooper wait_for_ggate_device ${ggate_dev} 15115b69ab2SEnji Cooper 152b42fffb4SEnji Cooper atf_check -e ignore -o ignore \ 15315b69ab2SEnji Cooper dd if=/dev/$src of=${ggate_dev} bs=1m count=1 conv=notrunc 1549a1fe327SAlan Somers 1559a1fe327SAlan Somers checksum /dev/$src /dev/$work 1569a1fe327SAlan Somers} 1579a1fe327SAlan Somers 1589a1fe327SAlan Somersggatel_md_cleanup() 1599a1fe327SAlan Somers{ 1609a1fe327SAlan Somers common_cleanup 1619a1fe327SAlan Somers} 1629a1fe327SAlan Somers 1639a1fe327SAlan Somersatf_init_test_cases() 1649a1fe327SAlan Somers{ 1659a1fe327SAlan Somers atf_add_test_case ggated 1669a1fe327SAlan Somers atf_add_test_case ggatel_file 1679a1fe327SAlan Somers atf_add_test_case ggatel_md 168f5c6c43dSAlan Somers atf_add_test_case ggatec_trim 1699a1fe327SAlan Somers} 1709a1fe327SAlan Somers 1719a1fe327SAlan Somersalloc_ggate_dev() 1729a1fe327SAlan Somers{ 1739a1fe327SAlan Somers local us 1749a1fe327SAlan Somers 1759a1fe327SAlan Somers us=0 1769a1fe327SAlan Somers while [ -c /dev/ggate${us} ]; do 1779a1fe327SAlan Somers : $(( us += 1 )) 1789a1fe327SAlan Somers done 1799a1fe327SAlan Somers echo ${us} > ggate.devs 1809a1fe327SAlan Somers echo ${us} 1819a1fe327SAlan Somers} 1829a1fe327SAlan Somers 1839a1fe327SAlan Somersalloc_md() 1849a1fe327SAlan Somers{ 1859a1fe327SAlan Somers local md 1869a1fe327SAlan Somers 1879a1fe327SAlan Somers md=$(mdconfig -a -t malloc -s 1M) || \ 1889a1fe327SAlan Somers atf_fail "failed to allocate md device" 1899a1fe327SAlan Somers echo ${md} >> md.devs 1909a1fe327SAlan Somers echo ${md} 1919a1fe327SAlan Somers} 1929a1fe327SAlan Somers 1939a1fe327SAlan Somerschecksum() 1949a1fe327SAlan Somers{ 1959a1fe327SAlan Somers local src work 1969a1fe327SAlan Somers src=$1 1979a1fe327SAlan Somers work=$2 1989a1fe327SAlan Somers 1999a1fe327SAlan Somers src_checksum=$(md5 -q $src) 2009a1fe327SAlan Somers work_checksum=$(md5 -q $work) 2019a1fe327SAlan Somers 2029a1fe327SAlan Somers if [ "$work_checksum" != "$src_checksum" ]; then 2039a1fe327SAlan Somers atf_fail "work md5 checksum didn't match" 2049a1fe327SAlan Somers fi 2059a1fe327SAlan Somers 2069a1fe327SAlan Somers ggate_checksum=$(md5 -q /dev/ggate${us}) 2079a1fe327SAlan Somers if [ "$ggate_checksum" != "$src_checksum" ]; then 2089a1fe327SAlan Somers atf_fail "ggate md5 checksum didn't match" 2099a1fe327SAlan Somers fi 2109a1fe327SAlan Somers} 2119a1fe327SAlan Somers 2129a1fe327SAlan Somerscommon_cleanup() 2139a1fe327SAlan Somers{ 2149a1fe327SAlan Somers if [ -f "ggate.devs" ]; then 2159a1fe327SAlan Somers while read test_ggate; do 2169a1fe327SAlan Somers ggatec destroy -f -u $test_ggate >/dev/null 2179a1fe327SAlan Somers done < ggate.devs 2189a1fe327SAlan Somers rm ggate.devs 2199a1fe327SAlan Somers fi 2209a1fe327SAlan Somers 2219a1fe327SAlan Somers if [ -f "$PIDFILE" ]; then 2229a1fe327SAlan Somers pkill -F "$PIDFILE" 2239a1fe327SAlan Somers rm $PIDFILE 2249a1fe327SAlan Somers fi 2259a1fe327SAlan Somers 2269a1fe327SAlan Somers if [ -f "PLAINFILES" ]; then 2279a1fe327SAlan Somers while read f; do 2289a1fe327SAlan Somers rm -f ${f} 2299a1fe327SAlan Somers done < ${PLAINFILES} 2309a1fe327SAlan Somers rm ${PLAINFILES} 2319a1fe327SAlan Somers fi 2329a1fe327SAlan Somers 2339a1fe327SAlan Somers if [ -f "md.devs" ]; then 2349a1fe327SAlan Somers while read test_md; do 2354abfd5bdSAlan Somers # ggatec destroy doesn't release the provider 2364abfd5bdSAlan Somers # synchronously, so we may need to retry destroying it. 2374abfd5bdSAlan Somers while ! mdconfig -d -u $test_md; do 2384abfd5bdSAlan Somers sleep 0.1 2394abfd5bdSAlan Somers done 2409a1fe327SAlan Somers done < md.devs 2419a1fe327SAlan Somers rm md.devs 2429a1fe327SAlan Somers fi 2439a1fe327SAlan Somers true 2449a1fe327SAlan Somers} 24515b69ab2SEnji Cooper 246b8891d7cSEnji Cooperload_ggate() 247b8891d7cSEnji Cooper{ 248b8891d7cSEnji Cooper local class=gate 249b8891d7cSEnji Cooper 250b8891d7cSEnji Cooper # If the geom class isn't already loaded, try loading it. 251b8891d7cSEnji Cooper if ! kldstat -q -m g_${class}; then 252b8891d7cSEnji Cooper if ! geom ${class} load; then 253b8891d7cSEnji Cooper atf_skip "could not load module for geom class=${class}" 254b8891d7cSEnji Cooper fi 255b8891d7cSEnji Cooper fi 256b8891d7cSEnji Cooper} 257b8891d7cSEnji Cooper 25815b69ab2SEnji Cooper# Bug 204616: ggatel(8) creates /dev/ggate* asynchronously if `ggatel create` 25915b69ab2SEnji Cooper# isn't called with `-v`. 26015b69ab2SEnji Cooperwait_for_ggate_device() 26115b69ab2SEnji Cooper{ 26215b69ab2SEnji Cooper ggate_device=$1 26315b69ab2SEnji Cooper 26415b69ab2SEnji Cooper while [ ! -c $ggate_device ]; do 26515b69ab2SEnji Cooper sleep 0.5 26615b69ab2SEnji Cooper done 26715b69ab2SEnji Cooper} 268