for nic in "${disk}"/pci_dev/net/*; do
[ -d "$nic" ] || continue
if [ -n "${dev_port}" -a -e "${nic}/dev_port" ]; then
- if [ "$(cat ${nic}/dev_port)" -ne "${dev_port}" ]; then
+ if [ "$(cat "${nic}"/dev_port)" -ne "${dev_port}" ]; then
continue
fi
fi
- if [ -e ${nic}/address ]; then
+ if [ -e "${nic}"/address ]; then
fcoe_interface=${nic##*/}
if ! [ -e "/tmp/.fcoe-$fcoe_interface" ]; then
/sbin/fcoe-up "$fcoe_interface" "$dcb"
- > "/tmp/.fcoe-$fcoe_interface"
+ : > "/tmp/.fcoe-$fcoe_interface"
fi
fi
done
+++ /dev/null
-#!/bin/sh
-
-# We use (fcoe_interface or fcoe_mac) and fcoe_dcb as set by parse-fcoe.sh
-# If neither mac nor interface are set we don't continue
-[ -z "$fcoe_interface" -a -z "$fcoe_mac" ] && return
-
-# Write udev rules
-{
- if [ -n "$fcoe_mac" ]; then
- printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", RUN+="/sbin/initqueue --onetime --unique --name fcoe-up-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_mac" "$fcoe_dcb" "$fcoe_mode"
- printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", RUN+="/sbin/initqueue --onetime --timeout --unique --name fcoe-timeout-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_mac" "$fcoe_dcb" "$fcoe_mode"
- else
- printf 'ACTION=="add", SUBSYSTEM=="net", NAME=="%s", RUN+="/sbin/initqueue --onetime --unique --name fcoe-up-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_interface" "$fcoe_dcb" "$fcoe_mode"
- printf 'ACTION=="add", SUBSYSTEM=="net", NAME=="%s", RUN+="/sbin/initqueue --onetime --timeout --unique --name fcoe-timeout-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_interface" "$fcoe_dcb" "$fcoe_mode"
- fi
-} >> /etc/udev/rules.d/92-fcoe.rules
mode=$3
vlan="yes"
-iflink=$(cat /sys/class/net/$netif/iflink)
-ifindex=$(cat /sys/class/net/$netif/ifindex)
+iflink=$(cat /sys/class/net/"$netif"/iflink)
+ifindex=$(cat /sys/class/net/"$netif"/ifindex)
if [ "$iflink" != "$ifindex" ]; then
# Skip VLAN devices
exit 0
fi
-ip link set dev $netif up
+ip link set dev "$netif" up
linkup "$netif"
# Some fcoemon implementations expect --syslog=true
syslogopt="--syslog"
if fcoemon -h | grep syslog | grep -q yes; then
- fcoemonyes="$syslogopt=yes"
+ syslogopt="$syslogopt=yes"
fi
-netdriver=$(readlink -f /sys/class/net/$netif/device/driver)
+netdriver=$(readlink -f /sys/class/net/"$netif"/device/driver)
netdriver=${netdriver##*/}
write_fcoemon_cfg() {
- [ -f /etc/fcoe/cfg-$netif ] && return
- echo FCOE_ENABLE=\"yes\" > /etc/fcoe/cfg-$netif
+ [ -f /etc/fcoe/cfg-"$netif" ] && return
+ echo FCOE_ENABLE=\"yes\" > /etc/fcoe/cfg-"$netif"
if [ "$dcb" = "dcb" ]; then
- echo DCB_REQUIRED=\"yes\" >> /etc/fcoe/cfg-$netif
+ echo DCB_REQUIRED=\"yes\" >> /etc/fcoe/cfg-"$netif"
else
- echo DCB_REQUIRED=\"no\" >> /etc/fcoe/cfg-$netif
+ echo DCB_REQUIRED=\"no\" >> /etc/fcoe/cfg-"$netif"
fi
if [ "$vlan" = "yes" ]; then
- echo AUTO_VLAN=\"yes\" >> /etc/fcoe/cfg-$netif
+ echo AUTO_VLAN=\"yes\" >> /etc/fcoe/cfg-"$netif"
else
- echo AUTO_VLAN=\"no\" >> /etc/fcoe/cfg-$netif
+ echo AUTO_VLAN=\"no\" >> /etc/fcoe/cfg-"$netif"
fi
if [ "$mode" = "vn2vn" ]; then
- echo MODE=\"vn2vn\" >> /etc/fcoe/cfg-$netif
+ echo MODE=\"vn2vn\" >> /etc/fcoe/cfg-"$netif"
else
- echo MODE=\"fabric\" >> /etc/fcoe/cfg-$netif
+ echo MODE=\"fabric\" >> /etc/fcoe/cfg-"$netif"
fi
}
# called by dracut
check() {
is_fcoe() {
- block_is_fcoe $1 || return 1
+ block_is_fcoe "$1" || return 1
}
[[ $hostonly ]] || [[ $mount_needs ]] && {
for_each_host_dev_and_slaves is_fcoe || return 255
}
- require_binaries dcbtool fipvlan lldpad ip readlink fcoemon fcoeadm || return 1
+ require_binaries dcbtool fipvlan lldpad ip readlink fcoemon fcoeadm tr || return 1
return 0
}
get_vlan_parent() {
local link=$1
- [ -d $link ] || return
- read iflink < $link/iflink
+ [ -d "$link" ] || return
+ read -r iflink < "$link"/iflink
for if in /sys/class/net/*; do
- read idx < $if/ifindex
- if [ $idx -eq $iflink ]; then
- echo ${if##*/}
+ read -r idx < "$if"/ifindex
+ if [ "$idx" -eq "$iflink" ]; then
+ echo "${if##*/}"
fi
done
}
cmdline() {
{
for c in /sys/bus/fcoe/devices/ctlr_*; do
- [ -L $c ] || continue
- read enabled < $c/enabled
- read mode < $c/mode
- [ $enabled -eq 0 ] && continue
- if [ $mode = "VN2VN" ]; then
+ [ -L "$c" ] || continue
+ read -r enabled < "$c"/enabled
+ read -r mode < "$c"/mode
+ [ "$enabled" -eq 0 ] && continue
+ if [ "$mode" = "VN2VN" ]; then
mode="vn2vn"
else
mode="fabric"
fi
d=$(
- cd -P $c
- echo $PWD
+ cd -P "$c" || exit
+ echo "$PWD"
)
i=${d%/*}
ifname=${i##*/}
- read mac < ${i}/address
- s=$(dcbtool gc ${i##*/} dcb 2> /dev/null | sed -n 's/^DCB State:\t*\(.*\)/\1/p')
+ read -r mac < "${i}"/address
+ s=$(dcbtool gc "${i##*/}" dcb 2> /dev/null | sed -n 's/^DCB State:\t*\(.*\)/\1/p')
if [ -z "$s" ]; then
- p=$(get_vlan_parent ${i})
+ p=$(get_vlan_parent "${i}")
if [ "$p" ]; then
- s=$(dcbtool gc ${p} dcb 2> /dev/null | sed -n 's/^DCB State:\t*\(.*\)/\1/p')
+ s=$(dcbtool gc "${p}" dcb 2> /dev/null | sed -n 's/^DCB State:\t*\(.*\)/\1/p')
ifname=${p##*/}
fi
fi
# DCB_REQUIRED in "/etc/fcoe/cfg-xxx" is expected to set to "no".
#
# Force "nodcb" if there's any DCB_REQUIRED="no"(child or vlan parent).
- grep -q '^[[:blank:]]*DCB_REQUIRED="no"' /etc/fcoe/cfg-${i##*/} &> /dev/null
- [ $? -eq 0 ] && dcb="nodcb"
+ if grep -q '^[[:blank:]]*DCB_REQUIRED="no"' /etc/fcoe/cfg-"${i##*/}" &> /dev/null; then
+ dcb="nodcb"
+ fi
+
if [ "$p" ]; then
- grep -q '^[[:blank:]]*DCB_REQUIRED="no"' /etc/fcoe/cfg-${p} &> /dev/null
- [ $? -eq 0 ] && dcb="nodcb"
+ if grep -q '^[[:blank:]]*DCB_REQUIRED="no"' /etc/fcoe/cfg-"${p}" &> /dev/null; then
+ dcb="nodcb"
+ fi
fi
echo "ifname=${ifname}:${mac}"
# called by dracut
install() {
- inst_multiple ip dcbtool fipvlan lldpad readlink lldptool fcoemon fcoeadm
+ inst_multiple ip dcbtool fipvlan lldpad readlink lldptool fcoemon fcoeadm tr
if [[ -e $dracutsysrootdir/etc/hba.conf ]]; then
inst_libdir_file 'libhbalinux.so*'
inst_simple "/etc/hba.conf"
mkdir -m 0755 -p "$initdir/etc/fcoe"
if [[ $hostonly_cmdline == "yes" ]]; then
- local _fcoeconf=$(cmdline)
+ local _fcoeconf
+ _fcoeconf=$(cmdline)
[[ $_fcoeconf ]] && printf "%s\n" "$_fcoeconf" >> "${initdir}/etc/cmdline.d/95fcoe.conf"
fi
inst_multiple "/etc/fcoe/cfg-*"
inst "$moddir/fcoe-up.sh" "/sbin/fcoe-up"
inst "$moddir/fcoe-edd.sh" "/sbin/fcoe-edd"
- inst "$moddir/fcoe-genrules.sh" "/sbin/fcoe-genrules.sh"
inst_hook pre-trigger 03 "$moddir/lldpad.sh"
inst_hook cmdline 99 "$moddir/parse-fcoe.sh"
inst_hook cleanup 90 "$moddir/cleanup-fcoe.sh"
# fcoe=eth0:nodcb:vn2vn
# fcoe=4a:3f:4c:04:f8:d7:nodcb:fabric
+if [ -z "$fcoe" ] && ! getarg fcoe=; then
+ # If it's not set we don't continue
+ return 0
+fi
+
if ! getargbool 1 rd.fcoe -d -n rd.nofcoe; then
info "rd.fcoe=0: skipping fcoe"
return 0
fi
-[ -z "$fcoe" ] && fcoe=$(getarg fcoe=)
-
-# If it's not set we don't continue
-[ -z "$fcoe" ] && return
-
-[ -e /sys/bus/fcoe/ctlr_create ] || modprobe -b -a fcoe || modprobe -b -a libfcoe || die "FCoE requested but kernel/initrd does not support FCoE"
+if ! [ -e /sys/bus/fcoe/ctlr_create ] && ! modprobe -b -a fcoe && ! modprobe -b -a libfcoe; then
+ die "FCoE requested but kernel/initrd does not support FCoE"
+fi
initqueue --onetime modprobe -b -q bnx2fc
parse_fcoe_opts() {
+ local fcoe_interface
+ local fcoe_dcb
+ local fcoe_mode
+ local fcoe_mac
local OLDIFS="$IFS"
local IFS=:
- set $fcoe
+ # shellcheck disable=SC2086
+ # shellcheck disable=SC2048
+ set -- $*
IFS="$OLDIFS"
case $# in
fcoe_interface=$1
fcoe_dcb=$2
fcoe_mode="fabric"
- return 0
+ unset fcoe_mac
;;
3)
fcoe_interface=$1
fcoe_dcb=$2
fcoe_mode=$3
- return 0
+ unset fcoe_mac
;;
7)
- fcoe_mac=$1:$2:$3:$4:$5:$6
+ fcoe_mac=$(echo "$1:$2:$3:$4:$5:$6" | tr "[:upper:]" "[:lower:]")
fcoe_dcb=$7
fcoe_mode="fabric"
- return 0
+ unset fcoe_interface
;;
8)
- fcoe_mac=$1:$2:$3:$4:$5:$6
+ fcoe_mac=$(echo "$1:$2:$3:$4:$5:$6" | tr "[:upper:]" "[:lower:]")
fcoe_dcb=$7
fcoe_mode=$8
- return 0
+ unset fcoe_interface
;;
*)
warn "Invalid arguments for fcoe=$fcoe"
return 1
;;
esac
-}
-
-parse_fcoe_opts
-if [ "$fcoe_interface" = "edd" ]; then
if [ "$fcoe_dcb" != "nodcb" -a "$fcoe_dcb" != "dcb" ]; then
warn "Invalid FCoE DCB option: $fcoe_dcb"
fi
- /sbin/initqueue --settled --unique /sbin/fcoe-edd $fcoe_dcb
-else
- for fcoe in $(getargs fcoe=); do
- unset fcoe_mac
- unset fcoe_interface
- parse_fcoe_opts
- if [ "$fcoe_dcb" != "nodcb" -a "$fcoe_dcb" != "dcb" ]; then
- warn "Invalid FCoE DCB option: $fcoe_dcb"
+
+ if [ "$fcoe_interface" = "edd" ]; then
+ /sbin/initqueue --settled --unique /sbin/fcoe-edd "$fcoe_dcb"
+ return 0
+ fi
+
+ if [ -z "$fcoe_interface" -a -z "$fcoe_mac" ]; then
+ warn "fcoe: Neither interface nor MAC specified for fcoe=$fcoe"
+ return 1
+ fi
+
+ {
+ if [ -n "$fcoe_mac" ]; then
+ # shellcheck disable=SC2016
+ printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", RUN+="/sbin/initqueue --onetime --unique --name fcoe-up-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_mac" "$fcoe_dcb" "$fcoe_mode"
+ # shellcheck disable=SC2016
+ printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", RUN+="/sbin/initqueue --onetime --timeout --unique --name fcoe-timeout-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_mac" "$fcoe_dcb" "$fcoe_mode"
+ else
+ # shellcheck disable=SC2016
+ printf 'ACTION=="add", SUBSYSTEM=="net", NAME=="%s", RUN+="/sbin/initqueue --onetime --unique --name fcoe-up-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_interface" "$fcoe_dcb" "$fcoe_mode"
+ # shellcheck disable=SC2016
+ printf 'ACTION=="add", SUBSYSTEM=="net", NAME=="%s", RUN+="/sbin/initqueue --onetime --timeout --unique --name fcoe-timeout-$name /sbin/fcoe-up $name %s %s"\n' "$fcoe_interface" "$fcoe_dcb" "$fcoe_mode"
fi
- . $(command -v fcoe-genrules.sh)
- done
-fi
+ } >> /etc/udev/rules.d/92-fcoe.rules
+}
+
+for fcoe in $fcoe $(getargs fcoe=); do
+ parse_fcoe_opts "$fcoe"
+done
#!/bin/bash
for f in /sys/bus/fcoe/devices/ctlr_*; do
- [ -e $f ] || continue
- echo 0 > $f/enabled
+ [ -e "$f" ] || continue
+ echo 0 > "$f"/enabled
done