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# $FreeBSD$ 24 25# 26# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)slog.kshlib 1.2 08/11/03 SMI" 30# 31 32. $STF_SUITE/include/libtest.kshlib 33 34function cleanup 35{ 36 poolexists $TESTPOOL && log_must $ZPOOL status $TESTPOOL 37 poolexists $TESTPOOL2 && log_must $ZPOOL status $TESTPOOL2 38 destroy_pool $TESTPOOL 39 destroy_pool $TESTPOOL2 40} 41 42# 43# Try zpool status/iostat for given pool 44# 45# $1 pool 46# 47function display_status 48{ 49 typeset pool=$1 50 51 typeset -i ret=0 52 $ZPOOL status -xv $pool > /dev/null 2>&1 53 ret=$? 54 55 $ZPOOL iostat > /dev/null 2>&1 56 ((ret |= $?)) 57 58 typeset mntpnt=$(get_prop mountpoint $pool) 59 $DD if=/dev/random of=$mntpnt/testfile.${TESTCASE_ID} & 60 typeset pid=$! 61 62 $ZPOOL iostat -v 1 3 > /dev/null 63 ((ret |= $?)) 64 65 kill -9 $pid 66 67 return $ret 68} 69 70function slog_devstat_table 71{ 72 typeset pool=$1 73 74 $ZPOOL status -v $pool | $NAWK ' 75 BEGIN { start = 0; } 76 /\tlogs/ { start = 1; } 77 (start == 0) { next; } 78 /\t (\/|[a-zA-Z])/ { print "stripe:" $1 " " $2; } 79 /\t (\/|[a-zA-Z])/ { print "mirror:" $1 " " $2; } 80 /\t (\/|[0-9])/ {print "stripe:" $NF " " $2} 81 /\t (\/|[0-9])/ {print "mirror:" $NF " " $2} 82 # When a hotspare is replacing 83 /\t (\/|[a-zA-Z])/ {print "mirror:" $1 " " $2} 84 ' 85} 86 87# 88# Verify the given slog device have correct type and status 89# 90# $1 pool name 91# $2 device name 92# $3 device status 93# $4 device type 94# 95function verify_slog_device 96{ 97 typeset pool=$1 98 typeset device=$2 99 typeset status=$3 100 typeset type=$4 101 102 if [[ -z $pool || -z $device || -z $status ]]; then 103 log_fail "Usage: verify_slog_device <pool> <device> " \ 104 "<status> [type]" 105 fi 106 107 if [[ $WRAPPER == *"smi"* ]]; then 108 $ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 109 if (( $? == 0 )); then 110 device=${device}s2 111 fi 112 fi 113 114 # 115 # Get all the slog devices and status table like below 116 # 117 # mirror:/disks/d ONLINE mirror:/disks/e ONLINE stripe:/disks/f ONLINE 118 # 119 set -A dev_stat_tab $(slog_devstat_table $pool) 120 121 typeset find=0 122 for (( i = 0; i < ${#dev_stat_tab[@]}; i += 2 )); do 123 typeset dev=${dev_stat_tab[$i]} 124 typeset stat=${dev_stat_tab[((i+1))]} 125 126 typeset statmsg="$dev: Status($stat) != Expected stat($status)" 127 case $dev in 128 stripe:$device) 129 if [[ "$type" == 'mirror' ]]; then 130 log_note "Unexpected type: mirror" 131 return 1 132 fi 133 if [[ $stat != $status ]]; then 134 log_note statmsg 135 return 1 136 fi 137 return 0 138 ;; 139 mirror:$device) 140 if [[ -z "$type" || $type == 'stripe' ]]; then 141 log_note "Unexpected type: stripe" 142 return 1 143 fi 144 if [[ $stat != $status ]]; then 145 log_note statmsg 146 return 1 147 fi 148 return 0 149 ;; 150 esac 151 done 152 return 1 153} 154 155# Calls <callback> [args...] <pooltype> <sparetype>. 156function slog_foreach_nologtype # <callback> 157{ 158 typeset callback="$1" 159 160 for pooltype in "" "mirror" "raidz" "raidz2"; do 161 for sparetype in "" "spare"; do 162 $callback "$pooltype" "$sparetype" 163 done 164 done 165} 166 167# Calls <callback> [args...] <pooltype> <sparetype> <logtype>. 168# Unfortunately, this has to be duplicated because some arguments are empty, 169# so if they aren't explicitly forwarded they aren't arguments to $callback. 170function slog_foreach_all # <callback> 171{ 172 typeset callback="$1" 173 174 for pooltype in "" "mirror" "raidz" "raidz2"; do 175 for sparetype in "" "spare"; do 176 for logtype in "" "mirror"; do 177 $callback "$pooltype" "$sparetype" "$logtype" 178 done 179 done 180 done 181} 182