xref: /freebsd/tests/sys/cddl/zfs/tests/hotspare/hotspare_clone_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_clone_001_pos
33#
34# DESCRIPTION:
35#	If a storage pool has activated hot spares,
36#	create clone and remove the hot spare,
37#	the data in clone should keep integrity.
38#
39# STRATEGY:
40#	1. Create a storage pool with hot spares
41#	2. Create some files, create a snapshot & clone upon filesystem
42#	3. Activate a spare device to the pool
43#	4. Create some files, create an new snapshot & clone upon filesystem
44#	5. Do 'zpool detach' with the spare in device
45#	6. Verify the 2 clones are all kept, and verify the data integrity within them.
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	poolexists $TESTPOOL && \
62		destroy_pool $TESTPOOL
63
64	partition_cleanup
65}
66
67function verify_assertion # dev
68{
69	typeset dev=$1
70	typeset odev=${pooldevs[0]}
71
72	log_must $CP $MYTESTFILE $mtpt/$TESTFILE0
73	log_must $ZFS snapshot $TESTPOOL@snap.0
74	log_must $ZFS clone $TESTPOOL@snap.0 \
75		$TESTPOOL/clone.0
76
77	log_must $ZPOOL replace $TESTPOOL $odev $dev
78
79	log_must $CP $MYTESTFILE $mtpt/$TESTFILE1
80	log_must $ZFS snapshot $TESTPOOL@snap.1
81	log_must $ZFS clone $TESTPOOL@snap.1 \
82		$TESTPOOL/clone.1
83
84	log_must $SYNC
85
86	log_must $ZPOOL detach $TESTPOOL $dev
87
88	for file in "$mtpt/clone.0/$TESTFILE0" \
89		"$mtpt/clone.1/$TESTFILE1" ; do
90		[[ ! -e $file ]] && \
91			log_fail "$file missing after detach hotspare."
92		checksum2=$($SUM $file | $AWK '{print $1}')
93		[[ "$checksum1" != "$checksum2" ]] && \
94			log_fail "Checksums differ ($checksum1 != $checksum2"
95	done
96
97	log_must $RM -rf $mtpt/clone.0/*
98	log_must $RM -rf $mtpt/clone.1/*
99	log_must $ZFS destroy -Rf $TESTPOOL@snap.1
100	log_must $ZFS destroy -Rf $TESTPOOL@snap.0
101}
102
103log_assert "'zpool detach <pool> <vdev> ...' against hotspare should do no harm to clone."
104
105log_onexit cleanup
106
107typeset mtpt=""
108
109set_devs
110
111checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
112
113for keyword in "${keywords[@]}" ; do
114	setup_hotspares "$keyword"
115
116	mtpt=$(get_prop mountpoint $TESTPOOL)
117
118	iterate_over_hotspares verify_assertion
119
120	destroy_pool "$TESTPOOL"
121done
122
123log_pass "'zpool detach <pool> <vdev> ...' against hotspare should do no harm to clone."
124