]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Add vfswrap_check_async_with_thread_creds() helper
authorPawan Sahu <Pawan.Sahu1@ibm.com>
Wed, 4 Jun 2025 06:13:08 +0000 (08:13 +0200)
committerGünther Deschner <gd@samba.org>
Tue, 30 Sep 2025 12:06:41 +0000 (12:06 +0000)
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 <Pawan.Sahu1@ibm.com>
Reviewed-by: Vinit Agnihotri <vagnihot@redhat.com>
Reviewed-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
source3/include/vfs.h
source3/modules/vfs_default.c

index 75156c777181c17e68dd54372b5f4b97a3862a35..0acd7c86cada657b10a412fc95b382eb1952b28c 100644 (file)
@@ -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
  */
index 9d884f91cde54d77dbd8382c4b715b6a5e68e8f1..918cea2855aa0664451082188cdd2bb02536e8ce 100644 (file)
@@ -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,