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 2009 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_012_pos 34# 35# DESCRIPTION: 36# Once a pool has been exported, it should be recreated after a 37# successful import, all the sub-filesystems within it should all be restored, 38# include mount & share status. Verify that is true. 39# 40# STRATEGY: 41# 1. Create the test pool and hierarchical filesystems. 42# 2. Export the test pool, or destroy the test pool, 43# depend on testing import [-Df]. 44# 3. Import it using the various combinations. 45# - Regular import 46# - Alternate Root Specified 47# 4. Verify the mount & share status is restored. 48# 49# TESTABILITY: explicit 50# 51# TEST_AUTOMATION_LEVEL: automated 52# 53# CODING_STATUS: COMPLETED (2006-11-01) 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 71 while (( i < ${#pools[*]} )); do 72 if poolexists ${pools[i]} ; then 73 log_must $ZPOOL export ${pools[i]} 74 log_note "Try to import ${devs[i]} ${pools[i]}" 75 $ZPOOL import ${devs[i]} ${pools[i]} 76 else 77 log_note "Try to import $option ${devs[i]} ${pools[i]}" 78 $ZPOOL import $option ${devs[i]} ${pools[i]} 79 fi 80 81 if poolexists ${pools[i]} ; then 82 is_shared ${pools[i]} && \ 83 log_must $ZFS set sharenfs=off ${pools[i]} 84 85 ismounted "${pools[i]}/$TESTFS" || \ 86 log_must $ZFS mount ${pools[i]}/$TESTFS 87 fi 88 89 ((i = i + 1)) 90 done 91 92 destroy_pool $TESTPOOL1 93 94 if datasetexists $TESTPOOL/$TESTFS ; then 95 log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS 96 fi 97 log_must $ZFS create $TESTPOOL/$TESTFS 98 log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS 99 100 [[ -d $ALTER_ROOT ]] && \ 101 log_must $RM -rf $ALTER_ROOT 102} 103 104log_onexit cleanup 105 106log_assert "Verify all mount & share status of sub-filesystems within a pool \ 107 can be restored after import [-Df]." 108 109setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1 110for pool in ${pools[@]} ; do 111 log_must $ZFS create $pool/$TESTFS/$TESTCTR 112 log_must $ZFS create $pool/$TESTFS/$TESTCTR/$TESTCTR1 113 log_must $ZFS set canmount=off $pool/$TESTFS/$TESTCTR 114 log_must $ZFS set canmount=off $pool/$TESTFS/$TESTCTR/$TESTCTR1 115 log_must $ZFS create $pool/$TESTFS/$TESTCTR/$TESTFS1 116 log_must $ZFS create $pool/$TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1 117 log_must $ZFS create $pool/$TESTFS/$TESTFS1 118 log_must $ZFS snapshot $pool/$TESTFS/$TESTFS1@snap 119 log_must $ZFS clone $pool/$TESTFS/$TESTFS1@snap $pool/$TESTCLONE1 120done 121 122typeset mount_fs="$TESTFS $TESTFS/$TESTFS1 $TESTCLONE1 \ 123 $TESTFS/$TESTCTR/$TESTFS1 $TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1" 124typeset nomount_fs="$TESTFS/$TESTCTR $TESTFS/$TESTCTR/$TESTCTR1" 125 126typeset -i i=0 127typeset -i j=0 128typeset basedir 129 130for option in "" "-Df" ; do 131 i=0 132 while (( i < ${#pools[*]} )); do 133 pool=${pools[i]} 134 guid=$(get_config $pool pool_guid) 135 j=0 136 while (( j < ${#options[*]} )); do 137 typeset f_share="" 138 if ((RANDOM % 2 == 0)); then 139 log_note "Set sharenfs=on $pool" 140 log_must $ZFS set sharenfs=on $pool 141 log_must is_shared $pool 142 f_share="true" 143 fi 144 145 if [[ -z $option ]]; then 146 log_must $ZPOOL export $pool 147 else 148 log_must $ZPOOL destroy $pool 149 fi 150 151 typeset target=$pool 152 if (( RANDOM % 2 == 0 )) ; then 153 log_note "Import by guid." 154 if [[ -z $guid ]]; then 155 log_fail "guid should not be empty!" 156 else 157 target=$guid 158 fi 159 fi 160 log_must $ZPOOL import $option \ 161 ${devs[i]} ${options[j]} $target 162 163 log_must poolexists $pool 164 165 for fs in $mount_fs ; do 166 log_must ismounted $pool/$fs 167 [[ -n $f_share ]] && \ 168 log_must is_shared $pool/$fs 169 done 170 171 for fs in $nomount_fs ; do 172 log_mustnot ismounted $pool/$fs 173 log_mustnot is_shared $pool/$fs 174 done 175 176 if [[ -n $f_share ]] ; then 177 log_must $ZFS set sharenfs=off $pool 178 log_mustnot is_shared $pool 179 fi 180 181 ((j = j + 1)) 182 done 183 184 ((i = i + 1)) 185 done 186done 187 188log_pass "All mount & share status of sub-filesystems within a pool \ 189 can be restored after import [-Df]." 190