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