xref: /titanic_52/usr/src/test/zfs-tests/tests/functional/cache/cache.kshlib (revision f38cb554a534c6df738be3f4d23327e69888e634)
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 2009 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
33*f38cb554SJohn Wren Kennedyfunction cleanup
34*f38cb554SJohn Wren Kennedy{
35*f38cb554SJohn Wren Kennedy	if datasetexists $TESTPOOL ; then
36*f38cb554SJohn Wren Kennedy		log_must $ZPOOL destroy -f $TESTPOOL
37*f38cb554SJohn Wren Kennedy	fi
38*f38cb554SJohn Wren Kennedy	if datasetexists $TESTPOOL2 ; then
39*f38cb554SJohn Wren Kennedy		log_must $ZPOOL destroy -f $TESTPOOL2
40*f38cb554SJohn Wren Kennedy	fi
41*f38cb554SJohn Wren Kennedy}
42*f38cb554SJohn Wren Kennedy
43*f38cb554SJohn Wren Kennedy#
44*f38cb554SJohn Wren Kennedy# Try zpool status/iostat for given pool
45*f38cb554SJohn Wren Kennedy#
46*f38cb554SJohn Wren Kennedy# $1 pool
47*f38cb554SJohn Wren Kennedy#
48*f38cb554SJohn Wren Kennedyfunction display_status
49*f38cb554SJohn Wren Kennedy{
50*f38cb554SJohn Wren Kennedy	typeset pool=$1
51*f38cb554SJohn Wren Kennedy
52*f38cb554SJohn Wren Kennedy	typeset -i ret=0
53*f38cb554SJohn Wren Kennedy	$ZPOOL status -xv $pool > /dev/null 2>&1
54*f38cb554SJohn Wren Kennedy	ret=$?
55*f38cb554SJohn Wren Kennedy
56*f38cb554SJohn Wren Kennedy	$ZPOOL iostat > /dev/null 2>&1
57*f38cb554SJohn Wren Kennedy	((ret |= $?))
58*f38cb554SJohn Wren Kennedy
59*f38cb554SJohn Wren Kennedy	typeset mntpnt=$(get_prop mountpoint $pool)
60*f38cb554SJohn Wren Kennedy	$DD if=/dev/random of=$mntpnt/testfile.$$ &
61*f38cb554SJohn Wren Kennedy	typeset pid=$!
62*f38cb554SJohn Wren Kennedy
63*f38cb554SJohn Wren Kennedy	$ZPOOL iostat -v 1 3 > /dev/null
64*f38cb554SJohn Wren Kennedy	((ret |= $?))
65*f38cb554SJohn Wren Kennedy
66*f38cb554SJohn Wren Kennedy	kill -9 $pid
67*f38cb554SJohn Wren Kennedy
68*f38cb554SJohn Wren Kennedy	return $ret
69*f38cb554SJohn Wren Kennedy}
70*f38cb554SJohn Wren Kennedy
71*f38cb554SJohn Wren Kennedy#
72*f38cb554SJohn Wren Kennedy# Verify the given cache device have correct type and status
73*f38cb554SJohn Wren Kennedy#
74*f38cb554SJohn Wren Kennedy# $1 pool name
75*f38cb554SJohn Wren Kennedy# $2 device name
76*f38cb554SJohn Wren Kennedy# $3 device status
77*f38cb554SJohn Wren Kennedy# $4 device type
78*f38cb554SJohn Wren Kennedy#
79*f38cb554SJohn Wren Kennedyfunction verify_cache_device
80*f38cb554SJohn Wren Kennedy{
81*f38cb554SJohn Wren Kennedy	typeset pool=$1
82*f38cb554SJohn Wren Kennedy	typeset device=$2
83*f38cb554SJohn Wren Kennedy	typeset status=$3
84*f38cb554SJohn Wren Kennedy	typeset type=$4
85*f38cb554SJohn Wren Kennedy
86*f38cb554SJohn Wren Kennedy	if [[ -z $pool || -z $device || -z $status ]]; then
87*f38cb554SJohn Wren Kennedy		log_fail "Usage: verify_cache_device <pool> <device> " \
88*f38cb554SJohn Wren Kennedy			"<status> [type]"
89*f38cb554SJohn Wren Kennedy	fi
90*f38cb554SJohn Wren Kennedy
91*f38cb554SJohn Wren Kennedy	if [[ $WRAPPER == *"smi"* ]]; then
92*f38cb554SJohn Wren Kennedy		$ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1
93*f38cb554SJohn Wren Kennedy		if (( $? == 0 )); then
94*f38cb554SJohn Wren Kennedy			device=${device}s2
95*f38cb554SJohn Wren Kennedy		fi
96*f38cb554SJohn Wren Kennedy	fi
97*f38cb554SJohn Wren Kennedy
98*f38cb554SJohn Wren Kennedy	#
99*f38cb554SJohn Wren Kennedy	# Get all the cache devices and status table like below
100*f38cb554SJohn Wren Kennedy	#
101*f38cb554SJohn Wren Kennedy	# mirror:/disks/d ONLINE mirror:/disks/e ONLINE stripe:/disks/f ONLINE
102*f38cb554SJohn Wren Kennedy	#
103*f38cb554SJohn Wren Kennedy	set -A dev_stat_tab $($ZPOOL status -v $pool | $NAWK 'BEGIN {start=0} \
104*f38cb554SJohn Wren Kennedy				/\tcache/ {start=1}
105*f38cb554SJohn Wren Kennedy				/\tmirror/ || /\tspares/ || /^$/ {start=0}
106*f38cb554SJohn Wren Kennedy				(start==1) && /\t  (\/|[a-zA-Z])/ \
107*f38cb554SJohn Wren Kennedy					{print "stripe:" $1 " " $2}
108*f38cb554SJohn Wren Kennedy				(start==1) && /\t    (\/|[a-zA-Z])/ \
109*f38cb554SJohn Wren Kennedy					{print "mirror:" $1 " " $2}
110*f38cb554SJohn Wren Kennedy				# When hotspare is replacing
111*f38cb554SJohn Wren Kennedy				(start==1) && /\t      (\/|[a-zA-Z])/ \
112*f38cb554SJohn Wren Kennedy					{print "mirror:" $1 " " $2}'
113*f38cb554SJohn Wren Kennedy			     )
114*f38cb554SJohn Wren Kennedy
115*f38cb554SJohn Wren Kennedy	typeset -i i=0
116*f38cb554SJohn Wren Kennedy	typeset find=0
117*f38cb554SJohn Wren Kennedy	while (( i < ${#dev_stat_tab[@]} )); do
118*f38cb554SJohn Wren Kennedy		typeset dev=${dev_stat_tab[$i]}
119*f38cb554SJohn Wren Kennedy		typeset stat=${dev_stat_tab[((i+1))]}
120*f38cb554SJohn Wren Kennedy
121*f38cb554SJohn Wren Kennedy		case $dev in
122*f38cb554SJohn Wren Kennedy			stripe:$device)
123*f38cb554SJohn Wren Kennedy				if [[ "$type" == 'mirror' ]]; then
124*f38cb554SJohn Wren Kennedy					log_note "Unexpected type: mirror"
125*f38cb554SJohn Wren Kennedy					return 1
126*f38cb554SJohn Wren Kennedy				else
127*f38cb554SJohn Wren Kennedy					if [[ $stat != $status ]]; then
128*f38cb554SJohn Wren Kennedy						log_note "Status($stat) " \
129*f38cb554SJohn Wren Kennedy							"!= Expected stat($status)"
130*f38cb554SJohn Wren Kennedy						return 1
131*f38cb554SJohn Wren Kennedy					fi
132*f38cb554SJohn Wren Kennedy					return 0
133*f38cb554SJohn Wren Kennedy				fi
134*f38cb554SJohn Wren Kennedy				;;
135*f38cb554SJohn Wren Kennedy			mirror:$device)
136*f38cb554SJohn Wren Kennedy				if [[ -z "$type" || $type == 'stripe' ]]; then
137*f38cb554SJohn Wren Kennedy					log_note "Unexpected type: stripe"
138*f38cb554SJohn Wren Kennedy					return 1
139*f38cb554SJohn Wren Kennedy				else
140*f38cb554SJohn Wren Kennedy					if [[ $stat != $status ]]; then
141*f38cb554SJohn Wren Kennedy						log_note "Status($stat) " \
142*f38cb554SJohn Wren Kennedy							"!= Expected stat($status)"
143*f38cb554SJohn Wren Kennedy						return 1
144*f38cb554SJohn Wren Kennedy					fi
145*f38cb554SJohn Wren Kennedy					return 0
146*f38cb554SJohn Wren Kennedy				fi
147*f38cb554SJohn Wren Kennedy				;;
148*f38cb554SJohn Wren Kennedy		esac
149*f38cb554SJohn Wren Kennedy		((i += 2))
150*f38cb554SJohn Wren Kennedy	done
151*f38cb554SJohn Wren Kennedy
152*f38cb554SJohn Wren Kennedy	log_note "Can not find device: $device"
153*f38cb554SJohn Wren Kennedy	return 1
154*f38cb554SJohn Wren Kennedy}
155*f38cb554SJohn Wren Kennedy
156*f38cb554SJohn Wren Kennedyfunction verify_cache_support
157*f38cb554SJohn Wren Kennedy{
158*f38cb554SJohn Wren Kennedy	$ZPOOL upgrade -v | $GREP "Cache devices" > /dev/null 2>&1
159*f38cb554SJohn Wren Kennedy	return $?
160*f38cb554SJohn Wren Kennedy}
161