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