smbd: introduce sconn->sync_thread_pool
authorStefan Metzmacher <metze@samba.org>
Tue, 24 Jul 2018 08:56:34 +0000 (10:56 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 25 Jul 2018 15:49:06 +0000 (17:49 +0200)
This just simulates a threadpool, but executes the
job functions inline (blocking) in the main thread.

This will be used to work arround some OS limitations,
e.g. if per thread credentials or per thread working directory
are not supported.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/globals.h
source3/smbd/msdfs.c
source3/smbd/process.c

index e75ec5408f33dcf32ba045ff11535b6211a65fe9..19a130e64f64eb9c71b97b78e3469f57b3036451 100644 (file)
@@ -939,6 +939,7 @@ struct smbd_server_connection {
                } locks;
        } smb2;
 
+       struct pthreadpool_tevent *sync_thread_pool;
        struct pthreadpool_tevent *raw_thread_pool;
 
        struct smbXsrv_client *client;
index c74de7acf880fa618f4a6fe0bfadc545c17dae01..bf9b3abee4a797a3c35c36b332c633447f2bf62d 100644 (file)
@@ -32,6 +32,7 @@
 #include "libcli/security/security.h"
 #include "librpc/gen_ndr/ndr_dfsblobs.h"
 #include "lib/tsocket/tsocket.h"
+#include "lib/pthreadpool/pthreadpool_tevent.h"
 
 /**********************************************************************
  Parse a DFS pathname of the form \hostname\service\reqpath
@@ -251,6 +252,7 @@ static NTSTATUS create_conn_struct_as_root(TALLOC_CTX *ctx,
        const char *vfs_user;
        struct smbd_server_connection *sconn;
        const char *servicename = lp_const_servicename(snum);
+       int ret;
 
        sconn = talloc_zero(ctx, struct smbd_server_connection);
        if (sconn == NULL) {
@@ -274,6 +276,16 @@ static NTSTATUS create_conn_struct_as_root(TALLOC_CTX *ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
+       /*
+        * We only provide sync threadpools.
+        */
+       ret = pthreadpool_tevent_init(sconn, 0, &sconn->sync_thread_pool);
+       if (ret != 0) {
+               TALLOC_FREE(sconn);
+               return NT_STATUS_NO_MEMORY;
+       }
+       sconn->raw_thread_pool = sconn->sync_thread_pool;
+
        sconn->msg_ctx = msg;
 
        conn = conn_new(sconn);
index 8e1fceab0aaf6fbc7bcc727e5ffce240cc8ab655..35b5f4df385deac116f7b565b464df73296ed554 100644 (file)
@@ -3907,6 +3907,7 @@ void smbd_process(struct tevent_context *ev_ctx,
        const char *locaddr = NULL;
        const char *remaddr = NULL;
        int ret;
+       size_t max_threads;
        NTSTATUS status;
        struct timeval tv = timeval_current();
        NTTIME now = timeval_to_nttime(&tv);
@@ -3952,7 +3953,20 @@ void smbd_process(struct tevent_context *ev_ctx,
        ret = pthreadpool_tevent_init(sconn, lp_aio_max_threads(),
                                      &sconn->raw_thread_pool);
        if (ret != 0) {
-               exit_server("pthreadpool_tevent_init() failed.");
+               exit_server("pthreadpool_tevent_init(raw) failed.");
+       }
+
+       max_threads = pthreadpool_tevent_max_threads(sconn->raw_thread_pool);
+       if (max_threads == 0) {
+               /*
+                * We only have a sync pool, no need to create a 2nd one.
+                */
+               sconn->sync_thread_pool = sconn->raw_thread_pool;
+       } else {
+               ret = pthreadpool_tevent_init(sconn, 0, &sconn->sync_thread_pool);
+               if (ret != 0) {
+                       exit_server("pthreadpool_tevent_init(sync) failed.");
+               }
        }
 
        if (lp_server_max_protocol() >= PROTOCOL_SMB2_02) {