Blame SOURCES/0269-fcoe-fcoe-edd.sh-cleanup-the-script.patch

712866
From 34203d03c0d43aa0aed12988d2719455e80eae54 Mon Sep 17 00:00:00 2001
712866
From: Harald Hoyer <harald@redhat.com>
712866
Date: Fri, 3 Jul 2015 13:52:32 +0200
712866
Subject: [PATCH] fcoe/fcoe-edd.sh: cleanup the script
712866
712866
- check if modprobe was successful
712866
- add a timeout for /sys/firmware/edd
712866
- only remove the module, if it was loaded by the script
712866
---
712866
 modules.d/95fcoe/fcoe-edd.sh | 46 ++++++++++++++++++++++++++++++--------------
712866
 1 file changed, 32 insertions(+), 14 deletions(-)
712866
712866
diff --git a/modules.d/95fcoe/fcoe-edd.sh b/modules.d/95fcoe/fcoe-edd.sh
5c6c2a
index d0ea60d5..8607b568 100755
712866
--- a/modules.d/95fcoe/fcoe-edd.sh
712866
+++ b/modules.d/95fcoe/fcoe-edd.sh
712866
@@ -2,37 +2,55 @@
712866
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
712866
 # ex: ts=8 sw=4 sts=4 et filetype=sh
712866
 
712866
-dcb=$1
712866
+dcb="$1"
712866
 
712866
-if ! [ -d /sys/firmware/edd ]; then
712866
-    modprobe edd
712866
-    while ! [ -d /sys/firmware/edd ]; do sleep 0.1; done
712866
-fi
712866
+_modprobe_r_edd="0"
712866
+
712866
+check_edd() {
712866
+    local cnt=0
712866
+
712866
+    [ -d /sys/firmware/edd ] && return 0
712866
+
712866
+    _modprobe_r_edd="1"
712866
+    modprobe edd || return $?
712866
+
712866
+    while [ $cnt -lt 600 ]; do
712866
+        [ -d /sys/firmware/edd ] && return 0
712866
+        cnt=$(($cnt+1))
712866
+        sleep 0.1
712866
+    done
712866
+    return 1
712866
+}
712866
+
712866
+check_edd || exit 1
712866
 
712866
 for disk in /sys/firmware/edd/int13_*; do
712866
-    [ -d $disk ] || continue
712866
-    if [ -e ${disk}/pci_dev/driver ]; then
712866
-	    driver=`readlink ${disk}/pci_dev/driver`
712866
+    [ -d "$disk" ] || continue
712866
+    if [ -e "${disk}/pci_dev/driver" ]; then
712866
+	    driver=$(readlink "${disk}/pci_dev/driver")
712866
 	    driver=${driver##*/}
712866
     fi
712866
     # i40e uses dev_port 1 for a virtual fcoe function
712866
     if [ "${driver}" == "i40e" ]; then
712866
 	    dev_port=1
712866
     fi
712866
-    for nic in ${disk}/pci_dev/net/*; do
712866
-        [ -d $nic ] || continue
712866
-	if [ -n "${dev_port}" -a -e ${nic}/dev_port ]; then
712866
-		if [ `cat ${nic}/dev_port` -ne ${dev_port} ]; then
712866
+    for nic in "${disk}"/pci_dev/net/*; do
712866
+        [ -d "$nic" ] || continue
712866
+	if [ -n "${dev_port}" -a -e "${nic}/dev_port" ]; then
712866
+		if [ "$(cat ${nic}/dev_port)" -ne "${dev_port}" ]; then
712866
 			continue
712866
 		fi
712866
 	fi
712866
         if [ -e ${nic}/address ]; then
712866
 	    fcoe_interface=${nic##*/}
712866
 	    if ! [ -e "/tmp/.fcoe-$fcoe_interface" ]; then
712866
-		/sbin/fcoe-up $fcoe_interface $dcb
712866
+		/sbin/fcoe-up "$fcoe_interface" "$dcb"
712866
 		> "/tmp/.fcoe-$fcoe_interface"
712866
 	    fi
712866
         fi
712866
     done
712866
 done
712866
-modprobe -r edd
712866
+
712866
+[ "$_modprobe_r_edd" = "1" ] && modprobe -r edd
712866
+
712866
+unset _modprobe_r_edd