Skip to content

Commit

Permalink
ZTS: zpool_trim tests throttle trim process
Browse files Browse the repository at this point in the history
Otherwise trim may finish before progress checks.

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: George Melikov <[email protected]>
Closes #11296
  • Loading branch information
gmelikov authored Dec 7, 2020
1 parent 83b698d commit 8e8fdce
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8e8fdce

Please sign in to comment.