Home | History | Annotate | Download | only in zfs
      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 2007 Sun Microsystems, Inc.  All rights reserved.
     25 # Use is subject to license terms.
     26 #
     27 # ident	"@(#)iscsi_tsetup.ksh	1.2	07/07/31 SMI"
     28 #
     29 
     30 #
     31 # The script is to create pool with vdevs specified, then make two volumes
     32 # as iSCSI targets
     33 # $1 specified vdevs, if $1 is "detect", then all available disks are used
     34 # Return 0 if the script succeeds, otherwise return 1
     35 #
     36 
     37 # Prepare the environment first, such as getting the value of
     38 # $STF_TOOLS and $STF_SUITE
     39 
     40 typeset STF_TOOLS_PKG="SUNWstc-stf"
     41 typeset STF_SUITE_PKG="SUNWstc-zfs"
     42 typeset STF_TOOLS_DIR
     43 typeset STF_SUITE_DIR
     44 
     45 typeset CUR_PROG=$(whence $0)
     46 typeset CUR_DIR=$(dirname $CUR_PROG)
     47 
     48 . ${CUR_DIR}/libremote.kshlib
     49 
     50 if pkg_isinstalled $STF_TOOLS_PKG ; then
     51 	STF_TOOLS_DIR=$(pkg_getinstbase $STF_TOOLS_PKG)
     52 	export STF_TOOLS=$STF_TOOLS_DIR
     53 fi
     54 
     55 if pkg_isinstalled $STF_SUITE_PKG ; then
     56 	STF_SUITE_DIR=$(pkg_getinstbase $STF_SUITE_PKG)
     57 	export STF_SUITE=$STF_SUITE_DIR
     58 fi
     59 
     60 if [[ -z $STF_TOOLS ]] ; then
     61 	print -u2 "Package $STF_TOOLS_PKG is not installed."
     62 	exit 1
     63 fi
     64 
     65 if [[ -z $STF_SUITE ]]; then
     66 	print -u2 "Package $STF_SUITE_PKG is not installed."
     67 	exit 1
     68 fi
     69 
     70 . ${STF_SUITE}/default.cfg
     71 . ${STF_SUITE}/include/libtest.kshlib
     72 . ${STF_SUITE}/tests/functional/remote/remote_common.kshlib
     73 # Environment preparation ends here
     74 
     75 typeset ISCSIT_FMRI="svc:/system/iscsitgt:default"
     76 typeset TPOOL="tpool$$"
     77 typeset TVOL1="vol1"
     78 typeset TVOL2="vol2"
     79 typeset -i SIZE12G=$(( 1024 * 1024 * 1024 * 12 ))
     80 typeset -i TVOLSIZE=$(( 1024 * 1024 * 1024 * 5 )) # default is 5G
     81 
     82 # get available disks used for iscsi targets on remote machine first
     83 if [[ $1 == "detect" ]]; then
     84 	TDISKS=$(find_disks)
     85 else
     86 	TDISKS=$(find_disks $1)
     87 fi
     88 
     89 for disk in ${TDISKS}; do
     90         $ZPOOL create -f foo_pool$$ $disk > /dev/null 2>&1
     91         # if disk is found not usable to create a pool, exclude it from $TDISKS
     92         if (( $? == 0 )); then
     93                 $ECHO $TDISKS | $GREP $disk > /dev/null 2>&1
     94                 if (( $? == 0 )) ; then
     95 			gooddisks="$disk $gooddisks"
     96 		fi
     97                 $ZPOOL destroy -f foo_pool$$
     98         fi
     99 done
    100 
    101 if (( ${#gooddisks} == 0 )) ; then
    102 	log_fail "No good disks for test."
    103 fi
    104 TDISKS="$gooddisks"
    105 
    106 # check svc:/system/iscsitgt:default state, try to enable it if the state
    107 # is not ON
    108 if [[ "ON" != $($SVCS -H -o sta $ISCSIT_FMRI) ]]; then
    109 	log_must $SVCADM enable $ISCSIT_FMRI
    110 
    111 	typeset -i retry=20
    112 	while [[ "ON" != $($SVCS -H -o sta $ISCSIT_FMRI) && ( $retry -ne 0 ) ]]
    113 	do
    114 		(( retry = retry - 1 ))
    115 		$SLEEP 1
    116 	done
    117 
    118 	if [[ "ON" != $($SVCS -H -o sta $ISCSIT_FMRI) ]]; then
    119 		log_fail "$ISCSIT_FMRI service can not be enabled!"
    120 	fi
    121 
    122 fi
    123 
    124 log_must $ZPOOL create -f $TPOOL $TDISKS
    125 TPOOL_SIZE=$(get_prop avail $TPOOL)
    126 
    127 if [[ $TPOOL_SIZE -lt $SIZE12G ]]; then
    128 	(( TPOOL_SIZE = TPOOL_SIZE - TPOOL_SIZE / 5 ))
    129 	(( TVOLSIZE = TPOOL_SIZE / 2 ))
    130 fi
    131 
    132 log_must $ZFS set shareiscsi=on $TPOOL
    133 log_must $ZFS create -V $TVOLSIZE $TPOOL/$TVOL1
    134 log_must $ZFS create -V $TVOLSIZE $TPOOL/$TVOL2
    135 
    136 # Verify targets is created
    137 log_must is_iscsi_target $TPOOL/$TVOL1
    138 log_must is_iscsi_target $TPOOL/$TVOL2
    139 
    140 log_pass "Targets setup is complete."
    141