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 2008 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)zpool_import_all_001_pos.ksh 1.5 08/11/03 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_all_001_pos 39# 40# DESCRIPTION: 41# Verify that 'zpool import -a' succeeds as root. 42# 43# STRATEGY: 44# 1. Create a group of pools with specified vdev. 45# 2. Create zfs filesystems within the given pools. 46# 3. Export the pools. 47# 4. Verify that import command succeed. 48# 49# TESTABILITY: explicit 50# 51# TEST_AUTOMATION_LEVEL: automated 52# 53# CODING_STATUS: COMPLETED (2005-07-04) 54# 55# __stc_assertion_end 56# 57################################################################################ 58 59verify_runnable "global" 60 61set -A options "" "-R $ALTER_ROOT" 62 63typeset -i number=0 64typeset -i id=0 65typeset -i i=0 66typeset checksum1 67typeset unwantedpool 68 69function setup_single_disk #disk #pool #fs #mtpt 70{ 71 typeset disk=$1 72 typeset pool=$2 73 typeset fs=${3##/} 74 typeset mtpt=$4 75 76 setup_filesystem "$disk" "$pool" "$fs" "$mtpt" 77 78 log_must $CP $MYTESTFILE $mtpt/$TESTFILE0 79 80 log_must $ZPOOL export $pool 81 82 [[ -d $mtpt ]] && \ 83 $RM -rf $mtpt 84} 85 86function cleanup_all 87{ 88 typeset -i id=0 89 90 # 91 # Try import individually if 'import -a' failed. 92 # 93 for pool in `$ZPOOL import | $GREP "pool:" | $AWK '{print $2}'`; do 94 $ZPOOL import -f $pool 95 done 96 97 for pool in `$ZPOOL import -d $DEVICE_DIR | $GREP "pool:" | $AWK '{print $2}'`; do 98 log_must $ZPOOL import -d $DEVICE_DIR -f $pool 99 done 100 101 while (( id < number )); do 102 if ! poolexists ${TESTPOOL}-$id ; then 103 (( id = id + 1 )) 104 continue 105 fi 106 107 if (( id == 0 )); then 108 log_must $ZPOOL export ${TESTPOOL}-$id 109 110 [[ -d /${TESTPOOL}-$id ]] && \ 111 log_must $RM -rf /${TESTPOOL}-$id 112 113 log_must $ZPOOL import -f ${TESTPOOL}-$id $TESTPOOL 114 115 [[ -e $TESTDIR/$TESTFILE0 ]] && \ 116 log_must $RM -rf $TESTDIR/$TESTFILE0 117 else 118 cleanup_filesystem "${TESTPOOL}-$id" $TESTFS 119 120 destroy_pool ${TESTPOOL}-$id 121 fi 122 123 (( id = id + 1 )) 124 done 125 126 [[ -d $ALTER_ROOT ]] && \ 127 $RM -rf $ALTER_ROOT 128} 129 130function checksum_all #alter_root 131{ 132 typeset alter_root=$1 133 typeset -i id=0 134 typeset file 135 typeset checksum2 136 137 while (( id < number )); do 138 if (( id == 2 )); then 139 (( id = id + 1 )) 140 continue 141 fi 142 143 if (( id == 0 )); then 144 file=${alter_root}/$TESTDIR/$TESTFILE0 145 else 146 file=${alter_root}/$TESTDIR.$id/$TESTFILE0 147 fi 148 [[ ! -e $file ]] && \ 149 log_fail "$file missing after import." 150 151 checksum2=$($SUM $file | $AWK '{print $1}') 152 [[ "$checksum1" != "$checksum2" ]] && \ 153 log_fail "Checksums differ ($checksum1 != $checksum2)" 154 155 (( id = id + 1 )) 156 done 157 158 return 0 159} 160 161 162log_assert "Verify that 'zpool import -a' succeeds as root." 163 164log_onexit cleanup_all 165 166checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') 167 168log_must $ZPOOL export $TESTPOOL 169log_must $ZPOOL import $TESTPOOL ${TESTPOOL}-0 170log_must $CP $MYTESTFILE $TESTDIR/$TESTFILE0 171log_must $ZPOOL export ${TESTPOOL}-0 172[[ -d /${TESTPOOL}-0 ]] && \ 173 log_must $RM -rf /${TESTPOOL}-0 174 175# 176# setup exported pools on normal devices 177# 178number=1 179while (( number <= $GROUP_NUM )); do 180 if [[ `$UNAME -s` != "FreeBSD" ]]; then 181 if (( number == 2)); then 182 (( number = number + 1 )) 183 continue 184 fi 185 fi 186 set_partition $number "" $PART_SIZE ${ZFS_DISK2} 187 188 setup_single_disk "${ZFS_DISK2}p${number}" \ 189 "${TESTPOOL}-$number" \ 190 "$TESTFS" \ 191 "$TESTDIR.$number" 192 193 (( number = number + 1 )) 194done 195 196# 197# setup exported pools on raw files 198# 199for disk in $DEVICE_FILES 200do 201 202 setup_single_disk "$disk" \ 203 "${TESTPOOL}-$number" \ 204 "$TESTFS" \ 205 "$TESTDIR.$number" 206 207 (( number = number + 1 )) 208done 209 210while (( i < ${#options[*]} )); do 211 212 log_must $ZPOOL import -d /dev -d $DEVICE_DIR ${options[i]} -a -f 213 214 # destroy unintentional imported pools 215 typeset exclude=`eval $ECHO \"'(${KEEP})'\"` 216 for unwantedpool in $($ZPOOL list -H -o name \ 217 | $EGREP -v "$exclude" | $GREP -v $TESTPOOL); do 218 log_must $ZPOOL export $unwantedpool 219 done 220 221 if [[ -n ${options[i]} ]]; then 222 checksum_all $ALTER_ROOT 223 else 224 checksum_all 225 fi 226 227 id=0 228 while (( id < number )); do 229 if poolexists ${TESTPOOL}-$id ; then 230 log_must $ZPOOL export ${TESTPOOL}-$id 231 fi 232 (( id = id + 1 )) 233 done 234 235 (( i = i + 1 )) 236done 237 238log_pass "'zpool import -a' succeeds as root." 239