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 2016 Spectra Logic  All rights reserved.
27# Use is subject to license terms.
28#
29
30. $STF_SUITE/include/libtest.kshlib
31
32#################################################################################
33#
34# __stc_assertion_start
35#
36# ID: zpool_import_missing_005_pos
37#
38# DESCRIPTION:
39#	Verify that a pool can still be imported even if its devices' names
40#	have changed, for all types of devices.  This is a test of vdev_geom's
41#	import_by_guid functionality.
42# STRATEGY:
43#	1. Create a supply of file-backed md devices
44#	2. Create a disk-backed pool with regular, cache, log, and spare vdevs
45#	3. Export it
46#	4. Cause all the md devices names to change
47#	5. Verify 'zpool import' can import it
48#
49# TESTABILITY: explicit
50#
51# TEST_AUTOMATION_LEVEL: automated
52#
53# CODING_STATUS: COMPLETED (2015-01-4)
54#
55# __stc_assertion_end
56#
57################################################################################
58
59verify_runnable "global"
60
61log_assert "Verify that all types of vdevs of a disk-backed exported pool can be imported even if they have been renamed"
62
63# Create md devices so we can control their devnames
64# Use high devnames so we'll be unlikely to have collisions
65typeset -i REGULAR_U=4000
66typeset -i LOG_U=4001
67typeset -i CACHE_U=4002
68typeset -i SPARE_U=4003
69typeset -i REGULAR_ALTU=5000
70typeset -i LOG_ALTU=5001
71typeset -i CACHE_ALTU=5002
72typeset -i SPARE_ALTU=5003
73typeset REGULAR=${TMPDIR}/regular
74typeset LOG=${TMPDIR}/log
75typeset CACHE=${TMPDIR}/cache
76typeset SPARE=${TMPDIR}/spare
77
78function cleanup
79{
80	destroy_pool $TESTPOOL
81	$MDCONFIG -d -u $REGULAR_U 2>/dev/null
82	$MDCONFIG -d -u $LOG_U 2>/dev/null
83	$MDCONFIG -d -u $CACHE_U 2>/dev/null
84	$MDCONFIG -d -u $SPARE_U 2>/dev/null
85	$MDCONFIG -d -u $REGULAR_ALTU 2>/dev/null
86	$MDCONFIG -d -u $LOG_ALTU 2>/dev/null
87	$MDCONFIG -d -u $CACHE_ALTU 2>/dev/null
88	$MDCONFIG -d -u $SPARE_ALTU 2>/dev/null
89	$RM -f $REGULAR
90	$RM -f $CACHE
91	$RM -f $LOG
92	$RM -f $SPARE
93}
94log_onexit cleanup
95
96log_must $TRUNCATE -s 64m $REGULAR
97log_must $TRUNCATE -s 64m $LOG
98log_must $TRUNCATE -s 64m $CACHE
99log_must $TRUNCATE -s 64m $SPARE
100log_must $MDCONFIG -t vnode -a -f $REGULAR -u $REGULAR_U
101log_must $MDCONFIG -t vnode -a -f $LOG -u $LOG_U
102log_must $MDCONFIG -t vnode -a -f $CACHE -u $CACHE_U
103log_must $MDCONFIG -t vnode -a -f $SPARE -u $SPARE_U
104
105log_must $ZPOOL create $TESTPOOL md$REGULAR_U log md$LOG_U cache md$CACHE_U spare md$SPARE_U
106log_must $ZPOOL export $TESTPOOL
107# Now destroy the md devices, then recreate them with different names
108log_must $MDCONFIG -d -u $REGULAR_U
109log_must $MDCONFIG -d -u $LOG_U
110log_must $MDCONFIG -d -u $CACHE_U
111log_must $MDCONFIG -d -u $SPARE_U
112log_must $MDCONFIG -t vnode -a -f $REGULAR -u $REGULAR_ALTU
113log_must $MDCONFIG -t vnode -a -f $LOG -u $LOG_ALTU
114log_must $MDCONFIG -t vnode -a -f $CACHE -u $CACHE_ALTU
115log_must $MDCONFIG -t vnode -a -f $SPARE -u $SPARE_ALTU
116
117log_must $ZPOOL import $TESTPOOL
118zpool status $TESTPOOL
119log_must check_state $TESTPOOL md${REGULAR_ALTU} ONLINE
120log_must check_state $TESTPOOL md${LOG_ALTU} ONLINE
121log_must check_state $TESTPOOL md${CACHE_ALTU} ONLINE
122log_must check_state $TESTPOOL md${SPARE_ALTU} AVAIL
123
124log_pass
125