BRT: Fix tests to work on non-empty pools

It should not normally happen, but if it does, better to not fail
everything for no good reason, or it may be hard to debug.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alexander Motin <mav@FreeBSD.org>
Sponsored by: iXsystems, Inc.
Closes #16007
This commit is contained in:
Alexander Motin 2024-03-19 12:25:14 -04:00 committed by Brian Behlendorf
parent 2ea370a4e3
commit e3c1c9153f

View File

@ -97,20 +97,19 @@ function verify_pool_prop_eq
function verify_pool_props
{
typeset -r dsize=$1
typeset -r ratio=$2
typeset -r oused=$1
typeset -r osaved=$2
typeset dsize=$3
typeset ratio=$4
if [[ $dsize -eq 0 ]]; then
verify_pool_prop_eq bcloneused 0
verify_pool_prop_eq bclonesaved 0
verify_pool_prop_eq bcloneratio 1.00
else
if [[ $ratio -eq 1 ]]; then
verify_pool_prop_eq bcloneused 0
else
verify_pool_prop_eq bcloneused $dsize
ratio=1
elif [[ $ratio -eq 1 ]]; then
dsize=0
fi
verify_pool_prop_eq bclonesaved $((dsize*(ratio-1)))
verify_pool_prop_eq bcloneused $(($oused+$dsize))
verify_pool_prop_eq bclonesaved $(($osaved+dsize*(ratio-1)))
if [[ $oused -eq 0 ]]; then
verify_pool_prop_eq bcloneratio "${ratio}.00"
fi
}
@ -124,16 +123,22 @@ function bclone_test
typeset -r srcdir=$4
typeset -r dstdir=$5
typeset dsize
typeset oused
typeset osaved
typeset -r original="${srcdir}/original"
typeset -r clone="${dstdir}/clone"
log_note "Testing file copy with datatype $datatype, file size $filesize, embedded $embedded"
# Save current block cloning stats for later use.
sync_pool $TESTPOOL
oused=$(get_pool_prop bcloneused $TESTPOOL)
osaved=$(get_pool_prop bclonesaved $TESTPOOL)
# Create a test file with known content.
case $datatype in
random|text)
sync_pool $TESTPOOL
if [[ $datatype = "random" ]]; then
dd if=/dev/urandom of=$original bs=$filesize count=1 2>/dev/null
else
@ -146,13 +151,13 @@ function bclone_test
sync_pool $TESTPOOL
# It is hard to predict block sizes that will be used,
# so just do one clone and take it from bcloneused.
filesize=$(zpool get -Hp -o value bcloneused $TESTPOOL)
dsize=$(get_pool_prop bcloneused $TESTPOOL)
dsize=$(($dsize-$oused))
if [[ $embedded = "false" ]]; then
log_must test $filesize -gt 0
log_must test $dsize -gt 0
fi
rm -f "${clone}-tmp"
sync_pool $TESTPOOL
dsize=$filesize
;;
hole)
log_must truncate_test -s $filesize -f $original
@ -217,7 +222,7 @@ function bclone_test
test_file_integrity $original_checksum "${clone}4" $filesize
test_file_integrity $original_checksum "${clone}5" $filesize
verify_pool_props $dsize 7
verify_pool_props $oused $osaved $dsize 7
# Clear cache and test after fresh import.
log_must zpool export $TESTPOOL
@ -240,7 +245,7 @@ function bclone_test
sync_pool $TESTPOOL
verify_pool_props $dsize 11
verify_pool_props $oused $osaved $dsize 11
log_must zpool export $TESTPOOL
log_must zpool import $TESTPOOL
@ -268,7 +273,7 @@ function bclone_test
test_file_integrity $original_checksum "${clone}8" $filesize
test_file_integrity $original_checksum "${clone}9" $filesize
verify_pool_props $dsize 6
verify_pool_props $oused $osaved $dsize 6
rm -f "${clone}0" "${clone}2" "${clone}4" "${clone}8" "${clone}9"
@ -276,11 +281,11 @@ function bclone_test
test_file_integrity $original_checksum "${clone}6" $filesize
verify_pool_props $dsize 1
verify_pool_props $oused $osaved $dsize 1
rm -f "${clone}6"
sync_pool $TESTPOOL
verify_pool_props $dsize 1
verify_pool_props $oused $osaved $dsize 1
}