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