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