From d834b9ce5ba6be96ce13c31351cf92c89f7762fe Mon Sep 17 00:00:00 2001 From: George Melikov Date: Thu, 9 Feb 2017 02:27:37 +0300 Subject: [PATCH] Add `wait_freeing` helper function to ZTS Sometimes the ZTS checks freed space just after `zfs destroy snapshot` and gets an unexpected value because of space being freed asynchronously. For cases like this add a `wait_freeing` function which blocks until the pools `freeing` property drops to zero. Reviewed-by: Brian Behlendorf Signed-off-by: George Melikov Closes #5740 --- tests/zfs-tests/include/libtest.shlib | 14 ++++++++++++++ .../cli_root/zfs_set/zfs_set_common.kshlib | 2 ++ .../tests/functional/snapshot/snapshot_008_pos.ksh | 2 ++ 3 files changed, 18 insertions(+) diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index 4127d35a8..31b1e1dfc 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -3078,3 +3078,17 @@ function sync_pool #pool log_must $SLEEP 2 done } + +# +# Wait for zpool 'freeing' property drops to zero. +# +# $1 pool name +# +function wait_freeing #pool +{ + typeset pool=${1:-$TESTPOOL} + while true; do + [[ "0" == "$($ZPOOL list -Ho freeing $pool)" ]] && break + log_must $SLEEP 1 + done +} diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib index 44f85e801..f818b754d 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib @@ -92,6 +92,8 @@ function set_n_check_prop log_mustnot $ZFS set $prop=$expect_value $dataset [[ -n $prop ]] && cur_value=$(get_prop $prop $dataset) + + wait_freeing if [[ "$expect_value" != "" && "$cur_value" != "$old_value" ]]; then diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_008_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_008_pos.ksh index 3610491b0..b4437a2a8 100755 --- a/tests/zfs-tests/tests/functional/snapshot/snapshot_008_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapshot/snapshot_008_pos.ksh @@ -88,6 +88,8 @@ while [[ $i -lt $COUNT ]]; do (( i = i + 1 )) done +wait_freeing $TESTPOOL + new_size=`get_prop available $TESTPOOL` typeset -i tolerance=0