* [PATCH] infiniband-diags: saquery; clean up name/lid processing
@ 2011-03-25 0:52 Ira Weiny
0 siblings, 0 replies; only message in thread
From: Ira Weiny @ 2011-03-25 0:52 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
[-- Attachment #1: Type: text/plain, Size: 1981 bytes --]
For NodeRecord querys in particular if a name was not found all NodeRecords
were printed. Correct behavior is to report "node not found".
Signed-off-by: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
---
src/saquery.c | 27 +++++++++++++++++++--------
1 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/src/saquery.c b/src/saquery.c
index 18c5a1c..532116f 100644
--- a/src/saquery.c
+++ b/src/saquery.c
@@ -48,7 +48,6 @@
#include <ctype.h>
#include <string.h>
#include <errno.h>
-#include <assert.h>
#define _GNU_SOURCE
#include <getopt.h>
@@ -891,6 +890,7 @@ static int get_lid_from_name(bind_handle_t h, const char *name, uint16_t * lid)
if (ret)
return ret;
+ ret = IB_NOT_FOUND;
for (i = 0; i < result.result_cnt; i++) {
node_record = get_query_rec(result.p_result_madw, i);
p_ni = &(node_record->node_info);
@@ -899,11 +899,12 @@ static int get_lid_from_name(bind_handle_t h, const char *name, uint16_t * lid)
sizeof(node_record->node_desc.description)) ==
0) {
*lid = cl_ntoh16(node_record->lid);
+ ret = IB_SUCCESS;
break;
}
}
return_mad();
- return 0;
+ return ret;
}
static uint16_t get_lid(bind_handle_t h, const char *name)
@@ -912,12 +913,22 @@ static uint16_t get_lid(bind_handle_t h, const char *name)
if (!name)
return 0;
- if (isalpha(name[0]))
- assert(get_lid_from_name(h, name, &rc_lid) == IB_SUCCESS);
- else
- rc_lid = (uint16_t) atoi(name);
- if (rc_lid == 0)
- fprintf(stderr, "Failed to find lid for \"%s\"\n", name);
+ if (isalpha(name[0])) {
+ if (get_lid_from_name(h, name, &rc_lid) != IB_SUCCESS) {
+ fprintf(stderr, "Failed to find lid for \"%s\"\n", name);
+ exit(EINVAL);
+ }
+ } else {
+ long val;
+ errno = 0;
+ val = strtol(name, NULL, 0);
+ if (errno != 0 || val <= 0 || val > UINT16_MAX) {
+ fprintf(stderr, "Invalid lid specified: \"%s\"\n", name);
+ exit(EINVAL);
+ }
+ rc_lid = (uint16_t)val;
+ }
+
return rc_lid;
}
--
1.5.4.5
[-- Attachment #2: 0001-infiniband-diags-saquery-clean-up-name-lid-process.patch --]
[-- Type: application/octet-stream, Size: 2176 bytes --]
From f84627d8775d2789e828777ce89d12819f01c7b0 Mon Sep 17 00:00:00 2001
From: Ira Weiny <weiny2@llnl.gov>
Date: Thu, 17 Mar 2011 17:34:52 -0700
Subject: [PATCH] infiniband-diags: saquery; clean up name/lid processing
For NodeRecord querys in particular if a name was not found all NodeRecords
were printed. Correct behavior is to report "node not found".
Signed-off-by: Ira Weiny <weiny2@llnl.gov>
---
src/saquery.c | 27 +++++++++++++++++++--------
1 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/src/saquery.c b/src/saquery.c
index 18c5a1c..532116f 100644
--- a/src/saquery.c
+++ b/src/saquery.c
@@ -48,7 +48,6 @@
#include <ctype.h>
#include <string.h>
#include <errno.h>
-#include <assert.h>
#define _GNU_SOURCE
#include <getopt.h>
@@ -891,6 +890,7 @@ static int get_lid_from_name(bind_handle_t h, const char *name, uint16_t * lid)
if (ret)
return ret;
+ ret = IB_NOT_FOUND;
for (i = 0; i < result.result_cnt; i++) {
node_record = get_query_rec(result.p_result_madw, i);
p_ni = &(node_record->node_info);
@@ -899,11 +899,12 @@ static int get_lid_from_name(bind_handle_t h, const char *name, uint16_t * lid)
sizeof(node_record->node_desc.description)) ==
0) {
*lid = cl_ntoh16(node_record->lid);
+ ret = IB_SUCCESS;
break;
}
}
return_mad();
- return 0;
+ return ret;
}
static uint16_t get_lid(bind_handle_t h, const char *name)
@@ -912,12 +913,22 @@ static uint16_t get_lid(bind_handle_t h, const char *name)
if (!name)
return 0;
- if (isalpha(name[0]))
- assert(get_lid_from_name(h, name, &rc_lid) == IB_SUCCESS);
- else
- rc_lid = (uint16_t) atoi(name);
- if (rc_lid == 0)
- fprintf(stderr, "Failed to find lid for \"%s\"\n", name);
+ if (isalpha(name[0])) {
+ if (get_lid_from_name(h, name, &rc_lid) != IB_SUCCESS) {
+ fprintf(stderr, "Failed to find lid for \"%s\"\n", name);
+ exit(EINVAL);
+ }
+ } else {
+ long val;
+ errno = 0;
+ val = strtol(name, NULL, 0);
+ if (errno != 0 || val <= 0 || val > UINT16_MAX) {
+ fprintf(stderr, "Invalid lid specified: \"%s\"\n", name);
+ exit(EINVAL);
+ }
+ rc_lid = (uint16_t)val;
+ }
+
return rc_lid;
}
--
1.5.4.5
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2011-03-25 0:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-25 0:52 [PATCH] infiniband-diags: saquery; clean up name/lid processing Ira Weiny
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox