3 # Copyright (C) Voltaire Ltd. 2006. ALL RIGHTS RESERVED.
5 # This program is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 # You should have received a copy of the GNU General Public License along with
16 # this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 # Place, Suite 330, Boston, MA 02111-1307 USA
19 # Author: Dan Bar Dov <danb@voltaire.com>
22 # * does a send-targets discovery to the given IP
23 # * set the transport type to the preferred transport (or tcp is -t flag is not used)
27 # o mark record autmatic (unless -m flag is used)
29 # o reset transport type to TCP
33 # + mark record automatic (unless -m flag is used)
38 echo "Usage: $0 <IP> [-p <port>] [-d] [-t <tcp|iser> [-f]] [-m] [-l]"
40 echo "-p set the port number (defualt is 3260)."
41 echo "-d print debugging information"
42 echo "-t set trasnpot (default is tcp)."
43 echo "-f force specific transport -disable the fallback to tcp (default is fallback enabled)."
44 echo " force the transport specified by the argument of the -t flag."
45 echo "-m manual startup - will set manual startup (default is automatic startup)."
46 echo "-l login to the new discovered nodes (defualt is false)."
61 #set defualt transport to tcp
63 #set defualt port to 3260
74 # check if the IP address is valid
75 ip=`echo $1 | awk -F'.' '$1 != "" && $1 <=255 && $2 != "" && $2 <= 255 && $3 != "" && $3 <= 255 && $4 != "" && $4 <= 255 {print $0}'`
77 echo "$1 is not a vaild IP address!"
81 while getopts "dfmlt:p:" options; do
85 t ) transport=$OPTARG;;
87 m ) startup_manual="1";;
99 # If open-iscsi is already logged in to the portal, exit
100 if [ $(iscsiadm -m session | grep -c ${ip}:${port}) -ne 0 ]; then
101 echo "Please logout from all targets on ${ip}:${port} before trying to run discovery on that portal"
107 df=/tmp/discovered.$$
109 dbg "starting discovery to $ip"
110 iscsiadm -m discovery --type sendtargets --portal ${ip}:${port} > ${df}
111 while read portal target
117 discovered=$(cat ${df} | wc -l)
118 if [ ${discovered} = 0 ]; then
119 echo "failed to discover targets at ${ip}"
122 echo "discovered ${discovered} targets at ${ip}"
129 if [ "$startup_manual" != "1" ]; then
130 iscsiadm -m node --targetname ${target} --portal ${portal} --op update -n node.conn[0].startup -v automatic
132 iscsiadm -m node --targetname ${target} --portal ${portal} --login >/dev/null 2>&1
134 if [ ${ret} = 0 ]; then
135 echo "Set target ${target} to automatic login over ${transport} to portal ${portal}"
136 connected=$(($connected + 1))
137 if [ "$log_out" = "1" ]; then
138 iscsiadm -m node --targetname ${target} --portal ${portal} --logout
141 echo "Cannot login over ${transport} to portal ${portal}"
142 iscsiadm -m node --targetname ${target} --portal ${portal} --op update -n node.conn[0].startup -v manual
150 if [ "$transport" == "iser" ];then
151 iscsiadm -m node --targetname ${target} --portal ${portal} \
152 --op update -n node.conn[0].iscsi.HeaderDigest -v None
153 iscsiadm -m node --targetname ${target} --portal ${portal} \
154 --op update -n node.conn[0].iscsi.DataDigest -v None
156 transport_name=`iscsiadm -m node -p ${portal} -T ${target} |awk '/transport_name/ {print $1}'`
157 iscsiadm -m node --targetname ${target} --portal ${portal} \
158 --op update -n ${transport_name} -v ${transport}
163 set_transport $transport
164 dbg "Testing $transport-login to target ${target} portal ${portal}"
166 if [ $? != 0 -a "$force" = "0" ]; then
168 dbg "starting to test tcp-login to target ${target} portal ${portal}"
175 #check if iscsid is running
176 pidof iscsid &>/dev/null
178 if [ $ret -ne 0 ]; then
179 echo "iscsid is not running"