summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--doc/iscsi_discovery.839
-rw-r--r--utils/iscsi_discovery123
3 files changed, 163 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 1f31443..00f8af1 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ etcdir = /etc
initddir = $(etcdir)/init.d
MANPAGES = doc/iscsid.8 doc/iscsiadm.8
-PROGRAMS = usr/iscsid usr/iscsiadm
+PROGRAMS = usr/iscsid usr/iscsiadm utils/iscsi_discovery
INSTALL = install
ETCFILES = etc/iscsid.conf
diff --git a/doc/iscsi_discovery.8 b/doc/iscsi_discovery.8
new file mode 100644
index 0000000..e772130
--- /dev/null
+++ b/doc/iscsi_discovery.8
@@ -0,0 +1,39 @@
+.de Vb \" Begin verbatim text
+.ft CW
+.nf
+.ne \\$1
+..
+
+.TH "iscsi_discovery" 8
+.SH NAME
+iscsi_discovery \- discover iscsi devices
+.SH SYNOPSIS
+.B iscsi_discovery <IP> [port]
+
+.SH DESCRIPTION
+Perform send-targets discovery to the specified IP. If a discovery record
+is generated, try to login to the portal using iSER and TCP transports.
+If login using a certain transport succeeds, mark the portal for automatic
+login, and disconnect.
+
+For iscsi discovery to work, open-iscsi services must be running. e.g. iscsid
+should be up, and the iscsi modules loaded. This is best accomplished by the
+init.d startup script.
+
+.\" .SH OPTIONS
+.\" .TP
+.\" .B \-<a command line switch>
+.\" <description of what that switch does>
+.\" .TP
+.\" .B \-<a command line switch>
+.\" <description of what that switch does>
+.\" .TP
+.\" .B <etc . . .>
+.\" .SH "SEE ALSO"
+.\" <a list of related man pages>
+.SH AUTHOR
+Written by Dan Bar Dov
+.SH "REPORTING BUGS"
+Report bugs to <danb@voltaire.com>.
+.SH COPYRIGHT
+Copyright \(co Voltaire Ltd. 2006.
diff --git a/utils/iscsi_discovery b/utils/iscsi_discovery
new file mode 100644
index 0000000..d21f1df
--- /dev/null
+++ b/utils/iscsi_discovery
@@ -0,0 +1,123 @@
+#!/bin/bash
+#
+# Copyright (C) Voltaire Ltd. 2006. ALL RIGHTS RESERVED.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Author: Dan Bar Dov <danb@voltaire.com>
+
+# iscsi_discovery:
+# * does a send-targets discovery to the given IP
+# * set the transport type to ISER
+# * tries to login
+# * if succeeds,
+# o logout,
+# o mark record autmatic
+# * else
+# o reset transport type to TCP
+# o try to login
+# o if succeeded
+# + logout
+# + mark record automatic
+#
+
+dbg()
+{
+ $debug || echo $@
+}
+
+initialize()
+{
+ trap "exit" 2
+ usage="Usage: $0 [-d] <IP> [<port>]"
+ debug=false
+}
+
+parse_cmdline()
+{
+ if [ "$1" = "-d" ]; then
+ debug=true
+ shift
+ fi
+ if [ $# -lt 1 ]; then
+ echo ${usage}
+ exit 1
+ fi
+
+ ip=$1
+ port=${2:-3260}
+}
+
+
+discover()
+{
+ dbg "starting to discover $ip"
+ discovered=$(iscsiadm -m discovery --type sendtargets --portal ${ip}:${port})
+ if [ -z "${discovered}" ]; then
+ echo "failed discovery to ${ip}"
+ exit 2
+ fi
+ set ${discovered}
+ record=${1#*[}
+ record=${record%%]*}
+ portal=$2
+ target=$3
+}
+
+set_auto_if_login()
+{
+ record=$1
+ iscsiadm -m node --record ${record} --login
+ ret=$?
+ if [ ${ret} = 0 ]; then
+ iscsiadm -m node --record ${record} --logout
+ iscsiadm -m node --record ${record} --op update -n node.conn[0].startup -v automatic
+ echo "Set record ${record} to automatic login over ${transport} to ${target} portal ${portal}"
+ fi
+ return ${ret}
+}
+
+set_transport_iser()
+{
+ record=$1
+ transport=iser
+ iscsiadm -m node --record ${record} --op update -n node.conn[0].iscsi.HeaderDigest -v None
+ iscsiadm -m node --record ${record} --op update -n node.transport_name -v ${transport}
+}
+
+set_transport_tcp()
+{
+ record=$1
+ transport=tcp
+ iscsiadm -m node --record ${record} --op update -n node.conn[0].iscsi.HeaderDigest -v None
+ iscsiadm -m node --record ${record} --op update -n node.transport_name -v ${transport}
+}
+
+select_transport()
+{
+ set_transport_iser ${record}
+ dbg "starting to test iser-login to $ip"
+ set_auto_if_login ${record}
+ if [ $? != 0 ]; then
+ set_transport_tcp ${record}
+ dbg "starting to test tcp-login to $ip"
+ set_auto_if_login ${record}
+ fi
+}
+
+initialize
+parse_cmdline "$@"
+discover
+select_transport