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
32. $STF_SUITE/include/libtest.kshlib
33. $STF_SUITE/include/libgnop.kshlib
34. $STF_SUITE/tests/hotspare/hotspare.kshlib
35. $STF_SUITE/tests/zfsd/zfsd.kshlib
36
37function cleanup
38{
39	destroy_pool $TESTPOOL
40	[[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
41	for md in $MD0 $MD1 $MD2 $MD3; do
42		gnop destroy -f $md
43		for ((i=0; i<5; i=i+1)); do
44			$MDCONFIG -d -u $md && break
45			$SLEEP 1
46		done
47	done
48}
49
50log_assert "ZFSD will correctly replace disks that disappear and reappear \
51	   with different devnames"
52
53# Outline
54# Use gnop on top of file-backed md devices
55# * file-backed md devices so we can destroy them and recreate them with
56#   different devnames
57# * gnop so we can destroy them while still in use
58# Create a double-parity pool
59# Remove two vdevs
60# Destroy the md devices and recreate in the opposite order
61# Check that the md's devnames have swapped
62# Verify that the pool regains its health
63
64log_onexit cleanup
65ensure_zfsd_running
66
67
68N_DEVARRAY_FILES=4
69set_devs
70typeset FILE0="${devarray[0]}"
71typeset FILE1="${devarray[1]}"
72typeset FILE2="${devarray[2]}"
73typeset FILE3="${devarray[3]}"
74typeset MD0=`$MDCONFIG -a -t vnode -f ${FILE0}`
75[ $? -eq 0 ] || atf_fail "Failed to create md device"
76typeset MD1=`$MDCONFIG -a -t vnode -f ${FILE1}`
77[ $? -eq 0 ] || atf_fail "Failed to create md device"
78typeset MD2=`$MDCONFIG -a -t vnode -f ${FILE2}`
79[ $? -eq 0 ] || atf_fail "Failed to create md device"
80typeset MD3=`$MDCONFIG -a -t vnode -f ${FILE3}`
81[ $? -eq 0 ] || atf_fail "Failed to create md device"
82log_must create_gnops $MD0 $MD1 $MD2 $MD3
83
84for type in "raidz2" "mirror"; do
85	# Create a pool on the supplied disks
86	create_pool $TESTPOOL $type ${MD0}.nop ${MD1}.nop ${MD2}.nop ${MD3}.nop
87
88	log_must destroy_gnop $MD0
89	for ((i=0; i<5; i=i+1)); do
90		$MDCONFIG -d -u $MD0 && break
91		$SLEEP 1
92	done
93	[ -c /dev/$MD0.nop ] && atf_fail "failed to destroy $MD0"
94	log_must destroy_gnop $MD1
95	for ((i=0; i<5; i=i+1)); do
96		$MDCONFIG -d -u $MD1 && break
97		$SLEEP 1
98	done
99	[ -c /dev/$MD1.nop ] && atf_fail "failed to destroy $MD0"
100
101	# Make sure that the pool is degraded
102	$ZPOOL status $TESTPOOL |grep "state:" |grep DEGRADED > /dev/null
103	if [ $? != 0 ]; then
104		log_fail "Pool $TESTPOOL not listed as DEGRADED"
105	fi
106
107	# Do some I/O to ensure that the old vdevs will be out of date
108	log_must $DD if=/dev/random of=/$TESTPOOL/randfile bs=1m count=1
109	log_must $SYNC
110
111	# Recreate the vdevs in the opposite order
112	typeset MD0=`$MDCONFIG -a -t vnode -f ${FILE1}`
113	[ $? -eq 0 ] || atf_fail "Failed to create md device"
114	typeset MD1=`$MDCONFIG -a -t vnode -f ${FILE0}`
115	[ $? -eq 0 ] || atf_fail "Failed to create md device"
116	log_must create_gnops $MD0 $MD1
117
118	wait_until_resilvered
119	destroy_pool $TESTPOOL
120done
121
122log_pass
123