Clean up do_vol_test in zfs_copies tests

Get rid of the `get_used_prop` function. `get_prop used` works fine.

Fix the comment describing the function parameters. The type does not
have a default, and mntp is also used for ext2.

Rename the variable for the number of copies from `copy` to `copies`.

Use a `case` statement to match the type parameter, order the cases
alphabetically, and add a little sanity checking for good measure.

Use eval to make sure the output of commands is silenced rather than
the log messages when redirecting output to /dev/null.

Simplify cases where zfs requires special behavior.

Don't allow the test to loop forever in the event space usage does not
change. Bail out of the loop and fail after an arbitrary number of
iterations.

Add more information to the log message when the test fails, to help
debugging.

Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@ixsystems.com>
Closes #9286
This commit is contained in:
Ryan Moeller 2019-09-09 19:04:05 -04:00 committed by Brian Behlendorf
parent 4bbf0477a7
commit 43f4495bde

View File

@ -49,19 +49,6 @@ function cmp_prop
fi fi
} }
#
# Get the value of property used via zfs list
# $1, the dataset name
#
function get_used_prop
{
typeset ds=$1
typeset used
used=`zfs list -H -p -o used $ds`
echo $used
}
# #
# Check the used space is charged correctly # Check the used space is charged correctly
# $1, the number of used space # $1, the number of used space
@ -85,64 +72,72 @@ function check_used
# #
# test ncopies on volume # test ncopies on volume
# $1 test type zfs|ufs, default zfs # $1 test type zfs|ufs|ext2
# $2 copies # $2 copies
# $3 mntp for ufs test # $3 mntp for ufs|ext2 test
function do_vol_test function do_vol_test
{ {
typeset type=$1 typeset type=$1
typeset copy=$2 typeset copies=$2
typeset mntp=$3 typeset mntp=$3
vol=$TESTPOOL/$TESTVOL1 vol=$TESTPOOL/$TESTVOL1
vol_b_path=$ZVOL_DEVDIR/$TESTPOOL/$TESTVOL1 vol_b_path=$ZVOL_DEVDIR/$TESTPOOL/$TESTVOL1
vol_r_path=$ZVOL_RDEVDIR/$TESTPOOL/$TESTVOL1 vol_r_path=$ZVOL_RDEVDIR/$TESTPOOL/$TESTVOL1
log_must zfs create -V $VOLSIZE -o copies=$copy $vol log_must zfs create -V $VOLSIZE -o copies=$copies $vol
log_must zfs set refreservation=none $vol log_must zfs set refreservation=none $vol
block_device_wait block_device_wait
if [[ $type == "ufs" ]]; then case "$type" in
log_must echo y | newfs $vol_r_path >/dev/null 2>&1 "ext2")
log_must mount -F ufs -o rw $vol_b_path $mntp log_must eval "echo y | newfs $vol_r_path >/dev/null 2>&1"
elif [[ $type == "ext2" ]]; then
log_must echo y | newfs $vol_r_path >/dev/null 2>&1
log_must mount -o rw $vol_b_path $mntp log_must mount -o rw $vol_b_path $mntp
else ;;
"ufs")
if is_linux; then
log_unsupported "ufs test not implemented for linux"
fi
log_must eval "newfs $vol_r_path >/dev/null 2>&1"
log_must mount $vol_b_path $mntp
;;
"zfs")
log_must zpool create $TESTPOOL1 $vol_b_path log_must zpool create $TESTPOOL1 $vol_b_path
log_must zfs create $TESTPOOL1/$TESTFS1 log_must zfs create $TESTPOOL1/$TESTFS1
fi ;;
*)
log_unsupported "$type test not implemented"
;;
esac
((nfilesize = copy * ${FILESIZE%m})) ((nfilesize = copies * ${FILESIZE%m}))
pre_used=$(get_used_prop $vol) pre_used=$(get_prop used $vol)
((target_size = pre_used + nfilesize)) ((target_size = pre_used + nfilesize))
if [[ $type == "ufs" ]]; then if [[ $type == "zfs" ]]; then
log_must mkfile $FILESIZE $mntp/$FILE
elif [[ $type == "ext2" ]]; then
log_must mkfile $FILESIZE $mntp/$FILE
else
log_must mkfile $FILESIZE /$TESTPOOL1/$TESTFS1/$FILE log_must mkfile $FILESIZE /$TESTPOOL1/$TESTFS1/$FILE
else
log_must mkfile $FILESIZE $mntp/$FILE
fi fi
post_used=$(get_used_prop $vol) post_used=$(get_prop used $vol)
while ((post_used < target_size)) ; do ((retries = 0))
while ((post_used < target_size && retries++ < 42)); do
sleep 1 sleep 1
post_used=$(get_used_prop $vol) post_used=$(get_prop used $vol)
done done
((used = post_used - pre_used)) ((used = post_used - pre_used))
if ((used < nfilesize)); then if ((used < nfilesize)); then
log_fail "The space is not charged correctly while setting" \ log_fail "The space is not charged correctly while setting" \
"copies as $copy" "copies as $copies ($used < $nfilesize)" \
"pre=${pre_used} post=${post_used}"
fi fi
if [[ $type == "ufs" ]]; then if [[ $type == "zfs" ]]; then
umount $mntp
elif [[ $type == "ext2" ]]; then
umount $mntp
else
log_must zpool destroy $TESTPOOL1 log_must zpool destroy $TESTPOOL1
else
log_must umount $mntp
fi fi
log_must zfs destroy $vol log_must zfs destroy $vol