Add trim support to zpool wait

Manual trims fall into the category of long-running pool activities
which people might want to wait synchronously for. This change adds
support to 'zpool wait' for waiting for manual trim operations to
complete. It also adds a '-w' flag to 'zpool trim' which can be used to
turn 'zpool trim' into a synchronous operation.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Serapheim Dimitropoulos <serapheim@delphix.com>
Signed-off-by: John Gallagher <john.gallagher@delphix.com>
Closes #10071
This commit is contained in:
Brian Behlendorf
2020-03-04 15:07:11 -08:00
committed by GitHub
parent b3212d2fa6
commit 2288d41968
17 changed files with 347 additions and 73 deletions
+1
View File
@@ -470,6 +470,7 @@ tests = ['zpool_wait_discard', 'zpool_wait_freeing',
'zpool_wait_initialize_basic', 'zpool_wait_initialize_cancel',
'zpool_wait_initialize_flag', 'zpool_wait_multiple',
'zpool_wait_no_activity', 'zpool_wait_remove', 'zpool_wait_remove_cancel',
'zpool_wait_trim_basic', 'zpool_wait_trim_cancel', 'zpool_wait_trim_flag',
'zpool_wait_usage']
tags = ['functional', 'cli_root', 'zpool_wait']
@@ -11,6 +11,9 @@ dist_pkgdata_SCRIPTS = \
zpool_wait_no_activity.ksh \
zpool_wait_remove.ksh \
zpool_wait_remove_cancel.ksh \
zpool_wait_trim_basic.ksh \
zpool_wait_trim_cancel.ksh \
zpool_wait_trim_flag.ksh \
zpool_wait_usage.ksh
dist_pkgdata_DATA = \
@@ -0,0 +1,68 @@
#!/bin/ksh -p
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright (c) 2020 by Delphix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zpool_wait/zpool_wait.kshlib
#
# DESCRIPTION:
# 'zpool wait' works when waiting for devices to finish being trimmed
#
# STRATEGY:
# 1. Create a pool.
# 2. Start trimming the vdev in the pool, making sure the rate is slow enough
# that the trim can be observed.
# 3. Start 'zpool wait'.
# 4. Monitor the waiting process to make sure it returns neither too soon nor
# too late.
#
function cleanup
{
kill_if_running $pid
poolexists $TESTPOOL && destroy_pool $TESTPOOL
[[ -d "$TESTDIR" ]] && log_must rm -r "$TESTDIR"
}
# Check wether any vdevs in given pool are being trimmed
function trim_in_progress
{
typeset pool="$1"
zpool status -t "$pool" | grep "trimmed, started"
}
if is_freebsd; then
log_unsupported "FreeBSD has no hole punching mechanism for the time being."
fi
typeset -r FILE_VDEV="$TESTDIR/file_vdev"
typeset pid
log_onexit cleanup
log_must mkdir "$TESTDIR"
log_must truncate -s 10G "$FILE_VDEV"
log_must zpool create -f $TESTPOOL "$FILE_VDEV"
log_must zpool trim -r 2G $TESTPOOL "$FILE_VDEV"
log_bkgrnd zpool wait -t trim $TESTPOOL
pid=$!
check_while_waiting $pid "trim_in_progress $TESTPOOL"
log_pass "'zpool wait -t trim' works."
@@ -0,0 +1,77 @@
#!/bin/ksh -p
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright (c) 2020 by Delphix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zpool_wait/zpool_wait.kshlib
#
# DESCRIPTION:
# 'zpool wait' works when a trim operation is canceled.
#
# STRATEGY:
# 1. Create a pool.
# 2. Start trimming the vdev in the pool, setting the rate low enough that the
# operation won't complete before the test finishes.
# 3. Start 'zpool wait'.
# 4. Wait a few seconds and then check that the wait process is actually
# waiting.
# 5. Cancel the trim.
# 6. Check that the wait process returns reasonably promptly.
# 7. Repeat 3-7, except pause the trim instead of canceling it.
#
function cleanup
{
kill_if_running $pid
poolexists $TESTPOOL && destroy_pool $TESTPOOL
[[ -d "$TESTDIR" ]] && log_must rm -r "$TESTDIR"
}
function do_test
{
typeset stop_cmd=$1
log_must zpool trim -r 1M $TESTPOOL "$FILE_VDEV"
log_bkgrnd zpool wait -t trim $TESTPOOL
pid=$!
# Make sure that we are really waiting
log_must sleep 3
proc_must_exist $pid
# Stop trimming and make sure process returns
log_must eval "$stop_cmd"
bkgrnd_proc_succeeded $pid
}
if is_freebsd; then
log_unsupported "FreeBSD has no hole punching mechanism for the time being."
fi
typeset pid
typeset -r FILE_VDEV="$TESTDIR/file_vdev1"
log_onexit cleanup
log_must mkdir "$TESTDIR"
log_must truncate -s 10G "$FILE_VDEV"
log_must zpool create -f $TESTPOOL "$FILE_VDEV"
do_test "zpool trim -c $TESTPOOL $FILE_VDEV"
do_test "zpool trim -s $TESTPOOL $FILE_VDEV"
log_pass "'zpool wait' works when trim is stopped before completion."
@@ -0,0 +1,88 @@
#!/bin/ksh -p
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright (c) 2020 by Delphix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zpool_wait/zpool_wait.kshlib
#
# DESCRIPTION:
# -w flag for 'zpool trim' waits for trimming to complete for all and only those
# vdevs kicked off by that invocation.
#
# STRATEGY:
# 1. Create a pool with 3 vdevs.
# 2. Start trimming vdevs 1 and 2 with one invocation of 'zpool trim -w'
# 3. Start trimming vdev 3 with a second invocation of 'zpool trim -w'
# 4. Cancel the trim of vdev 1. Check that neither waiting process exits.
# 5. Cancel the trim of vdev 3. Check that only the second waiting process
# exits.
# 6. Cancel the trim of vdev 2. Check that the first waiting process exits.
#
function cleanup
{
kill_if_running $trim12_pid
kill_if_running $trim3_pid
poolexists $TESTPOOL && destroy_pool $TESTPOOL
[[ -d "$TESTDIR" ]] && log_must rm -r "$TESTDIR"
}
if is_freebsd; then
log_unsupported "FreeBSD has no hole punching mechanism for the time being."
fi
typeset trim12_pid trim3_pid
typeset -r VDEV1="$TESTDIR/file_vdev1"
typeset -r VDEV2="$TESTDIR/file_vdev2"
typeset -r VDEV3="$TESTDIR/file_vdev3"
log_onexit cleanup
log_must mkdir "$TESTDIR"
log_must truncate -s 10G "$VDEV1" "$VDEV2" "$VDEV3"
log_must zpool create -f $TESTPOOL "$VDEV1" "$VDEV2" "$VDEV3"
log_bkgrnd zpool trim -r 1M -w $TESTPOOL "$VDEV1" "$VDEV2"
trim12_pid=$!
log_bkgrnd zpool trim -r 1M -w $TESTPOOL "$VDEV3"
trim3_pid=$!
# Make sure that we are really waiting
log_must sleep 3
proc_must_exist $trim12_pid
proc_must_exist $trim3_pid
#
# Cancel trim of one of disks started by trim12, make sure neither
# process exits
#
log_must zpool trim -c $TESTPOOL "$VDEV1"
proc_must_exist $trim12_pid
proc_must_exist $trim3_pid
#
# Cancel trim started by trim3, make sure that process exits, but
# trim12 doesn't
#
log_must zpool trim -c $TESTPOOL "$VDEV3"
proc_must_exist $trim12_pid
bkgrnd_proc_succeeded $trim3_pid
# Cancel last trim started by trim12, make sure it returns.
log_must zpool trim -c $TESTPOOL "$VDEV2"
bkgrnd_proc_succeeded $trim12_pid
log_pass "'zpool trim -w' works."
@@ -77,8 +77,7 @@ for type in "" "mirror" "raidz" "raidz2" "raidz3"; do
zpool sync
if [[ $((n % 4)) -eq 0 ]]; then
log_must zpool trim $TESTPOOL
wait_trim $TESTPOOL $TRIM_VDEVS
log_must timeout 120 zpool trim -w $TESTPOOL
fi
done
log_must du -hs /$TESTPOOL
@@ -118,37 +118,3 @@ function verify_vdevs # op size vdevs
fi
done
}
#
# Wait for up to 120 seconds for trimming of the listed vdevs to complete.
#
function wait_trim # pool vdevs
{
typeset stop_time=$(( $(date +%s) + 120 ))
typeset pool="$1"
shift
typeset vdevs=$@
typeset complete
while [[ $complete -eq 0 ]]; do
complete=1
for vdev in $vdevs; do
if [[ "$(trim_progress $pool $vdev)" -lt "100" ]]; then
complete=0
break
else
log_must eval "trim_prog_line $pool $vdev | \
grep complete"
fi
done
if [ "$(date +%s)" -ge $stop_time ]; then
log_fail "Exceeded trim time limit of 120s"
fi
sleep 0.5
done
log_note "Pool completed trim successfully."
}
@@ -92,8 +92,7 @@ for type in "" "mirror" "raidz2"; do
# Remove the file, issue trim, verify the vdevs are now sparse.
log_must rm /$TESTPOOL/file
log_must zpool trim $TESTPOOL
wait_trim $TESTPOOL $VDEVS
log_must timeout 120 zpool trim -w $TESTPOOL
verify_vdevs "-le" "$VDEV_MIN_MB" $VDEVS
log_must zpool destroy $TESTPOOL
@@ -76,8 +76,7 @@ for type in "" "mirror" "raidz" "raidz2" "raidz3"; do
done
log_must du -hs /$TESTPOOL
log_must zpool trim $TESTPOOL
wait_trim $TESTPOOL $TRIM_VDEVS
log_must timeout 120 zpool trim -w $TESTPOOL
verify_trim_io $TESTPOOL "ind" 10
verify_pool $TESTPOOL