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 29################################################################################ 30# 31# __stc_assertion_start 32# 33# ID: zpool_import_missing_003_pos 34# 35# DESCRIPTION: 36# Once a pool has been exported, but one or more devices are 37# overlapped with other exported pool, import should handle 38# this kind of situation properly. 39# 40# STRATEGY: 41# 1. Repeat 1-3, create two test pools upon device files separately. 42# These two pools should have one or more devices are overlapped. 43# using the various combinations. 44# - Regular pool 45# - Mirror 46# - Raidz 47# 2. Create necessary filesystem and test files. 48# 3. Export the test pool. 49# 4. Verify 'zpool import -d' with these two pools will have results 50# as described: 51# - Regular, report error while any number of devices failing. 52# - Mirror could withstand (N-1) devices failing 53# before data integrity is compromised 54# - Raidz could withstand one devices failing 55# before data integrity is compromised 56# 57# TESTABILITY: explicit 58# 59# TEST_AUTOMATION_LEVEL: automated 60# 61# CODING_STATUS: COMPLETED (2005-08-10) 62# 63# __stc_assertion_end 64# 65################################################################################ 66 67verify_runnable "global" 68 69set -A vdevs "" "mirror" "raidz" 70 71function verify 72{ 73 typeset pool=$1 74 typeset fs=$2 75 typeset mtpt=$3 76 typeset health=$4 77 typeset file=$5 78 typeset checksum1=$6 79 80 typeset myhealth 81 typeset mymtpt 82 typeset checksum2 83 84 log_must poolexists $pool 85 86 myhealth=$($ZPOOL list -H -o health $pool) 87 88 [[ $myhealth == $health ]] || \ 89 log_fail "$pool: Incorrect health ($myhealth), " \ 90 "expected ($health)." 91 92 log_must ismounted $pool/$fs 93 94 mymtpt=$(get_prop mountpoint $pool/$fs) 95 [[ $mymtpt == $mtpt ]] || \ 96 log_fail "$pool/$fs: Incorrect mountpoint ($mymtpt), " \ 97 "expected ($mtpt)." 98 99 [[ ! -e $mtpt/$file ]] && \ 100 log_fail "$mtpt/$file missing after import." 101 102 checksum2=$($SUM $mymtpt/$file | $AWK '{print $1}') 103 [[ "$checksum1" != "$checksum2" ]] && \ 104 log_fail "Checksums differ ($checksum1 != $checksum2)" 105 106 return 0 107 108} 109 110function cleanup 111{ 112 cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR" 113 114 for pool in $TESTPOOL1 $TESTPOOL2; do 115 if poolexists "$pool" ; then 116 cleanup_filesystem $pool $TESTFS 117 destroy_pool $pool 118 fi 119 done 120 121 [[ -e $DEVICE_ARCHIVE ]] && log_must $TAR xf $DEVICE_ARCHIVE 122} 123 124function cleanup_all 125{ 126 cleanup 127 128 # recover dev files 129 typeset i=0 130 while (( i < $MAX_NUM )); do 131 log_must create_vdevs ${DEVICE_DIR}/${DEVICE_FILE}$i 132 ((i += 1)) 133 done 134 135 log_must $RM -f $DEVICE_ARCHIVE 136 cd $CWD || log_fail "Unable change directory to $CWD" 137 138} 139 140log_onexit cleanup_all 141 142log_assert "Verify that import could handle device overlapped." 143 144CWD=$PWD 145 146cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR" 147log_must $TAR cf $DEVICE_ARCHIVE ${DEVICE_FILE}* 148 149checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') 150 151typeset -i i=0 152typeset -i j=0 153typeset -i count=0 154typeset -i num=0 155typeset vdev1="" 156typeset vdev2="" 157typeset action 158 159while (( num < $GROUP_NUM )); do 160 vdev1="$vdev1 ${DEVICE_DIR}/${DEVICE_FILE}$num" 161 (( num = num + 1 )) 162done 163 164while (( i < ${#vdevs[*]} )); do 165 j=0 166 while (( j < ${#vdevs[*]} )); do 167 168 (( j != 0 )) && \ 169 log_must $TAR xf $DEVICE_ARCHIVE 170 171 typeset -i overlap=1 172 typeset -i begin 173 typeset -i end 174 175 while (( overlap <= $GROUP_NUM )); do 176 vdev2="" 177 (( begin = $GROUP_NUM - overlap )) 178 (( end = 2 * $GROUP_NUM - overlap - 1 )) 179 (( num = begin )) 180 while (( num <= end )); do 181 vdev2="$vdev2 ${DEVICE_DIR}/${DEVICE_FILE}$num" 182 (( num = num + 1 )) 183 done 184 185 setup_filesystem "$vdev1" $TESTPOOL1 $TESTFS $TESTDIR1 \ 186 "" ${vdevs[i]} 187 log_must $CP $MYTESTFILE $TESTDIR1/$TESTFILE0 188 log_must $ZFS umount $TESTDIR1 189 poolexists $TESTPOOL1 && \ 190 log_must $ZPOOL export $TESTPOOL1 191 192 setup_filesystem "$vdev2" $TESTPOOL2 $TESTFS $TESTDIR2 \ 193 "" ${vdevs[j]} 194 log_must $CP $MYTESTFILE $TESTDIR2/$TESTFILE0 195 log_must $ZFS umount $TESTDIR2 196 poolexists $TESTPOOL2 && \ 197 log_must $ZPOOL export $TESTPOOL2 198 199 action=log_must 200 case "${vdevs[i]}" in 201 'mirror') (( overlap == $GROUP_NUM )) && \ 202 action=log_mustnot 203 ;; 204 'raidz') (( overlap > 1 )) && \ 205 action=log_mustnot 206 ;; 207 '') action=log_mustnot 208 ;; 209 esac 210 211 $action $ZPOOL import -d $DEVICE_DIR $TESTPOOL1 212 log_must $ZPOOL import -d $DEVICE_DIR $TESTPOOL2 213 214 if [[ $action == log_must ]]; then 215 verify "$TESTPOOL1" "$TESTFS" "$TESTDIR1" \ 216 "DEGRADED" "$TESTFILE0" "$checksum1" 217 fi 218 219 verify "$TESTPOOL2" "$TESTFS" "$TESTDIR2" \ 220 "ONLINE" "$TESTFILE0" "$checksum1" 221 222 cleanup 223 224 (( overlap = overlap + 1 )) 225 226 done 227 228 ((j = j + 1)) 229 done 230 231 ((i = i + 1)) 232done 233 234log_pass "Import could handle device overlapped." 235