From 4818563f85bf825df92ebc2ac1076443ad7af036 Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Mon, 9 Sep 2019 19:04:05 -0400 Subject: [PATCH] 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 Reviewed-by: Brian Behlendorf Signed-off-by: Ryan Moeller Closes #9286 --- .../cli_root/zfs_copies/zfs_copies.kshlib | 75 +++++++++---------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib index a86b2f78f..b0ced58c9 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib @@ -49,19 +49,6 @@ function cmp_prop 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 # $1, the number of used space @@ -85,64 +72,72 @@ function check_used # # test ncopies on volume -# $1 test type zfs|ufs, default zfs +# $1 test type zfs|ufs|ext2 # $2 copies -# $3 mntp for ufs test +# $3 mntp for ufs|ext2 test function do_vol_test { typeset type=$1 - typeset copy=$2 + typeset copies=$2 typeset mntp=$3 vol=$TESTPOOL/$TESTVOL1 vol_b_path=$ZVOL_DEVDIR/$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 block_device_wait - if [[ $type == "ufs" ]]; then - log_must echo y | newfs $vol_r_path >/dev/null 2>&1 - log_must mount -F ufs -o rw $vol_b_path $mntp - elif [[ $type == "ext2" ]]; then - log_must echo y | newfs $vol_r_path >/dev/null 2>&1 + case "$type" in + "ext2") + log_must eval "echo y | newfs $vol_r_path >/dev/null 2>&1" 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 zfs create $TESTPOOL1/$TESTFS1 - fi + ;; + *) + log_unsupported "$type test not implemented" + ;; + esac - ((nfilesize = copy * ${FILESIZE%m})) - pre_used=$(get_used_prop $vol) + ((nfilesize = copies * ${FILESIZE%m})) + pre_used=$(get_prop used $vol) ((target_size = pre_used + nfilesize)) - if [[ $type == "ufs" ]]; then - log_must mkfile $FILESIZE $mntp/$FILE - elif [[ $type == "ext2" ]]; then - log_must mkfile $FILESIZE $mntp/$FILE - else + if [[ $type == "zfs" ]]; then log_must mkfile $FILESIZE /$TESTPOOL1/$TESTFS1/$FILE + else + log_must mkfile $FILESIZE $mntp/$FILE fi - post_used=$(get_used_prop $vol) - while ((post_used < target_size)) ; do + post_used=$(get_prop used $vol) + ((retries = 0)) + while ((post_used < target_size && retries++ < 42)); do sleep 1 - post_used=$(get_used_prop $vol) + post_used=$(get_prop used $vol) done ((used = post_used - pre_used)) if ((used < nfilesize)); then 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 - if [[ $type == "ufs" ]]; then - umount $mntp - elif [[ $type == "ext2" ]]; then - umount $mntp - else + if [[ $type == "zfs" ]]; then log_must zpool destroy $TESTPOOL1 + else + log_must umount $mntp fi log_must zfs destroy $vol