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.
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.
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]
26 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
27 # Use is subject to license terms.
29 # ident "@(#)cache.kshlib 1.4 09/05/19 SMI"
32 . $STF_SUITE/include/libtest.kshlib
36 log_note "Final pool configurations:"
37 poolexists $TESTPOOL && log_must $ZPOOL status -v $TESTPOOL
38 poolexists $TESTPOOL2 && log_must $ZPOOL status -v $TESTPOOL2
39 destroy_pool $TESTPOOL
40 destroy_pool $TESTPOOL2
44 # Try zpool status/iostat for given pool
48 function display_status
53 $ZPOOL status -xv $pool > /dev/null 2>&1
56 $ZPOOL iostat > /dev/null 2>&1
59 typeset mntpnt=$(get_prop mountpoint $pool)
60 $DD if=/dev/random of=$mntpnt/testfile.${TESTCASE_ID} &
63 $ZPOOL iostat -v 1 3 > /dev/null
72 # Verify the give cache device have correct type and status
79 function verify_cache_device
86 if [[ -z $pool || -z $device || -z $status ]]; then
87 log_fail "Usage: verify_cache_device <pool> <device> " \
91 # Zpool status returns on the device name sans the /dev, so
92 # if the device contains /dev/ remove it.
93 device=${device#"/dev/"}
95 if [[ $WRAPPER == *"smi"* ]]; then
96 $ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1
97 if (( $? == 0 )); then
103 # Get all the cache devices and status table like below
105 # mirror:/disks/d ONLINE mirror:/disks/e ONLINE stripe:/disks/f ONLINE
107 set -A dev_stat_tab $($ZPOOL status -v $pool | $NAWK '
108 function parse_name(status)
110 if (status == "OFFLINE")
112 else if (status == "UNAVAIL")
119 /\tcache/ {in_cache=1}
120 /\tlog/ || /\tspares/ || /^$/ {in_cache=0}
122 # Skip if not in a cache section
123 (in_cache==0) { next; }
125 /\t (\/|[0-9a-zA-Z])/ {
126 print "stripe:" parse_name($2) " " $2;
130 print "mirror:" parse_name($2) " " $2;
133 # When hotspare is replacing
135 print "mirror:" parse_name($2) " " $2;
141 while (( i < ${#dev_stat_tab[@]} )); do
142 typeset dev=${dev_stat_tab[$i]}
143 typeset stat=${dev_stat_tab[((i+1))]}
147 if [[ "$type" == 'mirror' ]]; then
148 log_note "Unexpected type: mirror"
151 if [[ $stat != $status ]]; then
152 log_note "Status($stat) " \
153 "!= Expected stat($status)"
160 if [[ -z "$type" || $type == 'stripe' ]]; then
161 log_note "Unexpected type: stripe"
164 if [[ $stat != $status ]]; then
165 log_note "Status($stat) " \
166 "!= Expected stat($status)"
177 log_note "Can not find device: $device"