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