1#!/usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
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.
8#
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.
13#
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]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26. $STF_SUITE/tests/hotspare/hotspare.kshlib
27
28################################################################################
29#
30# __stc_assertion_start
31#
32# ID: hotspare_scrub_001_pos
33#
34# DESCRIPTION:
35#	If a storage pool has hot spare,
36#	regardless it has been activated or NOT,
37#	invoke "zpool scrub" with this storage pool should successful.
38#
39# STRATEGY:
40#	1. Create a storage pool with hot spares
41#	2. Make the storage pool dirty.
42#	3. Do 'zpool scrub' with following scernarios
43#		- the hotspare is only in available list
44#		- the hotspare is activated
45#	4. Verify the scrub runs successfully.
46#
47# TESTABILITY: explicit
48#
49# TEST_AUTOMATION_LEVEL: automated
50#
51# CODING STATUS: COMPLETED (2006-06-07)
52#
53# __stc_assertion_end
54#
55###############################################################################
56
57verify_runnable "global"
58
59function cleanup
60{
61	# Record status so we can see the current state on failure.
62	$ZPOOL status
63	poolexists $TESTPOOL && \
64		destroy_pool $TESTPOOL
65
66	partition_cleanup
67}
68
69function verify_assertion # dev
70{
71	typeset dev=$1
72	typeset odev=${pooldevs[0]}
73
74	log_must $MKFILE 100m $mtpt/$TESTFILE0
75	log_must $ZPOOL scrub $TESTPOOL
76	while is_pool_scrubbing $TESTPOOL ; do
77		$SLEEP 2
78	done
79
80	log_must $MKFILE 100m $mtpt/$TESTFILE1
81	log_must $ZPOOL replace $TESTPOOL $odev $dev
82
83	while ! is_pool_resilvered $TESTPOOL ; do
84		$SLEEP 2
85	done
86
87	log_must $ZPOOL scrub $TESTPOOL
88
89	while is_pool_scrubbing $TESTPOOL ; do
90		$SLEEP 2
91	done
92
93	log_must $ZPOOL detach $TESTPOOL $dev
94	log_must $RM -f $mtpt/$TESTFILE0 \
95		$mtpt/$TESTFILE1
96}
97
98log_assert "'zpool scrub <pool>' should runs successfully regardless " \
99	"the hotspare is only in list or activated."
100
101log_onexit cleanup
102
103typeset mtpt=""
104
105set_devs
106
107for keyword in "${keywords[@]}" ; do
108	setup_hotspares "$keyword"
109	mtpt=$(get_prop mountpoint $TESTPOOL)
110	iterate_over_hotspares verify_assertion "${vdev%% *}"
111	destroy_pool "$TESTPOOL"
112done
113
114log_pass "'zpool scrub <pool>' runs successfully regardless " \
115	"the hotspare is only in list or activated."
116