From b527e8169670d70ed883d62248ab2571526e3e3b Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Fri, 30 Sep 2016 19:24:17 -0700 Subject: [PATCH] WIP --- libcli/smb/smb_direct.c | 133 ++++++++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 53 deletions(-) diff --git a/libcli/smb/smb_direct.c b/libcli/smb/smb_direct.c index d648672f4186..c9974722fc08 100644 --- a/libcli/smb/smb_direct.c +++ b/libcli/smb/smb_direct.c @@ -54,8 +54,13 @@ struct smb_direct_listener { struct rdma_event_channel *cm_channel; struct tevent_fd *fde_channel; enum rdma_cm_event_type expected_event; + /* + * We fetch events from the ready queue and store it + * here, it's acked in the listener destructor. + */ struct rdma_cm_event *cm_event; } rdma; + struct smb_direct_connection *pending; struct smb_direct_connection *ready; }; @@ -87,7 +92,13 @@ struct smb_direct_connection { struct rdma_cm_id *cm_id; struct tevent_fd *fde_channel; enum rdma_cm_event_type expected_event; + /* + * We fetch events from the ready queue and store it + * here, it's acked in the listener destructor. + */ struct rdma_cm_event *cm_event; + struct rdma_conn_param conn_param; + uint8_t ird_ord_hdr[8]; } rdma; struct { struct ibv_pd *pd; @@ -1490,6 +1501,37 @@ DEBUG(0,("%s:%s: sock.fd[%d] sock.tmp_fd[%d]\n", return NT_STATUS_OK; } +struct smb_direct_connection_negotiate_accept_state { +}; + +static struct tevent_req *smb_direct_connection_negotiate_accept_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct smb_direct_connection *c) +{ +#if 0 + ret = rdma_accept(c->rdma.cm_id,conn_param); + if (ret != 0) { + DBG_ERR("rdma_accept failed [%s] result [%d]\n", strerror(errno), ret); + c->rdma.cm_id->context = NULL; + c->rdma.cm_id->channel = NULL; + c->rdma.cm_id = NULL; + TALLOC_FREE(c); + + //??? rdma_reject(l->rdma.cm_event->id); + /* wait for more */ + break; + } +#endif + return NULL; +} + +static NTSTATUS smb_direct_connection_negotiate_accept_recv(struct tevent_req *req) +{ + DEBUG(0,("%s:%s: here...\n", __location__, __func__)); + return tevent_req_simple_recv_ntstatus(req); +} + static void smb_direct_connection_disconnect(struct smb_direct_connection *c, NTSTATUS status) { @@ -2342,7 +2384,8 @@ struct tevent_req *smb_direct_listener_accept_send(TALLOC_CTX *mem_ctx, state->l = l; talloc_set_destructor(state, smb_direct_listener_accept_state_destructor); - smb_direct_listener_accept_rdma_handler(ev, NULL, 0, req); +// HACK: if smb_direct_listener_accept_rdma_handler is not triggered by fde +// smb_direct_listener_accept_rdma_handler(ev, NULL, 0, req); l->rdma.fde_channel = tevent_add_fd(ev, state, l->rdma.cm_channel->fd, @@ -2358,6 +2401,8 @@ struct tevent_req *smb_direct_listener_accept_send(TALLOC_CTX *mem_ctx, return req; } +static void smb_direct_listener_accept_done(struct tevent_req *subreq); + static void smb_direct_listener_accept_rdma_handler(struct tevent_context *ev, struct tevent_fd *fde, uint16_t flags, @@ -2370,6 +2415,8 @@ static void smb_direct_listener_accept_rdma_handler(struct tevent_context *ev, tevent_req_data(req, struct smb_direct_listener_accept_state); struct smb_direct_listener *l = state->l; + struct smb_direct_connection *c = NULL; + struct tevent_req *subreq = NULL; NTSTATUS status; int ret; @@ -2408,42 +2455,10 @@ static void smb_direct_listener_accept_rdma_handler(struct tevent_context *ev, } switch (l->rdma.cm_event->event) { - case RDMA_CM_EVENT_ADDR_RESOLVED: - DBG_DEBUG("RDMA_CM_EVENT_ADDR_RESOLVED\n"); - - errno = 0; - ret = rdma_resolve_route(l->rdma.cm_id, 5000); - 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))); - smb_direct_listener_destructor(l); //TODO cleanup??? - tevent_req_nterror(req, status); - return; - } - l->rdma.expected_event = RDMA_CM_EVENT_ROUTE_RESOLVED; - smb_direct_listener_destructor(l); //TODO cleanup??? - tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR); - return; - - case RDMA_CM_EVENT_CONNECT_REQUEST: { - struct rdma_conn_param conn_param; - uint8_t ird_ord_hdr[8]; - struct smb_direct_connection *c = NULL; - - RSIVAL(ird_ord_hdr, 0, 0); - RSIVAL(ird_ord_hdr, 4, 16); + case RDMA_CM_EVENT_CONNECT_REQUEST: DBG_ERR("RDMA_CM_EVENT_CONNECT_REQUEST\n"); - conn_param = l->rdma.cm_event->param.conn; -// ZERO_STRUCT(conn_param); - conn_param.private_data = ird_ord_hdr; - conn_param.private_data_len = sizeof(ird_ord_hdr); -// conn_param.responder_resources = 1; -// conn_param.initiator_depth = 1; -// conn_param.retry_count = 10; - c = smb_direct_connection_create(l); if (c == NULL) { DBG_ERR("smb_direct_connection_create failed - ignoring\n"); @@ -2453,9 +2468,16 @@ static void smb_direct_listener_accept_rdma_handler(struct tevent_context *ev, break; } + RSIVAL(c->rdma.ird_ord_hdr, 0, 0); + RSIVAL(c->rdma.ird_ord_hdr, 4, 16); + + c->rdma.conn_param = l->rdma.cm_event->param.conn; + c->rdma.conn_param.private_data = c->rdma.ird_ord_hdr; + c->rdma.conn_param.private_data_len = sizeof(c->rdma.ird_ord_hdr); + c->rdma.cm_id = l->rdma.cm_event->id; c->rdma.cm_id->context = &c->rdma.context; - //c->rdma.cm_id->channel = c->rdma.cm_channel; + ret = rdma_migrate_id(c->rdma.cm_id, c->rdma.cm_channel); if (ret != 0) { DBG_ERR("rdma_migrate_id failed [%s] result [%d]\n", strerror(errno), ret); @@ -2481,28 +2503,19 @@ static void smb_direct_listener_accept_rdma_handler(struct tevent_context *ev, break; } - ret = rdma_accept(c->rdma.cm_id, &conn_param); - if (ret != 0) { - DBG_ERR("rdma_accept failed [%s] result [%d]\n", strerror(errno), ret); - c->rdma.cm_id->context = NULL; - c->rdma.cm_id->channel = NULL; - c->rdma.cm_id = NULL; - TALLOC_FREE(c); + c->l = l; + DLIST_ADD_END(l->pending, c); - //??? rdma_reject(l->rdma.cm_event->id); + subreq = smb_direct_connection_negotiate_accept_send(state, + state->ev, + c); + if (subreq == NULL) { + DBG_ERR("smb_direct_connection_accept_send ENOMEM\n"); + TALLOC_FREE(c); /* wait for more */ break; } - - l->rdma.cm_event->id = NULL; - - c->l = l; - DLIST_ADD_END(l->ready, c); -DEBUG(0,("%s:%s: here...\n", __location__, __func__)); - - tevent_req_defer_callback(req, state->ev); - tevent_req_done(req); - } + tevent_req_set_callback(subreq, smb_direct_listener_accept_done, c); break; case RDMA_CM_EVENT_DISCONNECTED: @@ -2524,6 +2537,20 @@ DEBUG(0,("%s:%s: here...\n", __location__, __func__)); return; } +static void smb_direct_listener_accept_done(struct tevent_req *subreq) +{ +#if 0 + DEBUG(0,("%s:%s: here...\n", __location__, __func__)); + + DLIST_REMOVE(l->pending, c); + DLIST_ADD_END(l->ready, c); + + tevent_req_defer_callback(req, state->ev); + tevent_req_done(req); +#endif + return; +} + NTSTATUS smb_direct_listener_accept_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, struct smb_direct_connection **_c, -- 2.34.1