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