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_rename_001_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_rename_001_pos 39# 40# DESCRIPTION: 41# An exported pool can be imported under a different name. Hence 42# we test that a previously exported pool can be renamed. 43# 44# STRATEGY: 45# 1. Copy a file into the default test directory. 46# 2. Umount the default directory. 47# 3. Export the pool. 48# 4. Import the pool using the name ${TESTPOOL}-new, 49# and using the various combinations. 50# - Regular import 51# - Alternate Root Specified 52# 5. Verify it exists in the 'zpool list' output. 53# 6. Verify the default file system is mounted and that the file 54# from step (1) is present. 55# 56# TESTABILITY: explicit 57# 58# TEST_AUTOMATION_LEVEL: automated 59# 60# CODING_STATUS: COMPLETED (2005-07-04) 61# 62# __stc_assertion_end 63# 64################################################################################ 65 66verify_runnable "global" 67 68set -A pools "$TESTPOOL" "$TESTPOOL1" 69set -A devs "" "-d $DEVICE_DIR" 70set -A options "" "-R $ALTER_ROOT" 71set -A mtpts "$TESTDIR" "$TESTDIR1" 72 73 74function cleanup 75{ 76 typeset -i i=0 77 while (( i < ${#pools[*]} )); do 78 if poolexists "${pools[i]}-new" ; then 79 log_must $ZPOOL export "${pools[i]}-new" 80 81 [[ -d /${pools[i]}-new ]] && \ 82 log_must $RM -rf /${pools[i]}-new 83 84 log_must $ZPOOL import ${devs[i]} \ 85 "${pools[i]}-new" ${pools[i]} 86 fi 87 88 datasetexists "${pools[i]}" || \ 89 log_must $ZPOOL import ${devs[i]} ${pools[i]} 90 91 ismounted "${pools[i]}/$TESTFS" || \ 92 log_must $ZFS mount ${pools[i]}/$TESTFS 93 94 [[ -e ${mtpts[i]}/$TESTFILE0 ]] && \ 95 log_must $RM -rf ${mtpts[i]}/$TESTFILE0 96 97 ((i = i + 1)) 98 99 done 100 101 cleanup_filesystem $TESTPOOL1 $TESTFS $TESTDIR1 102 103 destroy_pool $TESTPOOL1 104 105 [[ -d $ALTER_ROOT ]] && \ 106 log_must $RM -rf $ALTER_ROOT 107} 108 109function perform_inner_test 110{ 111 target=$1 112 113 log_must $ZPOOL import ${devs[i]} ${options[j]} \ 114 $target ${pools[i]}-new 115 116 log_must poolexists "${pools[i]}-new" 117 118 log_must ismounted ${pools[i]}-new/$TESTFS 119 120 basedir=${mtpts[i]} 121 [[ -n ${options[j]} ]] && \ 122 basedir=$ALTER_ROOT/${mtpts[i]} 123 124 [[ ! -e $basedir/$TESTFILE0 ]] && \ 125 log_fail "$basedir/$TESTFILE0 missing after import." 126 127 checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}') 128 [[ "$checksum1" != "$checksum2" ]] && \ 129 log_fail "Checksums differ ($checksum1 != $checksum2)" 130 131 log_must $ZPOOL export "${pools[i]}-new" 132 133 [[ -d /${pools[i]}-new ]] && \ 134 log_must $RM -rf /${pools[i]}-new 135 136 target=${pools[i]}-new 137 if (( RANDOM % 2 == 0 )) ; then 138 target=$guid 139 fi 140 log_must $ZPOOL import ${devs[i]} $target ${pools[i]} 141} 142 143log_onexit cleanup 144 145log_assert "Verify that an imported pool can be renamed." 146 147setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1 148checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') 149 150typeset -i i=0 151typeset -i j=0 152typeset basedir 153 154while (( i < ${#pools[*]} )); do 155 guid=$(get_config ${pools[i]} pool_guid) 156 log_must $CP $MYTESTFILE ${mtpts[i]}/$TESTFILE0 157 158 log_must $ZFS umount ${mtpts[i]} 159 160 j=0 161 while (( j < ${#options[*]} )); do 162 log_must $ZPOOL export ${pools[i]} 163 164 [[ -d /${pools[i]} ]] && \ 165 log_must $RM -rf /${pools[i]} 166 167 log_note "Testing import by name." 168 perform_inner_test ${pools[i]} 169 170 log_must $ZPOOL export ${pools[i]} 171 172 log_note "Testing import by GUID." 173 perform_inner_test $guid 174 175 ((j = j + 1)) 176 done 177 178 ((i = i + 1)) 179done 180 181log_pass "Successfully imported and renamed a ZPOOL" 182