WIP move around fde
authorRalph Boehme <slow@samba.org>
Fri, 30 Sep 2016 21:23:02 +0000 (14:23 -0700)
committerStefan Metzmacher <metze@samba.org>
Fri, 1 Jun 2018 12:35:13 +0000 (14:35 +0200)
libcli/smb/smb_direct.c
libcli/smb/smb_direct.h
libcli/smb/smb_direct_daemon.c
source3/smbd/server.c

index 4bfe03d005971be0cbc1ac15c1e2378ec57fe33f..24fbfdc2e4ac8d285f7a567c5dafe67553fc1b87 100644 (file)
@@ -57,6 +57,7 @@ struct smb_direct_listener {
                struct rdma_cm_event *cm_event;
        } rdma;
        struct smb_direct_connection *ready;
+       struct tevent_req *listen_req;
 };
 
 struct smb_direct_connection {
@@ -2208,7 +2209,13 @@ uint32_t smb_direct_connection_max_read_write_size(struct smb_direct_connection
 
 static int smb_direct_listener_destructor(struct smb_direct_listener *l);
 
+static void smb_direct_listener_accept_rdma_handler(struct tevent_context *ev,
+                                                   struct tevent_fd *fde,
+                                                   uint16_t flags,
+                                                   void *private_data);
+
 NTSTATUS smbd_direct_listener_setup(TALLOC_CTX *mem_ctx,
+                                   struct tevent_context *ev,
                                    const struct sockaddr_storage *addr,
                                    struct smb_direct_listener **_l)
 {
@@ -2257,7 +2264,14 @@ DEBUG(0,("%s:%s: here...\n", __location__, __func__));
                return status;
        }
 
-       l->rdma.cm_channel = l->rdma.cm_id->channel;
+       l->rdma.fde_channel = tevent_add_fd(ev, l,
+                                       l->rdma.cm_channel->fd,
+                                       TEVENT_FD_READ,
+                                       smb_direct_listener_accept_rdma_handler,
+                                       l);
+       if (l->rdma.fde_channel == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
        errno = 0;
        ret = rdma_bind_addr(l->rdma.cm_id, bind_addr);
@@ -2321,11 +2335,6 @@ static int smb_direct_listener_accept_state_destructor(
        return 0;
 }
 
-static void smb_direct_listener_accept_rdma_handler(struct tevent_context *ev,
-                                                   struct tevent_fd *fde,
-                                                   uint16_t flags,
-                                                   void *private_data);
-
 struct tevent_req *smb_direct_listener_accept_send(TALLOC_CTX *mem_ctx,
                                                   struct tevent_context *ev,
                                                   struct smb_direct_listener *l)
@@ -2342,8 +2351,7 @@ 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);
-
+       if (0) {
        l->rdma.fde_channel = tevent_add_fd(ev, state,
                                        l->rdma.cm_channel->fd,
                                        TEVENT_FD_READ,
@@ -2352,7 +2360,9 @@ struct tevent_req *smb_direct_listener_accept_send(TALLOC_CTX *mem_ctx,
        if (tevent_req_nomem(l->rdma.fde_channel, req)) {
                return tevent_req_post(req, ev);
        }
+       }
 
+       l->listen_req = req;
        DBG_ERR("SMB-D daemon started accepting SMB-D connections on listener[%p]\n", l);
 
        return req;
@@ -2363,6 +2373,7 @@ static void smb_direct_listener_accept_rdma_handler(struct tevent_context *ev,
                                                    uint16_t flags,
                                                    void *private_data)
 {
+#if 0
        struct tevent_req *req =
                talloc_get_type_abort(private_data,
                struct tevent_req);
@@ -2370,6 +2381,13 @@ 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;
+#endif
+       struct smb_direct_listener *l = talloc_get_type_abort(
+               private_data, struct smb_direct_listener);
+       struct tevent_req *req = l->listen_req;
+       struct smb_direct_listener_accept_state *state =
+               tevent_req_data(req,
+               struct smb_direct_listener_accept_state);
        NTSTATUS status;
        int ret;
 
index 62e15eaa082cc073249bda6b57835a81bf13e3ad..edc96b9b73f39ec2d96444e8a1de76e67e021bd8 100644 (file)
@@ -41,6 +41,7 @@ struct smb_direct_rdma_context {
 extern struct smb_direct_connection *smb_direct_conn;
 
 NTSTATUS smbd_direct_listener_setup(TALLOC_CTX *mem_ctx,
+                                   struct tevent_context *ev,
                                    const struct sockaddr_storage *addr,
                                    struct smb_direct_listener **_l);
 struct tevent_req *smb_direct_listener_accept_send(TALLOC_CTX *mem_ctx,
index f380c151406a5370d57df2829d23f944f08d7d5c..dd09cc8fa3746040b9a38319f973d520732b84a9 100644 (file)
@@ -550,7 +550,7 @@ static NTSTATUS smbd_direct_daemon_listen(
        ZERO_STRUCT(ip);
        in_addr_to_sockaddr_storage(&bind_addr, ip);
 
-       status = smbd_direct_listener_setup(conn, &bind_addr, &l);
+       status = smbd_direct_listener_setup(conn, daemon_state->ev, &bind_addr, &l);
        if (!NT_STATUS_IS_OK(status)) {
                DBG_ERR("smbd_direct_listener_setup() => %s\n",
                        nt_errstr(status));
index 347a7d2b9d212de7fab58c503a44f964b546bf97..d9e077b01d77cd7de594455be557bdf4d2b3f55d 100644 (file)
@@ -793,7 +793,7 @@ static void cleanupd_started(struct tevent_req *req)
 }
 
 static void smb_direct_daemon_stopped(struct tevent_req *req);
-
+#if 0
 static void smb_direct_daemon_accept_done(struct tevent_req *subreq)
 {
        struct tevent_context *ev = tevent_req_callback_data(subreq,
@@ -831,7 +831,7 @@ DEBUG(0,("%s:%s: here...\n", __location__, __func__));
        close(fd);
 DEBUG(0,("%s:%s: here...\n", __location__, __func__));
 }
-
+#endif
 static bool smb_direct_daemon_init(struct tevent_context *ev,
                                   struct messaging_context *msg,
                                   bool interactive,
@@ -850,6 +850,7 @@ static bool smb_direct_daemon_init(struct tevent_context *ev,
 
 
        if (interactive) {
+#if 0
                struct smb_direct_listener *l = NULL;
                struct tevent_req *subreq = NULL;
                struct sockaddr_storage bind_addr;
@@ -884,7 +885,7 @@ static bool smb_direct_daemon_init(struct tevent_context *ev,
                tevent_req_set_callback(subreq,
                                        smb_direct_daemon_accept_done,
                                        ev);
-
+#endif
                req = tevent_wakeup_send(ev, ev, timeval_current_ofs(999999,0));
                *ppid = getpid();
                return (req != NULL);
@@ -1477,7 +1478,6 @@ static bool smb_direct_client_start(struct smbd_parent_context *parent)
        int result;
        bool ok;
 
-       if (0) {
        parent->smbd_ctr_socket = smb_direct_socket(parent);
        if (parent->smbd_ctr_socket == NULL) {
                DBG_ERR("smb_direct_socket failed\n");
@@ -1492,12 +1492,12 @@ static bool smb_direct_client_start(struct smbd_parent_context *parent)
        }
 
        DBG_ERR("smb_direct_ping got [%" PRIx32 "]\n", ping_data);
-       }
+
        s = talloc_zero(parent, struct smbd_open_socket);
        if (s == NULL) {
                return false;
        }
-if (0) {
+
        result = smb_direct_bind(parent->smbd_ctr_socket, NULL);
        if (result != 0) {
                DBG_ERR("smb_direct_bind failed\n");
@@ -1531,7 +1531,7 @@ if (0) {
        }
 
        tevent_fd_set_close_fn(s->fde, smbd_open_socket_close_fn);
-}
+
        DLIST_ADD_END(parent->sockets, s);
 
        return true;