1# vim: filetype=sh 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 2009 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26 27. $STF_SUITE/include/libtest.kshlib 28 29function cleanup 30{ 31 log_note "Final pool configurations:" 32 poolexists $TESTPOOL && log_must $ZPOOL status -v $TESTPOOL 33 poolexists $TESTPOOL2 && log_must $ZPOOL status -v $TESTPOOL2 34 destroy_pool $TESTPOOL 35 destroy_pool $TESTPOOL2 36} 37 38# 39# Try zpool status/iostat for given pool 40# 41# $1 pool 42# 43function display_status 44{ 45 typeset pool=$1 46 47 typeset -i ret=0 48 $ZPOOL status -xv $pool > /dev/null 2>&1 49 ret=$? 50 51 $ZPOOL iostat > /dev/null 2>&1 52 ((ret |= $?)) 53 54 typeset mntpnt=$(get_prop mountpoint $pool) 55 $DD if=/dev/random of=$mntpnt/testfile.${TESTCASE_ID} & 56 typeset pid=$! 57 58 $ZPOOL iostat -v 1 3 > /dev/null 59 ((ret |= $?)) 60 61 kill -9 $pid 62 63 return $ret 64} 65 66# 67# Verify the give cache device have correct type and status 68# 69# $1 pool name 70# $2 device name 71# $3 device status 72# $4 device type 73# 74function verify_cache_device 75{ 76 typeset pool=$1 77 typeset device=$2 78 typeset status=$3 79 typeset type=$4 80 81 if [[ -z $pool || -z $device || -z $status ]]; then 82 log_fail "Usage: verify_cache_device <pool> <device> " \ 83 "<status> [type]" 84 fi 85 86 # Zpool status returns on the device name sans the /dev, so 87 # if the device contains /dev/ remove it. 88 device=${device#"/dev/"} 89 90 if [[ $WRAPPER == *"smi"* ]]; then 91 $ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 92 if (( $? == 0 )); then 93 device=${device}s2 94 fi 95 fi 96 97 # 98 # Get all the cache devices and status table like below 99 # 100 # mirror:/disks/d ONLINE mirror:/disks/e ONLINE stripe:/disks/f ONLINE 101 # 102 set -A dev_stat_tab $($ZPOOL status -v $pool | $NAWK ' 103 function parse_name(status) 104 { 105 if (status == "OFFLINE") 106 return substr($7,6) 107 else if (status == "UNAVAIL") 108 return substr($7,6) 109 else 110 return $1 111 } 112 113 BEGIN {in_cache=0} 114 /\tcache/ {in_cache=1} 115 /\tlog/ || /\tspares/ || /^$/ {in_cache=0} 116 117 # Skip if not in a cache section 118 (in_cache==0) { next; } 119 120 /\t (\/|[0-9a-zA-Z])/ { 121 print "stripe:" parse_name($2) " " $2; 122 } 123 124 /\t (\/|[a-zA-Z])/ { 125 print "mirror:" parse_name($2) " " $2; 126 } 127 128 # When hotspare is replacing 129 /\t (\/|[a-zA-Z])/ { 130 print "mirror:" parse_name($2) " " $2; 131 } 132 ') 133 134 typeset -i i=0 135 typeset find=0 136 while (( i < ${#dev_stat_tab[@]} )); do 137 typeset dev=${dev_stat_tab[$i]} 138 typeset stat=${dev_stat_tab[((i+1))]} 139 140 case $dev in 141 stripe:$device) 142 if [[ "$type" == 'mirror' ]]; then 143 log_note "Unexpected type: mirror" 144 return 1 145 else 146 if [[ $stat != $status ]]; then 147 log_note "Status($stat) " \ 148 "!= Expected stat($status)" 149 return 1 150 fi 151 return 0 152 fi 153 ;; 154 mirror:$device) 155 if [[ -z "$type" || $type == 'stripe' ]]; then 156 log_note "Unexpected type: stripe" 157 return 1 158 else 159 if [[ $stat != $status ]]; then 160 log_note "Status($stat) " \ 161 "!= Expected stat($status)" 162 return 1 163 fi 164 return 0 165 fi 166 ;; 167 esac 168 169 ((i += 2)) 170 done 171 172 log_note "Can not find device: $device" 173 174 return 1 175} 176