]> git.openfabrics.org - ~shefty/libibverbs.git/commitdiff
The ibv_cmd_* create functions need to set context
authorSteve Wise <swise@opengridcomputing.com>
Fri, 19 Jan 2007 21:16:59 +0000 (15:16 -0600)
committerRoland Dreier <rolandd@cisco.com>
Mon, 29 Jan 2007 17:16:12 +0000 (09:16 -0800)
If the ibv_cmd_* create function succeeds, then the object context
pointer must be set by that function so that the corresponding destroy
function will work.  This avoids problems in the error cleanup path of
a low-level driver's create function that fails after calling an
ibv_cmd_* create function.

Signed-off-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
src/cmd.c
src/verbs.c

index b2676031d4adcf8c3b2b5109532296ddba63e08a..f7d3fdef08e1c0dd86d571e7af93e436060874ad 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -209,7 +209,8 @@ int ibv_cmd_alloc_pd(struct ibv_context *context, struct ibv_pd *pd,
 
        VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
 
-       pd->handle = resp->pd_handle;
+       pd->handle  = resp->pd_handle;
+       pd->context = context;
 
        return 0;
 }
@@ -250,6 +251,7 @@ int ibv_cmd_reg_mr(struct ibv_pd *pd, void *addr, size_t length,
        mr->handle  = resp->mr_handle;
        mr->lkey    = resp->lkey;
        mr->rkey    = resp->rkey;
+       mr->context = pd->context;
 
        return 0;
 }
@@ -289,8 +291,9 @@ static int ibv_cmd_create_cq_v2(struct ibv_context *context, int cqe,
 
        VALGRIND_MAKE_MEM_DEFINED(resp, sizeof resp_size);
 
-       cq->handle = resp->cq_handle;
-       cq->cqe    = resp->cqe;
+       cq->handle  = resp->cq_handle;
+       cq->cqe     = resp->cqe;
+       cq->context = context;
 
        return 0;
 }
@@ -317,8 +320,9 @@ int ibv_cmd_create_cq(struct ibv_context *context, int cqe,
 
        VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
 
-       cq->handle = resp->cq_handle;
-       cq->cqe    = resp->cqe;
+       cq->handle  = resp->cq_handle;
+       cq->cqe     = resp->cqe;
+       cq->context = context;
 
        return 0;
 }
@@ -458,7 +462,8 @@ int ibv_cmd_create_srq(struct ibv_pd *pd,
 
        VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
 
-       srq->handle = resp->srq_handle;
+       srq->handle  = resp->srq_handle;
+       srq->context = pd->context;
 
        if (abi_ver > 5) {
                attr->attr.max_wr = resp->max_wr;
@@ -607,6 +612,7 @@ int ibv_cmd_create_qp(struct ibv_pd *pd,
 
        qp->handle                = resp->qp_handle;
        qp->qp_num                = resp->qpn;
+       qp->context               = pd->context;
 
        if (abi_ver > 3) {
                attr->cap.max_recv_sge    = resp->max_recv_sge;
@@ -1025,7 +1031,8 @@ int ibv_cmd_create_ah(struct ibv_pd *pd, struct ibv_ah *ah,
 
        VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp);
 
-       ah->handle = resp.handle;
+       ah->handle  = resp.handle;
+       ah->context = pd->context;
 
        return 0;
 }
index 6ac56d347eee05180032236c31a1d26e96aa086a..f719572078686ae6f3dacada65e39da034b75b79 100644 (file)
@@ -134,13 +134,7 @@ int ibv_query_pkey(struct ibv_context *context, uint8_t port_num,
 
 struct ibv_pd *ibv_alloc_pd(struct ibv_context *context)
 {
-       struct ibv_pd *pd;
-
-       pd = context->ops.alloc_pd(context);
-       if (pd)
-               pd->context = context;
-
-       return pd;
+       return context->ops.alloc_pd(context);
 }
 
 int ibv_dealloc_pd(struct ibv_pd *pd)
@@ -158,7 +152,6 @@ struct ibv_mr *ibv_reg_mr(struct ibv_pd *pd, void *addr,
 
        mr = pd->context->ops.reg_mr(pd, addr, length, access);
        if (mr) {
-               mr->context = pd->context;
                mr->pd      = pd;
                mr->addr    = addr;
                mr->length  = length;
@@ -248,7 +241,6 @@ struct ibv_cq *ibv_create_cq(struct ibv_context *context, int cqe, void *cq_cont
                                                   comp_vector);
 
        if (cq) {
-               cq->context                = context;
                cq->cq_context             = cq_context;
                cq->comp_events_completed  = 0;
                cq->async_events_completed = 0;
@@ -308,7 +300,6 @@ struct ibv_srq *ibv_create_srq(struct ibv_pd *pd,
 
        srq = pd->context->ops.create_srq(pd, srq_init_attr);
        if (srq) {
-               srq->context          = pd->context;
                srq->srq_context      = srq_init_attr->srq_context;
                srq->pd               = pd;
                srq->events_completed = 0;
@@ -342,7 +333,6 @@ struct ibv_qp *ibv_create_qp(struct ibv_pd *pd,
        struct ibv_qp *qp = pd->context->ops.create_qp(pd, qp_init_attr);
 
        if (qp) {
-               qp->context          = pd->context;
                qp->qp_context       = qp_init_attr->qp_context;
                qp->pd               = pd;
                qp->send_cq          = qp_init_attr->send_cq;
@@ -397,10 +387,8 @@ struct ibv_ah *ibv_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr)
 {
        struct ibv_ah *ah = pd->context->ops.create_ah(pd, attr);
 
-       if (ah) {
-               ah->context = pd->context;
+       if (ah)
                ah->pd      = pd;
-       }
 
        return ah;
 }