]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_trim_flag.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zpool_wait / zpool_wait_trim_flag.ksh
1 #!/bin/ksh -p
2 #
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
6 # 1.0 of the CDDL.
7 #
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.
11 #
12
13 #
14 # Copyright (c) 2020 by Delphix. All rights reserved.
15 #
16
17 . $STF_SUITE/include/libtest.shlib
18 . $STF_SUITE/tests/functional/cli_root/zpool_wait/zpool_wait.kshlib
19
20 #
21 # DESCRIPTION:
22 # -w flag for 'zpool trim' waits for trimming to complete for all and only those
23 # vdevs kicked off by that invocation.
24 #
25 # STRATEGY:
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
31 #    exits.
32 # 6. Cancel the trim of vdev 2. Check that the first waiting process exits.
33 #
34
35 function cleanup
36 {
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"
41 }
42
43 if is_freebsd; then
44         log_unsupported "FreeBSD has no hole punching mechanism for the time being."
45 fi
46
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"
51
52 log_onexit cleanup
53
54 log_must mkdir "$TESTDIR"
55 log_must truncate -s 10G "$VDEV1" "$VDEV2" "$VDEV3"
56 log_must zpool create -f $TESTPOOL "$VDEV1" "$VDEV2" "$VDEV3"
57
58 log_bkgrnd zpool trim -r 1M -w $TESTPOOL "$VDEV1" "$VDEV2"
59 trim12_pid=$!
60 log_bkgrnd zpool trim -r 1M -w $TESTPOOL "$VDEV3"
61 trim3_pid=$!
62
63 # Make sure that we are really waiting
64 log_must sleep 3
65 proc_must_exist $trim12_pid
66 proc_must_exist $trim3_pid
67
68 #
69 # Cancel trim of one of disks started by trim12, make sure neither
70 # process exits
71 #
72 log_must zpool trim -c $TESTPOOL "$VDEV1"
73 proc_must_exist $trim12_pid
74 proc_must_exist $trim3_pid
75
76 #
77 # Cancel trim started by trim3, make sure that process exits, but
78 # trim12 doesn't
79 #
80 log_must zpool trim -c $TESTPOOL "$VDEV3"
81 proc_must_exist $trim12_pid
82 bkgrnd_proc_succeeded $trim3_pid
83
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
87
88 log_pass "'zpool trim -w' works."