s3:smbd: call pthreadpool_tevent_init() already in smbd_process()
authorStefan Metzmacher <metze@samba.org>
Fri, 9 Mar 2018 13:59:31 +0000 (14:59 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 23 Apr 2018 08:30:18 +0000 (10:30 +0200)
pthreadpool_tevent_init() doesn't start any thread yet, it only
allocates a bit of memory.

It's easier to start this in a central place, so that it's
available to all VFS modules.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/modules/vfs_default.c
source3/smbd/process.c

index a9c87e444fe43e0f67a27612efb94edec41d948b..e2efdabf47ce98d62ebfc67e4bee84dd42fe4c07 100644 (file)
@@ -717,19 +717,6 @@ static ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, cons
        return result;
 }
 
-static int vfswrap_init_pool(struct smbd_server_connection *conn)
-{
-       int ret;
-
-       if (conn->pool != NULL) {
-               return 0;
-       }
-
-       ret = pthreadpool_tevent_init(conn, lp_aio_max_threads(),
-                                     &conn->pool);
-       return ret;
-}
-
 struct vfswrap_pread_state {
        ssize_t ret;
        int fd;
@@ -754,18 +741,12 @@ static struct tevent_req *vfswrap_pread_send(struct vfs_handle_struct *handle,
 {
        struct tevent_req *req, *subreq;
        struct vfswrap_pread_state *state;
-       int ret;
 
        req = tevent_req_create(mem_ctx, &state, struct vfswrap_pread_state);
        if (req == NULL) {
                return NULL;
        }
 
-       ret = vfswrap_init_pool(handle->conn->sconn);
-       if (tevent_req_error(req, ret)) {
-               return tevent_req_post(req, ev);
-       }
-
        state->ret = -1;
        state->fd = fsp->fh->fd;
        state->buf = data;
@@ -878,18 +859,12 @@ static struct tevent_req *vfswrap_pwrite_send(struct vfs_handle_struct *handle,
 {
        struct tevent_req *req, *subreq;
        struct vfswrap_pwrite_state *state;
-       int ret;
 
        req = tevent_req_create(mem_ctx, &state, struct vfswrap_pwrite_state);
        if (req == NULL) {
                return NULL;
        }
 
-       ret = vfswrap_init_pool(handle->conn->sconn);
-       if (tevent_req_error(req, ret)) {
-               return tevent_req_post(req, ev);
-       }
-
        state->ret = -1;
        state->fd = fsp->fh->fd;
        state->buf = data;
@@ -997,18 +972,12 @@ static struct tevent_req *vfswrap_fsync_send(struct vfs_handle_struct *handle,
 {
        struct tevent_req *req, *subreq;
        struct vfswrap_fsync_state *state;
-       int ret;
 
        req = tevent_req_create(mem_ctx, &state, struct vfswrap_fsync_state);
        if (req == NULL) {
                return NULL;
        }
 
-       ret = vfswrap_init_pool(handle->conn->sconn);
-       if (tevent_req_error(req, ret)) {
-               return tevent_req_post(req, ev);
-       }
-
        state->ret = -1;
        state->fd = fsp->fh->fd;
 
index f992e65fc90412bffccdaa096a4a08739a275f08..516ac4cb2904dffcf30ac2fdb9ba58f14d365a1f 100644 (file)
@@ -42,6 +42,7 @@
 #include "lib/id_cache.h"
 #include "lib/util/sys_rw_data.h"
 #include "system/threads.h"
+#include "lib/pthreadpool/pthreadpool_tevent.h"
 
 /* Internal message queue for deferred opens. */
 struct pending_message_list {
@@ -3927,6 +3928,12 @@ void smbd_process(struct tevent_context *ev_ctx,
        sconn->ev_ctx = ev_ctx;
        sconn->msg_ctx = msg_ctx;
 
+       ret = pthreadpool_tevent_init(sconn, lp_aio_max_threads(),
+                                     &sconn->pool);
+       if (ret != 0) {
+               exit_server("pthreadpool_tevent_init() failed.");
+       }
+
        if (lp_server_max_protocol() >= PROTOCOL_SMB2_02) {
                /*
                 * We're not making the decision here,