From: Pawan Sahu Date: Wed, 4 Jun 2025 06:13:08 +0000 (+0200) Subject: smbd: Add vfswrap_check_async_with_thread_creds() helper X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b75ce05c5c468ce96fc5477533f4a3ddb4fdbf94;p=thirdparty%2Fsamba.git smbd: Add vfswrap_check_async_with_thread_creds() helper Move the logic that checks for sufficient threads and per-thread credential support into a dedicated helper function: vfswrap_check_async_with_thread_creds(). Signed-off-by: Pawan Sahu Reviewed-by: Vinit Agnihotri Reviewed-by: Christof Schmitt Reviewed-by: Guenther Deschner --- diff --git a/source3/include/vfs.h b/source3/include/vfs.h index 75156c77718..0acd7c86cad 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -414,6 +414,7 @@ struct ea_list; struct smb_file_time; struct smb_filename; struct dfs_GetDFSReferral; +struct pthreadpool_tevent; typedef union unid_t { uid_t uid; @@ -1875,6 +1876,8 @@ void *vfs_fetch_fsp_extension(vfs_handle_struct *handle, const struct files_stru void smb_vfs_assert_all_fns(const struct vfs_fn_pointers* fns, const char *module); +bool vfswrap_check_async_with_thread_creds(struct pthreadpool_tevent *pool); + /* * Helper functions from source3/modules/vfs_not_implemented.c */ diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 9d884f91cde..918cea2855a 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -3588,6 +3588,34 @@ static int vfswrap_getxattrat_state_destructor( return -1; } +/* Check if there are enough threads available + * to run asynchronous jobs and if the current + * platform provides per-thread credentials. + */ +bool vfswrap_check_async_with_thread_creds(struct pthreadpool_tevent *pool) +{ + size_t max_threads = 0; + bool have_per_thread_cwd = false; + bool have_per_thread_creds = false; + bool do_async = false; + + max_threads = pthreadpool_tevent_max_threads(pool); + if (max_threads >= 1) { + /* + * We need a non sync threadpool! + */ + have_per_thread_cwd = per_thread_cwd_supported(); + } +#ifdef HAVE_LINUX_THREAD_CREDENTIALS + have_per_thread_creds = true; +#endif + if (have_per_thread_cwd && have_per_thread_creds) { + do_async = true; + } + + return do_async; +} + static void vfswrap_getxattrat_do_sync(struct tevent_req *req); static void vfswrap_getxattrat_do_async(void *private_data); static void vfswrap_getxattrat_done(struct tevent_req *subreq); @@ -3604,9 +3632,6 @@ static struct tevent_req *vfswrap_getxattrat_send( struct tevent_req *req = NULL; struct tevent_req *subreq = NULL; struct vfswrap_getxattrat_state *state = NULL; - size_t max_threads = 0; - bool have_per_thread_cwd = false; - bool have_per_thread_creds = false; bool do_async = false; SMB_ASSERT(!is_named_stream(smb_fname)); @@ -3623,19 +3648,8 @@ static struct tevent_req *vfswrap_getxattrat_send( .job_state.smb_fname = smb_fname, }; - max_threads = pthreadpool_tevent_max_threads(dir_fsp->conn->sconn->pool); - if (max_threads >= 1) { - /* - * We need a non sync threadpool! - */ - have_per_thread_cwd = per_thread_cwd_supported(); - } -#ifdef HAVE_LINUX_THREAD_CREDENTIALS - have_per_thread_creds = true; -#endif - if (have_per_thread_cwd && have_per_thread_creds) { - do_async = true; - } + do_async = vfswrap_check_async_with_thread_creds( + dir_fsp->conn->sconn->pool); SMBPROFILE_BYTES_ASYNC_START_X(SNUM(handle->conn), syscall_asys_getxattrat,