]> git.openfabrics.org - ~shefty/librdmacm.git/commitdiff
librdmacm: convert ibv error values to errno
authorSean Hefty <sean.hefty@intel.com>
Tue, 20 Jul 2010 22:24:55 +0000 (15:24 -0700)
committerSean Hefty <sean.hefty@intel.com>
Fri, 23 Jul 2010 00:36:03 +0000 (17:36 -0700)
The librdmacm documentation (rdma_cm.7 man page) specifies that librdmacm
functions return 0 on success and -1 on error, with errno set correctly.
The libibverbs abstractions simply pass the libibverbs return codes
through to the user.  Since libibverbs may return errno directly through
a given call, convert the return status to use errno where appropriate.

This fixes an issue with rdma_get_send_comp and rdma_get_recv_comp, where
a return value of 1 could indicate both success (1 completed request
returned) and failure (EPERM error).

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
include/rdma/rdma_verbs.h
src/cma.c

index 12429a7111dab3962a4d14c5129445f880d2e999..d75d906f774735458699fcec83b4bd6ccb9e4c20 100644 (file)
 #include <assert.h>
 #include <infiniband/verbs.h>
 #include <rdma/rdma_cma.h>
+#include <errno.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+static inline int rdma_seterrno(int ret)
+{
+       if (ret) {
+               errno = ret;
+               ret = -1;
+       }
+       return ret;
+}
+
 /*
  * Memory registration helpers.
  */
@@ -53,7 +63,7 @@ rdma_reg_msgs(struct rdma_cm_id *id, void *addr, size_t length)
 static inline struct ibv_mr *
 rdma_reg_read(struct rdma_cm_id *id, void *addr, size_t length)
 {
-       return ibv_reg_mr(id->qp->pd, addr, length, IBV_ACCESS_LOCAL_WRITE|
+       return ibv_reg_mr(id->qp->pd, addr, length, IBV_ACCESS_LOCAL_WRITE |
                                                    IBV_ACCESS_REMOTE_READ);
 }
 
@@ -67,7 +77,7 @@ rdma_reg_write(struct rdma_cm_id *id, void *addr, size_t length)
 static inline int
 rdma_dereg_mr(struct ibv_mr *mr)
 {
-       return ibv_dereg_mr(mr);
+       return rdma_seterrno(ibv_dereg_mr(mr));
 }
 
 
@@ -86,7 +96,7 @@ rdma_post_recvv(struct rdma_cm_id *id, void *context, struct ibv_sge *sgl,
        wr.sg_list = sgl;
        wr.num_sge = nsge;
 
-       return ibv_post_recv(id->qp, &wr, &bad);
+       return rdma_seterrno(ibv_post_recv(id->qp, &wr, &bad));
 }
 
 static inline int
@@ -102,7 +112,7 @@ rdma_post_sendv(struct rdma_cm_id *id, void *context, struct ibv_sge *sgl,
        wr.opcode = IBV_WR_SEND;
        wr.send_flags = flags;
 
-       return ibv_post_send(id->qp, &wr, &bad);
+       return rdma_seterrno(ibv_post_send(id->qp, &wr, &bad));
 }
 
 static inline int
@@ -120,7 +130,7 @@ rdma_post_readv(struct rdma_cm_id *id, void *context, struct ibv_sge *sgl,
        wr.wr.rdma.remote_addr = remote_addr;
        wr.wr.rdma.rkey = rkey;
 
-       return ibv_post_send(id->qp, &wr, &bad);
+       return rdma_seterrno(ibv_post_send(id->qp, &wr, &bad));
 }
 
 static inline int
@@ -138,7 +148,7 @@ rdma_post_writev(struct rdma_cm_id *id, void *context, struct ibv_sge *sgl,
        wr.wr.rdma.remote_addr = remote_addr;
        wr.wr.rdma.rkey = rkey;
 
-       return ibv_post_send(id->qp, &wr, &bad);
+       return rdma_seterrno(ibv_post_send(id->qp, &wr, &bad));
 }
 
 /*
@@ -221,7 +231,7 @@ rdma_post_ud_send(struct rdma_cm_id *id, void *context, void *addr,
        wr.wr.ud.remote_qpn = remote_qpn;
        wr.wr.ud.remote_qkey = RDMA_UDP_QKEY;
 
-       return ibv_post_send(id->qp, &wr, &bad);
+       return rdma_seterrno(ibv_post_send(id->qp, &wr, &bad));
 }
 
 static inline int
@@ -233,22 +243,22 @@ rdma_get_send_comp(struct rdma_cm_id *id, struct ibv_wc *wc)
 
        ret = ibv_poll_cq(id->send_cq, 1, wc);
        if (ret)
-               return ret;
+               goto out;
 
        ret = ibv_req_notify_cq(id->send_cq, 0);
        if (ret)
-               return ret;
+               return rdma_seterrno(ret);
 
        while (!(ret = ibv_poll_cq(id->send_cq, 1, wc))) {
                ret = ibv_get_cq_event(id->send_cq_channel, &cq, &context);
                if (ret)
-                       break;
+                       return rdma_seterrno(ret);
 
                assert(cq == id->send_cq && context == id);
                ibv_ack_cq_events(id->send_cq, 1);
        }
-
-       return ret;
+out:
+       return (ret < 0) ? rdma_seterrno(ret) : ret;
 }
 
 static inline int
@@ -260,22 +270,22 @@ rdma_get_recv_comp(struct rdma_cm_id *id, struct ibv_wc *wc)
 
        ret = ibv_poll_cq(id->recv_cq, 1, wc);
        if (ret)
-               return ret;
+               goto out;
 
        ret = ibv_req_notify_cq(id->recv_cq, 0);
        if (ret)
-               return ret;
+               return rdma_seterrno(ret);
 
        while (!(ret = ibv_poll_cq(id->recv_cq, 1, wc))) {
                ret = ibv_get_cq_event(id->recv_cq_channel, &cq, &context);
                if (ret)
-                       break;
+                       return rdma_seterrno(ret);
 
                assert(cq == id->recv_cq && context == id);
                ibv_ack_cq_events(id->recv_cq, 1);
        }
-
-       return ret;
+out:
+       return (ret < 0) ? rdma_seterrno(ret) : ret;
 }
 
 #ifdef __cplusplus
index 7ddccbb5569f1872cc5cef35ca7b97d5ba2528a5..a20e2f5971ef9d47310de29de0ff0ac3ffec1414 100644 (file)
--- a/src/cma.c
+++ b/src/cma.c
@@ -56,6 +56,7 @@
 #include <infiniband/marshall.h>
 #include <rdma/rdma_cma.h>
 #include <rdma/rdma_cma_abi.h>
+#include <rdma/rdma_verbs.h>
 #include <infiniband/ib.h>
 
 #define CMA_CREATE_MSG_CMD_RESP(msg, cmd, resp, type, size) \