All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] opensm: Add better error output when parsing node name maps
@ 2012-11-09 21:55 Albert Chu
       [not found] ` <1352498124.25353.139.camel-akkeaxHeDKRliZ7u+bvwcg@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Albert Chu @ 2012-11-09 21:55 UTC (permalink / raw)
  To: linux-rdma-u79uwXL29TY76Z2rM5mHXA

Presently, any error in opening a node name map file leads
to a generic:

"WARNING failed to open node name map"

error.  This patch adds better error output when the issue
is specifically parsing errors in the file.  The user
will get:

"WARNING failed to parse node name map"

and an output of the line with the particular issue.

Signed-off-by: Albert Chu <chu11-i2BcT+NCU+M@public.gmane.org>
---
 complib/cl_nodenamemap.c |   55 ++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 48 insertions(+), 7 deletions(-)

diff --git a/complib/cl_nodenamemap.c b/complib/cl_nodenamemap.c
index a99d46d..f47ad40 100644
--- a/complib/cl_nodenamemap.c
+++ b/complib/cl_nodenamemap.c
@@ -43,8 +43,18 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <config.h>
+#include <errno.h>
 
 #include <complib/cl_nodenamemap.h>
+#include <complib/cl_math.h>
+
+#define PARSE_NODE_MAP_BUFLEN  256
+
+static int parse_node_map_wrap(const char *file_name,
+			       int (*create)(void *, uint64_t, char *),
+			       void *cxt,
+			       char *linebuf,
+			       unsigned int linebuflen);
 
 static int map_name(void *cxt, uint64_t guid, char *p)
 {
@@ -67,6 +77,7 @@ static int map_name(void *cxt, uint64_t guid, char *p)
 nn_map_t *open_node_name_map(char *node_name_map)
 {
 	nn_map_t *map;
+	char linebuf[PARSE_NODE_MAP_BUFLEN + 1];
 
 	if (!node_name_map) {
 #ifdef HAVE_DEFAULT_NODENAME_MAP
@@ -84,10 +95,23 @@ nn_map_t *open_node_name_map(char *node_name_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));
+	memset(linebuf, '\0', PARSE_NODE_MAP_BUFLEN + 1);
+	if (parse_node_map_wrap(node_name_map, map_name, map,
+				linebuf, PARSE_NODE_MAP_BUFLEN)) {
+		if (errno == EIO) {
+			fprintf(stderr,
+				"WARNING failed to parse node name map "
+				"\"%s\"\n",
+				node_name_map);
+			fprintf(stderr,
+				"WARNING failed line: \"%s\"\n",
+				linebuf);
+		}
+		else
+			fprintf(stderr,
+				"WARNING failed to open node name map "
+				"\"%s\" (%s)\n",
+				node_name_map, strerror(errno));
 		close_node_name_map(map);
 		return NULL;
 	}
@@ -144,10 +168,13 @@ char *clean_nodedesc(char *nodedesc)
 	return (nodedesc);
 }
 
-int parse_node_map(const char *file_name,
-		   int (*create) (void *, uint64_t, char *), void *cxt)
+static int parse_node_map_wrap(const char *file_name,
+			       int (*create) (void *, uint64_t, char *),
+			       void *cxt,
+			       char *linebuf,
+			       unsigned int linebuflen)
 {
-	char line[256];
+	char line[PARSE_NODE_MAP_BUFLEN];
 	FILE *f;
 
 	if (!(f = fopen(file_name, "r")))
@@ -166,6 +193,14 @@ int parse_node_map(const char *file_name,
 		guid = strtoull(p, &e, 0);
 		if (e == p || (!isspace(*e) && *e != '#' && *e != '\0')) {
 			fclose(f);
+			errno = EIO;
+			if (linebuf) {
+				memcpy(linebuf, line,
+				       MIN(PARSE_NODE_MAP_BUFLEN, linebuflen));
+				e = strpbrk(linebuf, "\n");
+				if (e)
+					*e = '\0';
+			}
 			return -1;
 		}
 
@@ -186,3 +221,9 @@ int parse_node_map(const char *file_name,
 	fclose(f);
 	return 0;
 }
+
+int parse_node_map(const char *file_name,
+		   int (*create) (void *, uint64_t, char *), void *cxt)
+{
+	return parse_node_map_wrap(file_name, create, cxt, NULL, 0);
+}
-- 
1.7.1



--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] opensm: Add better error output when parsing node name maps
       [not found] ` <1352498124.25353.139.camel-akkeaxHeDKRliZ7u+bvwcg@public.gmane.org>
@ 2013-02-03 17:52   ` Alex Netes
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Netes @ 2013-02-03 17:52 UTC (permalink / raw)
  To: Albert Chu; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA

Hi Albert,

On 13:55 Fri 09 Nov     , Albert Chu wrote:
> Presently, any error in opening a node name map file leads
> to a generic:
> 
> "WARNING failed to open node name map"
> 
> error.  This patch adds better error output when the issue
> is specifically parsing errors in the file.  The user
> will get:
> 
> "WARNING failed to parse node name map"
> 
> and an output of the line with the particular issue.
> 
> Signed-off-by: Albert Chu <chu11-i2BcT+NCU+M@public.gmane.org>
> ---

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-02-03 17:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-09 21:55 [PATCH] opensm: Add better error output when parsing node name maps Albert Chu
     [not found] ` <1352498124.25353.139.camel-akkeaxHeDKRliZ7u+bvwcg@public.gmane.org>
2013-02-03 17:52   ` Alex Netes

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.