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. $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_002_pos 34# 35# DESCRIPTION: 36# Verify that an exported pool cannot be imported 37# more than once. 38# 39# STRATEGY: 40# 1. Populate the default test directory and unmount it. 41# 2. Export the default test pool. 42# 3. Import it using the various combinations. 43# - Regular import 44# - Alternate Root Specified 45# 4. Verify it shows up under 'zpool list'. 46# 5. Verify it contains a file. 47# 6. Attempt to import it for a second time. Verify this fails. 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 pools "$TESTPOOL" "$TESTPOOL1" 62set -A devs "" "-d $DEVICE_DIR" 63set -A options "" "-R $ALTER_ROOT" 64set -A mtpts "$TESTDIR" "$TESTDIR1" 65 66 67function cleanup 68{ 69 typeset -i i=0 70 while (( i < ${#pools[*]} )); do 71 poolexists ${pools[i]} && \ 72 log_must $ZPOOL export ${pools[i]} 73 74 datasetexists "${pools[i]}/$TESTFS" || \ 75 log_must $ZPOOL import ${devs[i]} ${pools[i]} 76 77 ismounted "${pools[i]}/$TESTFS" || \ 78 log_must $ZFS mount ${pools[i]}/$TESTFS 79 80 [[ -e ${mtpts[i]}/$TESTFILE0 ]] && \ 81 log_must $RM -rf ${mtpts[i]}/$TESTFILE0 82 83 ((i = i + 1)) 84 done 85 86 cleanup_filesystem $TESTPOOL1 $TESTFS 87 88 destroy_pool $TESTPOOL1 89 90 [[ -d $ALTER_ROOT ]] && \ 91 log_must $RM -rf $ALTER_ROOT 92} 93 94log_onexit cleanup 95 96log_assert "Verify that an exported pool cannot be imported more than once." 97 98setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1 99 100checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') 101 102typeset -i i=0 103typeset -i j=0 104typeset basedir 105 106function inner_test 107{ 108 typeset pool=$1 109 typeset target=$2 110 typeset devs=$3 111 typeset opts=$4 112 typeset mtpt=$5 113 114 log_must $ZPOOL import ${devs} ${opts} $target 115 log_must poolexists $pool 116 log_must ismounted $pool/$TESTFS 117 118 basedir=$mtpt 119 [ -n "$opts" ] && basedir="$ALTER_ROOT/$mtpt" 120 121 [ ! -e "$basedir/$TESTFILE0" ] && \ 122 log_fail "ERROR: $basedir/$TESTFILE0 missing after import." 123 124 checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}') 125 [[ "$checksum1" != "$checksum2" ]] && \ 126 log_fail "ERROR: Checksums differ ($checksum1 != $checksum2)" 127 128 log_mustnot $ZPOOL import $devs $target 129} 130 131while (( i < ${#pools[*]} )); do 132 log_must $CP $MYTESTFILE ${mtpts[i]}/$TESTFILE0 133 134 log_must $ZFS umount ${mtpts[i]} 135 136 j=0 137 while (( j < ${#options[*]} )); do 138 typeset pool=${pools[i]} 139 typeset vdevdir="" 140 141 log_must $ZPOOL export $pool 142 143 [ "$pool" = "$TESTPOOL1" ] && vdevdir="$DEVICE_DIR" 144 guid=$(get_config $pool pool_guid $vdevdir) 145 log_must test -n "$guid" 146 log_note "Importing '$pool' by guid '$guid'" 147 inner_test $pool $guid "${devs[i]}" "${options[j]}" ${mtpts[i]} 148 149 log_must $ZPOOL export $pool 150 151 log_note "Importing '$pool' by name." 152 inner_test $pool $pool "${devs[i]}" "${options[j]}" ${mtpts[i]} 153 154 ((j = j + 1)) 155 done 156 157 ((i = i + 1)) 158 159done 160 161log_pass "Able to import exported pools and import only once." 162