From 65c4c9a233119b1d7f3a4eb8e71caf3336694d48 Mon Sep 17 00:00:00 2001 From: George Melikov Date: Mon, 7 Dec 2020 21:06:10 +0300 Subject: [PATCH] ZTS: zpool_trim tests throttle trim process Otherwise trim may finish before progress checks. Reviewed-by: Brian Behlendorf Signed-off-by: George Melikov Closes #11296 --- .../cli_root/zpool_trim/zpool_trim.kshlib | 17 +++++++++++++++++ .../zpool_trim/zpool_trim_online_offline.ksh | 8 +++++--- .../zpool_trim_start_and_cancel_neg.ksh | 6 ++++-- 3 files changed, 26 insertions(+), 5 deletions(-) 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 1c54c66c12..e8d43cc8c7 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 681cd12f71..afc9a2ed19 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 faf134fbbd..68e9909007 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"