3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
14 # Copyright (c) 2020 by Delphix. All rights reserved.
17 . $STF_SUITE/include/libtest.shlib
18 . $STF_SUITE/tests/functional/cli_root/zpool_wait/zpool_wait.kshlib
22 # -w flag for 'zpool trim' waits for trimming to complete for all and only those
23 # vdevs kicked off by that invocation.
26 # 1. Create a pool with 3 vdevs.
27 # 2. Start trimming vdevs 1 and 2 with one invocation of 'zpool trim -w'
28 # 3. Start trimming vdev 3 with a second invocation of 'zpool trim -w'
29 # 4. Cancel the trim of vdev 1. Check that neither waiting process exits.
30 # 5. Cancel the trim of vdev 3. Check that only the second waiting process
32 # 6. Cancel the trim of vdev 2. Check that the first waiting process exits.
37 kill_if_running $trim12_pid
38 kill_if_running $trim3_pid
39 poolexists $TESTPOOL && destroy_pool $TESTPOOL
40 [[ -d "$TESTDIR" ]] && log_must rm -r "$TESTDIR"
44 log_unsupported "FreeBSD has no hole punching mechanism for the time being."
47 typeset trim12_pid trim3_pid
48 typeset -r VDEV1="$TESTDIR/file_vdev1"
49 typeset -r VDEV2="$TESTDIR/file_vdev2"
50 typeset -r VDEV3="$TESTDIR/file_vdev3"
54 log_must mkdir "$TESTDIR"
55 log_must truncate -s 10G "$VDEV1" "$VDEV2" "$VDEV3"
56 log_must zpool create -f $TESTPOOL "$VDEV1" "$VDEV2" "$VDEV3"
58 log_bkgrnd zpool trim -r 1M -w $TESTPOOL "$VDEV1" "$VDEV2"
60 log_bkgrnd zpool trim -r 1M -w $TESTPOOL "$VDEV3"
63 # Make sure that we are really waiting
65 proc_must_exist $trim12_pid
66 proc_must_exist $trim3_pid
69 # Cancel trim of one of disks started by trim12, make sure neither
72 log_must zpool trim -c $TESTPOOL "$VDEV1"
73 proc_must_exist $trim12_pid
74 proc_must_exist $trim3_pid
77 # Cancel trim started by trim3, make sure that process exits, but
80 log_must zpool trim -c $TESTPOOL "$VDEV3"
81 proc_must_exist $trim12_pid
82 bkgrnd_proc_succeeded $trim3_pid
84 # Cancel last trim started by trim12, make sure it returns.
85 log_must zpool trim -c $TESTPOOL "$VDEV2"
86 bkgrnd_proc_succeeded $trim12_pid
88 log_pass "'zpool trim -w' works."