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 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# Copyright 2012,2013 Spectra Logic Corporation.  All rights reserved.
28# Use is subject to license terms.
29#
30# Portions taken from:
31# ident	"@(#)replacement_001_pos.ksh	1.4	08/02/27 SMI"
32#
33# $FreeBSD$
34
35. $STF_SUITE/tests/hotspare/hotspare.kshlib
36. $STF_SUITE/tests/zfsd/zfsd.kshlib
37. $STF_SUITE/include/libtest.kshlib
38. $STF_SUITE/include/libgnop.kshlib
39
40log_assert "ZFSD will automatically replace a SAS disk that disappears and reappears in the same location, with the same devname"
41
42ensure_zfsd_running
43
44set_disks
45
46typeset REMOVAL_DISK=$DISK0
47typeset REMOVAL_NOP=${DISK0}.nop
48typeset OTHER_DISKS="${DISK1} ${DISK2}"
49typeset ALLDISKS="${DISK0} ${DISK1} ${DISK2}"
50typeset ALLNOPS=${ALLDISKS//~(E)([[:space:]]+|$)/.nop\1}
51
52log_must create_gnops $ALLDISKS
53for type in "raidz" "mirror"; do
54	# Create a pool on the supplied disks
55	create_pool $TESTPOOL $type $ALLNOPS
56	log_must $ZFS create $TESTPOOL/$TESTFS
57	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
58
59	# Disable the first disk.
60	log_must destroy_gnop $REMOVAL_DISK
61
62	# Write out data to make sure we can do I/O after the disk failure
63	log_must $DD if=/dev/zero of=$TESTDIR/$TESTFILE bs=1m count=1
64	log_must $FSYNC $TESTDIR/$TESTFILE
65
66	# Check to make sure ZFS sees the disk as removed
67	wait_for_pool_dev_state_change 20 $REMOVAL_NOP REMOVED
68
69	# Re-enable the disk
70	log_must create_gnop $REMOVAL_DISK
71
72	# Disk should auto-join the zpool & be resilvered.
73	wait_for_pool_dev_state_change 20 $REMOVAL_NOP ONLINE
74	wait_until_resilvered
75
76	$ZPOOL status $TESTPOOL
77	destroy_pool $TESTPOOL
78	log_must $RM -rf /$TESTPOOL
79done
80
81log_pass
82