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 2009 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)hotspare_import_001_pos.ksh 1.4 09/06/22 SMI" 30# 31. $STF_SUITE/tests/hotspare/hotspare.kshlib 32 33################################################################################ 34# 35# __stc_assertion_start 36# 37# ID: hotspare_import_001_pos 38# 39# DESCRIPTION: 40# If a storage pool has hot spare, 41# regardless it has been activated or NOT, 42# invoke "zpool export" then import with this storage pool 43# should runs successfully, and the data should keep integrity 44# after import. 45# 46# STRATEGY: 47# 1. Create a storage pool with hot spares 48# 2. Do 'zpool export' then 'zpool import' with following scernarios 49# - the hotspare is only in available list 50# - the hotspare is activated 51# - the hotspare is activated but offline 52# - the hotspare is activated but the basic vdev is offline 53# 3. Verify the export/import runs successfully, 54# and the data keep integrity after import 55# 56# TESTABILITY: explicit 57# 58# TEST_AUTOMATION_LEVEL: automated 59# 60# CODING STATUS: COMPLETED (2006-06-14) 61# 62# __stc_assertion_end 63# 64############################################################################### 65 66verify_runnable "global" 67 68function cleanup 69{ 70 poolexists $TESTPOOL && \ 71 destroy_pool $TESTPOOL 72 73 partition_cleanup 74} 75 76function verify_export_import #pool #file #chksum 77{ 78 typeset pool=$1 79 typeset file=$2 80 typeset checksum1=$3 81 typeset -i n=0 82 83 if ! $ZPOOL export $pool; then 84 # Rarely, this can fail with EBUSY if the pool's configuration 85 # has already changed within the same transaction group. In 86 # that case, it is appropriate to retry. 87 while ((n < 3)); do 88 $SYNC 89 log_note "$ZPOOL busy, retrying export (${n})..." 90 if ((n == 2)); then 91 log_must $ZPOOL export $pool 92 else 93 $ZPOOL export $pool && break 94 fi 95 $SLEEP 1 96 n=$((n + 1)) 97 done 98 fi 99 log_must $ZPOOL import -d $HOTSPARE_TMPDIR $pool 100 101 [[ ! -e $file ]] && \ 102 log_fail "$file missing after detach hotspare." 103 checksum2=$($SUM $file | $AWK '{print $1}') 104 [[ "$checksum1" != "$checksum2" ]] && \ 105 log_fail "Checksums differ ($checksum1 != $checksum2)" 106 107 return 0 108} 109 110function verify_assertion # dev 111{ 112 typeset dev=$1 113 typeset odev=${pooldevs[0]} 114 115 # 116 # - the hotspare is activated 117 # 118 log_must $ZPOOL replace $TESTPOOL $odev $dev 119 while ! is_pool_resilvered $TESTPOOL ; do 120 $SLEEP 2 121 done 122 123 verify_export_import $TESTPOOL \ 124 $mtpt/$TESTFILE0 $checksum1 125 126 # 127 # - the hotspare is activated 128 # but the basic vdev is offline 129 # 130 log_must $ZPOOL offline $TESTPOOL $odev 131 verify_export_import $TESTPOOL \ 132 $mtpt/$TESTFILE0 $checksum1 133 134 log_must $ZPOOL online $TESTPOOL $odev 135 136 log_must $ZPOOL detach $TESTPOOL $dev 137} 138 139log_assert "'zpool export/import <pool>' should runs successfully regardless the hotspare is only in list, activated, or offline." 140 141log_onexit cleanup 142 143typeset mtpt="" 144 145set_devs 146 147checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') 148 149for keyword in "${keywords[@]}" ; do 150 setup_hotspares "$keyword" 151 152 mtpt=$(get_prop mountpoint $TESTPOOL) 153 log_must $CP $MYTESTFILE $mtpt/$TESTFILE0 154 155 # 156 # - the hotspare is only in available list 157 # 158 verify_export_import $TESTPOOL \ 159 $mtpt/$TESTFILE0 $checksum1 160 161 iterate_over_hotspares verify_assertion "${vdev%% *}" 162 163 log_must $RM -f $mtpt/$TESTFILE0 164 destroy_pool "$TESTPOOL" 165done 166 167log_pass "'zpool export/import <pool>' should runs successfully regardless the hotspare is only in list, activated, or offline." 168