These are some updates to the SUSE init scripts, plus a new boot.open-iscsi script for SUSE. The latter is used for root on iscsi, to start iscsid as early as possible to avoid deadlocks on the root fs.
Signed-off-by: Hannes Reinecke <[EMAIL PROTECTED]> --- Makefile | 2 + etc/initd/boot.suse | 82 +++++++++++++++++++++++++++++++++++++++++++++ etc/initd/initd.suse | 91 ++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 168 insertions(+), 7 deletions(-) create mode 100644 etc/initd/boot.suse diff --git a/Makefile b/Makefile index 046c0f9..e405c9c 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,8 @@ install_initd_suse: $(INSTALL) -d $(DESTDIR)$(initddir) $(INSTALL) -m 755 etc/initd/initd.suse \ $(DESTDIR)$(initddir)/open-iscsi + $(INSTALL) -m 755 etc/initd/boot.suse \ + $(DESTDIR)$(initddir)/boot.open-iscsi install_initd_redhat: $(INSTALL) -d $(DESTDIR)$(initddir) diff --git a/etc/initd/boot.suse b/etc/initd/boot.suse new file mode 100644 index 0000000..df64e21 --- /dev/null +++ b/etc/initd/boot.suse @@ -0,0 +1,82 @@ +#!/bin/bash +# +# /etc/init.d/iscsi +# +### BEGIN INIT INFO +# Provides: iscsiboot +# Required-Start: boot.proc +# Should-Start: +# Required-Stop: +# Should-Stop: +# Default-Start: B +# Default-Stop: +# Short-Description: Starts the iSCSI initiator daemon +# +### END INIT INFO + +ISCSIADM=/sbin/iscsiadm +PID_FILE=/var/run/iscsi.pid +CONFIG_FILE=/etc/iscsid.conf +DAEMON=/sbin/iscsid +ARGS="-c $CONFIG_FILE -p $PID_FILE" + +# Source LSB init functions +. /etc/rc.status + +# +# This service is run right after booting. So all activated targets +# must be enabled during mkinitrd run and thus should not be removed +# when the open-iscsi service is stopped. +# +iscsi_mark_root_nodes() +{ + $ISCSIADM -m session 2> /dev/null | while read t num i target ; do + ip=${i%%:*} + STARTUP=`$ISCSIADM -m node -p $ip -T $target | grep "node.conn\[0\].startup" | cut -d' ' -f3` + if [ "$STARTUP" != "onboot" ] ; then + $ISCSIADM -m node -p $ip -T $target -o update -n node.conn[0].startup -v onboot + fi + done +} + +# Reset status of this service +rc_reset + +# We only need to start this for root on iSCSI +if ! grep -q iscsi_tcp /proc/modules ; then + rc_failed 6 + rc_exit +fi + +case "$1" in + start) + [ ! -d /var/lib/open-iscsi ] && mkdir -p /var/lib/open-iscsi + echo -n "Starting iSCSI initiator for the root device: " + startproc $DAEMON $ARGS + rc_status -v + iscsi_mark_root_nodes + ;; + stop) + rc_failed 0 + ;; + status) + echo -n "Checking for iSCSI initiator service: " + if checkproc $DAEMON ; then + rc_status -v + else + rc_failed 3 + rc_status -v + fi + ;; + restart) + $0 stop + sleep 1 + $0 start + ;; + *) + echo "Usage: $0 {start|stop|status|restart}" + exit 1 + ;; +esac +rc_exit + diff --git a/etc/initd/initd.suse b/etc/initd/initd.suse index 80611a6..d8b91cc 100644 --- a/etc/initd/initd.suse +++ b/etc/initd/initd.suse @@ -29,25 +29,65 @@ rc_reset iscsi_login_all_nodes() { echo -n "Setting up iSCSI targets: " - $ISCSIADM -m node --loginall=automatic + $ISCSIADM -m node --loginall=automatic 2> /dev/null + if [ $? == 19 ] ; then + rc_failed 6 + fi rc_status -v } iscsi_logout_all_nodes() { - # Logout from all active sessions - if $ISCSIADM -m node --logoutall=all ; then - rc_status -v - else - RETVAL=$? + echo -n "Closing all iSCSI connections: " + # Logout from all sessions marked automatic + if ! $ISCSIADM -m node --logoutall=automatic 2> /dev/null; then + if [ $? == 19 ] ; then + RETVAL=6 + else + RETVAL=1 + fi rc_failed $RETVAL fi + rc_status -v # Not sure whether this is still needed sleep 1 return ${RETVAL:-0} } +iscsi_umount_all_luns() +{ + local d m dev p s + + cat /proc/mounts | sed -ne '/^\/dev\/.*/p' | while read d m t o x; do + if [ "$m" = "/" ] ; then + continue; + fi + if [ -L "$d" ] ; then + d=$(readlink -f $d) + fi + dev=${d##/dev} + + if [ "${dev##/sd}" = "$dev" ] ; then + continue; + fi + p="/sys/block${dev%%[0-9]*}" + + if [ ! -d ${p} ] && [ ! -d ${p}/device ] ; then + continue; + fi + + s=$(cd -P ${p}/device && echo $PWD) + + case "$s" in + */session[0-9]*/*) + # This is an iSCSI device + umount "$m" + ;; + esac + done +} + iscsi_list_all_nodes() { # Check for active sessions @@ -61,6 +101,38 @@ iscsi_list_all_nodes() done } +iscsi_discover_all_targets() +{ + # Strip off any existing ID information + RAW_NODE_LIST=`iscsiadm -m node | sed -nre 's/^(\[[0-9a-f]*\] )?(.*)$/\2/p'` + # Obtain IPv4 list + IPV4_NODE_LIST=`echo "$RAW_NODE_LIST" | sed -nre 's/^([0-9]{1,3}(\.[0-9]{1,3}){3}):[^: ]* (.*)$/\1 \3/p'` + # Now obtain IPv6 list + IPV6_NODE_LIST=`echo "$RAW_NODE_LIST" | sed -nre 's/^([0-9a-f]{1,4}(:[0-9a-f]{0,4}){6}:[0-9a-f]{1,4}):[^: ]* (.*)$/\1 \3/p'` + + DISC_TARGETS="" + while read NODE_ADDR NODE_NAME; do + [ -z "$NODE_ADDR" -a -z "$NODE_NAME" ] && continue + NODE_ATTRS=`iscsiadm -m node -p "$NODE_ADDR" -T "$NODE_NAME"` + NODE_STATUS=`echo "$NODE_ATTRS" | sed -nre 's/^.*node\.conn\[0\]\.startup = ([a-z]*).*$/\1/p'` + + if [ "$NODE_STATUS" == 'automatic' ]; then + DISC_TARGETS=`echo "$DISC_TARGETS" | sed -re '/'"$NODE_ADDR"'/!{s/(.*)/\1 '"$NODE_ADDR"'/}'` + fi + done < <(echo "$IPV4_NODE_LIST"; echo "$IPV6_NODE_LIST") + + for TARGET_ADDR in $DISC_TARGETS; do + echo -n "Attempting discovery on target at ${TARGET_ADDR}: " + iscsiadm -m discovery -t st -p "$TARGET_ADDR" > /dev/null 2>&1 + if [ "$?" -ne 0 ]; then + rc_failed 1 + rc_status -v + return 1 + fi + rc_status -v + done +} + case "$1" in start) [ ! -d /var/lib/iscsi ] && mkdir -p /var/lib/iscsi @@ -75,10 +147,15 @@ case "$1" in rc_status -v fi if [ "$RETVAL" == "0" ]; then + iscsi_discover_all_targets + RETVAL=$? + fi + if [ "$RETVAL" == "0" ]; then iscsi_login_all_nodes fi ;; stop) + iscsi_umount_all_luns if iscsi_logout_all_nodes ; then killproc -KILL $DAEMON RETVAL=$? @@ -99,7 +176,7 @@ case "$1" in fi rc_failed $status else - rc_failed 1 + rc_failed $RETVAL fi rc_status -v ;; -- 1.5.3.4 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "open-iscsi" group. To post to this group, send email to open-iscsi@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/open-iscsi -~----------~----~----~----~------~----~------~--~---