]>
git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/kstat/state.ksh
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.
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.
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]
23 # Copyright (c) 2018 by Lawrence Livermore National Security, LLC.
28 # Test /proc/spl/kstat/zfs/<pool>/state kstat
31 # 1. Create a mirrored pool
32 # 2. Check that pool is ONLINE
34 # 4. Check that pool is DEGRADED
35 # 5. Create a new pool with a single scsi_debug disk
37 # 7. Check that pool is SUSPENDED
38 # 8. Add the disk back in
39 # 9. Clear errors and destroy the pools
41 .
$STF_SUITE/include
/libtest.shlib
43 verify_runnable
"both"
47 # Destroy the scsi_debug pool
48 if [ -n "$TESTPOOL2" ] ; then
49 if [ -n "$host" ] ; then
53 # Device may have changed names after being inserted
54 SDISK
=$
(get_debug_device
)
55 log_must
ln $DEV_RDSKDIR/$SDISK $REALDISK
58 # Restore our working pool image
59 if [ -n "$BACKUP" ] ; then
60 gunzip
-c $BACKUP > $REALDISK
61 log_must
rm -f $BACKUP
64 # Our disk is back. Now we can clear errors and destroy the
66 log_must zpool
clear $TESTPOOL2
68 # Now that the disk is back and errors cleared, wait for our
69 # hung 'zpool scrub' to finish.
72 destroy_pool
$TESTPOOL2
78 # Check that our pool state values match what's expected
81 # $2: expected state ("ONLINE", "DEGRADED", "SUSPENDED", etc)
87 state1
=$
(zpool status
$pool |
awk '/state: /{print $2}');
88 state2
=$
(zpool list
-H -o health
$pool)
89 state3
=$
(cat /proc
/spl
/kstat
/zfs
/$pool/state
)
90 log_note
"Checking $expected = $state1 = $state2 = $state3"
91 if [[ "$expected" == "$state1" && "$expected" == "$state2" && \
92 "$expected" == "$state3" ]] ; then
101 log_assert
"Testing /proc/spl/kstat/zfs/<pool>/state kstat"
103 # Test that the initial pool is healthy
104 check_all
$TESTPOOL "ONLINE"
106 # Fault one of the disks, and check that pool is degraded
107 DISK1
=$
(echo "$DISKS" |
awk '{print $2}')
108 zpool offline
-tf $TESTPOOL $DISK1
109 check_all
$TESTPOOL "DEGRADED"
111 # Create a new pool out of a scsi_debug disk
113 MINVDEVSIZE_MB
=$
((MINVDEVSIZE
/ 1048576))
114 load_scsi_debug
$MINVDEVSIZE_MB 1 1 1 '512b'
116 SDISK
=$
(get_debug_device
)
117 host=$
(get_scsi_host
$SDISK)
119 # Use $REALDISK instead of $SDISK in our pool because $SDISK can change names
120 # as we remove/add the disk (i.e. /dev/sdf -> /dev/sdg).
121 REALDISK
=/dev
/kstat-state-realdisk
122 log_must
[ ! -e $REALDISK ]
123 ln $DEV_RDSKDIR/$SDISK $REALDISK
125 log_must zpool create
$TESTPOOL2 $REALDISK
127 # Backup the contents of the disk image
128 BACKUP
=$TEST_BASE_DIR/kstat-state-realdisk.gz
129 log_must
[ ! -e $BACKUP ]
130 gzip -c $REALDISK > $BACKUP
132 # Yank out the disk from under the pool
133 log_must
rm $REALDISK
136 # Run a 'zpool scrub' in the background to suspend the pool. We run it in the
137 # background since the command will hang when the pool gets suspended. The
138 # command will resume and exit after we restore the missing disk later on.
139 zpool scrub
$TESTPOOL2 &
140 sleep 1 # Give the scrub some time to run before we check if it fails
142 log_must check_all
$TESTPOOL2 "SUSPENDED"
144 log_pass
"/proc/spl/kstat/zfs/<pool>/state test successful"