a0a3b4
From f501c955e86eb3043ab5e3c5f2648ed4c8bb58a3 Mon Sep 17 00:00:00 2001
a0a3b4
From: Hannes Reinecke <hare@suse.de>
a0a3b4
Date: Thu, 11 Dec 2014 15:46:22 +0100
a0a3b4
Subject: [PATCH] 95fcoe: Store current configuration in dracut cmdline
a0a3b4
a0a3b4
When running with --hostonly-cmdline we should be storing
a0a3b4
the current configuration in /etc/cmdline.d so that dracut
a0a3b4
will be configure the system automatically.
a0a3b4
a0a3b4
References: bnc#877288
a0a3b4
a0a3b4
Signed-off-by: Hannes Reinecke <hare@suse.de>
a0a3b4
Signed-off-by: Thomas Renninger <trenn@suse.de>
a0a3b4
(cherry picked from commit 8b257fcc86f9a470613c1a5719641144a688acf7)
a0a3b4
---
49e6a8
 modules.d/95fcoe/module-setup.sh | 45 ++++++++++++++++++++++++++++++++
a0a3b4
 1 file changed, 45 insertions(+)
a0a3b4
a0a3b4
diff --git a/modules.d/95fcoe/module-setup.sh b/modules.d/95fcoe/module-setup.sh
1755ca
index c000b3be..af2798dc 100755
a0a3b4
--- a/modules.d/95fcoe/module-setup.sh
a0a3b4
+++ b/modules.d/95fcoe/module-setup.sh
a0a3b4
@@ -13,6 +13,7 @@ check() {
a0a3b4
     }
a0a3b4
 
a0a3b4
     require_binaries dcbtool fipvlan lldpad ip readlink fcoemon fcoeadm || return 1
a0a3b4
+
a0a3b4
     return 0
a0a3b4
 }
a0a3b4
 
a0a3b4
@@ -25,6 +26,46 @@ installkernel() {
a0a3b4
     instmods fcoe 8021q edd
a0a3b4
 }
a0a3b4
 
a0a3b4
+get_vlan_parent() {
a0a3b4
+    local link=$1
a0a3b4
+
a0a3b4
+    [ -d $link ] || return
a0a3b4
+    read iflink < $link/iflink
a0a3b4
+    for if in /sys/class/net/* ; do
a0a3b4
+	read idx < $if/ifindex
a0a3b4
+	if [ $idx -eq $iflink ] ; then
a0a3b4
+	    echo ${if##*/}
a0a3b4
+	fi
a0a3b4
+    done
a0a3b4
+}
a0a3b4
+
a0a3b4
+# called by dracut
a0a3b4
+cmdline() {
a0a3b4
+
a0a3b4
+    for c in /sys/bus/fcoe/devices/ctlr_* ; do
a0a3b4
+        [ -L $c ] || continue
a0a3b4
+        read enabled < $c/enabled
a0a3b4
+        [ $enabled -eq 0 ] && continue
a0a3b4
+        d=$(cd -P $c; echo $PWD)
a0a3b4
+        i=${d%/*}
a0a3b4
+        read mac < ${i}/address
a0a3b4
+        s=$(dcbtool gc ${i##*/} dcb | sed -n 's/^DCB State:\t*\(.*\)/\1/p')
a0a3b4
+        if [ -z "$s" ] ; then
a0a3b4
+	    p=$(get_vlan_parent ${i})
a0a3b4
+	    if [ "$p" ] ; then
a0a3b4
+	        s=$(dcbtool gc ${p} dcb | sed -n 's/^DCB State:\t*\(.*\)/\1/p')
a0a3b4
+	    fi
a0a3b4
+        fi
a0a3b4
+        if [ "$s" = "on" ] ; then
a0a3b4
+	    dcb="dcb"
a0a3b4
+        else
a0a3b4
+	    dcb="nodcb"
a0a3b4
+        fi
a0a3b4
+        echo "fcoe=${mac}:${dcb}"
a0a3b4
+    done
a0a3b4
+}
a0a3b4
+
a0a3b4
+# called by dracut
a0a3b4
 install() {
a0a3b4
     inst_multiple ip dcbtool fipvlan lldpad readlink lldptool fcoemon fcoeadm
a0a3b4
     inst_libdir_file 'libhbalinux.so*'
a0a3b4
@@ -33,6 +74,10 @@ install() {
a0a3b4
     mkdir -m 0755 -p "$initdir/var/lib/lldpad"
a0a3b4
     mkdir -m 0755 -p "$initdir/etc/fcoe"
a0a3b4
 
a0a3b4
+    if [[ $hostonly_cmdline == "yes" ]] ; then
a0a3b4
+        local _fcoeconf=$(cmdline)
a0a3b4
+        [[ $_fcoeconf ]] && printf "%s\n" "$_fcoeconf" >> "${initdir}/etc/cmdline.d/95fcoe.conf"
a0a3b4
+    fi
a0a3b4
     inst "$moddir/fcoe-up.sh" "/sbin/fcoe-up"
a0a3b4
     inst "$moddir/fcoe-edd.sh" "/sbin/fcoe-edd"
a0a3b4
     inst "$moddir/fcoe-genrules.sh" "/sbin/fcoe-genrules.sh"