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