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 27# 28# Copyright (c) 2013, 2016 by Delphix. All rights reserved. 29# 30 31. $STF_SUITE/include/libtest.shlib 32. $STF_SUITE/tests/functional/slog/slog.cfg 33 34function cleanup 35{ 36 poolexists $TESTPOOL && destroy_pool $TESTPOOL 37 poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2 38} 39 40# 41# Try zpool status/iostat for given pool 42# 43# $1 pool 44# 45function display_status 46{ 47 typeset pool=$1 48 49 typeset -i ret=0 50 zpool status -xv $pool > /dev/null 2>&1 51 ret=$? 52 53 zpool iostat > /dev/null 2>&1 54 ((ret |= $?)) 55 56 typeset mntpnt=$(get_prop mountpoint $pool) 57 dd if=/dev/random of=$mntpnt/testfile.$$ & 58 typeset pid=$! 59 60 zpool iostat -v 1 3 > /dev/null 61 ((ret |= $?)) 62 63 kill -9 $pid 64 65 return $ret 66} 67 68# 69# Verify the give slog device have correct type and status 70# 71# $1 pool name 72# $2 device name 73# $3 device status 74# $4 device type 75# 76function verify_slog_device 77{ 78 typeset pool=$1 79 typeset device=$2 80 typeset status=$3 81 typeset type=$4 82 83 if [[ -z $pool || -z $device || -z $status ]]; then 84 log_fail "Usage: verify_slog_device <pool> <device> " \ 85 "<status> [type]" 86 fi 87 88 # 89 # Get all the slog devices and status table like below 90 # 91 # mirror:/disks/d ONLINE mirror:/disks/e ONLINE stripe:/disks/f ONLINE 92 # 93 set -A dev_stat_tab $(zpool status -v $pool | nawk 'BEGIN {start=0} \ 94 /\tlogs/ {start=1} 95 /\tmirror/ || /\tspares/ || /^$/ {start=0} 96 (start==1) && /\t (\/|[a-zA-Z])/ \ 97 {print "stripe:" $1 " " $2} 98 (start==1) && /\t (\/|[a-zA-Z])/ \ 99 {print "mirror:" $1 " " $2} 100 # When hotspare is replacing 101 (start==1) && /\t (\/|[a-zA-Z])/ \ 102 {print "mirror:" $1 " " $2}' 103 ) 104 105 typeset -i i=0 106 typeset find=0 107 while (( i < ${#dev_stat_tab[@]} )); do 108 typeset dev=${dev_stat_tab[$i]} 109 typeset stat=${dev_stat_tab[((i+1))]} 110 111 case $dev in 112 stripe:$device) 113 if [[ "$type" == 'mirror' ]]; then 114 log_note "Unexpected type: mirror" 115 return 1 116 else 117 if [[ $stat != $status ]]; then 118 log_note "Status($stat) " \ 119 "!= Expected stat($status)" 120 return 1 121 fi 122 return 0 123 fi 124 ;; 125 mirror:$device) 126 if [[ -z "$type" || $type == 'stripe' ]]; then 127 log_note "Unexpected type: stripe" 128 return 1 129 else 130 if [[ $stat != $status ]]; then 131 log_note "Status($stat) " \ 132 "!= Expected stat($status)" 133 return 1 134 fi 135 return 0 136 fi 137 ;; 138 esac 139 140 ((i += 2)) 141 done 142 143 log_note "Can not find device: $device" 144 145 return 1 146} 147