1#!/usr/local/bin/ksh93 -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# $FreeBSD$ 24 25# 26# Copyright 2013 Spectra Logic. All rights reserved. 27# Use is subject to license terms. 28# 29# 30. $STF_SUITE/tests/hotspare/hotspare.kshlib 31 32################################################################################ 33# 34# __stc_assertion_start 35# 36# ID: hotspare_scrub_002_pos 37# 38# DESCRIPTION: 39# 'zpool scrub will scan spares as well as original devices' 40# 41# STRATEGY: 42# 1. Create a storage pool 43# 2. Add hot spare devices to the pool 44# 4. Replace one of the original devices with a spare 45# 5. Simulate errors on the spare 46# 6. Scrub the pool 47# 7. Verify that scrub detected the simulated errors 48# 49# TESTABILITY: explicit 50# 51# TEST_AUTOMATION_LEVEL: automated 52# 53# CODING STATUS: COMPLETED (2013-01-14) 54# 55# __stc_assertion_end 56# 57############################################################################### 58 59verify_runnable "global" 60 61function cleanup 62{ 63 poolexists $TESTPOOL && destroy_pool $TESTPOOL 64 partition_cleanup 65} 66 67# Returns the number of checksums errors detected on the given vdev 68function get_cksum #pool, vdev 69{ 70 typeset pool=$1 71 typeset vdev=$2 72 $ZPOOL status $pool | awk -v vdev=$vdev '$1~vdev {print $5; exit}' 73} 74 75function verify_assertion # odev 76{ 77 typeset odev=$1 78 79 log_must $ZPOOL replace $TESTPOOL $odev $sdev 80 log_must check_state $TESTPOOL "$sdev" "INUSE" 81 82 # corrupt out the $TESTPOOL to make sdev in use 83 # Skip the first input block so we don't overwrite the vdev label 84 log_must $DD if=/dev/zero bs=1024k count=63 oseek=1 conv=notrunc of=$sdev 85 86 $SYNC 87 # The pool may already have started scrubbing, so don't assert this. 88 # Expected postconditions are checked below anyway. 89 $ZPOOL scrub $TESTPOOL 90 while is_pool_scrubbing $TESTPOOL ; do 91 $SLEEP 2 92 done 93 94 # Verify that scrub detected the errors 95 # Some vdevs (ie raidz1) will display the errors on the spare-0 line 96 # instead of on the basic vdev line 97 [[ $(get_cksum $TESTPOOL $sdev) > 0 ]] 98 sdev_errors=$? 99 [[ $(get_cksum $TESTPOOL "spare-0") > 0 ]] 100 spare0_errors=$? 101 log_must [ $sdev_errors -o $spare0_errors ] 102 103 # Now clear the old errors, remove the original device and scrub again. 104 # No new errors should be found, because the scrub should've found and 105 # fixed all errors 106 log_must $ZPOOL clear $TESTPOOL 107 log_must $ZPOOL detach $TESTPOOL $odev 108 $ZPOOL scrub $TESTPOOL 109 while is_pool_scrubbing $TESTPOOL ; do 110 $SLEEP 2 111 done 112 if [ $(get_cksum $TESTPOOL $sdev) -ne 0 ]; then 113 log_fail "ERROR: Scrub missed cksum errors on a spare vdev" 114 fi 115} 116 117log_assert "'zpool scrub' scans spare vdevs" 118 119log_onexit cleanup 120 121set_devs 122typeset odev="${devarray[3]}" 123typeset sdev="${devarray[0]}" 124 125# Don't test striped pools because they can't have spares 126set -A keywords "mirror" "raidz" "raidz2" 127for keyword in "${keywords[@]}" ; do 128 setup_hotspares "$keyword" 129 130 iterate_over_hotspares verify_assertion $odev 131 132 destroy_pool "$TESTPOOL" 133done 134 135log_pass "'zpool scrub scans spare vdevs'" 136