Skip to content

Commit

Permalink
BRT: Fix tests to work on non-empty pools
Browse files Browse the repository at this point in the history
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.

Signed-off-by:	Alexander Motin <mav@FreeBSD.org>
Sponsored by:	iXsystems, Inc.
  • Loading branch information
amotin committed Mar 20, 2024
1 parent 039f28f commit 78ab221
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions tests/zfs-tests/tests/functional/bclone/bclone_common.kshlib
Original file line number Diff line number Diff line change
Expand Up @@ -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
fi
verify_pool_prop_eq bclonesaved $((dsize*(ratio-1)))
ratio=1
elif [[ $ratio -eq 1 ]]; then
dsize=0
fi
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
}
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -268,19 +273,19 @@ 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"

sync_pool $TESTPOOL

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
}

0 comments on commit 78ab221

Please sign in to comment.