ibclearerrors.in revision 219820
1#!/bin/sh
2
3IBPATH=${IBPATH:-@IBSCRIPTPATH@}
4
5function 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
11function user_abort() {
12	echo "Aborted"
13	exit 1
14}
15
16trap user_abort SIGINT
17
18gflags=""
19verbose=""
20v=0
21oldlid=""
22topofile=""
23ca_info=""
24
25while [ "$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
56done
57
58if [ "$topofile" ]; then
59	netcmd="cat $topofile"
60else
61	netcmd="$IBPATH/ibnetdiscover $ca_info"
62fi
63
64text="`eval $netcmd`"
65rv=$?
66echo "$text" | awk '
67
68function clear_all_errors(lid, port)
69{
70	if (system("'$IBPATH'/perfquery'"$ca_info"' '$gflags' -R -a " lid " " port " 0x0fff"))
71		nodeerr++
72}
73
74function 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
107END {
108	printf "\n## Summary: %d nodes cleared %d errors\n", nnodes, nodeerr
109}
110'
111exit $rv
112