public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libibmad: Add setting of errno on function failure
       [not found] ` <515678FE.9010503-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
@ 2013-03-30 16:53   ` Boris Chiu
       [not found]     ` <5157187E.2070504-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Boris Chiu @ 2013-03-30 16:53 UTC (permalink / raw)
  To: Ira Weiny; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 3 bytes --]





[-- Attachment #2: 0001-libibmad-Add-setting-of-errno-on-function-failure.patch --]
[-- Type: text/plain, Size: 5698 bytes --]

>From d26b4c3cf435f2e89cb8c86c30043e7bfad7cec0 Mon Sep 17 00:00:00 2001
From: Brendan Doyle <brendan.doyle-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Date: Tue, 12 Mar 2013 19:38:52 +0000
Subject: [PATCH] libibmad: Add setting of errno on function failure

Signed-off-by: Brendan Doyle <brendan.doyle-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
---
 src/mad.c     |    3 +++
 src/resolve.c |   38 +++++++++++++++++++++++++++++---------
 src/rpc.c     |    3 +++
 src/serv.c    |    4 +++-
 4 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/src/mad.c b/src/mad.c
index 10f908c..5deefa2 100644
--- a/src/mad.c
+++ b/src/mad.c
@@ -41,6 +41,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
+#include <errno.h>
 
 #include <infiniband/umad.h>
 #include <infiniband/mad.h>
@@ -102,10 +103,12 @@ void *mad_encode(void *buf, ib_rpc_t * rpc, ib_dr_path_t * drpath, void *data)
 	if ((rpc->mgtclass & 0xff) == IB_SMI_DIRECT_CLASS) {
 		if (!drpath) {
 			IBWARN("encoding dr mad without drpath (null)");
+			errno = EINVAL;
 			return NULL;
 		}
 		if (drpath->cnt >= IB_SUBNET_PATH_HOPS_MAX) {
 			IBWARN("dr path with hop count %d", drpath->cnt);
+			errno = EINVAL;
 			return NULL;
 		}
 		mad_set_field(buf, 0, IB_DRSMP_HOPCNT_F, drpath->cnt);
diff --git a/src/resolve.c b/src/resolve.c
index f866bf4..bccd938 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -40,6 +40,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <arpa/inet.h>
+#include <errno.h>
 
 #include <infiniband/umad.h>
 #include <infiniband/mad.h>
@@ -61,6 +62,10 @@ int ib_resolve_smlid_via(ib_portid_t * sm_id, int timeout,
 		return -1;
 
 	mad_decode_field(portinfo, IB_PORT_SMLID_F, &lid);
+	if (!IB_LID_VALID(lid)) {
+		errno = ENXIO;
+		return -1;
+	}
 	mad_decode_field(portinfo, IB_PORT_SMSL_F, &sm_id->sl);
 
 	return ib_portid_set(sm_id, lid, 0, 0);
@@ -75,11 +80,13 @@ int ib_resolve_gid_via(ib_portid_t * portid, ibmad_gid_t gid,
 		       ib_portid_t * sm_id, int timeout,
 		       const struct ibmad_port *srcport)
 {
-	ib_portid_t sm_portid;
+	ib_portid_t sm_portid = { 0 };
 	char buf[IB_SA_DATA_SIZE] = { 0 };
 
-	if (!sm_id) {
+	if (!sm_id)
 		sm_id = &sm_portid;
+
+	if (!IB_LID_VALID(sm_id->lid)) {
 		if (ib_resolve_smlid_via(sm_id, timeout, srcport) < 0)
 			return -1;
 	}
@@ -95,15 +102,17 @@ int ib_resolve_guid_via(ib_portid_t * portid, uint64_t * guid,
 			ib_portid_t * sm_id, int timeout,
 			const struct ibmad_port *srcport)
 {
-	ib_portid_t sm_portid;
+	ib_portid_t sm_portid = { 0 };
 	uint8_t buf[IB_SA_DATA_SIZE] = { 0 };
 	ib_portid_t self = { 0 };
 	uint64_t selfguid, prefix;
 	ibmad_gid_t selfgid;
 	uint8_t nodeinfo[64];
 
-	if (!sm_id) {
+	if (!sm_id)
 		sm_id = &sm_portid;
+
+	if (!IB_LID_VALID(sm_id->lid)) {
 		if (ib_resolve_smlid_via(sm_id, timeout, srcport) < 0)
 			return -1;
 	}
@@ -145,18 +154,24 @@ int ib_resolve_portid_str_via(ib_portid_t * portid, char *addr_str,
 	switch (dest_type) {
 	case IB_DEST_LID:
 		lid = strtol(addr_str, 0, 0);
-		if (!IB_LID_VALID(lid))
+		if (!IB_LID_VALID(lid)) {
+			errno = EINVAL;
 			return -1;
+		}
 		return ib_portid_set(portid, lid, 0, 0);
 
 	case IB_DEST_DRPATH:
-		if (str2drpath(&portid->drpath, addr_str, 0, 0) < 0)
+		if (str2drpath(&portid->drpath, addr_str, 0, 0) < 0) {
+			errno = EINVAL;
 			return -1;
+		}
 		return 0;
 
 	case IB_DEST_GUID:
-		if (!(guid = strtoull(addr_str, 0, 0)))
+		if (!(guid = strtoull(addr_str, 0, 0))) {
+			errno = EINVAL;
 			return -1;
+		}
 
 		/* keep guid in portid? */
 		return ib_resolve_guid_via(portid, &guid, sm_id, 0, srcport);
@@ -164,16 +179,20 @@ int ib_resolve_portid_str_via(ib_portid_t * portid, char *addr_str,
 	case IB_DEST_DRSLID:
 		lid = strtol(addr_str, &routepath, 0);
 		routepath++;
-		if (!IB_LID_VALID(lid))
+		if (!IB_LID_VALID(lid)) {
+			errno = EINVAL;
 			return -1;
+		}
 		ib_portid_set(portid, lid, 0, 0);
 
 		/* handle DR parsing and set DrSLID to local lid */
 		if (ib_resolve_self_via(&selfportid, &selfport, 0, srcport) < 0)
 			return -1;
 		if (str2drpath(&portid->drpath, routepath, selfportid.lid, 0) <
-		    0)
+		    0) {
+			errno = EINVAL;
 			return -1;
+		}
 		return 0;
 
 	case IB_DEST_GID:
@@ -182,6 +201,7 @@ int ib_resolve_portid_str_via(ib_portid_t * portid, char *addr_str,
 		return ib_resolve_gid_via(portid, gid, sm_id, 0, srcport);
 	default:
 		IBWARN("bad dest_type %d", dest_type);
+		errno = EINVAL;
 	}
 
 	return -1;
diff --git a/src/rpc.c b/src/rpc.c
index 7d93180..08b6c19 100644
--- a/src/rpc.c
+++ b/src/rpc.c
@@ -184,6 +184,7 @@ _do_madrpc(int port_id, void *sndbuf, void *rcvbuf, int agentid, int len,
 			return length;
 	}
 
+	errno = status;
 	*p_error = ETIMEDOUT;
 	ERRS("timeout after %d retries, %d ms", retries, timeout * retries);
 	return -1;
@@ -260,6 +261,7 @@ void *mad_rpc(const struct ibmad_port *port, ib_rpc_t * rpc,
 	if (status != 0) {
 		ERRS("MAD completed with error status 0x%x; dport (%s)",
 		     status, portid2str(dport));
+		errno = EIO;
 		return NULL;
 	}
 
@@ -309,6 +311,7 @@ void *mad_rpc_rmpp(const struct ibmad_port *port, ib_rpc_t * rpc,
 	if ((status = mad_get_field(mad, 0, IB_MAD_STATUS_F)) != 0) {
 		ERRS("MAD completed with error status 0x%x; dport (%s)",
 		     status, portid2str(dport));
+		errno = EIO;
 		return NULL;
 	}
 
diff --git a/src/serv.c b/src/serv.c
index ae5fd6c..6da8163 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -98,8 +98,10 @@ int mad_respond_via(void *umad, ib_portid_t * portid, uint32_t rstatus,
 	int is_smi;
 
 	if (!portid) {
-		if (!(mad_addr = umad_get_mad_addr(umad)))
+		if (!(mad_addr = umad_get_mad_addr(umad))) {
+			errno = EINVAL;
 			return -1;
+		}
 
 		memset(&rport, 0, sizeof(rport));
 
-- 
1.7.9.2


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

* Re: [PATCH] libibmad: Add setting of errno on function failure
       [not found]     ` <5157187E.2070504-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
@ 2013-04-03 21:12       ` Ira Weiny
  0 siblings, 0 replies; 2+ messages in thread
From: Ira Weiny @ 2013-04-03 21:12 UTC (permalink / raw)
  To: Boris Chiu; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA

On Sat, 30 Mar 2013 09:53:18 -0700
Boris Chiu <boris.chiu-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> wrote:

> From: Boris Chiu <boris.chiu-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
> To: Ira Weiny <ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> From d26b4c3cf435f2e89cb8c86c30043e7bfad7cec0 Mon Sep 17 00:00:00 2001
> From: Brendan Doyle <brendan.doyle-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
> Date: Tue, 12 Mar 2013 19:38:52 +0000
> Subject: [PATCH] libibmad: Add setting of errno on function failure
> 
> Signed-off-by: Brendan Doyle <brendan.doyle-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>

Thanks applied,
Ira


--
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-04-03 21:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <515678FE.9010503@oracle.com>
     [not found] ` <515678FE.9010503-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-03-30 16:53   ` [PATCH] libibmad: Add setting of errno on function failure Boris Chiu
     [not found]     ` <5157187E.2070504-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-04-03 21:12       ` Ira Weiny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox