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#
27# ident	"@(#)hotspare_clone_002_pos.ksh	1.3	09/06/22 SMI"
28#
29. $STF_SUITE/tests/hotspare/hotspare.kshlib
30
31################################################################################
32#
33# __stc_assertion_start
34#
35# ID: hotspare_clone_002_pos
36#
37# DESCRIPTION:
38#	If a storage pool has activated hot spares,
39#	create clone and then invoke "zpool detach" with the original device,
40#	the data in clone should keep integrity.
41#
42# STRATEGY:
43#	1. Create a storage pool with hot spares activated.
44#	2. Create some files, create a snapshot & clone upon filesystem
45#	3. Activate a spare device to the pool
46#	4. Create some files, create an new snapshot & clone upon filesystem
47#	5. Do 'zpool detach' with the original device
48#	6. Verify the 2 clones are all kept, and verify the data integrity within them.
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING STATUS: COMPLETED (2006-06-07)
55#
56# __stc_assertion_end
57#
58###############################################################################
59
60verify_runnable "global"
61
62function cleanup
63{
64	poolexists $TESTPOOL && \
65		destroy_pool $TESTPOOL
66
67	partition_cleanup
68}
69
70function verify_assertion # dev
71{
72	typeset dev=$1
73	typeset odev=${pooldevs[0]}
74
75	log_must $CP $MYTESTFILE $mtpt/$TESTFILE0
76	log_must $ZFS snapshot $TESTPOOL@snap.0
77	log_must $ZFS clone $TESTPOOL@snap.0 \
78		$TESTPOOL/clone.0
79
80	log_must $ZPOOL replace $TESTPOOL $odev $dev
81
82	log_must $CP $MYTESTFILE $mtpt/$TESTFILE1
83	log_must $ZFS snapshot $TESTPOOL@snap.1
84	log_must $ZFS clone $TESTPOOL@snap.1 \
85		$TESTPOOL/clone.1
86
87	log_must $SYNC
88
89	log_must $ZPOOL detach $TESTPOOL $odev
90
91	for file in "$mtpt/clone.0/$TESTFILE0" \
92		"$mtpt/clone.1/$TESTFILE1" ; do
93		[[ ! -e $file ]] && \
94			log_fail "$file missing after detach hotspare."
95		checksum2=$($SUM $file | $AWK '{print $1}')
96		[[ "$checksum1" != "$checksum2" ]] && \
97			log_fail "Checksums differ ($checksum1 != $checksum2)"
98	done
99
100	log_must $RM -rf $mtpt/clone.0/*
101	log_must $RM -rf $mtpt/clone.1/*
102	log_must $ZFS destroy -Rf $TESTPOOL@snap.1
103	log_must $ZFS destroy -Rf $TESTPOOL@snap.0
104
105	log_must $RM -f $mtpt/*
106
107	log_must $ZPOOL add -f "$TESTPOOL" spare $odev
108	log_must $ZPOOL replace "$TESTPOOL" $dev $odev
109	log_must $SYNC
110	log_must $ZPOOL detach "$TESTPOOL" $dev
111	log_must $ZPOOL add -f "$TESTPOOL" spare $dev
112}
113
114log_assert "'zpool detach <pool> <vdev> ...' against basic vdev should do no harm to clone."
115
116log_onexit cleanup
117
118typeset mtpt=""
119
120set_devs
121
122checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
123
124for keyword in "${keywords[@]}" ; do
125	setup_hotspares "$keyword"
126
127	mtpt=$(get_prop mountpoint $TESTPOOL)
128
129	iterate_over_hotspares verify_assertion
130
131	destroy_pool "$TESTPOOL"
132done
133
134log_pass "'zpool detach <pool> <vdev> ...' against basic vdev should do no harm to clone."
135