1153184Spjd#!/bin/sh 2153184Spjd# $FreeBSD: releng/10.3/tools/regression/geom_subr.sh 294550 2016-01-22 07:23:50Z ngie $ 3153184Spjd 4153184Spjddevwait() 5153184Spjd{ 6153184Spjd while :; do 7153184Spjd if [ -c /dev/${class}/${name} ]; then 8153184Spjd return 9153184Spjd fi 10153184Spjd sleep 0.2 11153184Spjd done 12153184Spjd} 13294063Sngie 14294063Sngieattach_md() 15294063Sngie{ 16294063Sngie local test_md 17294063Sngie 18294063Sngie test_md=$(mdconfig -a "$@") || exit 19294063Sngie echo $test_md >> $TEST_MDS_FILE || exit 20294063Sngie echo $test_md 21294063Sngie} 22294063Sngie 23294063Sngiegeom_test_cleanup() 24294063Sngie{ 25294063Sngie local test_md 26294063Sngie 27294550Sngie if [ -f "$TEST_MDS_FILE" ]; then 28294063Sngie while read test_md; do 29294063Sngie # The "#" tells the TAP parser this is a comment 30294063Sngie echo "# Removing test memory disk: $test_md" 31294063Sngie mdconfig -d -u $test_md 32294063Sngie done < $TEST_MDS_FILE 33294063Sngie fi 34294550Sngie rm -f "$TEST_MDS_FILE" 35294063Sngie} 36294550Sngie 37294550Sngieif [ $(id -u) -ne 0 ]; then 38294550Sngie echo 'Tests must be run as root' 39294550Sngie echo 'Bail out!' 40294550Sngie exit 1 41294550Sngiefi 42294550Sngie# If the geom class isn't already loaded, try loading it. 43294550Sngieif ! kldstat -q -m g_${class}; then 44294550Sngie if ! geom ${class} load; then 45294550Sngie echo "Could not load module for geom class=${class}" 46294550Sngie echo 'Bail out!' 47294550Sngie exit 1 48294550Sngie fi 49294550Sngiefi 50294550Sngie 51294550Sngie# Need to keep track of the test md devices to avoid the scenario where a test 52294550Sngie# failing will cause the other tests to bomb out, or a test failing will leave 53294550Sngie# a large number of md(4) devices lingering around 54294550Sngie: ${TMPDIR=/tmp} 55294550Sngieexport TMPDIR 56294550Sngieif ! TEST_MDS_FILE=$(mktemp ${TMPDIR}/test_mds.XXXXXX); then 57294550Sngie echo 'Failed to create temporary file for tracking the test md(4) devices' 58294550Sngie echo 'Bail out!' 59294550Sngie exit 1 60294550Sngiefi 61