Home | History | Annotate | Download | only in nfsv4
      1 #! /usr/bin/ksh -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 2008 Sun Microsystems, Inc.  All rights reserved.
     25 # Use is subject to license terms.
     26 #
     27 # ident	"@(#)srv_setup.ksh	1.2	08/11/19 SMI"
     28 #
     29 # setup the $SERVER for testing NFS V4 protocols.
     30 #
     31 
     32 SETDEBUG
     33 [[ -n $DEBUG ]] && [[ $DEBUG != 0 ]] && set -x
     34 
     35 NAME=$(basename $0)
     36 
     37 id | grep "0(root)" > /dev/null 2>&1
     38 if (( $? != 0 )); then
     39 	echo "$NAME: ERROR - Must be root to run this script for setup."
     40 	exit 1
     41 fi
     42 
     43 Usage="ERROR - Usage: $NAME -s | -c | -r \n
     44 		-s: to setup this host w/v4 and share\n
     45 		-r: to cleanup the LOFI/ZFS filesystems for recovery tests\n
     46 		-c: to cleanup the server\n
     47 "
     48 if (( $# < 1 )); then
     49 	echo "$NAME: ERROR - incorrect usage."
     50 	echo $Usage
     51 	exit 2
     52 fi
     53 
     54 ENVFILE=ENV_from_client
     55 TMPDIR=Tmpdir_from_client
     56 CONFIGDIR=CONFIGDIR_from_client
     57 ZONE_PATH=ZONE_PATH_from_client
     58 
     59 QUOTA_FMRI="svc:/network/nfs/rquota:default"
     60 SMF_TIMEOUT=60
     61 
     62 # source the environment/config file from client to be consistent
     63 . $CONFIGDIR/$ENVFILE
     64 . $CONFIGDIR/libsmf.sh
     65 
     66 iscipso=0
     67 if [[ -x /usr/sbin/tninfo ]]; then
     68 	/usr/sbin/tninfo -h $(uname -n) | grep cipso >/dev/null 2>&1
     69 	if (( $? == 0 )); then
     70 		iscipso=1
     71 		if [[ -z $ZONE_PATH ]]; then
     72 			echo "$NAME: ERROR - ZONE_PATH is null!"
     73 			exit 2
     74 		fi
     75 
     76 		zlist=$(/usr/sbin/zoneadm list)
     77 		if [[ -z $zlist ]]; then
     78 			echo "$NAME: ERROR - no zones exist on server!"
     79 			exit 2
     80 		fi
     81 
     82 		if [[ $zlist == global ]]; then
     83 			echo "$NAME: ERROR - No non-global zones on server!"
     84 			exit 2
     85 		fi
     86 
     87 		fnd=0
     88 		for azone in $zlist
     89 		do
     90 			[[ $azone == global ]] && continue
     91 			X=$(zoneadm -z $azone list -p | cut -d ":" -f 4)
     92 			[[ -z $X ]] && continue
     93 			X1=$(echo "$X" | sed -e 's/\// /g' | awk '{print $1}')
     94 			X2=$(echo "$X" | sed -e 's/\// /g' | awk '{print $2}')
     95 			Y1=$(echo "$ZONE_PATH" | sed -e 's/\// /g' | \
     96 				awk '{print $1}')
     97 			Y2=$(echo "$ZONE_PATH" | sed -e 's/\// /g' | \
     98 				awk '{print $2}')
     99 			if [[ $X1 == $Y1 && $X2 == $Y2 ]]; then
    100 				fnd=1
    101 				localzone=$azone
    102 				break
    103 			fi
    104 		done
    105 
    106 		if (( fnd == 0 )); then
    107 			echo "$NAME: ERROR - ZONE_PATH doesn't match any zone!"
    108 			exit 2
    109 		fi
    110 	fi
    111 fi
    112 
    113 function cleanup {
    114 	rm -f $TMPDIR/*.$$
    115 	exit $1
    116 }
    117 
    118 # quick function to create sub ZFS pool
    119 function create_zpool
    120 {
    121 	[[ -n "$DEBUG" ]] && [[ "$DEBUG" != "0" ]] && set -x
    122 	typeset Fname=create_zpool
    123 	getopts fv opt
    124 	case $opt in
    125 	f) # create pool on file
    126 		typeset pname=$2 fname=$3
    127 		zpool create -f $pname $fname > $TMPDIR/zpool.out.$$ 2>&1
    128 		if [[ $? != 0 ]]; then
    129 			echo "$Fname: failed to create zpool -"
    130 			cat $TMPDIR/zpool.out.$$
    131 			zpool status $pname
    132 			return 2
    133 		fi
    134 	;;
    135 	v) # create pool on volume
    136 		typeset size=$2 # size is in the form of 5m/2g
    137 		typeset vname=$3
    138 		typeset pname=$4
    139 		echo "$NAME: Setting test filesystems with ZFS ..."
    140 		zpool status > $TMPDIR/zstatus.out.$$ 2>&1
    141 		grep "$vname" $TMPDIR/zstatus.out.$$ | \
    142 			grep ONLINE >/dev/null 2>&1
    143 		if [[ $? != 0 ]]; then
    144 			zfs create -V $size $vname > $TMPDIR/zpool.out.$$ 2>&1
    145 			if [[ $? != 0 ]]; then
    146 				echo "$NAME: failed to create volume -"
    147 				cat $TMPDIR/zpool.out.$$
    148 				grep "same dev" $TMPDIR/zpool.out.$$ \
    149 					> /dev/null 2>&1
    150 				[[ $? == 0 ]] && zpool status
    151 				return 2
    152 			fi
    153 			zpool create -f $pname /dev/zvol/dsk/$vname \
    154 				> $TMPDIR/zpool.out.$$ 2>&1
    155 			if [[ $? != 0 ]]; then
    156 				echo "$NAME: failed to create sub zpool -"
    157 				cat $TMPDIR/zpool.out.$$
    158 				grep "same dev" $TMPDIR/zpool.out.$$ \
    159 					> /dev/null 2>&1
    160 				[[ $? == 0 ]] && zpool status
    161 				return 2
    162 			fi
    163 		fi
    164 	;;
    165 	*)
    166 		echo "$Fname: ERROR - incorrect usage."
    167 		return 2
    168 	;;
    169 	esac
    170 
    171 }
    172 
    173 function destroy_zpool
    174 {
    175 	[[ -n $DEBUG ]] && [[ $DEBUG != 0 ]] && set -x
    176 	# NSPCPOOL is always created; so need to destroy
    177 	if [[ -n $NSPCPOOL ]]; then
    178 		zpool destroy -f $NSPCPOOL >> $TMPDIR/zfsDes.out.$$ 2>&1
    179 		if (( $? != 0 )); then
    180 			echo "WARNING, failed to destroy [$NSPCPOOL];"
    181 			cat $TMPDIR/zfsDes.out.$$
    182 			echo "\t Please clean it up manually."
    183 		fi
    184 	fi
    185 
    186 	ZFSn=$(zfs list | grep "$BASEDIR" | nawk '{print $1}')
    187 	zfs destroy -f -r $ZFSn > $TMPDIR/zfsDes.out.$$ 2>&1
    188 	if (( $? != 0 )); then
    189 		echo "WARNING, unable to cleanup [$BASEDIR];"
    190 		cat $TMPDIR/zfsDes.out.$$
    191 		echo "\t Please clean it up manually."
    192 	fi
    193 }
    194 
    195 function create_test_fs
    196 {
    197 	[[ -n $DEBUG ]] && [[ $DEBUG != 0 ]] && set -x
    198 
    199 	fsname=$1
    200 	shift
    201 	FSdir_opt=$*
    202 	typeset ret=0
    203 
    204 	if (( TestZFS == 1 )); then
    205 		if [[ $fsname == NSPCDIR ]]; then
    206 			typeset pool=NSPCpool
    207 			mkfile 64m $BASEDIR/NSPCpoolfile
    208 			create_zpool -f $pool $BASEDIR/NSPCpoolfile \
    209 				> $TMPDIR/nspc.out.$$ 2>&1
    210 			if [[ $? != 0 ]]; then
    211 				echo "ERROR, unable to setup NSPC pool;"
    212 				cat $TMPDIR/nspc.out.$$
    213 				cleanup 3
    214 			fi
    215 			echo "NSPCPOOL=$pool; export NSPCPOOL" \
    216 				>> $CONFIGDIR/$ENVFILE
    217 			zfs set mountpoint=$NSPCDIR $pool \
    218 				> $TMPDIR/$fsname.out.$$ 2>&1
    219 			ret=$?
    220 			chmod 0777 $NSPCDIR
    221 		else
    222 			create_zfs_fs $FSdir_opt > $TMPDIR/$fsname.out.$$ 2>&1
    223 			ret=$?
    224 		fi
    225 	else
    226 		$CONFIGDIR/setupFS -s $FSdir_opt > $TMPDIR/$fsname.out.$$ 2>&1
    227 		ret=$?
    228 	fi
    229 	if (( $ret != 0 )); then
    230 		echo "WARNING: unable to setup $fsname - "
    231 		cat $TMPDIR/$fsname.out.$$
    232 		cleanup $ret
    233 	fi
    234 }
    235 
    236 function create_some_files 	# quick function to create some files
    237 {
    238 	[[ -n $DEBUG ]] && [[ $DEBUG != 0 ]] && set -x
    239 	UDIR=$1
    240 
    241 	head -88 $CONFIGDIR/setserver > $UDIR/$RWFILE
    242 	chmod 0666 $UDIR/$RWFILE
    243 	tail -38 $CONFIGDIR/setupFS > $UDIR/$ROFILE
    244 	chmod 0444 $UDIR/$ROFILE
    245 	mkdir -p $UDIR/$DIR0755/dir2/dir3
    246 	chmod -R 0755 $UDIR/$DIR0755
    247 	if (( TestZFS == 1 )); then
    248 		ACLs=write_xattr/write_attributes/write_acl/add_file:allow
    249 		chmod A+everyone@:${ACLs} $UDIR/$DIR0755 $UDIR/$RWFILE
    250 	fi
    251 	echo "this is the ext-attr file for $UDIR/$DIR0755" | \
    252 		runat $UDIR/$DIR0755 "cat > $ATTRDIR_AT1; chmod 0777 ."
    253 	runat $UDIR/$DIR0755 \
    254 		"cp $ATTRDIR_AT1 $ATTRDIR_AT2; chmod 0 $ATTRDIR_AT2"
    255 }
    256 
    257 function create_zfs_fs 		# quick function to create ZFS filesystem
    258 {
    259 	[[ -n $DEBUG ]] && [[ $DEBUG != 0 ]] && set -x
    260 	FSname=$1
    261 	(( $# == 2 )) && FSsize=$2	# size is in the form of 5m/2g
    262 	(( $# == 3 )) && FSmopt=$3	# remount option
    263 	
    264 	typeset -u ZName=$(basename $FSname)
    265 	zfs create $ZFSPOOL/$ZName > $TMPDIR/czfs.out.$$ 2>&1
    266 	if (( $? != 0 )); then
    267 		echo "create_zfs_fs failed to zfs create $ZFSPOOL/$ZName"
    268 		cat $TMPDIR/czfs.out.$$
    269 		return 2
    270 	fi
    271 	zfs set mountpoint=$FSname $ZFSPOOL/$ZName > $TMPDIR/szfs.out.$$ 2>&1
    272 	if (( $? != 0 )); then
    273 		echo "create_zfs_fs failed to zfs set mountpoint=$FSname \c"
    274 		echo "to $ZFSPOOL/$Zname"
    275 		cat $TMPDIR/szfs.out.$$
    276 		return 2
    277 	fi
    278 	chmod 777 $FSname
    279 	ACLs=write_xattr/write_attributes/write_acl/add_file:allow
    280 	chmod A+everyone@:${ACLs} $FSname
    281 
    282 	if [[ -n $FSsize ]]; then
    283 		zfs set quota=$FSsize $ZFSPOOL/$ZName > $TMPDIR/qzfs.out.$$ 2>&1
    284 		if (( $? != 0 )); then
    285 			echo "create_zfs_fs failed to zfs set quota=$FSsize"
    286 			cat $TMPDIR/qzfs.out.$$
    287 			return 2
    288 		fi
    289 		unset FSsize
    290 	fi
    291 	if [[ -n $FSmopt ]]; then
    292 		zfs umount $ZFSPOOL/$ZName > $TMPDIR/mzfs.out.$$ 2>&1
    293 		zfs mount -o $FSmopt $ZFSPOOL/$ZName >> $TMPDIR/mzfs.out.$$ 2>&1
    294 		if (( $? != 0 )); then
    295 			echo "create_zfs_fs failed to zfs remount $FSmopt"
    296 			cat $TMPDIR/mzfs.out.$$
    297 			return 2
    298 		fi
    299 		unset FSmopt
    300 	fi
    301 }
    302 
    303 
    304 getopts scr opt
    305 case $opt in
    306 s)
    307 	# Check if correct arch is in path (in case default got wrong value)
    308 	arch=$(uname -p)
    309 	if [[ $arch == sparc ]]; then
    310 		arch2="i386"
    311 	else
    312 		arch2="sparc"
    313 	fi
    314 	# Make sure the wrong arch is not in string
    315 	res=$(echo $CC_SRV | grep $arch2)
    316 	if (( $? == 0 )); then
    317 		OLD_CC=$CC_SRV;
    318 		# try to fix by replacing with correct arch
    319 		CC_SRV=$(echo $CC_SRV | sed "s/$arch2/$arch/g")
    320 		sed "s@$OLD_CC@$CC_SRV@" $TMPDIR/$ENVFILE \
    321 			> $TMPDIR/env.fil
    322 		rm -f $TMPDIR/$ENVFILE
    323 		mv $TMPDIR/env.fil $TMPDIR/$ENVFILE
    324 	fi
    325 	# Check if the specified compiler is available
    326 	$CC_SRV -flags > $TMPDIR/cc-flags.out.$$ 2>&1
    327 	if (( $? != 0 )); then
    328 		echo "WARNING: the compiler <$CC_SRV> failed to run"
    329 		echo "\tsome tests may fail"
    330 		echo "\t<cc -flags> output was:"
    331 		cat $TMPDIR/cc-flags.out.$$
    332 	fi
    333 
    334 	cp -p /etc/passwd /etc/passwd.orig
    335 	cp -p /etc/group /etc/group.orig
    336 	# remove users left from setups not cleaned
    337 	/usr/xpg4/bin/egrep -v "2345678." /etc/passwd.orig > /etc/passwd 2>&1
    338 	/usr/xpg4/bin/egrep -v "2345678." /etc/group.orig > /etc/group 2>&1
    339 
    340 	# add test users ... should be same as in $TESTHOST
    341 	echo "$TUSER1:x:23456787:10:NFSv4 Test User 1:$TMPDIR:/bin/sh" \
    342 		>>/etc/passwd
    343 	echo "$TUSER2:x:23456788:10:NFSv4 Test User 2:$TMPDIR:/bin/sh" \
    344 		>>/etc/passwd
    345 	echo "$TUSER3:x:23456789:1:NFSv4 Test User 3:$TMPDIR:/bin/sh" \
    346 		>>/etc/passwd
    347 	#except this user
    348 	echo "$TUSERS:x:$TUSERSID:10:NFSv4 Test User Server:$TMPDIR:/bin/sh" \
    349 		>>/etc/passwd
    350 	echo "$TUSERS2:x:$TUSERID:10:NFSv4 Test User Server 2:$TMPDIR:/bin/sh" \
    351 		>>/etc/passwd
    352 	echo \
    353 		"$TUSERS3:x:$TUSERSID3:10:NFSv4 Test User Server 3:$TMPDIR:/bin/sh" \
    354 		>>/etc/passwd
    355 	echo "$UTF8_USR:x:$TUSERUTF8:$TUSERUTF8:uts8 USER 1:$TMPDIR:/sbin/sh"\
    356 		>>/etc/passwd
    357 	echo "$UTF8_USR::$TUSERUTF8:" >> /etc/group
    358 
    359 	pwconv	# make sure shadow file match
    360 	N=1
    361 	n=$(/usr/xpg4/bin/egrep "2345678." /etc/group | wc -l | \
    362 		nawk '{print $1}')
    363 	if (( n != N )); then
    364 		echo "$NAME: ERROR - adding test groups failed, \
    365 			groups file shows n=$n not $N"
    366 		cleanup 2
    367 	fi
    368 	n=$(/usr/xpg4/bin/egrep \
    369 	"^$TUSER1|^$TUSER2|^$TUSER3|^$TUSERS|^$TUSERS2|^$TUSERS3" \
    370 		/etc/shadow | wc -l | nawk '{print $1}')
    371 	N=6
    372 	if (( n != N )); then
    373 		echo "$NAME: ERROR - adding normal test users failed, \
    374 			shadow file shows n=$n not $N"
    375 		cleanup 2
    376 	fi
    377 	res=$(locale | awk -F= '{print $2}' | grep -v "^$" | grep -v "C")
    378 	if (( $? == 0 )); then
    379 		echo "WARNING: locale not set to C. Some utf8 tests may fail."
    380 		[[ $DEBUG != 0 ]] && echo "locale = $(locale)\n"
    381 	else
    382 		# this test is broken with some locales, so only execute
    383 		n=$(/usr/xpg4/bin/egrep "^$(echo $UTF8_USR)" /etc/shadow | \
    384 			wc -l | nawk '{print $1}')
    385 		N=1
    386 		if (( n != N )); then
    387 			echo "$NAME: ERROR - adding UTF8 test users failed, \
    388 				shadow file shows n=$n not $N"
    389 			[[ $DEBUG != 0 ]] && echo "locale = $(locale)\n"
    390 			cleanup 2
    391 		fi
    392 	fi
    393 
    394 	# check if the nfs tunable values meet the requirement, if not,
    395 	# set the new values and save the old values to .nfs.flg file
    396 	if [[ ! -f $CONFIGDIR/$SERVER.nfs.flg ]]; then
    397 		res=$($CONFIGDIR/set_nfstunable SERVER_VERSMIN=2 SERVER_VERSMAX=4)
    398 		if (( $? != 0 )); then
    399 			echo "ERROR: cannot set the specific nfs tunable on $SERVER"
    400 			cleanup 1
    401 		else
    402 			[[ -n $res ]] && echo $res > $CONFIGDIR/$SERVER.nfs.flg
    403 		fi
    404 	fi
    405 
    406 	# backup BASEDIR if it exists
    407 	rm -fr $BASEDIR.Saved > /dev/null 2>&1
    408 	[[ -d $BASEDIR ]] && mkdir -m 0777 $BASEDIR.Saved && \
    409 		mv $BASEDIR/* $BASEDIR.Saved > /dev/null 2>&1
    410 
    411 	# Create pre-defined test files/directories in $BASEDIR
    412 	if (( TestZFS == 1 )); then
    413 		# check first and create the pool only when it's not yet available
    414 		if [[ -z $ZFSDISK ]]; then
    415 			echo "$NAME: setup failed at $SERVER -"
    416 			echo "\tmust define a valid ZFSDISK=<$ZFSDISK> \c"
    417 			cleanup 2
    418 		fi
    419 
    420 		zpool status > $TMPDIR/zstatus.out.$$ 2>&1
    421 		grep "$ZFSDISK" $TMPDIR/zstatus.out.$$ |grep ONLINE >/dev/null 2>&1
    422 		if (( $? != 0 )); then
    423 			echo "$NAME: zpool<$ZFSDISK> is not online -"
    424 			cat $TMPDIR/zstatus.out.$$
    425 			cleanup 2
    426 		fi
    427 		ZFSPOOL=$ZFSDISK; export ZFSPOOL
    428 
    429 		echo "$NAME: Setting test filesystems with ZFS ..."
    430 		create_zfs_fs $BASEDIR > $TMPDIR/zfs.out.$$ 2>&1
    431 		if (( $? != 0 )); then
    432 			echo "$NAME: failed to create_zfs_fs $BASEDIR -"
    433 			cat $TMPDIR/zfs.out.$$
    434 			cleanup 2
    435 		fi
    436 		# set aclinherit as "passthrough", which causes sub-dirs
    437 		# and sub-files to inherit all inheritable ACL entries
    438 		# without any modifications;
    439 		# used for acl test
    440 		typeset -u ZName=$(basename $BASEDIR)
    441 		zfs set aclinherit=passthrough $ZFSPOOL/$ZName \
    442 			> $TMPDIR/setprop.out.$$ 2>&1
    443 		if (( $? != 0 )); then
    444 			echo "$NAME: WARNING - Failed to set zfs property aclinherit \c"
    445 			echo "to <passthrough> for $BASEDIR in $SERVER.  \c"
    446 			echo "Some acl tests may fail."
    447 			cat $TMPDIR/setprop.out.$$
    448 		fi
    449 		# verify the property is set to passthrough
    450 		aclprop=$(zfs get -H -o value aclinherit $ZFSPOOL/$ZName 2>&1)
    451 		if [[ $? != 0 || $aclprop != passthrough ]]; then
    452 			echo "$NAME: WARNING - Failed to get zfs property aclinherit. \c"
    453 			echo "Expected value is <passthrough>, while returned <$aclprop>"
    454 			echo "Some acl tests may fail."
    455 		fi
    456 	fi
    457 
    458 	# create test files/directories in the BASEDIR
    459 	$CONFIGDIR/mk_srvdir $BASEDIR > $TMPDIR/mkbd.out.$$ 2>&1
    460 	if (( $? != 0 )); then
    461 		echo "$NAME: ERROR - failed to create test files/dirs in $BASEDIR"
    462 		cat $TMPDIR/mkbd.out.$$
    463 		cleanup 99
    464 	fi
    465 
    466 	# share $BASEDIR with "-p" option for NFS testing;
    467 	# such that when it's enabled by smf it's persistent, even with reboot
    468 	share -F nfs -p -o rw $BASEDIR
    469 	share | grep "$BASEDIR" > /dev/null 2>&1
    470 	if (( $? != 0 )); then
    471 		echo "$NAME: ERROR - failed to share <$BASEDIR>, aborting ..."
    472 		share
    473 		cleanup 99
    474 	fi
    475 
    476 	if (( TestZFS != 1 )); then
    477 		# Create other FSs (with LOFI) for testing of different areas.
    478 		SRVTESTDIR=$BASEDIR/LOFI_FILES; export SRVTESTDIR
    479 		mkdir -m 0777 -p $SRVTESTDIR
    480 	fi
    481 
    482 	# ROFS test dir
    483 	create_test_fs ROFSDIR $ROFSDIR 5m
    484 	create_some_files $ROFSDIR
    485 	$CONFIGDIR/operate_dir "share" $ROFSDIR "ro"
    486 
    487 	# Create an FS to be exported with root access
    488 	create_test_fs ROOTDIR $ROOTDIR
    489 	create_some_files $ROOTDIR
    490 	$CONFIGDIR/operate_dir "share" $ROOTDIR "anon=0"
    491 
    492 	# PUBLIC test dir
    493 	create_test_fs PUBTDIR $PUBTDIR
    494 	$CONFIGDIR/mk_srvdir $PUBTDIR > $TMPDIR/cfpubt.out.$$ 2>&1
    495 	if (( $? != 0 )); then
    496 		echo "WARNING, unable to create files/dirs in [$PUBTDIR];"
    497 		cat $TMPDIR/cfpubt.out.$$
    498 		echo "\t testing in the area may fail."
    499 	fi
    500 	$CONFIGDIR/operate_dir "share" $PUBTDIR "rw,public"
    501 
    502 	# NSPCDIR test dir
    503 	create_test_fs NSPCDIR $NSPCDIR
    504 	# Create few test files/dirs first
    505 	create_some_files $NSPCDIR
    506 	# Also fill up the FS here
    507 	$CONFIGDIR/fillDisk $NSPCDIR
    508 	$CONFIGDIR/operate_dir "share" $NSPCDIR
    509 
    510 	# KRB5 test dir
    511 	create_test_fs KRB5DIR $KRB5DIR
    512 	$CONFIGDIR/mk_srvdir $KRB5DIR > $TMPDIR/cfkrb5.out.$$ 2>&1
    513 	if (( $? != 0 )); then
    514 		echo "WARNING, unable to create files/dirs in [$KRB5DIR];"
    515 		cat $TMPDIR/cfkrb5.out.$$
    516 		echo "\t testing in the area may fail."
    517 	fi
    518 	# XXX test system needs to be able to kinit in order to share w/krb5
    519 	#$CONFIGDIR/operate_dir "share" $KRB5DIR "sec=krb5:krb5i:krb5p"
    520 
    521 	# SSPC test dir
    522 	create_test_fs SSPCDIR $SSPCDIR
    523 	$CONFIGDIR/mk_srvdir $SSPCDIR > $TMPDIR/cfsspc.out.$$ 2>&1
    524 	if (( $? != 0 )); then
    525 		echo "WARNING, unable to create files/dirs in [$SSPCDIR];"
    526 		cat $TMPDIR/cfsspc.out.$$
    527 		echo "\t testing in the area may fail."
    528 	fi
    529 	$CONFIGDIR/operate_dir "share" $SSPCDIR
    530 
    531 	# QUOTA test dir
    532 	create_test_fs QUOTADIR $QUOTADIR 5m
    533 	$CONFIGDIR/mk_srvdir $QUOTADIR > $TMPDIR/cfpubt.out.$$ 2>&1
    534 	if (( $? != 0 )); then
    535 		echo "WARNING, unable to create files/dirs in [$QUOTADIR];"
    536 		cat $TMPDIR/cfpubt.out.$$
    537 		echo "\t testing in the area may fail."
    538 	fi
    539 	touch $QUOTADIR/quotas
    540 	if (( TestZFS != 1 )); then
    541 		# also set quota for $TUSER2 and fill the quotas:
    542 		quotaoff $QUOTADIR
    543 		edquota $TUSER2 << __END > /dev/null 2>&1
    544 :s/hard = 0/hard = 5/g
    545 :wq
    546 __END
    547 		quotaon $QUOTADIR
    548 		smf_fmri_transition_state do $QUOTA_FMRI online $SMF_TIMEOUT
    549 		if [[ $? != 0 ]]; then
    550 			echo "$NAME: ERROR - unable to start $QUOTA_FMRI"
    551 			echo "\t testing in the area may fail."
    552 		fi
    553 	fi
    554 	if (( iscipso == 1 )); then
    555 		ZONEDIR=${QUOTADIR#$ZONE_PATH/root}
    556 		zlogin $localzone "su $TUSER2 -c \
    557 			\"cd $ZONEDIR; \
    558 			touch file_$TUSER2.1 file_$TUSER2.2 file_$TUSER2.3; \
    559 			mkfile 4k file_$TUSER2.4\""
    560 	else
    561 		su $TUSER2 -c \
    562 			"cd $QUOTADIR; \
    563 			touch file_$TUSER2.1 file_$TUSER2.2 file_$TUSER2.3; \
    564 			mkfile 4k file_$TUSER2.4"
    565 	fi
    566 	if (( TestZFS == 1 )); then
    567 		$CONFIGDIR/fillDisk $QUOTADIR
    568 	fi
    569 	$CONFIGDIR/operate_dir "share" $QUOTADIR
    570 
    571 	# SSPCDIR2 test dir
    572 	create_test_fs SSPCDIR2 $SSPCDIR2 3m
    573 	$CONFIGDIR/operate_dir "share" $SSPCDIR2
    574 
    575 	# SSPCDIR3 test dir with noxattr
    576 	create_test_fs SSPCDIR3 $SSPCDIR3 6m noxattr
    577 	$CONFIGDIR/operate_dir "share" $SSPCDIR3
    578 
    579 	# NOTSHDIR - test requirement not to share this UFS
    580 	create_test_fs NOTSHDIR $NOTSHDIR
    581 	create_some_files $NOTSHDIR
    582 
    583 	# and some symlinks for mounting symlink testing
    584 	ln -s $BASEDIR/$LONGDIR $BASEDIR/symldir2
    585 	ln -s $BASEDIR/nosuchdir $BASEDIR/syml_nodir
    586 	ln -s $NOTSHDIR/$RWFILE $BASEDIR/syml_nofile
    587 	ln -s $SSPCDIR2 $BASEDIR/syml_sh_fs
    588 	if (( iscipso == 1 )); then
    589 		ln -s $ZONE_PATH/root/usr/lib $BASEDIR/syml_outns
    590 	else
    591 		ln -s /usr/lib $BASEDIR/syml_outns
    592 	fi
    593 	ln -s $NOTSHDIR $BASEDIR/syml_nosh_fs
    594 	ln -s $NOTSHDIR $NOTSHDIR/syml_shnfs
    595 
    596 	cd $BASEDIR
    597 	ln -s ./$DIR0755 syml_dotd
    598 	ln -s ./$DIR0755/../$RWFILE syml_dotf
    599 	Last=$(basename $SSPCDIR3)
    600 	ln -s $SSPCDIR3/../$Last syml_dotdot
    601 
    602 	# check for correct register on protocols and version 4
    603 	# give some time to nfsd to register protocols
    604 	sleep 1
    605 	rpcinfo -p | grep nfs | awk '{print $2}' | grep 4 \
    606 		> $TMPDIR/rpcinfoT.out.$$ 2>&1
    607 	if (( $? != 0 )); then
    608 		echo "$NAME: ERROR - nfs did not register on $SERVER with v4"
    609 		cat $TMPDIR/rpcinfoT.out.$$
    610 		cleanup 1
    611 	fi
    612 
    613 	# also return the server's grace period
    614 	grace=$($CONFIGDIR/get_tunable rfs4_grace_period K 2> $TMPDIR/dmerr.out.$$)
    615 	if (( $? != 0 )); then
    616 		echo "$NAME: ERROR - cannot get grace_period in $SERVER"
    617 		echo "Output was:\n$grace\n"
    618 		echo "Stderr was:"
    619 		cat $TMPDIR/dmerr.out.$$
    620 		cleanup 2
    621 	else
    622 		echo "SERVER_GRACE_PERIOD=$grace"
    623 		[[ $DEBUG != 0 ]] && cat $TMPDIR/dmerr.out.$$
    624 	fi
    625 	# and server's NFS mapid domain
    626 	Sdomain=$(cat /var/run/nfs4_domain 2> $TMPDIR/dmerr.out.$$)
    627 	if (( $? != 0 )); then
    628 		echo "$NAME: ERROR - failed to get NFS mapid domain in $SERVER"
    629 		echo "Output was:\nSdomain=<$Sdomain>\n"
    630 		echo "Stderr was:"
    631 		cat $TMPDIR/dmerr.out.$$
    632 		cleanup 2
    633 	else
    634 		echo "SERVER_NFSmapid_Domain=$Sdomain"
    635 	fi
    636 
    637 	echo "Done - setup daemons and shared $BASEDIR OKAY."
    638 	rm -f $CONFIGDIR/._DONE_cleanup_LOFI_for_recovery
    639 	;;
    640 
    641 r)
    642 	SHARE_LIST="$SSPCDIR3 $SSPCDIR2 $SSPCDIR $PUBTDIR $QUOTADIR"
    643 	SHARE_LIST="$SHARE_LIST $NSPCDIR $ROFSDIR $ROOTDIR $KRB5DIR"
    644 	for fs in $SHARE_LIST $NOTSHDIR; do
    645 		# unshare FS if is shared, before clean it up
    646 		share | awk '{print $2}' | grep -w "$fs" > /dev/null 2>&1
    647 		if (( $? == 0 )); then
    648 		    $CONFIGDIR/operate_dir "unshare" $fs > \
    649 		        $TMPDIR/unshare.out.$$ 2>&1
    650 		    if (( $? != 0 )); then
    651 		        echo "$NAME: WARNING - failed to unshare [$fs]"
    652 		        cat $TMPDIR/unshare.out.$$
    653 		        echo "\trecovery tests may have problems after \c"
    654 		        echo "rebooting the server"
    655 		    fi
    656 		fi
    657 		if (( TestZFS == 1 )); then
    658 		    Zfs=$(df -h $fs | grep -v 'Mounted on' | nawk '{print $1}')
    659 		    zfs destroy -f -r $Zfs > $TMPDIR/zfsDes.out.$$ 2>&1
    660 		    if (( $? != 0 )); then
    661 		        echo "WARNING, unable to cleanup [$fs];"
    662 		        cat $TMPDIR/zfsDes.out.$$
    663 		        echo "\trecovery tests may have problems \c"
    664 		        echo "after rebooting the server"
    665 		    else
    666 		        rm -fr $fs > /dev/null 2>&1
    667 		    fi
    668 		else
    669 		    $CONFIGDIR/setupFS -c $fs > $TMPDIR/cleanFS.out.$$ 2>&1
    670 		    if (( $? != 0 )); then
    671 		        echo "WARNING, unable to cleanup [$fs];"
    672 		        cat $TMPDIR/cleanFS.out.$$
    673 		        echo "\trecovery tests may have problems \c"
    674 		        echo "after rebooting the server"
    675 		    fi
    676 		fi
    677 	done
    678 	echo "Done - cleanup LOFI/ZFS FS's OKAY."
    679 	touch $CONFIGDIR/._DONE_cleanup_LOFI_for_recovery
    680 	;;
    681 
    682 c)
    683 	# restore nfs tunable values
    684 	if [[ -f $CONFIGDIR/$SERVER.nfs.flg ]]; then
    685 		res=$(cat $CONFIGDIR/$SERVER.nfs.flg)
    686 		[[ -n $res ]] && $CONFIGDIR/set_nfstunable $res \
    687 			> $TMPDIR/nfs.out.$$ 2>&1
    688 		if (( $? != 0 )); then
    689 			echo "WARNING: restoring nfs tunable failed on $SERVER:"
    690 			cat $TMPDIR/nfs.out.$$
    691 			echo "Please restore the following nfs tunable manually: $res"
    692 		fi
    693 		rm -f $CONFIGDIR/$SERVER.nfs.flg > /dev/null 2>&1
    694 	fi
    695 
    696 	res=$(mv /etc/passwd.orig /etc/passwd 2>&1)
    697 	res=$(mv /etc/group.orig /etc/group 2>&1)
    698 	res=$(chmod 444 /etc/passwd /etc/group 2>&1)
    699 	res=$(pwconv 2>&1)
    700 	res=$(/usr/xpg4/bin/egrep "2345678." /etc/passwd > $TMPDIR/pwerr.out.$$)
    701 	n=$(cat $TMPDIR/pwerr.out.$$ | wc -l | nawk '{print $1}')
    702 	if (( n != 0 )); then
    703 		echo "WARNING: removing test users failed, \
    704 			remove the following users manually:"
    705 		cat $TMPDIR/pwerr.out.$$
    706 		echo "\n"
    707 	fi
    708 	res=$(/usr/xpg4/bin/egrep "2345678." /etc/group > $TMPDIR/grperr.out.$$)
    709 	n=$(cat $TMPDIR/grperr.out.$$ | wc -l | nawk '{print $1}')
    710 	if (( n != 0 )); then
    711 		echo "WARNING: removing test groups failed, \
    712 			remove the following groups manually:"
    713 		cat $TMPDIR/grperr.out.$$
    714 		echo "\n"
    715 	fi
    716 
    717 	if [[ ! -f $CONFIGDIR/._DONE_cleanup_LOFI_for_recovery ]]; then
    718 		SHARE_LIST="$SSPCDIR3 $SSPCDIR2 $SSPCDIR $PUBTDIR $QUOTADIR"
    719 		SHARE_LIST="$SHARE_LIST $NSPCDIR $ROFSDIR $ROOTDIR $KRB5DIR"
    720 		for fs in $SHARE_LIST; do
    721 			# need to check if KRB5DIR is shared
    722 			[[ $fs == $KRB5DIR ]] && break
    723 			$CONFIGDIR/operate_dir "unshare" $fs \
    724 				> $TMPDIR/unshare.out.$$ 2>&1
    725 			if (( $? != 0 )); then
    726 				echo "$NAME: ERROR - failed to unshare [$fs]"
    727 				cat $TMPDIR/unshare.out.$$
    728 			fi
    729 		done
    730 		if (( TestZFS == 1 )); then
    731 			for dir in $SHARE_LIST $NOTSHDIR; do
    732 				ZFSn=$(zfs list | grep "$dir" | \
    733 					nawk '{print $1}')
    734 				if [[ -n $ZFSn ]]; then
    735 				    zfs destroy -f -r $ZFSn \
    736 					> $TMPDIR/zfsDes.out.$$ 2>&1
    737 				    if (( $? != 0 )); then
    738 					echo "WARNING, unable to cleanup [$dir]"
    739 					cat $TMPDIR/zfsDes.out.$$
    740 					echo "\t Please clean it up manually."
    741 				    else
    742 					rm -fr $dir
    743 				    fi
    744 				fi
    745 			done
    746 		else
    747 			for dir in $SHARE_LIST $NOTSHDIR; do
    748 				$CONFIGDIR/setupFS -c $dir \
    749 					> $TMPDIR/cleanFS.out.$$ 2>&1
    750 				if (( $? != 0 )); then
    751 					echo "WARNING, unable to cleanup [$dir]"
    752 					cat $TMPDIR/cleanFS.out.$$
    753 					echo "\t Please clean it up manually."
    754 				fi
    755 			done
    756 		fi
    757 	fi
    758 
    759 	unshare -p $BASEDIR > $TMPDIR/unshareb.out.$$ 2>&1
    760 	if [[ $? != 0 ]]; then
    761 		echo "$NAME: ERROR - failed to unshare $BASEDIR"
    762 		cat $TMPDIR/unshareb.out.$$
    763 	fi
    764 	smf_fmri_transition_state do $QUOTA_FMRI disabled $SMF_TIMEOUT
    765 	if [[ $? != 0 ]]; then
    766 		echo "$NAME: ERROR - unable to disable $QUOTA_FMRI"
    767 		echo "\t testing in the area may fail."
    768 	fi
    769 
    770 	if (( TestZFS == 1 )); then
    771 		destroy_zpool
    772 	fi
    773 	rm -rf $BASEDIR
    774 
    775 	echo "Done - cleanup test filesystems/daemons OKAY"
    776 	rm -rf $CONFIGDIR/* $TMPDIR
    777 	exit 0
    778 	;;
    779 
    780 \?)
    781 	echo $Usage
    782 	exit 2
    783 	;;
    784 esac
    785 
    786 cleanup 0
    787