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