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_001_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. $STF_SUITE/tests/cli_root/zpool_import/zpool_import.kshlib 34 35################################################################################ 36# 37# __stc_assertion_start 38# 39# ID: zpool_import_missing_001_pos 40# 41# DESCRIPTION: 42# Once a pool has been exported, and one or more devices are 43# damaged or missing (d/m), import should handle this kind of situation 44# as described: 45# - Regular, report error while any number of devices failing. 46# - Mirror could withstand (N-1) devices failing 47# before data integrity is compromised 48# - Raidz could withstand one devices failing 49# before data integrity is compromised 50# Verify those are true. 51# 52# STRATEGY: 53# 1. Create test pool upon device files using the various combinations. 54# - Regular pool 55# - Mirror 56# - Raidz 57# 2. Create necessary filesystem and test files. 58# 3. Export the test pool. 59# 4. Remove one or more devices 60# 5. Verify 'zpool import' will handle d/m device successfully. 61# Using the various combinations. 62# - Regular import 63# - Alternate Root Specified 64# It should be succeed with single d/m device upon 'raidz' & 'mirror', 65# but failed against 'regular' or more d/m devices. 66# 6. If import succeed, verify following is true: 67# - The pool shows up under 'zpool list'. 68# - The pool's health should be DEGRADED. 69# - It contains the correct test file 70# 71# TESTABILITY: explicit 72# 73# TEST_AUTOMATION_LEVEL: automated 74# 75# CODING_STATUS: COMPLETED (2005-08-01) 76# 77# __stc_assertion_end 78# 79################################################################################ 80 81verify_runnable "global" 82 83set -A vdevs "" "mirror" "raidz" 84set -A options "" "-R $ALTER_ROOT" 85 86function perform_inner_test 87{ 88 typeset action=$1 89 typeset import_opts=$2 90 typeset target=$3 91 typeset basedir 92 93 $action $ZPOOL import -d $DEVICE_DIR ${import_opts} $target 94 [[ $action == "log_mustnot" ]] && return 95 96 log_must poolexists $TESTPOOL1 97 98 health=$($ZPOOL list -H -o health $TESTPOOL1) 99 [[ "$health" == "DEGRADED" ]] || \ 100 log_fail "ERROR: $TESTPOOL1: Incorrect health '$health'" 101 log_must ismounted $TESTPOOL1/$TESTFS 102 103 basedir=$TESTDIR1 104 [[ -n "${import_opts}" ]] && basedir=$ALTER_ROOT/$TESTDIR1 105 [[ ! -e "$basedir/$TESTFILE0" ]] && \ 106 log_fail "ERROR: $basedir/$TESTFILE0 missing after import." 107 108 checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}') 109 [[ "$checksum1" != "$checksum2" ]] && \ 110 log_fail "ERROR: Checksums differ ($checksum1 != $checksum2)" 111 112 log_must $ZPOOL export $TESTPOOL1 113} 114 115log_onexit cleanup_missing 116 117log_assert "Verify that import could handle damaged or missing device." 118 119CWD=$PWD 120cd $DEVICE_DIR || log_fail "ERROR: Unable change directory to $DEVICE_DIR" 121 122checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') 123 124typeset -i i=0 125while :; do 126 typeset vdtype="${vdevs[i]}" 127 128 typeset -i j=0 129 while (( j < ${#options[*]} )); do 130 typeset opts="${options[j]}" 131 [ -n "$vdtype" ] && typestr="$vdtype" || typestr="stripe" 132 133 # Prepare the pool. 134 setup_missing_test_pool $vdtype 135 guid=$(get_config $TESTPOOL1 pool_guid $DEVICE_DIR) 136 log_note "*** Testing $typestr tvd guid $guid opts '${opts}'" 137 138 typeset -i count=0 139 for device in $DEVICE_FILES ; do 140 log_mustnot poolexists $TESTPOOL1 141 log_must $RM -f $device 142 143 (( count = count + 1 )) 144 145 action=log_must 146 case "$vdtype" in 147 'mirror') (( count == $GROUP_NUM )) && \ 148 action=log_mustnot 149 ;; 150 'raidz') (( count > 1 )) && \ 151 action=log_mustnot 152 ;; 153 '') action=log_mustnot 154 ;; 155 esac 156 157 log_note "Testing import by name; ${count} removed." 158 perform_inner_test $action "${opts}" $TESTPOOL1 159 160 log_note "Testing import by GUID; ${count} removed." 161 perform_inner_test $action "${opts}" $guid 162 done 163 164 recreate_missing_files 165 (( j = j + 1 )) 166 done 167 (( i = i + 1 )) 168 (( i == ${#vdevs[*]} )) && break 169done 170 171log_pass "Import could handle damaged or missing device." 172