diff mbox

[v2,1/1] librdmacm: Return errno on create_qp failure

Message ID 20180329122045.5049-2-yuval.shaia@oracle.com (mailing list archive)
State Changes Requested
Headers show

Commit Message

Yuval Shaia March 29, 2018, 12:20 p.m. UTC
Upon QP creation failure provider's create_qp function sets errno with
error code and return NULL to caller.

Let's return this errno to caller to reflect the exact reason for the
error.

Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
---
 librdmacm/cma.c | 4 +++-
 librdmacm/cma.h | 8 ++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

Comments

Shamir Rabinovitch March 29, 2018, 1:52 p.m. UTC | #1
On Thu, Mar 29, 2018 at 03:20:45PM +0300, Yuval Shaia wrote:
> Upon QP creation failure provider's create_qp function sets errno with
> error code and return NULL to caller.
> 
> Let's return this errno to caller to reflect the exact reason for the
> error.
> 
> Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
> ---
>  librdmacm/cma.c | 4 +++-
>  librdmacm/cma.h | 8 ++++++++
>  2 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/librdmacm/cma.c b/librdmacm/cma.c
> index fa370650..9920eaba 100644
> --- a/librdmacm/cma.c
> +++ b/librdmacm/cma.c
> @@ -1367,9 +1367,11 @@ int rdma_create_qp_ex(struct rdma_cm_id *id,
>  		attr->recv_cq = id->recv_cq;
>  	if (id->srq && !attr->srq)
>  		attr->srq = id->srq;
> +
> +	errno = 0;
>  	qp = ibv_create_qp_ex(id->verbs, attr);
>  	if (!qp) {
> -		ret = ERR(ENOMEM);
> +		ret = CHK_ERRNO("ibv_create_qp_ex");
>  		goto err1;
>  	}
>  
> diff --git a/librdmacm/cma.h b/librdmacm/cma.h
> index 62821055..c2dc4865 100644
> --- a/librdmacm/cma.h
> +++ b/librdmacm/cma.h
> @@ -41,6 +41,7 @@
>  #include <endian.h>
>  #include <semaphore.h>
>  #include <stdatomic.h>
> +#include <stdio.h>
>  
>  #include <rdma/rdma_cma.h>
>  #include <infiniband/ib.h>
> @@ -92,6 +93,13 @@ static inline int ERR(int err)
>  	return -1;
>  }
>  
> +static inline int CHK_ERRNO(const char *funcname)

Suggest to change to:

#define CHK_ERRNO chk_errno(__FUNCTION__)

static inline int chk_errno(const char *funcname)

> +{
> +	if (!errno)
> +		fprintf(stderr, "Function %s did not set errno\n", funcname);
> +	return -1;
> +}
> +
>  int ucma_init(void);
>  extern int af_ib_support;
>  
> -- 
> 2.14.3
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

Beside this idea looks good to me.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jason Gunthorpe March 29, 2018, 4:21 p.m. UTC | #2
On Thu, Mar 29, 2018 at 03:20:45PM +0300, Yuval Shaia wrote:
> Upon QP creation failure provider's create_qp function sets errno with
> error code and return NULL to caller.
> 
> Let's return this errno to caller to reflect the exact reason for the
> error.
> 
> Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
>  librdmacm/cma.c | 4 +++-
>  librdmacm/cma.h | 8 ++++++++
>  2 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/librdmacm/cma.c b/librdmacm/cma.c
> index fa370650..9920eaba 100644
> +++ b/librdmacm/cma.c
> @@ -1367,9 +1367,11 @@ int rdma_create_qp_ex(struct rdma_cm_id *id,
>  		attr->recv_cq = id->recv_cq;
>  	if (id->srq && !attr->srq)
>  		attr->srq = id->srq;
> +
> +	errno = 0;
>  	qp = ibv_create_qp_ex(id->verbs, attr);
>  	if (!qp) {
> -		ret = ERR(ENOMEM);
> +		ret = CHK_ERRNO("ibv_create_qp_ex");
>  		goto err1;
>  	}
>  
> diff --git a/librdmacm/cma.h b/librdmacm/cma.h
> index 62821055..c2dc4865 100644
> +++ b/librdmacm/cma.h
> @@ -41,6 +41,7 @@
>  #include <endian.h>
>  #include <semaphore.h>
>  #include <stdatomic.h>
> +#include <stdio.h>
>  
>  #include <rdma/rdma_cma.h>
>  #include <infiniband/ib.h>
> @@ -92,6 +93,13 @@ static inline int ERR(int err)
>  	return -1;
>  }
>  
> +static inline int CHK_ERRNO(const char *funcname)
> +{
> +	if (!errno)
> +		fprintf(stderr, "Function %s did not set errno\n", funcname);
> +	return -1;
> +}

This doesn't belong in cma, this is a verbs problem. ibv_create_qp_ex
is supposed to return errno, cma should assume it does.

If we have broken drivers then they need to be fixed, or we need core
verbs to wrapper the driver callback with one that fixes it.

Also, no prints in libraries. Just return EINVAL.

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

Patch

diff --git a/librdmacm/cma.c b/librdmacm/cma.c
index fa370650..9920eaba 100644
--- a/librdmacm/cma.c
+++ b/librdmacm/cma.c
@@ -1367,9 +1367,11 @@  int rdma_create_qp_ex(struct rdma_cm_id *id,
 		attr->recv_cq = id->recv_cq;
 	if (id->srq && !attr->srq)
 		attr->srq = id->srq;
+
+	errno = 0;
 	qp = ibv_create_qp_ex(id->verbs, attr);
 	if (!qp) {
-		ret = ERR(ENOMEM);
+		ret = CHK_ERRNO("ibv_create_qp_ex");
 		goto err1;
 	}
 
diff --git a/librdmacm/cma.h b/librdmacm/cma.h
index 62821055..c2dc4865 100644
--- a/librdmacm/cma.h
+++ b/librdmacm/cma.h
@@ -41,6 +41,7 @@ 
 #include <endian.h>
 #include <semaphore.h>
 #include <stdatomic.h>
+#include <stdio.h>
 
 #include <rdma/rdma_cma.h>
 #include <infiniband/ib.h>
@@ -92,6 +93,13 @@  static inline int ERR(int err)
 	return -1;
 }
 
+static inline int CHK_ERRNO(const char *funcname)
+{
+	if (!errno)
+		fprintf(stderr, "Function %s did not set errno\n", funcname);
+	return -1;
+}
+
 int ucma_init(void);
 extern int af_ib_support;