[ofw] [Patch] [Tools][infiniband-diags] ibclearerrors tool
Smith, Stan
stan.smith at intel.com
Wed Aug 4 09:38:27 PDT 2010
Hello,
Sean Hefty is the maintainer of the IB Diags code; he is currently on vacation.
All the corner cases look to be covered, I would recommend you SVN commit this.
Sean likes to keep the Windows source as 'close' as possible to the Linux source to ease the burden when updating source files.
Things like '__cdecl' for x86 are Windows only constructs and Sean likes to handle these with a patch.
When Sean returns the two of you can work out the minor details.
stan.
________________________________
From: ofw-bounces at lists.openfabrics.org [mailto:ofw-bounces at lists.openfabrics.org] On Behalf Of Irena Kruchkovsky
Sent: Wednesday, August 04, 2010 12:04 AM
To: ofw at lists.openfabrics.org
Subject: [ofw] [Patch] [Tools][infiniband-diags] ibclearerrors tool
A tool imported from Linux.
The tool runs perfquery on all the nodes that appear in ibnetdiscover output or in a given topology file.
Usage:
ibclearerrors [-h] [<topology-file> | -C ca_name -P ca_port -t timeout_ms]
h - Help (displays this message)
<topology-file> - should be in the format indicated by ibnetdiscover
ca_name - the name indicated by ibstat
Index: D:/Windows/MLNX_VPI/tools/infiniband-diags/src/ibclearerrors.c
===================================================================
--- D:/Windows/MLNX_VPI/tools/infiniband-diags/src/ibclearerrors.c (revision 0)
+++ D:/Windows/MLNX_VPI/tools/infiniband-diags/src/ibclearerrors.c (revision 6180)
@@ -0,0 +1,363 @@
+/*
+ * Copyright (c) 2004-2008 Voltaire Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <windows.h>
+#include <strsafe.h>
+#include <infiniband/umad.h>
+#include <infiniband/mad.h>
+
+#include "ibdiag_common.h"
+
+#define X_PARAMLEN 254
+#define X_LINELEN 4096
+#define X_TEMPFILE "ibnetdiscoverTMP.txt"
+#define X_TEMPFILELEN 20
+
+
+
+static void ShowUsage()
+{
+ printf( "ibclearerrors [-h] [<topology-file>" \
+ "| -C ca_name -P ca_port -t timeout_ms]\n"
+ "\th\t\t - Help (displays this message)\n"
+ "\t<topology-file>\t - should be in the format indicated by ibnetdiscover\n"
+ "\tca_name\t\t - the name indicated by ibstat\n");
+ exit(1);
+}
+
+static void printCopyError(char* copiedVal, HRESULT hr)
+{
+ if (hr == ERROR_INSUFFICIENT_BUFFER)
+ {
+ printf("The %s length is too long %08x.\n", copiedVal, hr);
+ }
+ else
+ {
+ printf("Error in getting the %s %08x.\n", copiedVal, hr);
+ }
+ exit(-1);
+}
+
+static int clearErrors(char* caInfo, char* lid, char* port, BOOL all)
+{
+ char usedCommand [ X_LINELEN ];
+ HRESULT hr;
+
+ if ((caInfo == NULL) ||
+ (lid == NULL) || (strlen(lid) <= 0)||
+ (port == NULL) || (strlen(port) <= 0))
+ {
+ return 1;
+ }
+
+ hr = StringCchPrintfEx(usedCommand,X_LINELEN,NULL,NULL,0,
+ "perfquery %s -R %s %s %s 0x0fff",
+ caInfo,
+ (all ? "-a" : ""),
+ lid,
+ port);
+ if (FAILED(hr))
+ {
+ StringCchPrintfEx(usedCommand,X_LINELEN,NULL,NULL,0,"used Command");
+ printCopyError(usedCommand,hr);
+ }
+
+ if (system(usedCommand))
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+static char* getLid(char* line, char* lidPrefix)
+{
+ //
+ //Get lid start position
+ //
+ char* lidStart = strstr(line, lidPrefix) + strlen(lidPrefix);
+
+ //
+ //Get the string from lidStart until the first position of a blank = exactly the lid
+ //
+ char* lid = strtok (lidStart," \t");
+
+ return lid;
+}
+
+int __cdecl main(int argc, char* argv[])
+{
+ char topofile[X_PARAMLEN];
+ BOOL topologyGiven = 0;
+
+ char caInfo[X_LINELEN];
+ BOOL caInfoGiven = 0;
+
+ int nodes = 0;
+ int errors = 0;
+
+ FILE *fp;
+ char line[X_LINELEN];
+ char templine[X_LINELEN];
+
+ int i;
+
+ char type[10];
+ char usedCommand[X_LINELEN];
+
+ HRESULT hr;
+
+ topofile[0] = '\0';
+
+ for( i = 1; i < argc; i++ )
+ {
+ char* pArg;
+ char* nextArg;
+
+ pArg = argv[i];
+
+ if (( *pArg != '-' ) && ( *pArg != '/' ))
+ {
+ if (strlen(topofile) == 0)
+ {
+ hr = HRESULT_CODE(StringCchCopyNExA(topofile,X_PARAMLEN,pArg,X_PARAMLEN,NULL,NULL,0));
+ if (FAILED(hr))
+ {
+ StringCchPrintfEx(topofile,X_PARAMLEN,NULL,NULL,0,"topofile");
+ printCopyError(topofile,hr);
+ }
+ topologyGiven = 1;
+ continue;
+ }
+ else
+ {
+ ShowUsage();
+ break;
+ }
+ }
+
+
+ // Skip leading dashes
+ while(( *pArg == '-' ) || ( *pArg == '/' ))
+ pArg++;
+
+ switch( *pArg )
+ {
+ case 'h':
+ case '?':
+ ShowUsage();
+ break;
+ case 'P':
+ case 'C':
+ case 't':
+ if( ++i == argc )
+ {
+ ShowUsage();
+ break;
+ }
+
+ nextArg = argv[i];
+ if( *nextArg == '-' )
+ {
+ ShowUsage();
+ break;
+ }
+
+ if (!caInfoGiven)
+ {
+ StringCchPrintfEx(caInfo,X_LINELEN,NULL,NULL,0,"");
+ }
+
+ hr = StringCchPrintfEx( caInfo,X_LINELEN,NULL,NULL,0,
+ "%s -%s %s",caInfo,pArg,nextArg);
+ if (FAILED(hr))
+ {
+ StringCchPrintfEx(caInfo,X_LINELEN,NULL,NULL,0,"caInfo");
+ printCopyError(caInfo,hr);
+ }
+
+ caInfoGiven = 1;
+ break;
+ default:
+ printf( "Unknown parameter %s\n", pArg );
+ ShowUsage();
+ }
+ }
+
+ //
+ // If a topology file was not given we will create one
+ //
+ if (!topologyGiven)
+ {
+ DWORD nPathLength = X_LINELEN+X_TEMPFILELEN;
+ char path[X_LINELEN+X_TEMPFILELEN];
+ int reqLen = GetTempPath(nPathLength, path);
+ if (reqLen > X_LINELEN)
+ {
+ printf("Obtaining a path to create temporary files failed\n");
+ exit(-1);
+ }
+
+ hr = StringCchPrintfEx( topofile,X_LINELEN,NULL,NULL,0,
+ "%s%s", path, X_TEMPFILE);
+ if (FAILED(hr))
+ {
+ StringCchPrintfEx(topofile,X_LINELEN,NULL,NULL,0,"topofile");
+ printCopyError(topofile,hr);
+ }
+
+ hr = StringCchPrintfEx( usedCommand,X_LINELEN,NULL,NULL,0,
+ "ibnetdiscover %s > %s",
+ caInfoGiven ? caInfo : "",
+ topofile );
+ if (FAILED(hr))
+ {
+ StringCchPrintfEx(usedCommand,X_LINELEN,NULL,NULL,0,"used Command");
+ printCopyError(usedCommand,hr);
+ }
+
+ if (system(usedCommand))
+ {
+ printf("ibnetdiscover execution failed (%d)\n", GetLastError() );
+ exit(1);
+ }
+ }
+
+ fp=fopen(topofile, "r");
+ if(fp == NULL)
+ {
+ printf("Cannot open file.\n");
+ exit(1);
+ }
+
+ while (fgets(line, X_LINELEN, fp) != NULL)
+ {
+ if (strstr( line, "Ca" ) == line ||
+ strstr( line, "Rt" ) == line ||
+ strstr( line, "Switch" ) == line)
+ {
+ nodes++;
+
+ //
+ //First word is the type (one of the above)
+ //
+ hr = HRESULT_CODE(StringCchCopyNExA(templine,X_LINELEN,line,X_LINELEN,NULL,NULL,0));
+ if (FAILED(hr))
+ {
+ StringCchPrintfEx(templine,X_LINELEN,NULL,NULL,0,"inner topology line");
+ printCopyError(templine,hr);
+ }
+
+ hr = HRESULT_CODE(StringCchCopyNExA(type,10,strtok (templine," \t"),10,NULL,NULL,0));
+ if (FAILED(hr))
+ {
+ StringCchPrintfEx(type,10,NULL,NULL,0,"type");
+ printCopyError(type,hr);
+ }
+
+ }
+
+
+ if (strstr( line, "Switch" ) == line)
+ {
+ errors += clearErrors( caInfoGiven ? caInfo : "",
+ getLid(line,"port 0 lid "),
+ "255",
+ 1 );
+ }
+
+ if (*line == '[')
+ {
+ char* port;
+
+ hr = HRESULT_CODE(StringCchCopyNExA(templine,X_LINELEN,line,X_LINELEN,NULL,NULL,0));
+ if (FAILED(hr))
+ {
+ StringCchPrintfEx(templine,X_LINELEN,NULL,NULL,0,"inner topology line");
+ printCopyError(templine,hr);
+ }
+
+ port = strtok (templine,"[]"); //First word is the port in []
+
+ if (strcmp(type,"Switch") != 0) //Got it from the previous line
+ {
+ errors += clearErrors( caInfoGiven ? caInfo : "",
+ getLid(line," lid "),
+ port,
+ 0 );
+ }
+ }
+
+ if (strstr( line, "ib" ) == line)
+ {
+ printf("%s\n", line);
+ }
+ }
+
+ printf ("\n## Summary: %d nodes cleared %d errors\n", nodes, errors);
+ fclose (fp);
+
+ //
+ // If we created our own topology file - we sould delete it
+ //
+ if (strstr( topofile, X_TEMPFILE ))
+ {
+ hr = StringCchPrintfEx( usedCommand,X_LINELEN,NULL,NULL,0, "del %s", topofile );
+ if (FAILED(hr))
+ {
+ StringCchPrintfEx(usedCommand,X_LINELEN,NULL,NULL,0,"used Command");
+ printCopyError(usedCommand,hr);
+ }
+
+ if (system(usedCommand))
+ {
+ printf("Temporary file cleanup failed\n");
+ exit(1);
+ }
+ }
+
+ return 0;
+}
+
+
+
+
Index: D:/Windows/MLNX_VPI/tools/infiniband-diags/src/ibclearerrors/ibclearerrors.rc
===================================================================
--- D:/Windows/MLNX_VPI/tools/infiniband-diags/src/ibclearerrors/ibclearerrors.rc (revision 0)
+++ D:/Windows/MLNX_VPI/tools/infiniband-diags/src/ibclearerrors/ibclearerrors.rc (revision 6180)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.
+ *
+ * This software is available to you under the OpenIB.org BSD license
+ * below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $Id$
+ */
+
+
+#include <oib_ver.h>
+
+#define VER_FILETYPE VFT_APP
+#define VER_FILESUBTYPE VFT2_UNKNOWN
+
+#ifdef DBG
+#define VER_FILEDESCRIPTION_STR "InfiniBand Fabric Clear Errors(Debug)"
+#else
+#define VER_FILEDESCRIPTION_STR "InfiniBand Fabric Clear Errors"
+#endif
+
+#define VER_INTERNALNAME_STR "ibclearerrors.exe"
+#define VER_ORIGINALFILENAME_STR "ibclearerrors.exe"
+
+#include <common.ver>
Index: D:/Windows/MLNX_VPI/tools/infiniband-diags/src/ibclearerrors/SOURCES
===================================================================
--- D:/Windows/MLNX_VPI/tools/infiniband-diags/src/ibclearerrors/SOURCES (revision 0)
+++ D:/Windows/MLNX_VPI/tools/infiniband-diags/src/ibclearerrors/SOURCES (revision 6180)
@@ -0,0 +1,31 @@
+TARGETNAME = ibclearerrors
+TARGETPATH = ..\..\..\..\bin\user\obj$(BUILD_ALT_DIR)
+TARGETTYPE = PROGRAM
+
+UMTYPE = console
+UMENTRY = main
+
+USE_MSVCRT = 1
+
+SOURCES = ..\ibclearerrors.c ibclearerrors.rc
+
+INCLUDES = ..\..\include;..\..\include\windows;\
+ ..\..\..\..\ulp\libibmad\include;\
+ ..\..\..\..\ulp\libibumad\include;\
+ ..\..\..\..\inc;..\..\..\..\inc\user;\
+ ..\..\..\..\inc\user\linux;
+
+C_DEFINES = $(C_DEFINES) /DHAVE_CONFIG_H
+
+TARGETLIBS = \
+ $(SDK_LIB_PATH)\kernel32.lib \
+ $(SDK_LIB_PATH)\ws2_32.lib \
+!if $(FREEBUILD)
+ $(TARGETPATH)\*\libibmad.lib \
+ $(TARGETPATH)\*\libibumad.lib
+!else
+ $(TARGETPATH)\*\libibmadd.lib \
+ $(TARGETPATH)\*\libibumadd.lib
+!endif
+
+MSC_WARNING_LEVEL = /W3 /WX /wd4007
Index: D:/Windows/MLNX_VPI/tools/infiniband-diags/src/ibclearerrors/makefile
===================================================================
--- D:/Windows/MLNX_VPI/tools/infiniband-diags/src/ibclearerrors/makefile (revision 0)
+++ D:/Windows/MLNX_VPI/tools/infiniband-diags/src/ibclearerrors/makefile (revision 6180)
@@ -0,0 +1,7 @@
+#
+# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
+# file to this component. This file merely indirects to the real make file
+# that is shared by all the driver components of the OpenIB Windows project.
+#
+
+!INCLUDE ..\..\..\..\inc\openib.def
Index: D:/Windows/MLNX_VPI/tools/infiniband-diags/src/dirs
===================================================================
--- D:/Windows/MLNX_VPI/tools/infiniband-diags/src/dirs (revision 6179)
+++ D:/Windows/MLNX_VPI/tools/infiniband-diags/src/dirs (revision 6180)
@@ -16,4 +16,5 @@
sminfo \
smpdump \
smpquery \
- vendstat
\ No newline at end of file
+ vendstat \
+ ibclearerrors
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20100804/43097245/attachment.html>
More information about the ofw
mailing list