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