2 * Copyright (c) 2008 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2007 Lawrence Livermore National Lab
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41 #include <sys/types.h>
49 #include <complib/cl_nodenamemap.h>
51 static int map_name(void *cxt, uint64_t guid, char *p)
54 name_map_item_t *item;
60 item = malloc(sizeof(*item));
64 item->name = strdup(p);
65 cl_qmap_insert(map, item->guid, (cl_map_item_t *)item);
70 open_node_name_map(char *node_name_map)
75 #ifdef HAVE_DEFAULT_NODENAME_MAP
77 node_name_map = HAVE_DEFAULT_NODENAME_MAP;
78 if (stat(node_name_map, &buf))
82 #endif /* HAVE_DEFAULT_NODENAME_MAP */
85 map = malloc(sizeof(*map));
90 if (parse_node_map(node_name_map, map_name, map)) {
92 "WARNING failed to open node name map \"%s\" (%s)\n",
93 node_name_map, strerror(errno));
94 close_node_name_map(map);
102 close_node_name_map(nn_map_t *map)
104 name_map_item_t *item = NULL;
109 item = (name_map_item_t *)cl_qmap_head(map);
110 while (item != (name_map_item_t *)cl_qmap_end(map)) {
111 item = (name_map_item_t *)cl_qmap_remove(map, item->guid);
114 item = (name_map_item_t *)cl_qmap_head(map);
120 remap_node_name(nn_map_t *map, uint64_t target_guid, char *nodedesc)
123 name_map_item_t *item = NULL;
128 item = (name_map_item_t *)cl_qmap_get(map, target_guid);
129 if (item != (name_map_item_t *)cl_qmap_end(map))
130 rc = strdup(item->name);
134 rc = strdup(clean_nodedesc(nodedesc));
139 clean_nodedesc(char *nodedesc)
144 while (nodedesc[i]) {
145 if (!isprint(nodedesc[i]))
153 int parse_node_map(const char *file_name,
154 int (*create)(void *, uint64_t, char *), void *cxt)
159 if (!(f = fopen(file_name, "r")))
162 while (fgets(line, sizeof(line), f)) {
169 if (*p == '\0' || *p == '\n' || *p == '#')
172 guid = strtoull(p, &e, 0);
173 if (e == p || (!isspace(*e) && *e != '#' && *e != '\0')) {
182 e = strpbrk(p, "\n");
186 if (create(cxt, guid, p)) {