[ofw] [PATCH] complib: add cl_nodenamemap

Sean Hefty sean.hefty at intel.com
Tue Feb 24 17:05:41 PST 2009


The ib-diags make use of a 'node name map' that was added to the OFED
version of complib.  Add cl_nodenamemap to the WinOF version of complib.

This patch relies on the linux compatibility header patch.  The imported
code is basically a direct import of the  OFED code, with an include file
change.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
And we've now reached the sad the state where the OS abstraction
layer uses abstracted calls.

diff -up -r -X trunk\docs\dontdiff.txt -I '\$Id:' -N trunk\core\complib/user/cl_nodenamemap.c
branches\winverbs\core\complib/user/cl_nodenamemap.c
--- trunk\core\complib/user/cl_nodenamemap.c	1969-12-31 16:00:00.000000000 -0800
+++ branches\winverbs\core\complib/user/cl_nodenamemap.c	2009-02-24 16:49:44.122986600 -0800
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2008 Voltaire, Inc. All rights reserved.
+ * Copyright (c) 2007 Lawrence Livermore National Lab
+ * Copyright (c) 2009 Intel Corp., Inc.
+ *
+ * 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.
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <_string.h>
+#include <stdlib.h>
+
+#include <complib/cl_nodenamemap.h>
+
+static int map_name(void *cxt, uint64_t guid, char *p)
+{
+	cl_qmap_t *map = cxt;
+	name_map_item_t *item;
+
+	p = strtok(p, "\"#");
+	if (!p)
+		return 0;
+
+	item = malloc(sizeof(*item));
+	if (!item)
+		return -1;
+	item->guid = guid;
+	item->name = strdup(p);
+	cl_qmap_insert(map, item->guid, (cl_map_item_t *)item);
+	return 0;
+}
+
+nn_map_t *
+open_node_name_map(char *node_name_map)
+{
+	nn_map_t *map;
+
+	if (!node_name_map) {
+#ifdef HAVE_DEFAULT_NODENAME_MAP
+		struct stat buf;
+		node_name_map = HAVE_DEFAULT_NODENAME_MAP;
+		if (stat(node_name_map, &buf))
+			return NULL;
+#else
+		return NULL;
+#endif /* HAVE_DEFAULT_NODENAME_MAP */
+	}
+
+	map = malloc(sizeof(*map));
+	if (!map)
+		return NULL;
+	cl_qmap_init(map);
+
+	if (parse_node_map(node_name_map, map_name, map)) {
+		fprintf(stderr,
+			"WARNING failed to open node name map \"%s\" (%s)\n",
+			node_name_map, strerror(errno));
+			close_node_name_map(map);
+			return NULL;
+	}
+
+	return map;
+}
+
+void
+close_node_name_map(nn_map_t *map)
+{
+	name_map_item_t *item = NULL;
+
+	if (!map)
+		return;
+
+	item = (name_map_item_t *)cl_qmap_head(map);
+	while (item != (name_map_item_t *)cl_qmap_end(map)) {
+		item = (name_map_item_t *)cl_qmap_remove(map, item->guid);
+		free(item->name);
+		free(item);
+		item = (name_map_item_t *)cl_qmap_head(map);
+	}
+	free(map);
+}
+
+char *
+remap_node_name(nn_map_t *map, uint64_t target_guid, char *nodedesc)
+{
+	char *rc = NULL;
+	name_map_item_t *item = NULL;
+
+	if (!map)
+		goto done;
+
+	item = (name_map_item_t *)cl_qmap_get(map, target_guid);
+	if (item != (name_map_item_t *)cl_qmap_end(map))
+		rc = strdup(item->name);
+
+done:
+	if (rc == NULL)
+		rc = strdup(clean_nodedesc(nodedesc));
+	return (rc);
+}
+
+char *
+clean_nodedesc(char *nodedesc)
+{
+	int i = 0;
+
+	nodedesc[63] = '\0';
+	while (nodedesc[i]) {
+		if (!isprint(nodedesc[i]))
+			nodedesc[i] = ' ';
+		i++;
+	}
+
+	return (nodedesc);
+}
+
+int parse_node_map(const char *file_name,
+		   int (*create)(void *, uint64_t, char *), void *cxt)
+{
+	char line[256];
+	FILE *f;
+
+	if (!(f = fopen(file_name, "r")))
+		return -1;
+
+	while (fgets(line, sizeof(line), f)) {
+		uint64_t guid;
+		char *p, *e;
+
+		p = line;
+		while (isspace(*p))
+			p++;
+		if (*p == '\0' || *p == '\n' || *p == '#')
+			continue;
+
+		guid = strtoull(p, &e, 0);
+		if (e == p || (!isspace(*e) && *e != '#' && *e != '\0')) {
+			fclose(f);
+			return -1;
+		}
+
+		p = e;
+		while (isspace(*p))
+			p++;
+
+		e = strpbrk(p, "\n");
+		if (e)
+			*e = '\0';
+
+		if (create(cxt, guid, p)) {
+			fclose(f);
+			return -1;
+		}
+	}
+
+	fclose(f);
+	return 0;
+}
diff -up -r -X trunk\docs\dontdiff.txt -I '\$Id:' -N trunk\core\complib/user/complib.src
branches\winverbs\core\complib/user/complib.src
--- trunk\core\complib/user/complib.src	2008-02-21 00:45:47.706414500 -0800
+++ branches\winverbs\core\complib/user/complib.src	2009-02-18 15:14:08.436091500 -0800
@@ -290,4 +290,9 @@ cl_waitobj_destroy
 cl_waitobj_signal
 cl_waitobj_reset
 cl_waitobj_wait_on
+clean_nodedesc
+open_node_name_map
+close_node_name_map
+remap_node_name
+parse_node_map
 #endif
diff -up -r -X trunk\docs\dontdiff.txt -I '\$Id:' -N trunk\core\complib/user/SOURCES branches\winverbs\core\complib/user/SOURCES
--- trunk\core\complib/user/SOURCES	2008-04-30 12:42:25.228625000 -0700
+++ branches\winverbs\core\complib/user/SOURCES	2009-02-24 16:58:38.455539800 -0800
@@ -25,6 +25,7 @@ SOURCES=\
 	cl_syscallback.c	\
 	cl_thread.c			\
 	cl_timer.c			\
+	cl_nodenamemap.c	\
 	..\cl_async_proc.c	\
 	..\cl_list.c		\
 	..\cl_map.c			\
@@ -38,7 +39,7 @@ SOURCES=\
 	..\cl_threadpool.c	\
 	..\cl_vector.c		\
 
-INCLUDES=..\..\..\inc;..\..\..\inc\user;
+INCLUDES=..\..\..\inc;..\..\..\inc\user;..\..\..\inc\user\linux;
 
 USER_C_FLAGS=$(USER_C_FLAGS) -DEXPORT_CL_SYMBOLS
 
diff -up -r -N -X trunk\docs\dontdiff.txt -I '\$Id:' trunk\inc\complib/cl_nodenamemap.h
branches\winverbs\inc\complib/cl_nodenamemap.h
--- trunk\inc\complib/cl_nodenamemap.h	1969-12-31 16:00:00.000000000 -0800
+++ branches\winverbs\inc\complib/cl_nodenamemap.h	2009-02-18 15:13:24.873312700 -0800
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2008 Voltaire, Inc. All rights reserved.
+ * Copyright (c) 2007 Lawrence Livermore National Lab
+ *
+ * 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.
+ *
+ */
+
+#ifndef _CL_NODE_NAME_MAP_H_
+#define _CL_NODE_NAME_MAP_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdio.h>
+#include <complib/cl_qmap.h>
+
+/* NOTE: this may modify the parameter "nodedesc". */
+CL_EXPORT char *clean_nodedesc(char *nodedesc);
+
+typedef struct _name_map_item {
+	cl_map_item_t item;
+	uint64_t guid;
+	char *name;
+} name_map_item_t;
+
+typedef cl_qmap_t nn_map_t;
+
+/**
+ * Node name map interface.
+ * It is OK to pass NULL for the node_name_map[_fp] parameters.
+ */
+CL_EXPORT nn_map_t * CL_API open_node_name_map(char *node_name_map);
+CL_EXPORT void  CL_API close_node_name_map(nn_map_t *map);
+CL_EXPORT char * CL_API remap_node_name(nn_map_t *map, uint64_t target_guid,
+			char *nodedesc);
+	/* NOTE: parameter "nodedesc" may be modified here. */
+CL_EXPORT int CL_API parse_node_map(const char *file_name,
+		   int (*create)(void *, uint64_t, char *), void *cxt);
+
+#ifdef __cplusplus
+}	/* extern "C" */
+#endif
+
+#endif				/* _CL_NODE_NAME_MAP_H_ */
diff -up -r -N -X trunk\docs\dontdiff.txt -I '\$Id:' trunk\inc\user\linux/_string.h branches\winverbs\inc\user\linux/_string.h
--- trunk\inc\user\linux/_string.h	2009-02-24 16:56:27.294730000 -0800
+++ branches\winverbs\inc\user\linux/_string.h	2009-02-24 16:48:41.847242700 -0800
@@ -39,5 +39,6 @@
 #define strdup _strdup
 #define strdupa _strdup
 #define strncasecmp _strnicmp
+#define strtoull _strtoui64
 
 #endif	/* __STRING_H_ */





More information about the ofw mailing list