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