7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zpool_import / zpool_import_missing_002_pos.ksh
blob7534ebca87fe9ceecefba4d469ba25575a5c7b79
1 #!/bin/ksh -p
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
34 . $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
37 # DESCRIPTION:
38 # Once a pool has been exported, and one or more devices are
39 # move to other place, import should handle this kind of situation
40 # as described:
41 # - Regular, report error while any number of devices failing.
42 # - Mirror could withstand (N-1) devices failing
43 # before data integrity is compromised
44 # - Raidz could withstand one devices failing
45 # before data integrity is compromised
46 # Verify that is true.
48 # STRATEGY:
49 # 1. Create test pool upon device files using the various combinations.
50 # - Regular pool
51 # - Mirror
52 # - Raidz
53 # 2. Create necessary filesystem and test files.
54 # 3. Export the test pool.
55 # 4. Move one or more device files to other directory
56 # 5. Verify 'zpool import -d' with the new directory
57 # will handle moved files successfullly.
58 # Using the various combinations.
59 # - Regular import
60 # - Alternate Root Specified
63 verify_runnable "global"
65 set -A vdevs "" "mirror" "raidz"
66 set -A options "" "-R $ALTER_ROOT"
68 function cleanup
70 cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
71 [[ -e $DEVICE_DIR/$DEVICE_ARCHIVE ]] && \
72 log_must tar xf $DEVICE_DIR/$DEVICE_ARCHIVE
74 poolexists $TESTPOOL1 || \
75 log_must zpool import -d $DEVICE_DIR $TESTPOOL1
77 cleanup_filesystem $TESTPOOL1 $TESTFS
79 destroy_pool $TESTPOOL1
82 function cleanup_all
84 cleanup
86 # recover dev files
87 typeset i=0
88 while (( i < $MAX_NUM )); do
89 typeset dev_file=${DEVICE_DIR}/${DEVICE_FILE}$i
90 if [[ ! -e ${dev_file} ]]; then
91 log_must mkfile $FILE_SIZE ${dev_file}
93 ((i += 1))
94 done
96 log_must rm -f $DEVICE_DIR/$DEVICE_ARCHIVE
97 cd $CWD || log_fail "Unable change directory to $CWD"
99 [[ -d $ALTER_ROOT ]] && \
100 log_must rm -rf $ALTER_ROOT
102 [[ -d $BACKUP_DEVICE_DIR ]] && \
103 log_must rm -rf $BACKUP_DEVICE_DIR
106 log_onexit cleanup_all
108 log_assert "Verify that import could handle moving device."
110 CWD=$PWD
112 [[ ! -d $BACKUP_DEVICE_DIR ]] &&
113 log_must mkdir -p $BACKUP_DEVICE_DIR
115 cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
117 typeset -i i=0
118 typeset -i j=0
119 typeset -i count=0
120 typeset basedir backup
121 typeset action
123 while (( i < ${#vdevs[*]} )); do
125 (( i != 0 )) && \
126 log_must tar xf $DEVICE_DIR/$DEVICE_ARCHIVE
128 setup_filesystem "$DEVICE_FILES" \
129 $TESTPOOL1 $TESTFS $TESTDIR1 \
130 "" ${vdevs[i]}
132 guid=$(get_config $TESTPOOL1 pool_guid)
133 backup=""
135 log_must cp $MYTESTFILE $TESTDIR1/$TESTFILE0
137 log_must zfs umount $TESTDIR1
140 while (( j < ${#options[*]} )); do
142 count=0
145 # Restore all device files.
147 [[ -n $backup ]] && \
148 log_must tar xf $DEVICE_DIR/$DEVICE_ARCHIVE
150 log_must rm -f $BACKUP_DEVICE_DIR/*
152 for device in $DEVICE_FILES ; do
154 poolexists $TESTPOOL1 && \
155 log_must zpool export $TESTPOOL1
158 # Backup all device files while filesystem prepared.
160 if [[ -z $backup ]] ; then
161 log_must tar cf $DEVICE_DIR/$DEVICE_ARCHIVE ${DEVICE_FILE}*
162 backup="true"
165 log_must mv $device $BACKUP_DEVICE_DIR
167 (( count = count + 1 ))
169 action=log_mustnot
170 case "${vdevs[i]}" in
171 'mirror') (( count < $GROUP_NUM )) && \
172 action=log_must
174 'raidz') (( count == 1 )) && \
175 action=log_must
177 esac
179 typeset target=$TESTPOOL1
180 if (( RANDOM % 2 == 0 )) ; then
181 target=$guid
182 log_note "Import by guid."
184 $action zpool import \
185 -d $DEVICE_DIR ${options[j]} $target
187 done
189 ((j = j + 1))
190 done
192 cleanup
194 ((i = i + 1))
195 done
197 log_pass "Import could handle moving device."