more...
authorStefan Metzmacher <metze@samba.org>
Fri, 30 Sep 2016 05:46:38 +0000 (07:46 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 1 Jun 2018 12:35:10 +0000 (14:35 +0200)
libcli/smb/smb_direct.c
libcli/smb/smb_direct.h
libcli/smb/smb_direct_daemon.c

index 2aef0e2fbb21a4dbfc165a73d7e92bdbe5d13811..ed6a31a8db5ad70a1fdea147bd79d85f05b06320 100644 (file)
@@ -281,7 +281,7 @@ DEBUG(0,("%s:%s: here...\n", __location__, __func__));
        return c;
 }
 
-struct smb_direct_connection *smb_direct_connection_complete_alloc(struct smb_direct_connection *c)
+NTSTATUS smb_direct_connection_complete_alloc(struct smb_direct_connection *c)
 {
        int ret;
        uint16_t i;
@@ -289,16 +289,14 @@ struct smb_direct_connection *smb_direct_connection_complete_alloc(struct smb_di
 //DEBUG(0,("%s:%s: here...\n", __location__, __func__));
        c->ibv.pd = ibv_alloc_pd(c->rdma.cm_id->verbs);
        if (c->ibv.pd == NULL) {
-               TALLOC_FREE(c);
 DEBUG(0,("%s:%s: here...\n", __location__, __func__));
-               return NULL;
+               return NT_STATUS_NO_MEMORY;
        }
 
        c->ibv.comp_channel = ibv_create_comp_channel(c->rdma.cm_id->verbs);
        if (c->ibv.comp_channel == NULL) {
-               TALLOC_FREE(c);
 DEBUG(0,("%s:%s: here...\n", __location__, __func__));
-               return NULL;
+               return NT_STATUS_NO_MEMORY;
        }
        smb_set_close_on_exec(c->ibv.comp_channel->fd);
        set_blocking(c->ibv.comp_channel->fd, false);
@@ -314,9 +312,8 @@ DEBUG(0,("%s:%s: here...\n", __location__, __func__));
                                       c->ibv.init_attr.cap.max_send_wr,
                                       c, c->ibv.comp_channel, 0);
        if (c->ibv.send_cq == NULL) {
-               TALLOC_FREE(c);
 DEBUG(0,("%s:%s: here...\n", __location__, __func__));
-               return NULL;
+               return NT_STATUS_NO_MEMORY;
        }
        c->ibv.init_attr.send_cq = c->ibv.send_cq;
 
@@ -324,39 +321,33 @@ DEBUG(0,("%s:%s: here...\n", __location__, __func__));
                                       c->ibv.init_attr.cap.max_recv_wr,
                                       c, c->ibv.comp_channel, 0);
        if (c->ibv.recv_cq == NULL) {
-               TALLOC_FREE(c);
 DEBUG(0,("%s:%s: here...\n", __location__, __func__));
-               return NULL;
+               return NT_STATUS_NO_MEMORY;
        }
        c->ibv.init_attr.recv_cq = c->ibv.recv_cq;
 
        ret = ibv_req_notify_cq(c->ibv.send_cq, 0);
        if (ret != 0) {
-               TALLOC_FREE(c);
 DEBUG(0,("%s:%s: here...\n", __location__, __func__));
-               return NULL;
        }
 
        ret = ibv_req_notify_cq(c->ibv.recv_cq, 0);
        if (ret != 0) {
-               TALLOC_FREE(c);
 DEBUG(0,("%s:%s: here...\n", __location__, __func__));
-               return NULL;
+               return NT_STATUS_NO_MEMORY;
        }
 
        ret = rdma_create_qp(c->rdma.cm_id, c->ibv.pd, &c->ibv.init_attr);
        if (ret != 0) {
-               TALLOC_FREE(c);
 DEBUG(0,("%s:%s: here...\n", __location__, __func__));
-               return NULL;
+               return NT_STATUS_NO_MEMORY;
        }
        c->ibv.qp = c->rdma.cm_id->qp;
 
        c->io_mem_ctx = talloc_named_const(c, 0, "io_mem_ctx");
        if (c->io_mem_ctx == NULL) {
-               TALLOC_FREE(c);
 DEBUG(0,("%s:%s: here...\n", __location__, __func__));
-               return NULL;
+               return NT_STATUS_NO_MEMORY;
        }
 
        for (i = 0; i < c->state.receive_credit_max; i++) {
@@ -364,9 +355,8 @@ DEBUG(0,("%s:%s: here...\n", __location__, __func__));
 
                io = smb_direct_io_create(c);
                if (io == NULL) {
-                       TALLOC_FREE(c);
 DEBUG(0,("%s:%s: SETUP r2s here...\n", __location__, __func__));
-                       return NULL;
+                       return NT_STATUS_NO_MEMORY;
                }
                DLIST_ADD_END(c->r2s.idle, io);
 //DEBUG(0,("%s:%s: SETUP r2s here...\n", __location__, __func__));
@@ -377,16 +367,15 @@ DEBUG(0,("%s:%s: SETUP r2s here...\n", __location__, __func__));
 
                io = smb_direct_io_create(c);
                if (io == NULL) {
-                       TALLOC_FREE(c);
 DEBUG(0,("%s:%s: SETUP s2r here...\n", __location__, __func__));
-                       return NULL;
+                       return NT_STATUS_NO_MEMORY;
                }
                DLIST_ADD_END(c->s2r.idle, io);
 //DEBUG(0,("%s:%s: SETUP s2r here...\n", __location__, __func__));
        }
 
 //DEBUG(0,("%s:%s: here...\n", __location__, __func__));
-       return c;
+       return NT_STATUS_OK;
 }
 
 static void smb_direct_connection_debug_credits(struct smb_direct_connection *c,
@@ -820,103 +809,14 @@ static void smb_direct_connection_rdma_connect_handler(struct tevent_context *ev
        case RDMA_CM_EVENT_ROUTE_RESOLVED:
        errno = 0;
        ret = 0;
-               c = smb_direct_connection_complete_alloc(c);
-               if (c == NULL) {
-                       status = map_nt_error_from_unix_common(errno);
-                       DEBUG(0,("%s:%s: ret[%d] errno[%d] status[%s]\n",
-                               __location__, __FUNCTION__, ret, errno, nt_errstr(status)));
-                       tevent_req_nterror(req, status);
-                       return;
-               }
-#if 0
-               c->ibv.pd = ibv_alloc_pd(c->rdma.cm_id->verbs);
-               if (c->ibv.pd == NULL) {
-                       status = map_nt_error_from_unix_common(errno);
-                       DEBUG(0,("%s:%s: ret[%d] errno[%d] status[%s]\n",
-                               __location__, __FUNCTION__, ret, errno, nt_errstr(status)));
-                       tevent_req_nterror(req, status);
-                       return;
-               }
-
-               c->ibv.comp_channel = ibv_create_comp_channel(c->rdma.cm_id->verbs);
-               if (c->ibv.comp_channel == NULL) {
-                       status = map_nt_error_from_unix_common(errno);
-                       DEBUG(0,("%s:%s: ret[%d] errno[%d] status[%s]\n",
-                               __location__, __FUNCTION__, ret, errno, nt_errstr(status)));
-                       tevent_req_nterror(req, status);
-                       return;
-               }
-
-               set_blocking(c->ibv.comp_channel->fd, false);
-               smb_set_close_on_exec(c->ibv.comp_channel->fd);
-
-               ZERO_STRUCT(init_attr);
-               init_attr.cap.max_send_wr = 2;
-               init_attr.cap.max_recv_wr = 2;
-               init_attr.cap.max_recv_sge = 2;
-               init_attr.cap.max_send_sge = 2;
-               init_attr.qp_type = IBV_QPT_RC;
-               init_attr.sq_sig_all = 1;
-
-               c->ibv.send_cq = ibv_create_cq(c->rdma.cm_id->verbs,
-                                                     init_attr.cap.max_send_wr,
-                                                     c,
-                                                     c->ibv.comp_channel,
-                                                     0);
-               if (c->ibv.send_cq == NULL) {
-                       status = map_nt_error_from_unix_common(errno);
-                       DEBUG(0,("%s:%s: ret[%d] errno[%d] status[%s]\n",
-                               __location__, __FUNCTION__, ret, errno, nt_errstr(status)));
-                       tevent_req_nterror(req, status);
-                       return;
-               }
-               init_attr.send_cq = c->ibv.send_cq;
-               c->ibv.recv_cq = ibv_create_cq(c->rdma.cm_id->verbs,
-                                                     init_attr.cap.max_recv_wr,
-                                                     c,
-                                                     c->ibv.comp_channel,
-                                                     0);
-               if (c->ibv.recv_cq == NULL) {
-                       status = map_nt_error_from_unix_common(errno);
-                       DEBUG(0,("%s:%s: ret[%d] errno[%d] status[%s]\n",
-                               __location__, __FUNCTION__, ret, errno, nt_errstr(status)));
-                       tevent_req_nterror(req, status);
-                       return;
-               }
-               init_attr.recv_cq = c->ibv.recv_cq;
-
-               errno = 0;
-               ret = ibv_req_notify_cq(c->ibv.send_cq, 0);
-               if (ret != 0) {
-                       status = map_nt_error_from_unix_common(errno);
-                       DEBUG(0,("%s:%s: ret[%d] errno[%d] status[%s]\n",
-                               __location__, __FUNCTION__, ret, errno, nt_errstr(status)));
-                       tevent_req_nterror(req, status);
-                       return;
-               }
-
-               errno = 0;
-               ret = ibv_req_notify_cq(c->ibv.recv_cq, 0);
-               if (ret != 0) {
-                       status = map_nt_error_from_unix_common(errno);
+               status = smb_direct_connection_complete_alloc(c);
+               if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0,("%s:%s: ret[%d] errno[%d] status[%s]\n",
                                __location__, __FUNCTION__, ret, errno, nt_errstr(status)));
                        tevent_req_nterror(req, status);
                        return;
                }
 
-               errno = 0;
-               ret = rdma_create_qp(c->rdma.cm_id, c->ibv.pd,
-                                    &init_attr);
-               if (ret != 0) {
-                       status = map_nt_error_from_unix_common(errno);
-                       DEBUG(0,("%s:%s: ret[%d] errno[%d] status[%s]\n",
-                               __location__, __FUNCTION__, ret, errno, nt_errstr(status)));
-                       tevent_req_nterror(req, status);
-                       return;
-               }
-               c->ibv.qp = c->rdma.cm_id->qp;
-#endif
                RSIVAL(ird_ord_hdr, 0, 16);
                RSIVAL(ird_ord_hdr, 4, 0);
 
index ae303f9b3d7138ee9f4e22c1c9aa3f73a438029c..38e773f5debdac03db21925efcd9bd1118f416b7 100644 (file)
@@ -30,7 +30,7 @@ extern struct smb_direct_connection *smb_direct_conn;
 struct smb_direct_connection *smb_direct_connection_create(TALLOC_CTX *mem_ctx);
 struct smb_direct_connection *smb_direct_connection_listener(TALLOC_CTX *mem_ctx,
                                                             struct rdma_cm_id *cm_id);
-struct smb_direct_connection *smb_direct_connection_complete_alloc(struct smb_direct_connection *c);
+NTSTATUS smb_direct_connection_complete_alloc(struct smb_direct_connection *c);
 
 struct tevent_req *smb_direct_connection_connect_send(TALLOC_CTX *mem_ctx,
                                                      struct tevent_context *ev,
index 9ffd268d2ff939372e666e4271ccf825453d2c95..83d891fb21669a0079804bbe056aac2ced0c4f8a 100644 (file)
@@ -855,6 +855,7 @@ static void rdma_cm_handler(struct tevent_context *ev,
        struct rdma_cm_event *cm_ev = NULL;
        struct rdma_cm_event cm_ev_copy;
        int result;
+       NTSTATUS status;
 
        DBG_ERR("SMB-D got connection event\n");
 
@@ -900,7 +901,11 @@ static void rdma_cm_handler(struct tevent_context *ev,
 
                sconn = talloc_get_type_abort(cm_ev_copy.id->context,
                                              struct smb_direct_connection);
-               sconn = smb_direct_connection_complete_alloc(sconn);
+               status = smb_direct_connection_complete_alloc(sconn);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DBG_ERR("smb_direct_connection_complete_alloc failed\n");
+                       return;
+               }
                /*
                 * TODO: get things going...
                 */