#!/usr/sbin/sh # # Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. # # # This script is used to reconfigure fabric device(s) which were configured # prior to boot. The fcadm command used below is an expert level command # and has a restrictive usage for boot time reconfiguration of fabric # devices. # # DO NOT USE the command for any other purpose. # PATH=/usr/bin:/usr/sbin # # Translate from old NPIV physical path format fp@x,0 to new format fp@0,x. # Prints translated path or nothing if not in the correct format. # function translate_npiv_path { echo "$1" | sed -n 's/fp@\([0-9a-f]\{1,\}\),0:fc$/fp@0,\1:fc/p' } # # Translate from old NPIV physical path fp@x,0 to physical path of physical # port fp@0,0. Prints translated path or nothing if not in the correct format. # function npiv_phys_port_path { echo "$1" | sed -n 's/fp@[0-9a-f]\{1,\},0:fc$/fp@0,0:fc/p' } # # Get physical port WWN from /devices path. # Prints port WWN or nothing if not found. # function get_port_wwn_by_path { typeset ppath="$1" typeset cfgpath= typeset physpath= typeset pwwn= fcinfo hba-port | egrep 'HBA Port WWN|OS Device Name' | \ cut -d ':' -f 2 | while read pwwn; do read cfgpath physpath="$(readlink "$cfgpath")" if [ "$physpath" = "$ppath" ] ; then echo $pwwn return fi done } # # Determine if physical port has NPIV ports configured. # Returns 0 if port has NPIV ports configured, != 0 if not. # function port_has_npiv_ports { typeset pwwn="$1" svcprop -p npiv-port-list/port_list network/npiv_config | \ grep "$pwwn" >/dev/null 2>&1 } # # Check if argument is an NPIV port path in old format and if so, # translate it to the new format. Prints translated path or nothing # if this is not an NPIV port path. # # Returns 0 if it made any changes, != 0 otherwise. # function check_translate_npiv_path { typeset vpath="$1" typeset ppath= typeset pwwn= # Get /devices path of physical port ppath="$(npiv_phys_port_path "$vpath")" if [ -z "$ppath" ] || [ "$ppath" = "$vpath" ] ; then return 1 fi # Get WWN of physical port pwwn="$(get_port_wwn_by_path "$ppath")" if [ -z "$pwwn" ] ; then return 1 fi # Check NPIV port(s) are configured for physical port port_has_npiv_ports "$pwwn" if [ $? -ne 0 ] ; then return 1 fi # We will assume that we actually have an NPIV port since # NPIV ports and multiple-ports-per-FCA-node do not mix translate_npiv_path "$vpath" return 0 } # # Upgrade /dev/cfg/c* symlinks for NPIV ports from old format fp@x,0 to # new format fp@0,x. # function upgrade_npiv_links { typeset changed="false" typeset lname= typeset lnew= typeset ltgt= typeset upgraded= # Check if already upgraded upgraded="$(svccfg -s svc:/network/npiv_config:default listprop \ -o value general/linkupd 2>/dev/null)" if [ $? -eq 0 ] && [ "$upgraded" = " true" ] ; then return fi # Update devlinks for lname in /dev/cfg/c*; do if [ -L "$lname" ] ; then ltgt="$(readlink "$lname")" lnew="$(check_translate_npiv_path "$ltgt")" if [ $? -eq 0 ] ; then rm "$lname" ln -s "$lnew" "$lname" changed="true" fi fi done # Update devlink cache before creating NPIV ports if [ "$changed" = "true" ] ; then devfsadm -i fp fi svccfg -s svc:/network/npiv_config:default setprop general/linkupd = \ boolean: true } upgrade_npiv_links fcadm create-port-list