106253fa7Sriz 206253fa7Sriz# Common settings and functions for the various resize_ffs tests. 306253fa7Sriz# 406253fa7Sriz 506253fa7Sriz# called from atf_init_test_cases 606253fa7Srizsetupvars() 706253fa7Sriz{ 806253fa7Sriz IMG=fsimage 906253fa7Sriz TDBASE64=$(atf_get_srcdir)/testdata.tar.gz.base64 1006253fa7Sriz GOODMD5=$(atf_get_srcdir)/testdata.md5 1106253fa7Sriz # set BYTESWAP to opposite-endian. 1206253fa7Sriz if [ $(sysctl -n hw.byteorder) = "1234" ]; then 1306253fa7Sriz BYTESWAP=be 1406253fa7Sriz else 1506253fa7Sriz BYTESWAP=le 1606253fa7Sriz fi 1706253fa7Sriz} 1806253fa7Sriz 1906253fa7Sriz# test_case() taken from the tests/ipf/h_common.sh 2006253fa7Sriz# Used to declare the atf goop for a test. 2106253fa7Sriztest_case() 2206253fa7Sriz{ 2306253fa7Sriz local name="${1}"; shift 2406253fa7Sriz local check_function="${1}"; shift 2506253fa7Sriz 2606253fa7Sriz atf_test_case "${name}" cleanup 27a44c3b65Sriz eval "${name}_head() { \ 28c9ff7859Sriz atf_set "require.user" "root" ; \ 2994bcefa4Sjoerg atf_set "require.progs" "rump_ffs" ; \ 30a44c3b65Sriz }" 3106253fa7Sriz eval "${name}_body() { \ 3206253fa7Sriz ${check_function} " "${@}" "; \ 3306253fa7Sriz }" 3406253fa7Sriz eval "${name}_cleanup() { \ 35c9ff7859Sriz umount -f mnt ; \ 36c9ff7859Sriz : reset error ; \ 3706253fa7Sriz }" 3806253fa7Sriz} 3906253fa7Sriz 4006253fa7Sriz# Used to declare the atf goop for a test expected to fail. 4106253fa7Sriztest_case_xfail() 4206253fa7Sriz{ 4306253fa7Sriz local name="${1}"; shift 4406253fa7Sriz local reason="${1}"; shift 4506253fa7Sriz local check_function="${1}"; shift 4606253fa7Sriz 4706253fa7Sriz atf_test_case "${name}" cleanup 4859bc3aabSnjoly eval "${name}_head() { \ 4959bc3aabSnjoly atf_set "require.user" "root" ; \ 5059bc3aabSnjoly }" 5106253fa7Sriz eval "${name}_body() { \ 5206253fa7Sriz atf_expect_fail "${reason}" ; \ 5306253fa7Sriz ${check_function} " "${@}" "; \ 5406253fa7Sriz }" 5506253fa7Sriz eval "${name}_cleanup() { \ 5677229925Spooka umount -f mnt ; \ 57c876d9d9Spooka : reset error ; \ 5806253fa7Sriz }" 5906253fa7Sriz} 6006253fa7Sriz 6106253fa7Sriz# copy_data requires the mount already done; makes one copy of the test data 6206253fa7Srizcopy_data () 6306253fa7Sriz{ 64c9ff7859Sriz uudecode -p ${TDBASE64} | (cd mnt; tar xzf - -s/testdata/TD$1/) 6506253fa7Sriz} 6606253fa7Sriz 6706253fa7Srizcopy_multiple () 6806253fa7Sriz{ 6906253fa7Sriz local i 70468e2d30Sriz for i in $(seq $1); do 7106253fa7Sriz copy_data $i 7206253fa7Sriz done 7306253fa7Sriz} 7406253fa7Sriz 7506253fa7Sriz# remove_data removes one directory worth of test data; the purpose 7606253fa7Sriz# is to ensure data exists near the end of the fs under test. 7706253fa7Srizremove_data () 7806253fa7Sriz{ 79c9ff7859Sriz rm -rf mnt/TD$1 8006253fa7Sriz} 8106253fa7Sriz 8206253fa7Srizremove_multiple () 8306253fa7Sriz{ 8406253fa7Sriz local i 85468e2d30Sriz for i in $(seq $1); do 8606253fa7Sriz remove_data $i 8706253fa7Sriz done 8806253fa7Sriz} 8906253fa7Sriz 9006253fa7Sriz# verify that the data in a particular directory is still OK 9106253fa7Sriz# generated md5 file doesn't need explicit cleanup thanks to ATF 9206253fa7Srizcheck_data () 9306253fa7Sriz{ 94c9ff7859Sriz (cd mnt/TD$1 && md5 *) > TD$1.md5 95c9ff7859Sriz atf_check diff -u ${GOODMD5} TD$1.md5 9606253fa7Sriz} 9706253fa7Sriz 9806253fa7Sriz# supply begin and end arguments 9906253fa7Srizcheck_data_range () 10006253fa7Sriz{ 10106253fa7Sriz local i 102468e2d30Sriz for i in $(seq $1 $2); do 10306253fa7Sriz check_data $i 10406253fa7Sriz done 10506253fa7Sriz} 106b83a3548Sriz 107b83a3548Sriz 108b83a3548Srizresize_ffs() 109b83a3548Sriz{ 11089e455beSriz echo "in resize_ffs:" ${@} 111b83a3548Sriz local bs=$1 112b83a3548Sriz local fragsz=$2 113b83a3548Sriz local osize=$3 114b83a3548Sriz local nsize=$4 115b83a3548Sriz local fslevel=$5 116b83a3548Sriz local numdata=$6 117b83a3548Sriz local swap=$7 118*b4655104Smartin local avail=$( df -m . | awk '{if (int($4) > 0) print $4}' ) 119*b4655104Smartin # convert MB size to blocks 120*b4655104Smartin avail=$(( $avail \* 2 \* 1024 )) 121*b4655104Smartin if [ $avail -lt $osize ] || [ $avail -lt $nsize ]; then 122*b4655104Smartin atf_skip "not enough free space in working directory" 123*b4655104Smartin fi 124c9ff7859Sriz mkdir -p mnt 125b83a3548Sriz echo "bs is ${bs} numdata is ${numdata}" 12689e455beSriz echo "****resizing fs with blocksize ${bs}" 127b83a3548Sriz 128b83a3548Sriz # we want no more than 16K/inode to allow test files to copy. 129b83a3548Sriz local fpi=$((fragsz * 4)) 130b83a3548Sriz local i 131b83a3548Sriz if [ $fpi -gt 16384 ]; then 132b83a3548Sriz i="-i 16384" 133b83a3548Sriz fi 134b83a3548Sriz if [ x$swap != x ]; then 135b83a3548Sriz newfs -B ${BYTESWAP} -O${fslevel} -b ${bs} -f ${fragsz} \ 136b83a3548Sriz -s ${osize} ${i} -F ${IMG} 137b83a3548Sriz else 138b83a3548Sriz newfs -O${fslevel} -b ${bs} -f ${fragsz} -s ${osize} ${i} \ 139b83a3548Sriz -F ${IMG} 140b83a3548Sriz fi 141b83a3548Sriz 142b83a3548Sriz # we're specifying relative paths, so rump_ffs warns - ignore. 143981c4cd0Skre if ! rump_ffs ${IMG} mnt >/dev/null 2>S.Err 144981c4cd0Skre then 145981c4cd0Skre if grep 'puffs_daemon: Operation not supported by device' S.Err >/dev/null 146981c4cd0Skre then 147981c4cd0Skre atf_skip 'No PUFFS available in kernel' 148981c4cd0Skre else 1490c2085b2Smartin atf_fail "rump_ffs mount failed: $(tail -r S.Err | 150981c4cd0Skre sed -e '/^$/d' -e p -e q )" 151981c4cd0Skre fi 152981c4cd0Skre fi 153981c4cd0Skre 154b83a3548Sriz copy_multiple ${numdata} 155b83a3548Sriz 156b83a3548Sriz if [ ${nsize} -lt ${osize} ]; then 157b83a3548Sriz # how much data to remove so fs can be shrunk 158b83a3548Sriz local remove=$((numdata-numdata*nsize/osize)) 159b83a3548Sriz local dataleft=$((numdata-remove)) 160b83a3548Sriz echo remove is $remove dataleft is $dataleft 161b83a3548Sriz remove_multiple ${remove} 162b83a3548Sriz fi 163b83a3548Sriz 164c9ff7859Sriz umount mnt 1653fe0ea9cSchopps # Check that resize needed 1663fe0ea9cSchopps atf_check -s exit:0 -o ignore resize_ffs -c -y -s ${nsize} ${IMG} 167b83a3548Sriz atf_check -s exit:0 -o ignore resize_ffs -y -s ${nsize} ${IMG} 168b83a3548Sriz atf_check -s exit:0 -o ignore fsck_ffs -f -n -F ${IMG} 169c9ff7859Sriz atf_check -s exit:0 -e ignore rump_ffs ${IMG} mnt 170b83a3548Sriz if [ ${nsize} -lt ${osize} ]; then 171b83a3548Sriz check_data_range $((remove + 1)) ${numdata} 17264fbc2ffSriz else 17364fbc2ffSriz # checking everything because we don't delete on grow 17464fbc2ffSriz check_data_range 1 ${numdata} 175b83a3548Sriz fi 1763fe0ea9cSchopps # Check that no resize needed 1773fe0ea9cSchopps atf_check -s exit:1 -o ignore resize_ffs -c -y -s ${nsize} ${IMG} 178c9ff7859Sriz umount mnt 179b83a3548Sriz} 180