1 # 2 # CDDL HEADER START 3 # 4 # The contents of this file are subject to the terms of the 5 # Common Development and Distribution License (the "License"). 6 # You may not use this file except in compliance with the License. 7 # 8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 # or http://www.opensolaris.org/os/licensing. 10 # See the License for the specific language governing permissions 11 # and limitations under the License. 12 # 13 # When distributing Covered Code, include this CDDL HEADER in each 14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 # If applicable, add the following below this CDDL HEADER, with the 16 # fields enclosed by brackets "[]" replaced with your own identifying 17 # information: Portions Copyright [yyyy] [name of copyright owner] 18 # 19 # CDDL HEADER END 20 # 21 22 # 23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 # ident "@(#)slog.kshlib 1.2 08/11/03 SMI" 27 # 28 29 . $STF_SUITE/include/libtest.kshlib 30 31 function cleanup 32 { 33 if datasetexists $TESTPOOL ; then 34 log_must $ZPOOL destroy -f $TESTPOOL 35 fi 36 if datasetexists $TESTPOOL2 ; then 37 log_must $ZPOOL destroy -f $TESTPOOL2 38 fi 39 } 40 41 # 42 # Try zpool status/iostat for given pool 43 # 44 # $1 pool 45 # 46 function display_status 47 { 48 typeset pool=$1 49 50 typeset -i ret=0 51 $ZPOOL status -xv $pool > /dev/null 2>&1 52 ret=$? 53 54 $ZPOOL iostat > /dev/null 2>&1 55 ((ret |= $?)) 56 57 typeset mntpnt=$(get_prop mountpoint $pool) 58 $DD if=/dev/random of=$mntpnt/testfile.$$ & 59 typeset pid=$! 60 61 $ZPOOL iostat -v 1 3 > /dev/null 62 ((ret |= $?)) 63 64 kill -9 $pid 65 66 return $ret 67 } 68 69 # 70 # Verify the give slog device have correct type and status 71 # 72 # $1 pool name 73 # $2 device name 74 # $3 device status 75 # $4 device type 76 # 77 function verify_slog_device 78 { 79 typeset pool=$1 80 typeset device=$2 81 typeset status=$3 82 typeset type=$4 83 84 if [[ -z $pool || -z $device || -z $status ]]; then 85 log_fail "Usage: verify_slog_device <pool> <device> " \ 86 "<status> [type]" 87 fi 88 89 if [[ $WRAPPER == *"smi"* ]]; then 90 $ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 91 if (( $? == 0 )); then 92 device=${device}s2 93 fi 94 fi 95 96 # 97 # Get all the slog devices and status table like below 98 # 99 # mirror:/disks/d ONLINE mirror:/disks/e ONLINE stripe:/disks/f ONLINE 100 # 101 set -A dev_stat_tab $($ZPOOL status -v $pool | $NAWK 'BEGIN {start=0} \ 102 /\tlogs/ {start=1} 103 /\tmirror/ || /\tspares/ || /^$/ {start=0} 104 (start==1) && /\t (\/|[a-zA-Z])/ \ 105 {print "stripe:" $1 " " $2} 106 (start==1) && /\t (\/|[a-zA-Z])/ \ 107 {print "mirror:" $1 " " $2} 108 # When hotspare is replacing 109 (start==1) && /\t (\/|[a-zA-Z])/ \ 110 {print "mirror:" $1 " " $2}' 111 ) 112 113 typeset -i i=0 114 typeset find=0 115 while (( i < ${#dev_stat_tab[@]} )); do 116 typeset dev=${dev_stat_tab[$i]} 117 typeset stat=${dev_stat_tab[((i+1))]} 118 119 case $dev in 120 stripe:$device) 121 if [[ "$type" == 'mirror' ]]; then 122 log_note "Unexpected type: mirror" 123 return 1 124 else 125 if [[ $stat != $status ]]; then 126 log_note "Status($stat) " \ 127 "!= Expected stat($status)" 128 return 1 129 fi 130 return 0 131 fi 132 ;; 133 mirror:$device) 134 if [[ -z "$type" || $type == 'stripe' ]]; then 135 log_note "Unexpected type: stripe" 136 return 1 137 else 138 if [[ $stat != $status ]]; then 139 log_note "Status($stat) " \ 140 "!= Expected stat($status)" 141 return 1 142 fi 143 return 0 144 fi 145 ;; 146 esac 147 148 ((i += 2)) 149 done 150 151 log_note "Can not find device: $device" 152 153 return 1 154 } 155