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 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zpool_import_missing_002_pos.ksh	1.4	07/10/09 SMI"
30#
31. $STF_SUITE/include/libtest.kshlib
32. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib
33. $STF_SUITE/tests/cli_root/zpool_import/zpool_import.kshlib
34
35################################################################################
36#
37# __stc_assertion_start
38#
39# ID: zpool_import_missing_002_pos
40#
41# DESCRIPTION:
42# 	Once a pool has been exported, and one or more devices are
43#	move to other place, import should handle this kind of situation
44#	as described:
45#		- Regular, report error while any number of devices failing.
46#		- Mirror could withstand (N-1) devices failing
47#		  before data integrity is compromised
48#		- Raidz could withstand one devices failing
49#		  before data integrity is compromised
50# 	Verify that is true.
51#
52# STRATEGY:
53#	1. Create test pool upon device files using the various combinations.
54#		- Regular pool
55#		- Mirror
56#		- Raidz
57#	2. Create necessary filesystem and test files.
58#	3. Export the test pool.
59#	4. Move one or more device files to other directory
60#	5. Verify 'zpool import -d' with the new directory
61#	   will handle moved files successfullly.
62#	   Using the various combinations.
63#		- Regular import
64#		- Alternate Root Specified
65#
66# TESTABILITY: explicit
67#
68# TEST_AUTOMATION_LEVEL: automated
69#
70# CODING_STATUS: COMPLETED (2005-08-01)
71#
72# __stc_assertion_end
73#
74################################################################################
75
76verify_runnable "global"
77
78set -A vdevs "" "mirror" "raidz"
79set -A options "" "-R $ALTER_ROOT"
80
81log_onexit cleanup_missing
82
83log_assert "Verify that import could handle moving device."
84
85log_must $MKDIR -p $BACKUP_DEVICE_DIR
86cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
87
88typeset -i i=0
89typeset -i count=0
90typeset action
91
92function try_import # <action> <poolish> [opts]
93{
94	typeset action=$1; shift
95	typeset poolish="$1"; shift
96	log_note "try_import action=$action poolish=$poolish opts='$1'"
97	if [ -z "$1" ]; then
98		$action $ZPOOL import -d $DEVICE_DIR $poolish
99	else
100		$action $ZPOOL import -d $DEVICE_DIR $1 $poolish
101	fi
102	[ "$action" = "log_mustnot" ] && return
103	log_must $ZPOOL export $TESTPOOL1
104}
105
106while :; do
107	typeset vdtype="${vdevs[i]}"
108
109	typeset -i j=0
110	while (( j < ${#options[*]} )); do
111		typeset opts="${options[j]}"
112
113		[ -n "$vdtype" ] && typestr="$vdtype" || typestr="stripe"
114		setup_missing_test_pool $vdtype
115		guid=$(get_config $TESTPOOL1 pool_guid $DEVICE_DIR)
116		log_note "*** Testing $typestr tvd guid $guid opts '${opts}'"
117
118		typeset -i count=0
119		for device in $DEVICE_FILES ; do
120			log_mustnot poolexists $TESTPOOL1
121			log_must $MV $device $BACKUP_DEVICE_DIR
122
123			(( count = count + 1 ))
124
125			action=log_mustnot
126			case "${vdevs[i]}" in
127				'mirror') (( count < $GROUP_NUM )) && \
128					action=log_must
129					;;
130				'raidz')  (( count == 1 )) && \
131					action=log_must
132					;;
133 			esac
134
135			log_note "Testing import by name; ${count} moved."
136			try_import $action $TESTPOOL1 "$opts"
137
138			log_note "Testing import by GUID; ${count} moved."
139			try_import $action $guid "$opts"
140		done
141
142		log_must $RM -f $BACKUP_DEVICE_DIR/*
143		recreate_missing_files
144		((j = j + 1))
145	done
146	((i = i + 1))
147	(( i == ${#vdevs[*]} )) && break
148done
149
150log_pass "Import could handle moving device."
151