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]
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
38 # Once a pool has been exported, but one or more devices are
39 # overlapped with other exported pool, import should handle
40 # this kind of situation properly.
43 # 1. Repeat 1-3, create two test pools upon device files separately.
44 # These two pools should have one or more devices are overlapped.
45 # using the various combinations.
49 # 2. Create necessary filesystem and test files.
50 # 3. Export the test pool.
51 # 4. Verify 'zpool import -d' with these two pools will have results
53 # - Regular, report error while any number of devices failing.
54 # - Mirror could withstand (N-1) devices failing
55 # before data integrity is compromised
56 # - Raidz could withstand one devices failing
57 # before data integrity is compromised
60 verify_runnable "global"
62 # See issue: https://github.com/openzfs/zfs/issues/6839
64 log_unsupported "Test case may be slow"
67 set -A vdevs "" "mirror" "raidz"
82 log_must poolexists $pool
84 myhealth=$(zpool list -H -o health $pool)
86 [[ $myhealth == $health ]] || \
87 log_fail "$pool: Incorrect health ($myhealth), " \
90 log_must ismounted $pool/$fs
92 mymtpt=$(get_prop mountpoint $pool/$fs)
93 [[ $mymtpt == $mtpt ]] || \
94 log_fail "$pool/$fs: Incorrect mountpoint ($mymtpt), " \
97 [[ ! -e $mtpt/$file ]] && \
98 log_fail "$mtpt/$file missing after import."
100 checksum2=$(sum $mymtpt/$file | awk '{print $1}')
101 [[ "$checksum1" != "$checksum2" ]] && \
102 log_fail "Checksums differ ($checksum1 != $checksum2)"
110 cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
112 for pool in $TESTPOOL1 $TESTPOOL2; do
113 if poolexists "$pool" ; then
114 cleanup_filesystem $pool $TESTFS
119 [[ -e $DEVICE_DIR/$DEVICE_ARCHIVE ]] && \
120 log_must tar xf $DEVICE_DIR/$DEVICE_ARCHIVE
129 while (( i < $MAX_NUM )); do
130 typeset file=${DEVICE_DIR}/${DEVICE_FILE}$i
131 if [[ -e $file ]]; then
134 log_must mkfile $FILE_SIZE $file
138 log_must rm -f $DEVICE_DIR/$DEVICE_ARCHIVE
139 cd $CWD || log_fail "Unable change directory to $CWD"
143 log_onexit cleanup_all
145 log_assert "Verify that import could handle device overlapped."
149 cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
150 log_must tar cf $DEVICE_DIR/$DEVICE_ARCHIVE ${DEVICE_FILE}*
152 checksum1=$(sum $MYTESTFILE | awk '{print $1}')
162 while (( num < $GROUP_NUM )); do
163 vdev1="$vdev1 ${DEVICE_DIR}/${DEVICE_FILE}$num"
167 while (( i < ${#vdevs[*]} )); do
169 while (( j < ${#vdevs[*]} )); do
172 log_must tar xf $DEVICE_DIR/$DEVICE_ARCHIVE
178 while (( overlap <= $GROUP_NUM )); do
180 (( begin = $GROUP_NUM - overlap ))
181 (( end = 2 * $GROUP_NUM - overlap - 1 ))
183 while (( num <= end )); do
184 vdev2="$vdev2 ${DEVICE_DIR}/${DEVICE_FILE}$num"
188 setup_filesystem "$vdev1" $TESTPOOL1 $TESTFS $TESTDIR1 \
190 log_must cp $MYTESTFILE $TESTDIR1/$TESTFILE0
191 log_must zfs umount $TESTDIR1
192 poolexists $TESTPOOL1 && \
193 log_must zpool export $TESTPOOL1
195 setup_filesystem "$vdev2" $TESTPOOL2 $TESTFS $TESTDIR2 \
197 log_must cp $MYTESTFILE $TESTDIR2/$TESTFILE0
198 log_must zfs umount $TESTDIR2
199 poolexists $TESTPOOL2 && \
200 log_must zpool export $TESTPOOL2
203 case "${vdevs[i]}" in
204 'mirror') (( overlap == $GROUP_NUM )) && \
207 'raidz') (( overlap > 1 )) && \
210 '') action=log_mustnot
214 $action zpool import -d $DEVICE_DIR $TESTPOOL1
215 log_must zpool import -d $DEVICE_DIR $TESTPOOL2
217 if [[ $action == log_must ]]; then
218 verify "$TESTPOOL1" "$TESTFS" "$TESTDIR1" \
219 "DEGRADED" "$TESTFILE0" "$checksum1"
222 verify "$TESTPOOL2" "$TESTFS" "$TESTDIR2" \
223 "ONLINE" "$TESTFILE0" "$checksum1"
227 (( overlap = overlap + 1 ))
237 log_pass "Import could handle device overlapped."