]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/ofed/management/infiniband-diags/scripts/ibcheckerrors.in
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / ofed / management / infiniband-diags / scripts / ibcheckerrors.in
1 #!/bin/sh
2
3 IBPATH=${IBPATH:-@IBSCRIPTPATH@}
4
5 function usage() {
6         echo Usage: `basename $0` "[-h] [-b] [-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 brief=""
21 v=0
22 ntype=""
23 nodeguid=""
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                 brief=""
38                 v=1
39                 ;;
40         -b)
41                 brief=-b
42                 verbose=""
43                 ;;
44         -P | -C | -t | -timeout)
45                 case $2 in
46                 -*)
47                         usage
48                         ;;
49                 esac
50                 if [ x$2 = x ] ; then
51                         usage
52                 fi
53                 ca_info="$ca_info $1 $2"
54                 shift
55                 ;;
56         -*)
57                 usage
58                 ;;
59         *)
60                 if [ "$topofile" ]; then
61                         usage
62                 fi
63                 topofile="$1"
64                 ;;
65         esac
66         shift
67 done
68
69 if [ "$topofile" ]; then
70         netcmd="cat $topofile"
71 else
72         netcmd="$IBPATH/ibnetdiscover $ca_info"
73 fi
74
75 text="`eval $netcmd`"
76 rv=$?
77 echo "$text" | awk '
78 BEGIN {
79         ne=0
80 }
81 function check_node(lid, port)
82 {
83         if (system("'$IBPATH'/ibchecknode '"$ca_info"' '$gflags' '$verbose' " lid)) {
84                 ne++
85                 print "\n# " ntype ": nodeguid 0x" nodeguid " failed"
86                 return 1;
87         }
88         if (system("'$IBPATH'/ibcheckerrs '"$ca_info"' '$gflags' '$verbose' '$brief' " lid " " port))
89                 return 2;
90         return 0;
91 }
92
93 /^Ca/ || /^Switch/ || /^Rt/ {
94                         nnodes++
95                         ntype=$1; nodeguid=substr($3, 4, 16); ports=$2
96                         if ('$v')
97                                 print "\n# Checking " ntype ": nodeguid 0x" nodeguid
98
99                         err = 0;
100                         if (ntype != "Switch")
101                                 next
102
103                         lid = substr($0, index($0, "port 0 lid ") + 11)
104                         lid = substr(lid, 1, index(lid, " ") - 1)
105                         err = check_node(lid, 255)
106                 }
107 /^\[/   {
108                 nports++
109                 port = $1
110                 sub("\\(.*\\)", "", port)
111                 gsub("[\\[\\]]", "", port)
112                 if (ntype != "Switch") {
113                         lid = substr($0, index($0, " lid ") + 5)
114                         lid = substr(lid, 1, index(lid, " ") - 1)
115                         if (check_node(lid, port) == 2)
116                                 pcnterr++;
117                 } else if (err &&
118                            system("'$IBPATH'/ibcheckerrs '"$ca_info"' '$gflags' '$verbose' '$brief' " lid " " port))
119                         pcnterr++;
120 }
121
122 /^ib/   {print $0; next}
123 /ibpanic:/      {print $0}
124 /ibwarn:/       {print $0}
125 /iberror:/      {print $0}
126
127 END {
128         printf "\n## Summary: %d nodes checked, %d bad nodes found\n", nnodes, ne
129         printf "##          %d ports checked, %d ports have errors beyond threshold\n", nports, pcnterr
130         exit (ne + pcnterr)
131 }
132 '
133 exit $rv