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