diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim.kshlib b/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim.kshlib index 1c54c66c1..e8d43cc8c 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim.kshlib +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim.kshlib @@ -30,6 +30,23 @@ function trim_progress # pool disk trim_prog_line "$1" "$2" | sed 's/.*(\([0-9]\{1,\}\)% trimmed.*/\1/g' } +# +# Write a bit of data and sync several times. +# +function sync_and_rewrite_some_data_a_few_times +{ + typeset pool=$1 + typeset -i a_few_times=${2:-20} + + typeset file="/$pool/tmpfile" + for i in {0..$a_few_times}; do + dd if=/dev/urandom of=${file} bs=128k count=10 + sync_pool "$pool" + done + + return 0 +} + function cleanup { if poolexists $TESTPOOL; then diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_online_offline.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_online_offline.ksh index 681cd12f7..afc9a2ed1 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_online_offline.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_online_offline.ksh @@ -27,7 +27,7 @@ # Trimming automatically resumes across offline/online. # # STRATEGY: -# 1. Create a pool with a two-way mirror. +# 1. Create a pool with a two-way mirror, prepare blocks to trim. # 2. Start trimming one of the disks and verify that trimming is active. # 3. Offline the disk. # 4. Online the disk. @@ -39,8 +39,10 @@ DISK1=${DISKS%% *} DISK2="$(echo $DISKS | cut -d' ' -f2)" -log_must zpool create -f $TESTPOOL mirror $DISK1 $DISK2 -log_must zpool trim -r 128M $TESTPOOL $DISK1 +log_must zpool create -f $TESTPOOL mirror $DISK1 $DISK2 -O recordsize=4k +sync_and_rewrite_some_data_a_few_times $TESTPOOL + +log_must zpool trim -r 1 $TESTPOOL $DISK1 log_must zpool offline $TESTPOOL $DISK1 diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_start_and_cancel_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_start_and_cancel_neg.ksh index faf134fbb..68e990900 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_start_and_cancel_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_start_and_cancel_neg.ksh @@ -39,8 +39,10 @@ DISK2="$(echo $DISKS | cut -d' ' -f2)" DISK3="$(echo $DISKS | cut -d' ' -f3)" log_must zpool list -v -log_must zpool create -f $TESTPOOL $DISK1 $DISK2 $DISK3 -log_must zpool trim -r 128M $TESTPOOL $DISK1 +log_must zpool create -f $TESTPOOL $DISK1 $DISK2 $DISK3 -O recordsize=4k +sync_and_rewrite_some_data_a_few_times $TESTPOOL + +log_must zpool trim -r 1 $TESTPOOL $DISK1 [[ -z "$(trim_progress $TESTPOOL $DISK1)" ]] && \ log_fail "Trim did not start"