]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_offline_device.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zpool_scrub / zpool_scrub_offline_device.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
25 #
26
27 . $STF_SUITE/include/libtest.shlib
28 . $STF_SUITE/tests/functional/cli_root/zpool_reopen/zpool_reopen.shlib
29 . $STF_SUITE/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg
30
31 #
32 # DESCRIPTION:
33 # Scrubbing a pool with offline devices correctly preserves DTL entries
34 #
35 # STRATEGY:
36 # 1. Create the pool
37 # 2. Offline the first device
38 # 3. Write to the pool
39 # 4. Scrub the pool
40 # 5. Online the first device and offline the second device
41 # 6. Scrub the pool again
42 # 7. Verify data integrity
43 #
44 # NOTE:
45 # Ported from script used to reproduce issue #5806
46 #
47
48 verify_runnable "global"
49
50 function cleanup
51 {
52         poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
53         log_must rm -f $DISK1 $DISK2 $DISK3 $DISK4
54 }
55
56 #
57 # Update to [online|offline] $device status on $pool synchronously
58 #
59 function zpool_do_sync # <status> <pool> <device>
60 {
61         status="$1"
62         pool="$2"
63         device="$3"
64
65         if [[ $status != "online" && $status != "offline" ]]; then
66                 log_fail "zpool_do_sync: invalid status $status"
67         fi
68
69         log_must zpool $status $pool $device
70         for i in {1..10}; do
71                 check_state $pool $device $status && return 0
72         done
73         log_fail "Failed to $status device $device"
74 }
75
76 #
77 # Start a scrub on $pool and wait for its completion
78 #
79 function zpool_scrub_sync # <pool>
80 {
81         pool="$1"
82
83         log_must zpool scrub $pool
84         while ! is_pool_scrubbed $pool; do
85                 sleep 1
86         done
87 }
88
89 log_assert "Scrubbing a pool with offline devices correctly preserves DTLs"
90 log_onexit cleanup
91
92 DEVSIZE='128m'
93 FILESIZE='100m'
94 TESTDIR="$TEST_BASE_DIR/zpool_scrub_offline_device"
95 DISK1="$TEST_BASE_DIR/zpool_disk1.dat"
96 DISK2="$TEST_BASE_DIR/zpool_disk2.dat"
97 DISK3="$TEST_BASE_DIR/zpool_disk3.dat"
98 DISK4="$TEST_BASE_DIR/zpool_disk4.dat"
99 RESILVER_TIMEOUT=40
100
101 # 1. Create the pool
102 log_must truncate -s $DEVSIZE $DISK1
103 log_must truncate -s $DEVSIZE $DISK2
104 log_must truncate -s $DEVSIZE $DISK3
105 log_must truncate -s $DEVSIZE $DISK4
106 poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
107 log_must zpool create -O mountpoint=$TESTDIR $TESTPOOL2 \
108     raidz2 $DISK1 $DISK2 $DISK3 $DISK4
109
110 # 2. Offline the first device
111 zpool_do_sync 'offline' $TESTPOOL2 $DISK1
112
113 # 3. Write to the pool
114 log_must mkfile $FILESIZE "$TESTDIR/data.bin"
115
116 # 4. Scrub the pool
117 zpool_scrub_sync $TESTPOOL2
118
119 # 5. Online the first device and offline the second device
120 zpool_do_sync 'online' $TESTPOOL2 $DISK1
121 zpool_do_sync 'offline' $TESTPOOL2 $DISK2
122 log_must wait_for_resilver_end $TESTPOOL2 $RESILVER_TIMEOUT
123
124 # 6. Scrub the pool again
125 zpool_scrub_sync $TESTPOOL2
126
127 # 7. Verify data integrity
128 cksum=$(zpool status $TESTPOOL2 | awk 'L{print $NF;L=0} /CKSUM$/{L=1}')
129 if [[ $cksum != 0 ]]; then
130         log_fail "Unexpected CKSUM errors found on $TESTPOOL2 ($cksum)"
131 fi
132
133 log_pass "Scrubbing a pool with offline devices correctly preserves DTLs"