]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ofed/management/infiniband-diags/scripts/ibclearerrors.in
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ofed / management / infiniband-diags / scripts / ibclearerrors.in
1 #!/bin/sh
2
3 IBPATH=${IBPATH:-@IBSCRIPTPATH@}
4
5 function usage() {
6         echo Usage: `basename $0` "[-h] [-N | -nocolor] [<topology-file>" \
7             "| -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 oldlid=""
22 topofile=""
23 ca_info=""
24
25 while [ "$1" ]; do
26         case $1 in
27         -h)
28                 usage
29                 ;;
30         -N|-nocolor)
31                 gflags=-N
32                 ;;
33         -P | -C | -t | -timeout)
34                 case $2 in
35                 -*)
36                         usage
37                         ;;
38                 esac
39                 if [ x$2 = x ] ; then
40                         usage
41                 fi
42                 ca_info="$ca_info $1 $2"
43                 shift
44                 ;;
45         -*)
46                 usage
47                 ;;
48         *)
49                 if [ "$topofile" ]; then
50                         usage
51                 fi
52                 topofile="$1"
53                 ;;
54         esac
55         shift
56 done
57
58 if [ "$topofile" ]; then
59         netcmd="cat $topofile"
60 else
61         netcmd="$IBPATH/ibnetdiscover $ca_info"
62 fi
63
64 text="`eval $netcmd`"
65 rv=$?
66 echo "$text" | awk '
67
68 function clear_all_errors(lid, port)
69 {
70         if (system("'$IBPATH'/perfquery'"$ca_info"' '$gflags' -R -a " lid " " port " 0x0fff"))
71                 nodeerr++
72 }
73
74 function clear_errors(lid, port)
75 {
76         if (system("'$IBPATH'/perfquery'"$ca_info"' '$gflags' -R " lid " " port " 0x0fff"))
77                 nodeerr++
78 }
79
80 /^Ca/ || /^Switch/ || /^Rt/ {
81                         nnodes++
82                         ntype=$1; nodeguid=substr($3, 4, 16); ports=$2
83                         if (ntype != "Switch")
84                                 next
85
86                         lid = substr($0, index($0, "port 0 lid ") + 11)
87                         lid = substr(lid, 1, index(lid, " ") - 1)
88                         clear_all_errors(lid, 255)
89                 }
90
91 /^\[/   {
92                         port = $1
93                         sub("\\(.*\\)", "", port)
94                         gsub("[\\[\\]]", "", port)
95                         if (ntype != "Switch") {
96                                 lid = substr($0, index($0, " lid ") + 5)
97                                 lid = substr(lid, 1, index(lid, " ") - 1)
98                                 clear_errors(lid, port)
99                         }
100                 }
101
102 /^ib/   {print $0; next}
103 /ibpanic:/      {print $0}
104 /ibwarn:/       {print $0}
105 /iberror:/      {print $0}
106
107 END {
108         printf "\n## Summary: %d nodes cleared %d errors\n", nnodes, nodeerr
109 }
110 '
111 exit $rv