[ofa-general] [PATCH 2/6] Move switch map out of infiniband-diags and into ibcommon

Ira Weiny weiny2 at llnl.gov
Thu Oct 25 11:43:25 PDT 2007


>From 65777220855baea12d4b7f961daca85765614f4a Mon Sep 17 00:00:00 2001
From: Ira K. Weiny <weiny2 at llnl.gov>
Date: Fri, 19 Oct 2007 11:43:01 -0700
Subject: [PATCH] Move switch map out of infiniband-diags and into ibcommon


Signed-off-by: Ira K. Weiny <weiny2 at llnl.gov>
---
 infiniband-diags/configure.in            |   26 ---------
 infiniband-diags/include/ibdiag_common.h |   13 -----
 infiniband-diags/src/ibdiag_common.c     |   82 -----------------------------
 libibcommon/configure.in                 |   26 +++++++++
 libibcommon/include/infiniband/common.h  |   15 +++++
 libibcommon/src/libibcommon.map          |    4 ++
 libibcommon/src/util.c                   |   83 ++++++++++++++++++++++++++++++
 7 files changed, 128 insertions(+), 121 deletions(-)

diff --git a/infiniband-diags/configure.in b/infiniband-diags/configure.in
index 95c7b34..a24d478 100644
--- a/infiniband-diags/configure.in
+++ b/infiniband-diags/configure.in
@@ -72,32 +72,6 @@ AC_CHECK_FUNCS([strchr strrchr strtol strtoul memset])
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
 
-dnl Check for the specification of a default switch map file
-AC_MSG_CHECKING(for --with-switch-map )
-AC_ARG_WITH(switch-map,
-    AC_HELP_STRING([--with-switch-map=file],
-                   [define a default switch map file]),
-    [ case "$withval" in
-    no)
-        ;;
-    *)
-        withswitchmap=yes
-        SWITCHMAPFILE=$withval
-        ;;
-    esac ]
-)
-AC_MSG_RESULT(${withswitchmap=no})
-
-if test $withswitchmap = "yes"; then
-   SWITCHMAP_TMP1="`eval echo ${sysconfdir}/$SWITCHMAPFILE`"
-   SWITCHMAP_TMP2="`echo $SWITCHMAP_TMP1 | sed 's/^NONE/$ac_default_prefix/'`"
-   SWITCHMAP="`eval echo $SWITCHMAP_TMP2`"
-
-   AC_DEFINE_UNQUOTED(HAVE_DEFAULT_SWITCH_MAP,
-	         ["$SWITCHMAP"],
-	         [Define a default switch map file])
-fi
-
 dnl Check for perl and perl install location
 AC_MSG_CHECKING(for --with-perl-path )
 AC_ARG_WITH(perl-path,
diff --git a/infiniband-diags/include/ibdiag_common.h b/infiniband-diags/include/ibdiag_common.h
index 159e929..029d80e 100644
--- a/infiniband-diags/include/ibdiag_common.h
+++ b/infiniband-diags/include/ibdiag_common.h
@@ -45,16 +45,6 @@ extern int   ibdebug;
 /*                External interface                      */
 /*========================================================*/
 
-/**
- * Switch map interface.
- * It is OK to pass NULL for the switch_map[_fp] parameters.
- */
-FILE *open_switch_map(char *switch_map);
-void  close_switch_map(FILE *switch_map_fp);
-char *lookup_switch_name(FILE *switch_map_fp, uint64_t target_guid,
-			char *nodedesc);
-	/* NOTE: parameter "nodedesc" may be modified here. */
-
 #undef DEBUG
 #define	DEBUG	if (ibdebug || verbose) IBWARN
 #define	VERBOSE	if (ibdebug || verbose > 1) IBWARN
@@ -62,9 +52,6 @@ char *lookup_switch_name(FILE *switch_map_fp, uint64_t target_guid,
 
 void  iberror(const char *fn, char *msg, ...);
 
-/* NOTE: this modifies the parameter "nodedesc". */
-char *clean_nodedesc(char *nodedesc);
-
 #ifdef __BUILD_VERSION_TAG__
 
 #define stringify(s) to_string(s)
diff --git a/infiniband-diags/src/ibdiag_common.c b/infiniband-diags/src/ibdiag_common.c
index bfddfd7..68e90b2 100644
--- a/infiniband-diags/src/ibdiag_common.c
+++ b/infiniband-diags/src/ibdiag_common.c
@@ -51,73 +51,6 @@
 
 int ibdebug;
 
-FILE *
-open_switch_map(char *switch_map)
-{
-	FILE *rc = NULL;
-
-	if (switch_map != NULL) {
-		rc = fopen(switch_map, "r");
-		if (rc == NULL) {
-			fprintf(stderr,
-				"WARNING failed to open switch map \"%s\" (%s)\n",
-				switch_map, strerror(errno));
-		}
-#ifdef HAVE_DEFAULT_SWITCH_MAP
-	} else {
-		rc = fopen(HAVE_DEFAULT_SWITCH_MAP, "r");
-#endif /* HAVE_DEFAULT_SWITCH_MAP */
-	}
-	return (rc);
-}
-
-void
-close_switch_map(FILE *fp)
-{
-	if (fp)
-		fclose(fp);
-}
-
-char *
-lookup_switch_name(FILE *switch_map_fp, uint64_t target_guid, char *nodedesc)
-{
-#define NAME_LEN (256)
-	char     *line = NULL;
-	size_t    len = 0;
-	uint64_t  guid = 0;
-	char     *rc = NULL;
-	int       line_count = 0;
-
-	if (switch_map_fp == NULL)
-		goto done;
-
-	rewind(switch_map_fp);
-	for (line_count = 1;
-		getline(&line, &len, switch_map_fp) != -1;
-		line_count++) {
-		line[len-1] = '\0';
-		if (line[0] == '#')
-			goto next_one;
-		char *guid_str = strtok(line, "\"#");
-		char *name = strtok(NULL, "\"#");
-		if (!guid_str || !name)
-			goto next_one;
-		guid = strtoull(guid_str, NULL, 0);
-		if (target_guid == guid) {
-			rc = strdup(name);
-			free (line);
-			goto done;
-		}
-next_one:
-		free (line);
-		line = NULL;
-	}
-done:
-	if (rc == NULL)
-		rc = strdup(clean_nodedesc(nodedesc));
-	return (rc);
-}
-
 void
 iberror(const char *fn, char *msg, ...)
 {
@@ -140,18 +73,3 @@ iberror(const char *fn, char *msg, ...)
 
 	exit(-1);
 }
-
-char *
-clean_nodedesc(char *nodedesc)
-{
-	int i = 0;
-
-	nodedesc[63] = '\0';
-	while (nodedesc[i]) {
-		if (!isprint(nodedesc[i]))
-			nodedesc[i] = ' ';
-		i++;
-	}
-
-	return (nodedesc);
-}
diff --git a/libibcommon/configure.in b/libibcommon/configure.in
index 2e896a0..c9dcf78 100644
--- a/libibcommon/configure.in
+++ b/libibcommon/configure.in
@@ -48,5 +48,31 @@ AC_CACHE_CHECK(whether ld accepts --version-script, ac_cv_version_script,
 
 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$ac_cv_version_script" = "yes")
 
+dnl Check for the specification of a default switch map file
+AC_MSG_CHECKING(for --with-switch-map )
+AC_ARG_WITH(switch-map,
+    AC_HELP_STRING([--with-switch-map=file],
+                   [define a default switch map file]),
+    [ case "$withval" in
+    no)
+        ;;
+    *)
+        withswitchmap=yes
+        SWITCHMAPFILE=$withval
+        ;;
+    esac ]
+)
+AC_MSG_RESULT(${withswitchmap=no})
+
+if test $withswitchmap = "yes"; then
+   SWITCHMAP_TMP1="`eval echo ${sysconfdir}/$SWITCHMAPFILE`"
+   SWITCHMAP_TMP2="`echo $SWITCHMAP_TMP1 | sed 's/^NONE/$ac_default_prefix/'`"
+   SWITCHMAP="`eval echo $SWITCHMAP_TMP2`"
+
+   AC_DEFINE_UNQUOTED(HAVE_DEFAULT_SWITCH_MAP,
+	         ["$SWITCHMAP"],
+	         [Define a default switch map file])
+fi
+
 AC_CONFIG_FILES([Makefile libibcommon.spec])
 AC_OUTPUT
diff --git a/libibcommon/include/infiniband/common.h b/libibcommon/include/infiniband/common.h
index 4eb3872..bd78f41 100644
--- a/libibcommon/include/infiniband/common.h
+++ b/libibcommon/include/infiniband/common.h
@@ -126,6 +126,21 @@ void	logmsg(const char *const fn, char *msg, ...) IBCOMMON_STRICT_FORMAT;
 
 void	xdump(FILE *file, char *msg, void *p, int size);
 
+/* NOTE: this modifies the parameter "nodedesc". */
+char *clean_nodedesc(char *nodedesc);
+
+/**
+ * Switch map interface.
+ * It is OK to pass NULL for the switch_map[_fp] parameters.
+ */
+FILE *open_switch_map(char *switch_map);
+void  close_switch_map(FILE *switch_map_fp);
+char *lookup_switch_name(FILE *switch_map_fp, uint64_t target_guid,
+			char *nodedesc);
+	/* NOTE: parameter "nodedesc" may be modified here.
+	 *       return pointer must be free'd by caller
+	 */
+
 /* sysfs.c: /sys utilities */
 int	sys_read_string(char *dir_name, char *file_name, char *str, int max_len);
 int	sys_read_guid(char *dir_name, char *file_name, uint64_t *net_guid);
diff --git a/libibcommon/src/libibcommon.map b/libibcommon/src/libibcommon.map
index 96ce2d8..afd8e6d 100644
--- a/libibcommon/src/libibcommon.map
+++ b/libibcommon/src/libibcommon.map
@@ -13,5 +13,9 @@ IBCOMMON_1.0 {
 		ibpanic;
 		ibwarn;
 		xdump;
+		clean_nodedesc;
+		open_switch_map;
+		close_switch_map;
+		lookup_switch_name;
 	local: *;
 };
diff --git a/libibcommon/src/util.c b/libibcommon/src/util.c
index 7da967e..e2f45f4 100644
--- a/libibcommon/src/util.c
+++ b/libibcommon/src/util.c
@@ -133,3 +133,86 @@ xdump(FILE *file, char *msg, void *p, int size)
                 fputc('\n', file);
         }
 }
+
+char *
+clean_nodedesc(char *nodedesc)
+{
+	int i = 0;
+
+	nodedesc[63] = '\0';
+	while (nodedesc[i]) {
+		if (!isprint(nodedesc[i]))
+			nodedesc[i] = ' ';
+		i++;
+	}
+
+	return (nodedesc);
+}
+
+FILE *
+open_switch_map(char *switch_map)
+{
+	FILE *rc = NULL;
+
+	if (switch_map != NULL) {
+		rc = fopen(switch_map, "r");
+		if (rc == NULL) {
+			fprintf(stderr,
+				"WARNING failed to open switch map \"%s\" (%s)\n",
+				switch_map, strerror(errno));
+		}
+#ifdef HAVE_DEFAULT_SWITCH_MAP
+	} else {
+		rc = fopen(HAVE_DEFAULT_SWITCH_MAP, "r");
+#endif /* HAVE_DEFAULT_SWITCH_MAP */
+	}
+	return (rc);
+}
+
+void
+close_switch_map(FILE *fp)
+{
+	if (fp)
+		fclose(fp);
+}
+
+char *
+lookup_switch_name(FILE *switch_map_fp, uint64_t target_guid, char *nodedesc)
+{
+#define NAME_LEN (256)
+	char     *line = NULL;
+	size_t    len = 0;
+	uint64_t  guid = 0;
+	char     *rc = NULL;
+	int       line_count = 0;
+
+	if (switch_map_fp == NULL)
+		goto done;
+
+	rewind(switch_map_fp);
+	for (line_count = 1;
+		getline(&line, &len, switch_map_fp) != -1;
+		line_count++) {
+		line[len-1] = '\0';
+		if (line[0] == '#')
+			goto next_one;
+		char *guid_str = strtok(line, "\"#");
+		char *name = strtok(NULL, "\"#");
+		if (!guid_str || !name)
+			goto next_one;
+		guid = strtoull(guid_str, NULL, 0);
+		if (target_guid == guid) {
+			rc = strdup(name);
+			free (line);
+			goto done;
+		}
+next_one:
+		free (line);
+		line = NULL;
+	}
+done:
+	if (rc == NULL)
+		rc = strdup(clean_nodedesc(nodedesc));
+	return (rc);
+}
+
-- 
1.5.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Move-switch-map-out-of-infiniband-diags-and-into-ibc.patch
Type: application/octet-stream
Size: 9346 bytes
Desc: not available
URL: <http://lists.openfabrics.org/pipermail/general/attachments/20071025/9d49594e/attachment.obj>


More information about the general mailing list