From patchwork Fri Nov 9 21:55:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Chu X-Patchwork-Id: 1722441 X-Patchwork-Delegate: alexne@voltaire.com Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 5679D3FDD2 for ; Fri, 9 Nov 2012 21:55:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755905Ab2KIVzZ (ORCPT ); Fri, 9 Nov 2012 16:55:25 -0500 Received: from prdiron-2.llnl.gov ([128.15.143.172]:32245 "EHLO prdiron-2.llnl.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755578Ab2KIVzZ (ORCPT ); Fri, 9 Nov 2012 16:55:25 -0500 X-Attachments: Received: from auk59.llnl.gov (HELO [134.9.93.24]) ([134.9.93.24]) by prdiron-2.llnl.gov with ESMTP; 09 Nov 2012 13:55:24 -0800 Subject: [PATCH] opensm: Add better error output when parsing node name maps From: Albert Chu To: linux-rdma@vger.kernel.org Date: Fri, 09 Nov 2012 13:55:24 -0800 Message-Id: <1352498124.25353.139.camel@auk59.llnl.gov> Mime-Version: 1.0 X-Mailer: Evolution 2.12.3 (2.12.3-19.el5) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 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 --- 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 #include #include +#include #include +#include + +#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); +}