[ofa-general] [PATCH 1/7] use lookup_switch_name for all node types.
Ira Weiny
weiny2 at llnl.gov
Thu Nov 1 20:14:56 PDT 2007
>From f451c7b352b44747d1eb6f4627109a3f12b757e6 Mon Sep 17 00:00:00 2001
From: Ira K. Weiny <weiny2 at llnl.gov>
Date: Wed, 31 Oct 2007 16:22:12 -0700
Subject: [PATCH] use lookup_switch_name for all node types.
Signed-off-by: Ira K. Weiny <weiny2 at llnl.gov>
---
infiniband-diags/src/ibnetdiscover.c | 39 +++++++++++----------------------
infiniband-diags/src/ibtracert.c | 24 +++++---------------
infiniband-diags/src/saquery.c | 10 +++-----
infiniband-diags/src/smpquery.c | 6 +---
4 files changed, 25 insertions(+), 54 deletions(-)
diff --git a/infiniband-diags/src/ibnetdiscover.c b/infiniband-diags/src/ibnetdiscover.c
index e627e84..fd824c0 100644
--- a/infiniband-diags/src/ibnetdiscover.c
+++ b/infiniband-diags/src/ibnetdiscover.c
@@ -459,13 +459,9 @@ void
list_node(Node *node)
{
char *node_type;
- char *nodename = NULL;
-
- if (node->type == SWITCH_NODE)
- nodename = lookup_switch_name(switch_map_fp, node->nodeguid,
+ char *nodename = lookup_switch_name(switch_map_fp, node->nodeguid,
node->nodedesc);
- else
- nodename = clean_nodedesc(node->nodedesc);
+
switch(node->type) {
case SWITCH_NODE:
node_type = "Switch";
@@ -485,8 +481,7 @@ list_node(Node *node)
node->nodeguid, node->numports, node->devid, node->vendid,
nodename);
- if (nodename && (node->type == SWITCH_NODE))
- free(nodename);
+ free(nodename);
}
void
@@ -541,18 +536,16 @@ out_switch(Node *node, int group, char *chname)
fprintf(f, "%d Chip %d", node->chrecord->slotnum, node->chrecord->anafanum);
}
- if (node->type == SWITCH_NODE)
- nodename = lookup_switch_name(switch_map_fp, node->nodeguid,
+ nodename = lookup_switch_name(switch_map_fp, node->nodeguid,
node->nodedesc);
- else
- nodename = clean_nodedesc(node->nodedesc);
+
fprintf(f, "\nSwitch\t%d %s\t\t# \"%s\" %s port 0 lid %d lmc %d\n",
node->numports, node_name(node),
nodename,
node->smaenhsp0 ? "enhanced" : "base",
node->smalid, node->smalmc);
- if (nodename && (node->type == SWITCH_NODE))
- free(nodename);
+
+ free(nodename);
}
void
@@ -612,12 +605,9 @@ out_switch_port(Port *port, int group)
if (ext_port_str)
fprintf(f, "%s", ext_port_str);
- if (port->remoteport->node->type == SWITCH_NODE)
- rem_nodename = lookup_switch_name(switch_map_fp,
+ rem_nodename = lookup_switch_name(switch_map_fp,
port->remoteport->node->nodeguid,
port->remoteport->node->nodedesc);
- else
- rem_nodename = clean_nodedesc(port->remoteport->node->nodedesc);
ext_port_str = out_ext_port(port->remoteport, group);
fprintf(f, "\t%s[%d]%s",
@@ -638,8 +628,7 @@ out_switch_port(Port *port, int group)
fprintf(f, " (scp)");
fprintf(f, "\n");
- if (rem_nodename && (port->remoteport->node->type == SWITCH_NODE))
- free(rem_nodename);
+ free(rem_nodename);
}
void
@@ -660,19 +649,17 @@ out_ca_port(Port *port, int group)
if (port->remoteport->node->type != SWITCH_NODE)
fprintf(f, " (%" PRIx64 ") ", port->remoteport->portguid);
- if (port->remoteport->node->type == SWITCH_NODE)
- rem_nodename = lookup_switch_name(switch_map_fp,
+ rem_nodename = lookup_switch_name(switch_map_fp,
port->remoteport->node->nodeguid,
port->remoteport->node->nodedesc);
- else
- rem_nodename = clean_nodedesc(port->remoteport->node->nodedesc);
+
fprintf(f, "\t\t# lid %d lmc %d \"%s\" lid %d %s%s\n",
port->lid, port->lmc, rem_nodename,
port->remoteport->node->type == SWITCH_NODE ? port->remoteport->node->smalid : port->remoteport->lid,
get_linkwidth_str(port->linkwidth),
get_linkspeed_str(port->linkspeed));
- if (rem_nodename && (port->remoteport->node->type == SWITCH_NODE))
- free(rem_nodename);
+
+ free(rem_nodename);
}
int
diff --git a/infiniband-diags/src/ibtracert.c b/infiniband-diags/src/ibtracert.c
index e553f4f..5cf8043 100644
--- a/infiniband-diags/src/ibtracert.c
+++ b/infiniband-diags/src/ibtracert.c
@@ -204,10 +204,7 @@ dump_endnode(int dump, char *prompt, Node *node, Port *port)
return;
}
- if (node->type == IB_NODE_SWITCH)
- nodename = lookup_switch_name(switch_map_fp, node->nodeguid, node->nodedesc);
- else
- nodename = clean_nodedesc(node->nodedesc);
+ nodename = lookup_switch_name(switch_map_fp, node->nodeguid, node->nodedesc);
fprintf(f, "%s %s {0x%016" PRIx64 "} portnum %d lid 0x%x-0x%x \"%s\"\n",
prompt,
@@ -216,8 +213,7 @@ dump_endnode(int dump, char *prompt, Node *node, Port *port)
port->lid, port->lid + (1 << port->lmc) - 1,
nodename);
- if (nodename && (node->type == IB_NODE_SWITCH))
- free(nodename);
+ free(nodename);
}
static void
@@ -228,10 +224,7 @@ dump_route(int dump, Node *node, int outport, Port *port)
if (!dump && !verbose)
return;
- if (node->type == IB_NODE_SWITCH)
- nodename = lookup_switch_name(switch_map_fp, node->nodeguid, node->nodedesc);
- else
- nodename = clean_nodedesc(node->nodedesc);
+ nodename = lookup_switch_name(switch_map_fp, node->nodeguid, node->nodedesc);
if (dump == 1)
fprintf(f, "[%d] -> {0x%016" PRIx64 "}[%d]\n",
@@ -244,8 +237,7 @@ dump_route(int dump, Node *node, int outport, Port *port)
port->lid, port->lid + (1 << port->lmc) - 1,
nodename);
- if (nodename && (node->type == IB_NODE_SWITCH))
- free(nodename);
+ free(nodename);
}
static int
@@ -644,10 +636,7 @@ dump_mcpath(Node *node, int dumplevel)
if (node->upnode)
dump_mcpath(node->upnode, dumplevel);
- if (node->type == IB_NODE_SWITCH)
- nodename = lookup_switch_name(switch_map_fp, node->nodeguid, node->nodedesc);
- else
- nodename = clean_nodedesc(node->nodedesc);
+ nodename = lookup_switch_name(switch_map_fp, node->nodeguid, node->nodedesc);
if (!node->dist) {
printf("From %s 0x%" PRIx64 " port %d lid 0x%x-0x%x \"%s\"\n",
@@ -681,8 +670,7 @@ dump_mcpath(Node *node, int dumplevel)
nodename);
free_name:
- if (nodename && (node->type == IB_NODE_SWITCH))
- free(nodename);
+ free(nodename);
}
static void
diff --git a/infiniband-diags/src/saquery.c b/infiniband-diags/src/saquery.c
index e17ec5a..dfcc61a 100644
--- a/infiniband-diags/src/saquery.c
+++ b/infiniband-diags/src/saquery.c
@@ -136,13 +136,11 @@ print_node_record(ib_node_record_t *node_record)
return;
case NAME_OF_LID:
case NAME_OF_GUID:
- if (p_ni->node_type == IB_NODE_TYPE_SWITCH)
- name = lookup_switch_name(switch_map_fp,
- cl_ntoh64(p_ni->node_guid),
- (char *)p_nd->description);
- else
- name = clean_nodedesc((char *)p_nd->description);
+ name = lookup_switch_name(switch_map_fp,
+ cl_ntoh64(p_ni->node_guid),
+ (char *)p_nd->description);
printf("%s\n", name);
+ free(name);
return;
case ALL:
default:
diff --git a/infiniband-diags/src/smpquery.c b/infiniband-diags/src/smpquery.c
index 73e880b..7d09e35 100644
--- a/infiniband-diags/src/smpquery.c
+++ b/infiniband-diags/src/smpquery.c
@@ -107,10 +107,7 @@ node_desc(ib_portid_t *dest, char **argv, int argc)
if (!smp_query(nd, dest, IB_ATTR_NODE_DESC, 0, 0))
return "node desc query failed";
- if (node_type == IB_NODE_SWITCH)
- nodename = lookup_switch_name(switch_map_fp, node_guid, nd);
- else
- nodename = clean_nodedesc(nd);
+ nodename = lookup_switch_name(switch_map_fp, node_guid, nd);
l = strlen(nodename);
if (l < 32) {
@@ -119,6 +116,7 @@ node_desc(ib_portid_t *dest, char **argv, int argc)
}
printf("Node Description:%s%s\n", dots, nodename);
+ free(nodename);
return 0;
}
--
1.5.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-use-lookup_switch_name-for-all-node-types.patch
Type: application/octet-stream
Size: 7415 bytes
Desc: not available
URL: <http://lists.openfabrics.org/pipermail/general/attachments/20071101/f9d1c619/attachment.obj>
More information about the general
mailing list