]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_wait/scan/zpool_wait_replace.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zpool_wait / scan / zpool_wait_replace.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) 2018 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 # 'zpool wait' works when a replacing disks.
23 #
24 # STRATEGY:
25 # 1. Attach a disk to pool to form two-way mirror.
26 # 2. Start a replacement of the new disk.
27 # 3. Start 'zpool wait'.
28 # 4. Monitor the waiting process to make sure it returns neither too soon nor
29 #    too late.
30 # 5. Repeat 2-4, except using the '-w' flag with 'zpool replace' instead of
31 #    using 'zpool wait'.
32 #
33
34 function cleanup
35 {
36         remove_io_delay
37         kill_if_running $pid
38         get_disklist $TESTPOOL | grep $DISK2 >/dev/null && \
39             log_must zpool detach $TESTPOOL $DISK2
40         get_disklist $TESTPOOL | grep $DISK3 >/dev/null && \
41             log_must zpool detach $TESTPOOL $DISK3
42 }
43
44 function in_progress
45 {
46         zpool status $TESTPOOL | grep 'replacing-' >/dev/null
47 }
48
49 typeset pid
50
51 log_onexit cleanup
52
53 log_must zpool attach -w $TESTPOOL $DISK1 $DISK2
54
55 add_io_delay $TESTPOOL
56
57 # Test 'zpool wait -t replace'
58 log_must zpool replace $TESTPOOL $DISK2 $DISK3
59 log_bkgrnd zpool wait -t replace $TESTPOOL
60 pid=$!
61 check_while_waiting $pid in_progress
62
63 # Test 'zpool replace -w'
64 log_bkgrnd zpool replace -w $TESTPOOL $DISK3 $DISK2
65 pid=$!
66 while ! is_pool_resilvering $TESTPOOL && proc_exists $pid; do
67         log_must sleep .5
68 done
69 check_while_waiting $pid in_progress
70
71 log_pass "'zpool wait -t replace' and 'zpool replace -w' work."