libibmad: Add setting of errno on function failure
PATCH 1/1 libibmad: Add setting of errno on function failure
In reply to a message not in the archiveQuoted 1 line
From
d26b4c3cf435f2e89cb8c86c30043e7bfad7cec0Mon Sep 17 00:00:00 2001
From: Brendan Doyle <[email protected]>
Date: Tue, 12 Mar 2013 19:38:52 +0000
Subject: [PATCH] libibmad: Add setting of errno on function failure
--- src/mad.c | 3 +++ src/resolve.c | 38 +++++++++++++++++++++++++++++--------- src/rpc.c | 3 +++ src/serv.c | 4 +++- 4 files changed, 38 insertions(+), 10 deletions(-)
src/mad.c +3 -0
@@ -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);
src/resolve.c +29 -9
@@ -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 ;
src/rpc.c +3 -0
@@ -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 ; }
src/serv.c +3 -1
@@ -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));
Signature · 1 line
1.7.9.2
Ira Weiny
AppliedQuoted 8 lines · On Sat, 30 Mar 2013 09:53:18 -0700 Boris Chiu…
From: Boris Chiu <[email protected]>
To: Ira Weiny <[email protected]> Fromd26b4c3cf435f2e89cb8c86c30043e7bfad7cec0Mon Sep 17 00:00:00 2001
From: Brendan Doyle <[email protected]>
Date: Tue, 12 Mar 2013 19:38:52 +0000
Subject: [PATCH] libibmad: Add setting of errno on function failureSigned-off-by Brendan Doyle <[email protected]>
Thanks applied,
Ira
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html