"Fossies" - the Fresh Open Source Software Archive

Member "open-fcoe-3.19/fcoe-utils/contrib/fcoe_edd.sh" (15 Apr 2015, 5363 Bytes) of package /linux/misc/open-fcoe-3.19.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 
    3 # Script to read EDD information from sysfs and
    4 # echo the FCoE interface name and target info.
    5 # This is a work in progress and will be enhanced
    6 # with more options as we progress further.
    7 #
    8 # Author: Supreeth Venkataraman
    9 #     Yi Zou
   10 #         Intel Corporation
   11 #
   12 # Usage: fcoe_edd.sh -t for getting FCoE boot target information.
   13 #        fcoe_edd.sh -i for getting FCoE boot NIC name.
   14 #        fcoe_edd.sh -m for getting FCoE boot NIC MAC.
   15 #        fcoe_edd.sh -e for getting FCoE boot EDD information.
   16 #        fcoe_edd.sh -r for getting FCoE boot EDD interface type and path.
   17 #        fcoe_edd.sh -a for getting all FCoE boot information.
   18 #        fcoe_edd.sh -h for usage information.
   19 #        Optional: use -v to turn on verbose mode.
   20 #
   21 # Notes:
   22 # FCoE Boot Disk is identified by the following format of boot information
   23 # in its corresponding sysfs firmware edd entry, i.e.,
   24 #   /sys/firmware/edd/int13_dev??/interface
   25 # which is formatted as (for FCoE):
   26 # string format: FIBRE wwid: 8c1342b8a0001620 lun: 7f00
   27 # Please ref. to T13 BIOS Enhanced Disk Drive Specification v3.0 for more
   28 # defails on EDD.
   29 #
   30 
   31 SYSEDD=/sys/firmware/edd
   32 PREFIX="FIBRE"
   33 VERBOSE=
   34 FCOE_INF=
   35 FCOE_WWN=
   36 FCOE_LUN=
   37 FCOE_EDD=
   38 FCOE_NIC=
   39 FCOE_MAC=
   40 
   41 
   42 #
   43 #
   44 #
   45 LOG() {
   46     if [ -n "$1" ] && [ -n "${VERBOSE}" ]; then
   47         echo "LOG:$1"
   48     fi
   49 }
   50 
   51 
   52 find_fcoe_boot_disk() {
   53     local prefix=
   54 
   55     if [ ! -e $SYSEDD ]; then
   56         LOG "Need kernel EDD support!"
   57         return 1
   58     fi
   59 #   for disk in `find ${SYSEDD} -maxdepth 1 -name 'int13*'`
   60     for disk in ${SYSEDD}/int13_*
   61     do
   62         LOG " checking $disk..."
   63         if [ ! -e ${disk}/interface ]; then
   64             continue;
   65         fi
   66         LOG " checking ${disk}/interface..."
   67         prefix=`awk '{printf $1}' < ${disk}/interface`
   68         if [ "${PREFIX}" != "${prefix}" ]; then
   69             LOG " The FCoE Boot prefix ${prefix} is invalid!"
   70             continue;
   71         fi
   72         FCOE_INF=`cat ${disk}/interface`
   73         LOG " found FCoE boot info. from boot rom:${FCOE_INF}..."
   74 
   75         FCOE_WWN=`awk '{printf $3}' < ${disk}/interface`
   76         if [ ${#FCOE_WWN} -ne 16 ]; then
   77             LOG " The FCoE Boot WWID ${FCOE_WWN} is invalid!"
   78             continue;
   79         fi
   80         FCOE_LUN=`awk '{printf $5}' < ${disk}/interface`
   81         if [ -z "${#FCOE_LUN}" ]; then
   82             LOG " The FCoE Boot LUN ${FCOE_WWN} is invalid!"
   83             continue;
   84         fi
   85         # look for the correponding nic
   86         # FIXME:
   87         # 1) only supporst PCI device?
   88         # 2) at initrd time, the nic name is always eth*?
   89         if [ ! -e ${disk}/pci_dev ]; then
   90             LOG "Failed to locate the corresponing PCI device!"
   91             continue;
   92         fi
   93         if [ ! -e ${disk}/pci_dev/net ]; then
   94             LOG "Failed to detect any NIC device!"
   95             continue;
   96         fi
   97 
   98         for nic in ${disk}/pci_dev/net/*
   99         do
  100             if [ -e ${nic}/address ]; then
  101                 FCOE_MAC=`cat ${nic}/address`
  102                 FCOE_NIC=$(basename ${nic})
  103                 break;
  104             fi
  105         done
  106         if [ -z "${FCOE_MAC}" ] || [ -z "${FCOE_NIC}" ]; then
  107             LOG "Failed to locate the corresponing NIC device!"
  108             continue;
  109         fi
  110         # Found the FCoE Boot Device
  111         FCOE_EDD=$(basename ${disk})
  112         return 0;
  113     done
  114     return 1
  115 }
  116 
  117 get_fcoe_boot_all(){
  118     echo "### FCoE Boot Information ###"
  119     echo "EDD=${FCOE_EDD}"
  120     echo "INF=${FCOE_INF}"
  121     echo "WWN=${FCOE_WWN}"
  122     echo "LUN=${FCOE_LUN}"
  123     echo "NIC=${FCOE_NIC}"
  124     echo "MAC=${FCOE_MAC}"
  125     return 0
  126 }
  127 
  128 get_fcoe_boot_target() {
  129     if [ -z "${FCOE_WWN}" ] || [ -z "${FCOE_LUN}" ]; then
  130         LOG "No FCoE Boot Target information is found!"
  131         return 1
  132     fi
  133     echo "WWN=${FCOE_WWN}"
  134     echo "LUN=${FCOE_LUN}"
  135 }
  136 
  137 get_fcoe_boot_inf(){
  138     if [ -z "${FCOE_INF}" ]; then
  139         LOG "No FCoE Boot INF information is found!"
  140         return 1
  141     fi
  142     echo "INF=${FCOE_INF}"
  143     return 0
  144 }
  145 
  146 get_fcoe_boot_mac(){
  147     if [ -z "${FCOE_MAC}" ]; then
  148         LOG "No FCoE Boot NIC MAC information is found!"
  149         return 1
  150     fi
  151     echo "MAC=${FCOE_MAC}"
  152     return 0
  153 }
  154 
  155 get_fcoe_boot_ifname(){
  156     if [ -z "${FCOE_NIC}" ]; then
  157         LOG "No FCoE Boot NIC information is found!"
  158         return 1
  159     fi
  160     echo "NIC=${FCOE_NIC}"
  161     return 0
  162 }
  163 
  164 get_fcoe_boot_edd(){
  165     if [ -z "${FCOE_EDD}" ]; then
  166         LOG "No FCoE Boot Disk EDD information is found!"
  167         return 1
  168     fi
  169     echo "EDD=${FCOE_EDD}"
  170     return 0
  171 }
  172 
  173 
  174 # parse options
  175 prog=$(basename $0)
  176 while getopts "timeravh" OptionName; do
  177     case "$OptionName" in
  178         t)
  179         action=get_fcoe_boot_target
  180         ;;
  181         i)
  182         action=get_fcoe_boot_ifname
  183         ;;
  184         m)
  185         action=get_fcoe_boot_mac
  186         ;;
  187         e)
  188         action=get_fcoe_boot_edd
  189         ;;
  190         r)
  191         action=get_fcoe_boot_inf
  192         ;;
  193     a)
  194         action=get_fcoe_boot_all
  195         ;;
  196     v)
  197         VERBOSE="yes"
  198         ;;
  199         h)
  200         echo "Usage: ${prog} -t for getting FCoE boot target information."
  201         echo "       ${prog} -i for getting FCoE boot NIC name."
  202         echo "       ${prog} -m for getting FCoE boot NIC MAC."
  203         echo "       ${prog} -e for getting FCoE boot EDD information."
  204         echo "       ${prog} -r for getting FCoE boot EDD interface type and path."
  205         echo "       ${prog} -a for getting all FCoE boot information."
  206         echo "       ${prog} -h for usage information."
  207         echo "       Optional: use -v to turn on verbose mode."
  208         exit 0
  209         ;;
  210         *)
  211         echo "Invalid Option. Use -h option for help."
  212         exit 1
  213         ;;
  214     esac
  215 done
  216 if [ -z "${action}" ]; then
  217     echo "Must specify at least -t, -i, -m, -e, -r, -a, or -h."
  218     echo "Use -h option for help."
  219     exit 1
  220 fi
  221 # Locate FCoE boot disk and nic information
  222 find_fcoe_boot_disk
  223 if [ $? -ne 0 ]; then
  224     echo "No FCoE boot disk information is found in EDD!"
  225     exit 1
  226 fi
  227 if [ -z "${FCOE_EDD}" ]; then
  228     echo "No FCoE boot disk is found in EDD!"
  229     exit 1;
  230 fi
  231 
  232 ${action}
  233 
  234 exit $?