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