xref: /freebsd/tests/sys/cddl/zfs/tests/hotspare/hotspare_import_001_pos.ksh (revision ac00d4d59b18a76c6148ca5d7439bb446d38da5c)
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_import_001_pos
33#
34# DESCRIPTION:
35#	If a storage pool has hot spare,
36#	regardless it has been activated or NOT,
37#	invoke "zpool export" then import with this storage pool
38#	should runs successfully, and the data should keep integrity
39#	after import.
40#
41# STRATEGY:
42#	1. Create a storage pool with hot spares
43#	2. Do 'zpool export' then 'zpool import' with following scernarios
44#		- the hotspare is only in available list
45#		- the hotspare is activated
46#		- the hotspare is activated but offline
47#		- the hotspare is activated but the basic vdev is offline
48#	3. Verify the export/import runs successfully,
49#		and the data keep integrity after import
50#
51# TESTABILITY: explicit
52#
53# TEST_AUTOMATION_LEVEL: automated
54#
55# CODING STATUS: COMPLETED (2006-06-14)
56#
57# __stc_assertion_end
58#
59###############################################################################
60
61verify_runnable "global"
62
63function cleanup
64{
65	poolexists $TESTPOOL && \
66		destroy_pool $TESTPOOL
67
68	partition_cleanup
69}
70
71function verify_export_import #pool #file #chksum
72{
73	typeset pool=$1
74	typeset file=$2
75	typeset checksum1=$3
76	typeset -i n=0
77
78	if ! $ZPOOL export $pool; then
79		# Rarely, this can fail with EBUSY if the pool's configuration
80		# has already changed within the same transaction group.  In
81		# that case, it is appropriate to retry.
82		while ((n < 3)); do
83			$SYNC
84			log_note "$ZPOOL busy, retrying export (${n})..."
85			if ((n == 2)); then
86				log_must $ZPOOL export $pool
87			else
88				$ZPOOL export $pool && break
89			fi
90			$SLEEP 1
91			n=$((n + 1))
92		done
93	fi
94	log_must $ZPOOL import -d $HOTSPARE_TMPDIR $pool
95
96	[[ ! -e $file ]] && \
97		log_fail "$file missing after detach hotspare."
98	checksum2=$($SUM $file | $AWK '{print $1}')
99	[[ "$checksum1" != "$checksum2" ]] && \
100		log_fail "Checksums differ ($checksum1 != $checksum2)"
101
102	return 0
103}
104
105function verify_assertion # dev
106{
107	typeset dev=$1
108	typeset odev=${pooldevs[0]}
109
110	#
111	#	- the hotspare is activated
112	#
113	log_must $ZPOOL replace $TESTPOOL $odev $dev
114	while ! is_pool_resilvered $TESTPOOL ; do
115		$SLEEP 2
116	done
117
118	verify_export_import $TESTPOOL \
119		$mtpt/$TESTFILE0 $checksum1
120
121	#
122	#	- the hotspare is activated
123	#	  but the basic vdev is offline
124	#
125	log_must $ZPOOL offline $TESTPOOL $odev
126	verify_export_import $TESTPOOL \
127		$mtpt/$TESTFILE0 $checksum1
128
129	log_must $ZPOOL online $TESTPOOL $odev
130
131	log_must $ZPOOL detach $TESTPOOL $dev
132}
133
134log_assert "'zpool export/import <pool>' should runs successfully regardless the hotspare is only in list, activated, or offline."
135
136log_onexit cleanup
137
138typeset mtpt=""
139
140set_devs
141
142checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
143
144for keyword in "${keywords[@]}" ; do
145	setup_hotspares "$keyword"
146
147	mtpt=$(get_prop mountpoint $TESTPOOL)
148	log_must $CP $MYTESTFILE $mtpt/$TESTFILE0
149
150	#
151	#	- the hotspare is only in available list
152	#
153	verify_export_import $TESTPOOL \
154		$mtpt/$TESTFILE0 $checksum1
155
156	iterate_over_hotspares verify_assertion "${vdev%% *}"
157
158	log_must $RM -f $mtpt/$TESTFILE0
159	destroy_pool "$TESTPOOL"
160done
161
162log_pass "'zpool export/import <pool>' should runs successfully regardless the hotspare is only in list, activated, or offline."
163