From: Harald Hoyer Date: Thu, 29 Mar 2012 09:53:59 +0000 (+0200) Subject: add iscsi interface binding X-Git-Tag: 018~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ac3f1c6e87ae24129b24203968f1256d6dc502f8;p=thirdparty%2Fdracut.git add iscsi interface binding iscsi connections can now be bound to and --- diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc index 738d46459..bff2e280d 100644 --- a/dracut.cmdline.7.asc +++ b/dracut.cmdline.7.asc @@ -317,7 +317,7 @@ NFS iSCSI ~~~~~ -**root=**iscsi:[__:__[:__:__]@][__]:[__]:[__]:[__]:__:: +**root=**iscsi:[__:__[:__:__]@][__]:[__]:[__][:[__]:[__]]:[__]:__:: 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:[__:__[:__:__]@][__]:[__]:[__]:[__]:__ ...:: +**root=**_???_ **netroot=**iscsi:[__:__[:__:__]@][__]:[__]:[__][:[__]:[__]]:[__]:__ ...:: multiple netroot options allow setting up multiple iscsi disks. e.g.: + ---- diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh index e51ce94d8..4055ccf6f 100644 --- a/modules.d/40network/net-lib.sh +++ b/modules.d/40network/net-lib.sh @@ -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 +} + diff --git a/modules.d/95iscsi/iscsiroot.sh b/modules.d/95iscsi/iscsiroot.sh index 7fa27156b..57a3982f5 100755 --- a/modules.d/95iscsi/iscsiroot.sh +++ b/modules.d/95iscsi/iscsiroot.sh @@ -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 diff --git a/modules.d/95iscsi/parse-iscsiroot.sh b/modules.d/95iscsi/parse-iscsiroot.sh index 64aae8422..e7fc224ee 100755 --- a/modules.d/95iscsi/parse-iscsiroot.sh +++ b/modules.d/95iscsi/parse-iscsiroot.sh @@ -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?