1#!/bin/ksh -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 28# 29# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33 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 51verify_runnable "global" 52 53function cleanup 54{ 55 mntpnt=$(get_prop mountpoint $TESTPOOL) 56 datasetexists $TESTPOOL1 || log_must zpool import -d $mntpnt $TESTPOOL1 57 datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1 58 datasetexists $TESTPOOL2 && destroy_pool $TESTPOOL2 59 typeset -i i=0 60 while ((i < 5)); do 61 if [[ -e $mntpnt/vdev$i ]]; then 62 log_must rm -f $mntpnt/vdev$i 63 fi 64 ((i += 1)) 65 done 66} 67 68 69log_assert "Verify zpool export succeed or fail with spare." 70log_onexit cleanup 71 72mntpnt=$(get_prop mountpoint $TESTPOOL) 73 74typeset -i i=0 75while ((i < 5)); do 76 log_must mkfile $MINVDEVSIZE $mntpnt/vdev$i 77 eval vdev$i=$mntpnt/vdev$i 78 ((i += 1)) 79done 80 81log_must zpool create $TESTPOOL1 mirror $vdev0 $vdev1 spare $vdev4 82log_must zpool create $TESTPOOL2 mirror $vdev2 $vdev3 spare $vdev4 83 84log_must zpool export $TESTPOOL1 85log_must zpool import -d $mntpnt $TESTPOOL1 86 87log_must zpool replace $TESTPOOL1 $vdev0 $vdev4 88log_must zpool detach $TESTPOOL1 $vdev4 89log_must zpool export $TESTPOOL1 90log_must zpool import -d $mntpnt $TESTPOOL1 91 92log_must zpool replace $TESTPOOL1 $vdev0 $vdev4 93log_mustnot zpool export $TESTPOOL1 94 95log_must zpool export -f $TESTPOOL1 96log_must zpool import -d $mntpnt $TESTPOOL1 97 98log_pass "Verify zpool export succeed or fail with spare." 99 100