From d3d3b814417cd72ee58701355a00de1ac0fb5178 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Fri, 2 Jul 2010 13:20:53 +0200 Subject: [PATCH] Parse iface entry correctly in init script There are various ways an iface entry can specify the device. We need to parse all of these to get meaningful results. Signed-off-by: Hannes Reinecke diff --git a/etc/initd/initd.suse b/etc/initd/initd.suse index ef1ccbe..081bfc1 100644 --- a/etc/initd/initd.suse +++ b/etc/initd/initd.suse @@ -110,10 +110,33 @@ iscsi_get_hwaddress_from_iface() local hwaddress hwaddress=$(iscsiadm -m iface -I "$iface" 2> /dev/null | sed -n 's/iface.hwaddress = \(.*\)/\1/p') + [ "$hwaddress" = "" ] && hwaddress= echo $hwaddress } +iscsi_get_ifname_from_iface() +{ + local iface=$1 + local ifname + + ifname=$(iscsiadm -m iface -I "$iface" 2> /dev/null | sed -n 's/iface.net_ifacename = \(.*\)/\1/p') + [ "$ifname" = "" ] && ifname= + + echo $ifname +} + +iscsi_get_ipaddr_from_iface() +{ + local iface=$1 + local ipaddr + + ipaddr=$(iscsiadm -m iface -I "$iface" 2> /dev/null | sed -n 's/iface.ipaddress = \(.*\)/\1/p') + [ "$ipaddr" = "" ] && ipaddr= + + echo $ipaddr +} + iscsi_get_ifname_from_firmware() { local hwaddress @@ -140,6 +163,15 @@ iscsi_get_ifname_from_hwaddress() done } +iscsi_get_ifname_from_ipaddr() +{ + local ipaddr=$1 + local ifname + + ifname=$(ip addr show to $ipaddr | sed -n 's/[0-9]*: \([^ :]*\): .*/\1/p') + return $ifname +} + # # Handle 'default' interface: # It is basically impossible to determine via which @@ -169,14 +201,24 @@ iscsi_check_interface() iscsi_modify_all_interfaces elif [ "$i" = "fw" ] ; then n=$(iscsi_get_ifname_from_firmware) - iscsi_modify_if_startmode $n else - h=$(iscsi_get_hwaddress_from_iface $i) - if [ -n "$h" ] ; then - n=$(iscsi_get_ifname_from_hwaddress $h) - iscsi_modify_if_startmode $n + n=$(iscsi_get_ifname_from_iface $i) + if [ -z "$n" ] ; then + h=$(iscsi_get_hwaddress_from_iface $i) + if [ -n "$h" ] ; then + n=$(iscsi_get_ifname_from_hwaddress $h) + fi + fi + if [ -z "$n" ] ; then + h=$(iscsi_get_ipaddr_from_iface $i) + if [ -n "$h" ] ; then + n=$(iscsi_get_ifname_from_ipaddr $h) + fi fi fi + if [ "$n" ] ; then + iscsi_modify_if_startmode $n + fi } # @@ -317,7 +359,6 @@ iscsi_stop_sessions() m=$(iscsi_check_target $t) s=${session##*/session} if [ -z "$m" ] ; then - echo "stopping session $s" iscsiadm -m session -r ${s} -u i=$(( $i + 1 )) else @@ -361,7 +402,7 @@ case "$1" in stop) n=$(iscsi_stop_sessions) echo -n "Stopping iSCSI initiator service: " - if [ "$n" -gt 0 ] ; then + if [ "$n" ] && [ "$n" != "0" ] ; then m=$(iscsiadm -m session 2> /dev/null) if [ -z "$m" ] ; then killproc -KILL $DAEMON