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. $STF_SUITE/include/libtest.kshlib 28 29################################################################################# 30# 31# __stc_assertion_start 32# 33# ID: zpool_export_004_pos 34# 35# DESCRIPTION: 36# Verify zpool export succeed or fail with spare. 37# 38# STRATEGY: 39# 1. Create two mirror pools with same spare. 40# 2. Verify zpool export one pool succeed. 41# 3. Import the pool. 42# 4. Replace one device with the spare and detach it in one pool. 43# 5. Verify zpool export the pool succeed. 44# 6. Import the pool. 45# 7. Replace one device with the spare in one pool. 46# 8. Verify zpool export the pool fail. 47# 9. Verify zpool export the pool with "-f" succeed. 48# 10. Import the pool. 49# 50# TESTABILITY: explicit 51# 52# TEST_AUTOMATION_LEVEL: automated 53# 54# CODING_STATUS: COMPLETED (2009-03-10) 55# 56# __stc_assertion_end 57# 58################################################################################ 59 60verify_runnable "global" 61 62function cleanup 63{ 64 restart_zfsd 65 66 mntpnt=$(get_prop mountpoint $TESTPOOL) 67 datasetexists $TESTPOOL1 || log_must $ZPOOL import -d $mntpnt $TESTPOOL1 68 datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1 69 datasetexists $TESTPOOL2 && destroy_pool $TESTPOOL2 70 typeset -i i=0 71 while ((i < 5)); do 72 if [[ -e $mntpnt/vdev$i ]]; then 73 log_must $RM -f $mntpnt/vdev$i 74 fi 75 ((i += 1)) 76 done 77} 78 79 80log_assert "Verify zpool export succeed or fail with spare." 81log_onexit cleanup 82# Stop ZFSD because it interferes with our manually activated spares 83stop_zfsd 84 85mntpnt=$(get_prop mountpoint $TESTPOOL) 86 87typeset -i i=0 88while ((i < 5)); do 89 log_must create_vdevs $mntpnt/vdev$i 90 eval vdev$i=$mntpnt/vdev$i 91 ((i += 1)) 92done 93 94log_must $ZPOOL create $TESTPOOL1 mirror $vdev0 $vdev1 spare $vdev4 95log_must $ZPOOL create $TESTPOOL2 mirror $vdev2 $vdev3 spare $vdev4 96 97log_must $ZPOOL export $TESTPOOL1 98log_must $ZPOOL import -d $mntpnt $TESTPOOL1 99 100log_must $ZPOOL replace $TESTPOOL1 $vdev0 $vdev4 101log_must $ZPOOL detach $TESTPOOL1 $vdev4 102log_must $ZPOOL export $TESTPOOL1 103log_must $ZPOOL import -d $mntpnt $TESTPOOL1 104 105log_must $ZPOOL replace $TESTPOOL1 $vdev0 $vdev4 106log_mustnot $ZPOOL export $TESTPOOL1 107 108log_must $ZPOOL export -f $TESTPOOL1 109log_must $ZPOOL import -d $mntpnt $TESTPOOL1 110 111log_pass "Verify zpool export succeed or fail with spare." 112 113