]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
add iscsi interface binding
authorHarald Hoyer <harald@redhat.com>
Thu, 29 Mar 2012 09:53:59 +0000 (11:53 +0200)
committerHarald Hoyer <harald@redhat.com>
Thu, 29 Mar 2012 10:02:12 +0000 (12:02 +0200)
iscsi connections can now be bound to <iscsi_iface_name> and <netdev_name>

dracut.cmdline.7.asc
modules.d/40network/net-lib.sh
modules.d/95iscsi/iscsiroot.sh
modules.d/95iscsi/parse-iscsiroot.sh

index 738d464593374138dec278b666bfbb9d51ab368c..bff2e280d1d03bf9ca97a303a3a06f5fa615b520 100644 (file)
@@ -317,7 +317,7 @@ NFS
 
 iSCSI
 ~~~~~
-**root=**iscsi:[_<username>_:_<password>_[:_<reverse>_:_<password>_]@][_<servername>_]:[_<protocol>_]:[_<port>_]:[_<LUN>_]:_<targetname>_::
+**root=**iscsi:[_<username>_:_<password>_[:_<reverse>_:_<password>_]@][_<servername>_]:[_<protocol>_]:[_<port>_][:[_<iscsi_iface_name>_]:[_<netdev_name>_]]:[_<LUN>_]:_<targetname>_::
     protocol defaults to "6", LUN defaults to "0". If the "servername" field is
     provided by BOOTP or DHCP, then that field is used in conjunction with other
     associated fields to contact the boot server in the Boot stage. However, if
@@ -337,7 +337,7 @@ If servername is an IPv6 address, it has to be put in brackets. e.g.:
 root=iscsi:[2001:DB8::1]::::iqn.2009-06.dracut:target0
 ----
 
-**root=**_???_ **netroot=**iscsi:[_<username>_:_<password>_[:_<reverse>_:_<password>_]@][_<servername>_]:[_<protocol>_]:[_<port>_]:[_<LUN>_]:_<targetname>_ ...::
+**root=**_???_ **netroot=**iscsi:[_<username>_:_<password>_[:_<reverse>_:_<password>_]@][_<servername>_]:[_<protocol>_]:[_<port>_][:[_<iscsi_iface_name>_]:[_<netdev_name>_]]:[_<LUN>_]:_<targetname>_ ...::
     multiple netroot options allow setting up multiple iscsi disks. e.g.:
 +
 ----
index e51ce94d83be78322569a3601e7e5f7ad66427f9..4055ccf6f803f8fe911a810fcf2ef1a283c0436c 100644 (file)
@@ -139,3 +139,89 @@ ibft_to_cmdline() {
     # reread cmdline
     unset CMDLINE
 }
+
+parse_iscsi_root()
+{
+    local v
+    v=${1#iscsi:}
+
+# extract authentication info
+    case "$v" in
+       *@*:*:*:*:*)
+           authinfo=${v%%@*}
+           v=${v#*@}
+    # allow empty authinfo to allow having an @ in iscsi_target_name like this:
+    # netroot=iscsi:@192.168.1.100::3260::iqn.2009-01.com.example:testdi@sk
+           if [ -n "$authinfo" ]; then
+               OLDIFS="$IFS"
+               IFS=:
+               set $authinfo
+               IFS="$OLDIFS"
+               if [ $# -gt 4 ]; then
+                   warn "Wrong authentication info in iscsi: parameter!"
+                   return 1
+               fi
+               iscsi_username=$1
+               iscsi_password=$2
+               if [ $# -gt 2 ]; then
+                   iscsi_in_username=$3
+                   iscsi_in_password=$4
+               fi
+           fi
+           ;;
+    esac
+
+# extract target ip
+    case "$v" in
+       [[]*[]]:*)
+           iscsi_target_ip=${v#[[]}
+               iscsi_target_ip=${iscsi_target_ip%%[]]*}
+           v=${v#[[]$iscsi_target_ip[]]:}
+           ;;
+       *)
+           iscsi_target_ip=${v%%[:]*}
+           v=${v#$iscsi_target_ip:}
+           ;;
+    esac
+
+# extract target name
+    case "$v" in
+       *:iqn.*)
+           iscsi_target_name=iqn.${v##*:iqn.}
+           v=${v%:iqn.*}:
+           ;;
+       *:eui.*)
+           iscsi_target_name=iqn.${v##*:eui.}
+           v=${v%:iqn.*}:
+           ;;
+       *:naa.*)
+           iscsi_target_name=iqn.${v##*:naa.}
+           v=${v%:iqn.*}:
+           ;;
+       *)
+           warn "Invalid iscii target name, should begin with 'iqn.' or 'eui.' or 'naa.'"
+           return 1
+           ;;
+    esac
+
+# parse the rest
+    OLDIFS="$IFS"
+    IFS=:
+    set $v
+    IFS="$OLDIFS"
+
+    iscsi_protocol=$1; shift # ignored
+    iscsi_target_port=$1; shift
+    if [ $# -eq 3 ]; then
+       iscsi_iface_name=$1; shift
+    fi
+    if [ $# -eq 2 ]; then
+       iscsi_netdev_name=$1; shift
+    fi
+    iscsi_lun=$1; shift
+    if [ $# -ne 0 ]; then
+       warn "Invalid parameter in iscsi: parameter!"
+       return 1
+    fi
+}
+
index 7fa27156b22ba595b7bafa8b1f0395ae91619586..57a3982f5a0d5ac67ff5a1afce634d37c9deb53a 100755 (executable)
@@ -9,6 +9,7 @@
 #
 
 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
+type parse_iscsi_root >/dev/null 2>&1 || . /lib/net-lib.sh
 
 PATH=/usr/sbin:/usr/bin:/sbin:/bin
 
@@ -49,80 +50,38 @@ if getargbool 0 rd.iscsi.firmware -y iscsi_firmware ; then
     exit 0
 fi
 
-unset iscsi_initiator iscsi_target_name iscsi_target_ip iscsi_target_port
-unset iscsi_target_group iscsi_protocol iscsirw iscsi_lun
-unset iscsi_username iscsi_password
-unset iscsi_in_username iscsi_in_password
-
-# override conf settings by command line options
-arg=$(getargs rd.iscsi.initiator iscsi_initiator=)
-[ -n "$arg" ] && iscsi_initiator=$arg
-arg=$(getargs rd.iscsi.target.name iscsi_target_name=)
-[ -n "$arg" ] && iscsi_target_name=$arg
-arg=$(getargs rd.iscsi.target.ip iscsi_target_ip)
-[ -n "$arg" ] && iscsi_target_ip=$arg
-arg=$(getargs rd.iscsi.target.port iscsi_target_port=)
-[ -n "$arg" ] && iscsi_target_port=$arg
-arg=$(getargs rd.iscsi.target.group iscsi_target_group=)
-[ -n "$arg" ] && iscsi_target_group=$arg
-arg=$(getargs rd.iscsi.username iscsi_username=)
-[ -n "$arg" ] && iscsi_username=$arg
-arg=$(getargs rd.iscsi.password iscsi_password)
-[ -n "$arg" ] && iscsi_password=$arg
-arg=$(getargs rd.iscsi.in.username iscsi_in_username=)
-[ -n "$arg" ] && iscsi_in_username=$arg
-arg=$(getargs rd.iscsi.in.password iscsi_in_password=)
-[ -n "$arg" ] && iscsi_in_password=$arg
-
 handle_netroot()
 {
-    iroot=$1
-    # override conf/commandline options by dhcp root_path
-    # FIXME this assumes that all values have been provided
-    OLDIFS="$IFS"
-    IFS=@
-    set $iroot
-    if [ $# -gt 1 ]; then
-        authinfo=$1; shift
-        iroot=$*
-    # allow empty authinfo to allow having an @ in iscsi_target_name like this:
-    # netroot=iscsi:@192.168.1.100::3260::iqn.2009-01.com.example:testdi@sk
-        if [ -n "$authinfo" ]; then
-            IFS=:
-            set $authinfo
-            iscsi_username=$1
-            iscsi_password=$2
-            if [ $# -gt 2 ]; then
-                iscsi_in_username=$3
-                iscsi_in_password=$4
-            fi
-        fi
-    fi
+    local iscsi_initiator iscsi_target_name iscsi_target_ip iscsi_target_port
+    local iscsi_target_group iscsi_protocol iscsirw iscsi_lun
+    local iscsi_username iscsi_password
+    local iscsi_in_username iscsi_in_password
+    local iscsi_iface_name iscsi_netdev_name
+    local iscsi_param
+    local p
+
+    # override conf settings by command line options
+    arg=$(getargs rd.iscsi.initiator iscsi_initiator=)
+    [ -n "$arg" ] && iscsi_initiator=$arg
+    arg=$(getargs rd.iscsi.target.name iscsi_target_name=)
+    [ -n "$arg" ] && iscsi_target_name=$arg
+    arg=$(getargs rd.iscsi.target.ip iscsi_target_ip)
+    [ -n "$arg" ] && iscsi_target_ip=$arg
+    arg=$(getargs rd.iscsi.target.port iscsi_target_port=)
+    [ -n "$arg" ] && iscsi_target_port=$arg
+    arg=$(getargs rd.iscsi.target.group iscsi_target_group=)
+    [ -n "$arg" ] && iscsi_target_group=$arg
+    arg=$(getargs rd.iscsi.username iscsi_username=)
+    [ -n "$arg" ] && iscsi_username=$arg
+    arg=$(getargs rd.iscsi.password iscsi_password)
+    [ -n "$arg" ] && iscsi_password=$arg
+    arg=$(getargs rd.iscsi.in.username iscsi_in_username=)
+    [ -n "$arg" ] && iscsi_in_username=$arg
+    arg=$(getargs rd.iscsi.in.password iscsi_in_password=)
+    [ -n "$arg" ] && iscsi_in_password=$arg
+
+    parse_iscsi_root "$1" || return 1
 
-    IFS="$OLDIFS"
-
-    local v=${iroot}:
-    local i
-    set --
-    while [ -n "$v" ]; do
-        if [ "${v#\[*:*:*\]:}" != "$v" ]; then
-        # handle IPv6 address
-            i="${v%%\]:*}"
-            i="${i##\[}"
-            set -- "$@" "$i"
-            v=${v#\[$i\]:}
-        else
-            set -- "$@" "${v%%:*}"
-            v=${v#*:}
-        fi
-    done
-    iscsi_target_ip=$1; shift
-    iscsi_protocol=$1; shift # ignored
-    iscsi_target_port=$1; shift
-    iscsi_lun=$1; shift
-    IFS=:
-    iscsi_target_name=$*
-    IFS="$OLDIFS"
 # XXX is this needed?
     getarg ro && iscsirw=ro
     getarg rw && iscsirw=rw
@@ -187,7 +146,10 @@ handle_netroot()
         ${iscsi_username+-u $iscsi_username} \
         ${iscsi_password+-w $iscsi_password} \
         ${iscsi_in_username+-U $iscsi_in_username} \
-        ${iscsi_in_password+-W $iscsi_in_password} || :
+        ${iscsi_in_password+-W $iscsi_in_password} \
+       ${iscsi_iface_name+--param iface.iscsi_ifacename=$iscsi_iface_name} \
+       ${iscsi_netdev_name+--param iface.net_ifacename=$iscsi_netdev_name} \
+       || :
 }
 
 # loop over all netroot parameter
index 64aae84222dd471cb5aa8358e852e5af132a895b..e7fc224eeaed07fdfe5ed9ed2bf31898e1a514ab 100755 (executable)
@@ -69,11 +69,9 @@ fi
 # If it's not iscsi we don't continue
 [ "${netroot%%:*}" = "iscsi" ] || return
 
-# Check required arguments. there's only one, but it's at the end
 if [ -z "$iscsi_firmware" ] ; then
-    case "${netroot##iscsi:*:*:*:*:}" in
-        $netroot|'') die "Argument targetname for iscsiroot is missing";;
-    esac
+    type parse_iscsi_root >/dev/null 2>&1 || . /lib/net-lib.sh
+    parse_iscsi_root "$netroot" || return
 fi
 
 # ISCSI actually supported?