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