]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ofed/management/infiniband-diags/scripts/ibcheckstate.in
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ofed / management / infiniband-diags / scripts / ibcheckstate.in
1 #!/bin/sh
2
3 IBPATH=${IBPATH:-@IBSCRIPTPATH@}
4
5 function usage() {
6         echo Usage: `basename $0` "[-h] [-v] [-N | -nocolor]" \
7             "[<topology-file> | -C ca_name -P ca_port -t(imeout) timeout_ms]"
8         exit -1
9 }
10
11 function user_abort() {
12         echo "Aborted"
13         exit 1
14 }
15
16 trap user_abort SIGINT
17
18 gflags=""
19 verbose=""
20 v=0
21 ntype=""
22 nodeguid=""
23 oldlid=""
24 topofile=""
25 ca_info=""
26
27 while [ "$1" ]; do
28         case $1 in
29         -h)
30                 usage
31                 ;;
32         -N|-nocolor)
33                 gflags=-N
34                 ;;
35         -v)
36                 verbose=-v
37                 v=1
38                 ;;
39         -P | -C | -t | -timeout)
40                 case $2 in
41                 -*)
42                         usage
43                         ;;
44                 esac
45                 if [ x$2 = x ] ; then
46                         usage
47                 fi
48                 ca_info="$ca_info $1 $2"
49                 shift
50                 ;;
51         -*)
52                 usage
53                 ;;
54         *)
55                 if [ "$topofile" ]; then
56                         usage
57                 fi
58                 topofile="$1"
59                 ;;
60         esac
61         shift
62 done
63
64 if [ "$topofile" ]; then
65         netcmd="cat $topofile"
66 else
67         netcmd="$IBPATH/ibnetdiscover $ca_info"
68 fi
69
70 text="`eval $netcmd`"
71 rv=$?
72 echo "$text" | awk '
73 BEGIN {
74         ne=0
75         pe=0
76 }
77 function check_node(lid)
78 {
79         nodechecked=1
80         if (system("'$IBPATH'/ibchecknode'"$ca_info"' '$gflags' '$verbose' " lid)) {
81                 ne++
82                 badnode=1
83                 return
84         }
85 }
86
87 /^Ca/ || /^Switch/ || /^Rt/ {
88                         nnodes++
89                         ntype=$1; nodeguid=substr($3, 4, 16); ports=$2
90                         if ('$v')
91                                 print "\n# Checking " ntype ": nodeguid 0x" nodeguid
92
93                         nodechecked=0
94                         badnode=0
95                         if (ntype != "Switch")
96                                 next
97
98                         lid = substr($0, index($0, "port 0 lid ") + 11)
99                         lid = substr(lid, 1, index(lid, " ") - 1)
100                         check_node(lid)
101                 }
102 /^\[/   {
103                 nports++
104                 port = $1
105                 if (!nodechecked) {
106                         lid = substr($0, index($0, " lid ") + 5)
107                         lid = substr(lid, 1, index(lid, " ") - 1)
108                         check_node(lid)
109                 }
110                 if (badnode) {
111                         print "\n# " ntype ": nodeguid 0x" nodeguid " failed"
112                         next
113                 }
114                 sub("\\(.*\\)", "", port)
115                 gsub("[\\[\\]]", "", port)
116                 if (system("'$IBPATH'/ibcheckportstate'"$ca_info"' '$gflags' '$verbose' " lid " " port)) {
117                         if (!'$v' && oldlid != lid) {
118                                 print "# Checked " ntype ": nodeguid 0x" nodeguid " with failure"
119                                 oldlid = lid
120                         }
121                         pe++;
122                 }
123 }
124
125 /^ib/   {print $0; next}
126 /ibpanic:/      {print $0}
127 /ibwarn:/       {print $0}
128 /iberror:/      {print $0}
129
130 END {
131         printf "\n## Summary: %d nodes checked, %d bad nodes found\n", nnodes, ne
132         printf "##          %d ports checked, %d ports with bad state found\n", nports, pe
133 }
134 '
135 exit $rv