]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/replacement/rebuild_multiple.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / replacement / rebuild_multiple.ksh
1 #!/bin/ksh -p
2
3 #
4 # CDDL HEADER START
5 #
6 # This file and its contents are supplied under the terms of the
7 # Common Development and Distribution License ("CDDL"), version 1.0.
8 # You may only use this file in accordance with the terms of version
9 # 1.0 of the CDDL.
10 #
11 # A full copy of the text of the CDDL should have accompanied this
12 # source.  A copy of the CDDL is also available via the Internet at
13 # http://www.illumos.org/license/CDDL.
14 #
15 # CDDL HEADER END
16 #
17
18 #
19 # Copyright (c) 2019, Datto Inc. All rights reserved.
20 # Copyright (c) 2020 by Lawrence Livermore National Security, LLC.
21 #
22
23 . $STF_SUITE/include/libtest.shlib
24 . $STF_SUITE/tests/functional/replacement/replacement.cfg
25
26 #
27 # DESCRIPTION:
28 # Sequential reconstruction (unlike healing reconstruction) operate on the
29 # top-level vdev.  This means that a sequential resilver operation can be
30 # started/stopped on a different top-level vdev without impacting other
31 # sequential resilvers.
32 #
33 # STRATEGY:
34 # 1. Create a mirrored pool.
35 #
36
37 function cleanup
38 {
39         log_must set_tunable32 SCAN_SUSPEND_PROGRESS \
40             $ORIG_SCAN_SUSPEND_PROGRESS
41         destroy_pool $TESTPOOL1
42         rm -f ${VDEV_FILES[@]} $SPARE_VDEV_FILE $SPARE_VDEV_FILE2
43 }
44
45 function check_history
46 {
47         pool=$1
48         msg=$2
49         exp=$3
50
51         count=$(zpool history -i $pool | grep "rebuild" | grep -c "$msg")
52         if [[ "$count" -ne "$exp" ]]; then
53                 log_fail "Expected $exp rebuild '$msg' messages, found $count"
54         else
55                 log_note "Found $count/$exp rebuild '$msg' messages"
56         fi
57 }
58
59 log_assert "Rebuilds operate on the top-level vdevs"
60
61 ORIG_SCAN_SUSPEND_PROGRESS=$(get_tunable SCAN_SUSPEND_PROGRESS)
62
63 log_onexit cleanup
64
65 log_must truncate -s $VDEV_FILE_SIZE ${VDEV_FILES[@]} \
66     $SPARE_VDEV_FILE $SPARE_VDEV_FILE2
67
68 # Verify two sequential resilvers can run concurrently.
69 log_must zpool create -f $TESTPOOL1 \
70     mirror ${VDEV_FILES[0]} ${VDEV_FILES[1]} \
71     mirror ${VDEV_FILES[2]} ${VDEV_FILES[3]}
72 log_must zfs create $TESTPOOL1/$TESTFS
73
74 mntpnt=$(get_prop mountpoint $TESTPOOL1/$TESTFS)
75 log_must dd if=/dev/urandom of=$mntpnt/file bs=1M count=32
76 log_must zpool sync $TESTPOOL1
77
78 log_must set_tunable32 SCAN_SUSPEND_PROGRESS 1
79
80 log_must zpool replace -s $TESTPOOL1 ${VDEV_FILES[1]} $SPARE_VDEV_FILE
81 log_must zpool replace -s $TESTPOOL1 ${VDEV_FILES[3]} $SPARE_VDEV_FILE2
82
83 check_history $TESTPOOL1 "started" 2
84 check_history $TESTPOOL1 "reset" 0
85 check_history $TESTPOOL1 "complete" 0
86 check_history $TESTPOOL1 "canceled" 0
87
88 log_must set_tunable32 SCAN_SUSPEND_PROGRESS $ORIG_SCAN_SUSPEND_PROGRESS
89 log_must zpool wait -t resilver $TESTPOOL1
90
91 check_history $TESTPOOL1 "complete" 2
92 destroy_pool $TESTPOOL1
93
94 # Verify canceling one resilver (zpool detach) does not impact others.
95 log_must zpool create -f $TESTPOOL1 \
96     mirror ${VDEV_FILES[0]} ${VDEV_FILES[1]} \
97     mirror ${VDEV_FILES[2]} ${VDEV_FILES[3]}
98 log_must zfs create $TESTPOOL1/$TESTFS
99
100 mntpnt=$(get_prop mountpoint $TESTPOOL1/$TESTFS)
101 log_must dd if=/dev/urandom of=$mntpnt/file bs=1M count=32
102 log_must zpool sync $TESTPOOL1
103
104 log_must set_tunable32 SCAN_SUSPEND_PROGRESS 1
105
106 log_must zpool replace -s $TESTPOOL1 ${VDEV_FILES[1]} $SPARE_VDEV_FILE
107 log_must zpool replace -s $TESTPOOL1 ${VDEV_FILES[3]} $SPARE_VDEV_FILE2
108
109 check_history $TESTPOOL1 "started" 2
110 check_history $TESTPOOL1 "reset" 0
111 check_history $TESTPOOL1 "complete" 0
112 check_history $TESTPOOL1 "canceled" 0
113
114 log_must zpool detach $TESTPOOL1 $SPARE_VDEV_FILE2
115
116 check_history $TESTPOOL1 "complete" 0
117 check_history $TESTPOOL1 "canceled" 1
118
119 log_must set_tunable32 SCAN_SUSPEND_PROGRESS $ORIG_SCAN_SUSPEND_PROGRESS
120 log_must zpool wait -t resilver $TESTPOOL1
121
122 check_history $TESTPOOL1 "complete" 1
123 check_history $TESTPOOL1 "canceled" 1
124 destroy_pool $TESTPOOL1
125
126 log_pass "Rebuilds operate on the top-level vdevs"