Whamcloud - gitweb
LU-14646 flr: write a FLR file downgrade SoM
[fs/lustre-release.git] / lustre / scripts / lc_net.in
index d618c69..51f3c43 100644 (file)
@@ -1,4 +1,7 @@
 #!/bin/bash
+
+# vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
+
 #
 # lc_net - script for Lustre cluster network verification
 #
@@ -17,9 +20,9 @@ Usage:        `basename $0` [options] <csv file>
        -x hostname,hostname,...
                        exclude the specified list of nodes (separated by commas)
        -v              verbose mode
-       csv file        a spreadsheet that contains configuration parameters 
+       csv file        a spreadsheet that contains configuration parameters
                        (separated by commas) for each target in a Lustre cl-
-                       uster, the first field of each line is the host name 
+                       uster, the first field of each line is the host name
                        of the cluster node
 
 EOF
@@ -45,11 +48,11 @@ while getopts "aw:x:v" OPTION; do
                USE_ALLNODES=false
                EXCLUDED_NODELIST=$OPTARG
                ;;
-       v) 
+       v)
                VERBOSE_OUTPUT=true
                ;;
-        ?) 
-               usage 
+        ?)
+               usage
        esac
 done
 
@@ -58,7 +61,7 @@ shift  `expr $OPTIND - 1`
 
 # Here we expect the csv file
 if [ $# -eq 0 ]; then
-       echo >&2 $"`basename $0`: Missing csv file!"
+       error_output "Missing csv file!"
        usage
 fi
 
@@ -76,7 +79,7 @@ get_hostnames() {
 
        # Get the list of nodes to be operated on
        NODES_TO_USE=$(get_nodelist)
-       [ ${PIPESTATUS[0]} -ne 0 ] && echo >&2 "${NODES_TO_USE}" && return 1
+       [ ${PIPESTATUS[0]} -ne 0 ] && error_output "${NODES_TO_USE}" && return 1
 
        # Check the node list
        if [ -z "${NODES_TO_USE}" ]; then
@@ -92,7 +95,7 @@ get_hostnames() {
 }
 
 # ping_host host_name
-# Check whether host $host_name is reachable. 
+# Check whether host $host_name is reachable.
 # If it is, then return the IP address of this host.
 ping_host() {
        local host_name=$1
@@ -133,7 +136,7 @@ local_check() {
        # and get the IP address of this host from ping
        HOST_IPADDRS[i]=$(ping_host ${HOST_NAMES[i]})
        if [ ${PIPESTATUS[0]} -ne 0 ]; then
-               echo >&2 "${HOST_IPADDRS[i]}"
+               error_output "${HOST_IPADDRS[i]}"
                return 1
        fi
 
@@ -153,37 +156,33 @@ remote_check() {
        cmd="ping -c1 ${HOST_NAMES[i]} 2>&1"
        ret_str=$(${REMOTE} ${HOST_NAMES[i]} "${cmd}" 2>&1)
        if [ ${PIPESTATUS[0]} -ne 0 -a -n "${ret_str}" ]; then
-               echo >&2 "`basename $0`: remote_check() error:"\
+               error_output "remote_check():"\
                "remote to ${HOST_NAMES[i]} error: ${ret_str}!"
                return 1
        fi
 
        if [ -z "${ret_str}" ]; then
-               echo >&2 "`basename $0`: remote_check() error:"\
+               error_output "remote_check():"\
                "No results from ${HOST_NAMES[i]}! Check the network"\
                "connectivity between local host and ${HOST_NAMES[i]}!"
                return 1
        fi
 
        # Get the IP address of ${HOST_NAMES[i]} from its own ping
-       if is_pdsh; then
-               ip_addr=`echo "${ret_str}" | head -1 | awk '{print $4}'`
-       else
-               ip_addr=`echo "${ret_str}" | head -1 | awk '{print $3}'`
-       fi
-       ip_addr=`echo "${ip_addr}" | sed -e 's/^(//' -e 's/)$//'`
+       ip_pattern="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
+       ip_addr=`echo "${ret_str}" | egrep -m 1 -o "${ip_pattern}"`
 
        # Compare IP addresses
        # Check whether ${HOST_NAMES[i]} agrees with the local host
        # about what its name is resolved to.
        if [ "${ip_addr}" != "${HOST_IPADDRS[i]}" ]; then
-               echo >&2 "`basename $0`: remote_check() error:"\
+               error_output "remote_check():"\
                "Local host resolves ${HOST_NAMES[i]} to IP address"\
                "\"${HOST_IPADDRS[i]}\", while its own resolution is"\
                "\"${ip_addr}\". They are not the same!"
                return 1
        fi
-       
+
        return 0
 }
 
@@ -195,10 +194,10 @@ network_verify() {
        # Initialize the HOST_IPADDRS array
        unset HOST_IPADDRS
 
-       # Get all the host names to be operated on 
+       # Get all the host names to be operated on
        ! get_hostnames && return 1
 
-       # Check the network connectivity between local host 
+       # Check the network connectivity between local host
        # and other cluster nodes
        for ((i = 0; i < ${#HOST_NAMES[@]}; i++)); do
                [ "${HOST_NAMES[i]}" = "`hostname`" ] && continue
@@ -215,12 +214,12 @@ network_verify() {
 
 # Main flow
 if ! check_file ${CSV_FILE}; then
-       exit 1  
+       exit 1
 fi
 
 # Cluster network verification
 if ! network_verify; then
-       exit 1  
+       exit 1
 fi
 
 exit 0