summaryrefslogtreecommitdiff
path: root/lib/pthreadpool
AgeCommit message (Collapse)AuthorFilesLines
2026-02-20pthreadpool: Fix CID 1681387, Error handling issues (CHECKED_RETURN)Anoop C S1-2/+10
Signed-off-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Anoop C S <anoopcs@samba.org> Autobuild-Date(master): Fri Feb 20 08:37:17 UTC 2026 on atb-devel-224
2026-02-13lib/pthreadpool: Add some pthreadpool_pipe unit testsNoel Power2-0/+331
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz> Signed-off-by: Noel Power <noel.power@suse.com> Autobuild-User(master): Noel Power <npower@samba.org> Autobuild-Date(master): Fri Feb 13 11:22:34 UTC 2026 on atb-devel-224
2026-02-13lib/pthreadpool: Incorrect error state detected for dup2 callNoel Power1-1/+1
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz> Signed-off-by: Noel Power <noel.power@suse.com>
2026-01-18lib/pthreadpool: protect jobs list from concurrent thread accessNoel Power1-0/+40
ThreadSanitizer identifies a data race with pool->jobs with concurrent threads in test added in previous commit. This commit protects the pool->jobs list (trace and line numbers are from before glue fix in previous commit) WARNING: ThreadSanitizer: data race (pid=13574) Write of size 8 at 0x7b6000020260 by thread T16: #0 pthreadpool_tevent_job_done ../../lib/pthreadpool/pthreadpool_tevent.c:405 (pthreadpool_tevent_unit_test_san+0x407080) #1 tevent_common_invoke_immediate_handler ../../lib/tevent/tevent_immediate.c:190 (libtevent-private-samba.so+0x8dbf) #2 pthreadpool_tevent_job_fn ../../lib/pthreadpool/pthreadpool_tevent.c:351 (pthreadpool_tevent_unit_test_san+0x406bc4) #3 pthreadpool_server ../../lib/pthreadpool/pthreadpool.c:655 (pthreadpool_tevent_unit_test_san+0x4043bd) #4 <null> <null> (libtsan.so.0+0x323cf) Previous write of size 8 at 0x7b6000020260 by thread T13: #0 pthreadpool_tevent_job_send ../../lib/pthreadpool/pthreadpool_tevent.c:342 (pthreadpool_tevent_unit_test_san+0x406a09) #1 do_nested_pthread_job ../../lib/pthreadpool/test_pthreadpool_tevent.c:463 (pthreadpool_tevent_unit_test_san+0x408932) #2 pthreadpool_tevent_job_fn ../../lib/pthreadpool/pthreadpool_tevent.c:351 (pthreadpool_tevent_unit_test_san+0x406bc4) #3 pthreadpool_server ../../lib/pthreadpool/pthreadpool.c:655 (pthreadpool_tevent_unit_test_san+0x4043bd) #4 <null> <null> (libtsan.so.0+0x323cf) Thread T16 (tid=13591, running) created by main thread at: #0 pthread_create <null> (libtsan.so.0+0x5ed75) #1 pthreadpool_create_thread ../../lib/pthreadpool/pthreadpool.c:711 (pthreadpool_tevent_unit_test_san+0x4045ac) #2 pthreadpool_add_job ../../lib/pthreadpool/pthreadpool.c:792 (pthreadpool_tevent_unit_test_san+0x40496f) #3 pthreadpool_tevent_job_send ../../lib/pthreadpool/pthreadpool_tevent.c:329 (pthreadpool_tevent_unit_test_san+0x4065e2) #4 test_pthreadpool_tevent_job_send_multiple_3 ../../lib/pthreadpool/test_pthreadpool_tevent.c:515 (pthreadpool_tevent_unit_test_san+0x408c25) #5 cmocka_run_one_test_or_fixture ../../third_party/cmocka/cmocka.c:2948 (libcmocka-private-samba.so+0x6f92) #6 __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 (libc.so.6+0x40e6b) Thread T13 (tid=13588, running) created by main thread at: #0 pthread_create <null> (libtsan.so.0+0x5ed75) #1 pthreadpool_create_thread ../../lib/pthreadpool/pthreadpool.c:711 (pthreadpool_tevent_unit_test_san+0x4045ac) #2 pthreadpool_add_job ../../lib/pthreadpool/pthreadpool.c:792 (pthreadpool_tevent_unit_test_san+0x40496f) #3 pthreadpool_tevent_job_send ../../lib/pthreadpool/pthreadpool_tevent.c:329 (pthreadpool_tevent_unit_test_san+0x4065e2) #4 test_pthreadpool_tevent_job_send_multiple_3 ../../lib/pthreadpool/test_pthreadpool_tevent.c:515 (pthreadpool_tevent_unit_test_san+0x408c25) #5 cmocka_run_one_test_or_fixture ../../third_party/cmocka/cmocka.c:2948 (libcmocka-private-samba.so+0x6f92) #6 __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 (libc.so.6+0x40e6b) SUMMARY: ThreadSanitizer: data race ../../lib/pthreadpool/pthreadpool_tevent.c:405 in pthreadpool_tevent_job_done BUG: https://bugzilla.samba.org/show_bug.cgi?id=15958 Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Stefan Metzmacher <metze@samba.org> Autobuild-Date(master): Sun Jan 18 15:16:59 UTC 2026 on atb-devel-224
2026-01-18lib/pthreadpool: Fix possible concurrent access to pool->glue_listNoel Power1-1/+79
ThreadSanitizer run against tests added in previous commit identify a race condition with pool->glue_list with concurrent thread access WARNING: ThreadSanitizer: data race (pid=13574) Read of size 8 at 0x7b2000000368 by thread T7: #0 pthreadpool_tevent_job_signal ../../lib/pthreadpool/pthreadpool_tevent.c:370 (pthreadpool_tevent_unit_test_san+0x406c6e) #1 pthreadpool_server ../../lib/pthreadpool/pthreadpool.c:657 (pthreadpool_tevent_unit_test_san+0x40443b) #2 <null> <null> (libtsan.so.0+0x323cf) Previous write of size 8 at 0x7b2000000368 by main thread: #0 pthreadpool_tevent_glue_destructor ../../lib/pthreadpool/pthreadpool_tevent.c:165 (pthreadpool_tevent_unit_test_san+0x405aed) #1 _tc_free_internal ../../lib/talloc/talloc.c:1158 (libtalloc-private-samba.so+0x3419) #2 _tc_free_internal ../../lib/talloc/talloc.c:1158 (libtalloc-private-samba.so+0x3419) #3 cmocka_run_one_test_or_fixture ../../third_party/cmocka/cmocka.c:2948 (libcmocka-private-samba.so+0x6f92) #4 __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 (libc.so.6+0x40e6b) Location is heap block of size 120 at 0x7b2000000300 allocated by main thread: #0 malloc <null> (libtsan.so.0+0x35799) #1 __talloc_with_prefix ../../lib/talloc/talloc.c:783 (libtalloc-private-samba.so+0x2a99) #2 test_pthreadpool_tevent_job_send_multiple_2 ../../lib/pthreadpool/test_pthreadpool_tevent.c:399 (pthreadpool_tevent_unit_test_san+0x40856f) #3 cmocka_run_one_test_or_fixture ../../third_party/cmocka/cmocka.c:2948 (libcmocka-private-samba.so+0x6f92) #4 __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 (libc.so.6+0x40e6b) Thread T7 (tid=13582, running) created by main thread at: #0 pthread_create <null> (libtsan.so.0+0x5ed75) #1 pthreadpool_create_thread ../../lib/pthreadpool/pthreadpool.c:711 (pthreadpool_tevent_unit_test_san+0x4045ac) #2 pthreadpool_add_job ../../lib/pthreadpool/pthreadpool.c:792 (pthreadpool_tevent_unit_test_san+0x40496f) #3 pthreadpool_tevent_job_send ../../lib/pthreadpool/pthreadpool_tevent.c:329 (pthreadpool_tevent_unit_test_san+0x4065e2) #4 test_pthreadpool_tevent_job_send_multiple_2 ../../lib/pthreadpool/test_pthreadpool_tevent.c:423 (pthreadpool_tevent_unit_test_san+0x4086b2) #5 cmocka_run_one_test_or_fixture ../../third_party/cmocka/cmocka.c:2948 (libcmocka-private-samba.so+0x6f92) #6 __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 (libc.so.6+0x40e6b) SUMMARY: ThreadSanitizer: data race ../../lib/pthreadpool/pthreadpool_tevent.c:370 in pthreadpool_tevent_job_signal BUG: https://bugzilla.samba.org/show_bug.cgi?id=15958 Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2026-01-18lib/pthreadpool: fix free of already freed glue objectNoel Power1-1/+0
The lines are a bit skewed from actual sources (due to temp debug lines) but I have inserted the relevant source code below basically if we free ev_link then this will free the glue object, so deleting the glue object on the next line is not what we want to do. ==14263== Invalid read of size 4 ==14263== at 0x4D13E90: talloc_chunk_from_ptr (talloc.c:527) ==14263== by 0x4D1621E: _talloc_free (talloc.c:1770) 249 #ifdef HAVE_PTHREAD 250 glue->tctx = tevent_threaded_context_create(glue, ev); 251 if (glue->tctx == NULL) { 252 TALLOC_FREE(ev_link); * 253 TALLOC_FREE(glue); 254 return ENOMEM; 250 } ==14263== by 0x51FA0AF: pthreadpool_tevent_register_ev (pthreadpool_tevent.c:253) ==14263== by 0x51FA302: pthreadpool_tevent_job_send (pthreadpool_tevent.c:324) ==14263== by 0x4B01E68: vfswrap_fsync_send (vfs_default.c:1104) ==14263== by 0x49CD9B1: smb_vfs_call_fsync_send (vfs.c:1998) ==14263== by 0x49CDBF9: smb_vfs_fsync_sync (vfs.c:2057) ==14263== by 0x494B1E5: sync_file (fileio.c:320) ==14263== by 0x497CC77: reply_flush (reply.c:5398) ==14263== by 0x49E28CB: switch_message (process.c:1726) ==14263== by 0x49E2AA4: construct_reply (process.c:1762) ==14263== by 0x49E37F8: process_smb (process.c:2017) ==14263== Address 0xcb415d0 is 0 bytes inside a block of size 144 free'd ==14263== at 0x484494B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==14263== by 0x4D14F81: _tc_free_internal (talloc.c:1222) ==14263== by 0x4D15025: _talloc_free_internal (talloc.c:1248) ==14263== by 0x4D162ED: _talloc_free (talloc.c:1792) 190 static int pthreadpool_tevent_glue_link_destructor( 191 struct pthreadpool_tevent_glue_ev_link *ev_link) 192 { * 193 TALLOC_FREE(ev_link->glue); 194 return 0; 195 } ==14263== by 0x51F9EC3: pthreadpool_tevent_glue_link_destructor (pthreadpool_tevent.c:193) ==14263== by 0x4D14CA9: _tc_free_internal (talloc.c:1158) ==14263== by 0x4D15025: _talloc_free_internal (talloc.c:1248) ==14263== by 0x4D162ED: _talloc_free (talloc.c:1792) 249 #ifdef HAVE_PTHREAD 250 glue->tctx = tevent_threaded_context_create(glue, ev); 251 if (glue->tctx == NULL) { * 252 TALLOC_FREE(ev_link); 253 TALLOC_FREE(glue); 254 return ENOMEM; 250 } ==14263== by 0x51FA08D: pthreadpool_tevent_register_ev (pthreadpool_tevent.c:252) ==14263== by 0x51FA302: pthreadpool_tevent_job_send (pthreadpool_tevent.c:324) ==14263== by 0x4B01E68: vfswrap_fsync_send (vfs_default.c:1104) ==14263== by 0x49CD9B1: smb_vfs_call_fsync_send (vfs.c:1998) ==14263== Block was alloc'd at ==14263== at 0x4841984: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==14263== by 0x4D14339: __talloc_with_prefix (talloc.c:783) ==14263== by 0x4D144D3: __talloc (talloc.c:825) ==14263== by 0x4D1486C: _talloc_named_const (talloc.c:982) ==14263== by 0x4D1734D: _talloc_zero (talloc.c:2421) ==14263== by 0x51F9F46: pthreadpool_tevent_register_ev (pthreadpool_tevent.c:222) ==14263== by 0x51FA302: pthreadpool_tevent_job_send (pthreadpool_tevent.c:324) ==14263== by 0x4B01E68: vfswrap_fsync_send (vfs_default.c:1104) ==14263== by 0x49CD9B1: smb_vfs_call_fsync_send (vfs.c:1998) ==14263== by 0x49CDBF9: smb_vfs_fsync_sync (vfs.c:2057) ==14263== by 0x494B1E5: sync_file (fileio.c:320) ==14263== by 0x497CC77: reply_flush (reply.c:5398) ==14263== ==14263== Invalid read of size 4 ==14263== at 0x4D13EAE: talloc_chunk_from_ptr (talloc.c:528) ==14263== by 0x4D1621E: _talloc_free (talloc.c:1770) ==14263== by 0x51FA0AF: pthreadpool_tevent_register_ev (pthreadpool_tevent.c:253) ==14263== by 0x51FA302: pthreadpool_tevent_job_send (pthreadpool_tevent.c:324) ==14263== by 0x4B01E68: vfswrap_fsync_send (vfs_default.c:1104) ==14263== by 0x49CD9B1: smb_vfs_call_fsync_send (vfs.c:1998) ==14263== by 0x49CDBF9: smb_vfs_fsync_sync (vfs.c:2057) ==14263== by 0x494B1E5: sync_file (fileio.c:320) ==14263== by 0x497CC77: reply_flush (reply.c:5398) ==14263== by 0x49E28CB: switch_message (process.c:1726) ==14263== by 0x49E2AA4: construct_reply (process.c:1762) ==14263== by 0x49E37F8: process_smb (process.c:2017) ==14263== Address 0xcb415d0 is 0 bytes inside a block of size 144 free'd ==14263== at 0x484494B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-l BUG: https://bugzilla.samba.org/show_bug.cgi?id=15957 Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2026-01-18Add unit cmocka tests for pthreadpool_teventNoel Power2-0/+783
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15958 Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2026-01-18Add basic cmocka unit tests for pthreadpoolNoel Power2-0/+642
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15958 Pair-Programmed-With: Andreas Schneider <asn@samba.org> Signed-off-by: Noel Power <noel.power@suse.com> Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2025-10-17Add missing include needed for cmocka.hAndreas Schneider1-0/+1
This will be required in future. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org>
2023-04-11lib:pthreadpool: Fix code spellingAndreas Schneider1-1/+1
Best reviewed with: `git show --word-diff`. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2019-11-22build: Do not build selftest binaries for builds without --enable-selftestAndrew Bartlett1-2/+2
Add new for_selftest option to SAMBA_BINARY() and SAMBA3_BINARY() This allows us to be much more consistent (at least in the core Samba) and documents clearly why the binary should not be installed. Not modified are - test_lp_load - notifyd-tests - gendrandperf - test* from examples/libsmbclient - dbwrap_torture - split_tokens - locktest2 - msgtest - msg_sink - msg_source - versiontest - rpc_open_tcp - test_headers As these are not tested in selftest so any change would also be untested. Of course they probably should be added in a different MR. Also not modified (because they are not tests, nor part of the build system) are: - smb2mount - notifydd - log2pacp - debug2html - smbfilter - destroy_netlogon_creds_cli - spotlight2* - tevent_glib_tracker These do however appear to be untested. For now, the source4 forked client tools are left unchanged: - smbclient4 - nmblookup4 Finally, the heimdal binaries are left as install=False as they are either part of the build system or end-user tools that we just don't want to install. These are however tested. The motivation is commit like c34ec003b7d45aa4196ff93a0ac29694b25e5309 and da87fa998ab71328f30bcdf5b41aee8675aee48a, which are both totally correct but are not needed if the selftest is not run on MacOS. There are likely other platforms or build environments where building our test binaries is more pain than valuable, see for example also https://lists.samba.org/archive/samba/2019-November/227137.html Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Isaac Boukris <iboukris@samba.org> Autobuild-User(master): Isaac Boukris <iboukris@samba.org> Autobuild-Date(master): Fri Nov 22 11:48:59 UTC 2019 on sn-devel-184
2019-09-25pthreadpool: Only link pthreadpool against librt if we have toAndreas Schneider1-1/+6
This calls clock_gettime() which is available in glibc on Linux. If the wscript in libreplace detected that librt is needed for clock_gettime() we have to link against it. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14140 Signed-off-by: Andreas Schneider <asn@samba.org> Signed-off-by: Isaac Boukris <iboukris@gmail.com> Pair-Programmed-With: Isaac Boukris <iboukris@gmail.com> Reviewed-by: Matthias Dieter Wallnöfer <mdw@samba.org> Reviewed-by: Alexander Bokovoy <ab@samba.org>
2019-08-23pthreadpool: Remove wrong comment.Christof Schmitt1-4/+0
Commit e45d33e9 removed the sync fallback path for the case that no thread could be created. Remove the comment for that fallback as it does not make sense anymore. Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Ralph Böhme <slow@samba.org> Autobuild-User(master): Christof Schmitt <cs@samba.org> Autobuild-Date(master): Fri Aug 23 23:09:12 UTC 2019 on sn-devel-184
2019-06-04lib/pthreadpool: cppcheck: Fix Memory leakNoel Power1-0/+6
Fixes lib/pthreadpool/tests.c:63: error: memleak: Memory leak: finished <--[cppcheck] Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andreas Schneider <asn@samba.org>
2019-01-11Revert "pthreadpool: split out pthreadpool_tevent_job from ↵Ralph Boehme1-172/+66
pthreadpool_tevent_job_state" This reverts commit 245d684d28dab630f3d47ff61006a1fe3e5eeefa. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: add pthreadpool_tevent_job_cancel()"Ralph Boehme1-40/+0
This reverts commit 791c05144ee9296024cc0fdebe4afeaaf67e26bc. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: maintain a global list of orphaned pthreadpool_tevent_jobs"Ralph Boehme2-43/+0
This reverts commit 25756425aaf5465e56ea809cd415b6a387848919. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: add some lockless coordination between the main and job ↵Ralph Boehme2-221/+5
threads" This reverts commit 9656b8d8ee11ee351870286f16ea8fbe49112292. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: add helgrind magic to PTHREAD_TEVENT_JOB_THREAD_FENCE_*()"Ralph Boehme1-34/+0
This reverts commit 9b73fda926eb8493e80012794483039be66d4e6c. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: maintain a list of job_states on each ↵Ralph Boehme1-78/+24
pthreadpool_tevent_glue" This reverts commit aa9b64eccfd037941512bad108c4e3946714a502. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: add a comment about a further optimization in ↵Ralph Boehme1-17/+0
pthreadpool_tevent_job_destructor()" This reverts commit f23cac39b36b026650e0922c78fe0fd3fe567e35. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: test cancelling and freeing pending pthreadpool_tevent ↵Ralph Boehme1-434/+0
jobs/pools" This reverts commit 40d15260d24d0071732f47873f395fce29b8a6f4. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: add pthreadpool_tevent_[current_job_]per_thread_cwd()"Ralph Boehme2-33/+0
This reverts commit 12a45ee1a66379ba7562729b835ce0e2e4bfb3b3. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: add tests for ↵Ralph Boehme1-144/+0
pthreadpool_tevent_[current_job_]per_thread_cwd()" This reverts commit fbafdc99ef2cef11a1a28e795ffe965cb53ef7fa. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: call unshare(CLONE_FS) if available"Ralph Boehme3-56/+0
This reverts commit 65e4742d168454df6507d9e74993749063435dd6. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: add pthreadpool_restart_check[_monitor_{fd,drain}]()"Ralph Boehme3-365/+0
This reverts commit 3c4cdb290723432b00ff9ff88b892cb4e66e76cd. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: implement pthreadpool_tevent_wrapper_create() ↵Ralph Boehme2-433/+1
infrastructure" This reverts commit f9745d8b5234091c38e93ed57a255120b61f3ad7. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: test cancelling and freeing jobs of a wrapped ↵Ralph Boehme1-573/+0
pthreadpool_tevent" This reverts commit fb6b6cf3e43165ced4b1039f2683d19f277c0792. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: we need to use pthreadpool_tevent_per_thread_cwd() on ↵Ralph Boehme1-2/+1
the callers pool" This reverts commit ff863f2d98ac5e12073af824b794404c3d7198c5. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: ignore the return value of poll(NULL, 0UL, 1)"Ralph Boehme1-2/+2
This reverts commit 6da0d68f49bbd82f5a08427779c9f5ebd6f755aa. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: reset monitor_fd after calling tevent_fd_set_auto_close()"Ralph Boehme1-1/+0
This reverts commit f68b5ee75f002ed542a8423070fb01e3b0e83f65. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2018-07-31pthreadpool: reset monitor_fd after calling tevent_fd_set_auto_close()Stefan Metzmacher1-0/+1
This tries to convince Coverity that we don't have a resource leak: CID 1438157: (RESOURCE_LEAK) Handle variable "monitor_fd" going out of scope leaks the handle. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2018-07-31pthreadpool: ignore the return value of poll(NULL, 0UL, 1)Stefan Metzmacher1-2/+2
Otherwise Coverity reports this: CID 1438160: (CHECKED_RETURN) Calling "poll(NULL, 0UL, 1)" without checking return value. This library function may fail and return an error code. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2018-07-27pthreadpool: we need to use pthreadpool_tevent_per_thread_cwd() on the ↵Stefan Metzmacher1-1/+2
callers pool In pthreadpool_tevent_job_send() we remember if the job will be chdir safe. It means we means we need to ask the callers pool when calling pthreadpool_tevent_per_thread_cwd(), as the callers pool might be a wrapper using pthreadpool_tevent_force_per_thread_cwd(). Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-25pthreadpool: add a missing includeRalph Boehme2-0/+2
Reported-by: David Disseldorp <ddiss@samba.org> Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2018-07-24pthreadpool: test cancelling and freeing jobs of a wrapped pthreadpool_teventRalph Boehme1-0/+573
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: implement pthreadpool_tevent_wrapper_create() infrastructureStefan Metzmacher2-1/+433
This can be used implement a generic per thread impersonation for thread pools. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: add pthreadpool_restart_check[_monitor_{fd,drain}]()Stefan Metzmacher3-0/+365
This makes it possible to monitor the pthreadpool for exited worker threads and may restart new threads from the main thread again. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: add tests for pthreadpool_tevent_[current_job_]per_thread_cwd()Stefan Metzmacher1-0/+144
Note this currently this doesn't enforce the support for unshare(CLONE_FS) as some contraint container environment (e.g. docker) reject the whole unshare() system call. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: add pthreadpool_tevent_[current_job_]per_thread_cwd()Stefan Metzmacher2-0/+33
This can be used to check if worker threads run with unshare(CLONE_FS). Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: call unshare(CLONE_FS) if availableRalph Boehme3-0/+56
This paves the way for pthreadpool jobs that are path based. Callers can use pthreadpool_per_thread_cwd() to check if the current pool supports it. Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: test cancelling and freeing pending pthreadpool_tevent jobs/poolsRalph Boehme1-0/+434
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Ralph Boehme <slow@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org>
2018-07-24pthreadpool: add a comment about a further optimization in ↵Stefan Metzmacher1-0/+17
pthreadpool_tevent_job_destructor() This seems to be a really rare race, it's likely that the immediate event will still trigger and cleanup. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: maintain a list of job_states on each pthreadpool_tevent_glueStefan Metzmacher1-24/+78
We should avoid traversing a linked list within a thread without holding a mutex! Using a mutex would be very tricky as we'll likely deadlock with the mutexes at the raw pthreadpool layer. So we use somekind of spinlock using atomic_thread_fence in order to protect the access to job->state->glue->{tctx,ev} in pthreadpool_tevent_job_signal(). Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: add helgrind magic to PTHREAD_TEVENT_JOB_THREAD_FENCE_*()Stefan Metzmacher1-0/+34
This avoids the expected helgrind/drd warnings on the job states which are protected by the thread fence. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: add some lockless coordination between the main and job threadsStefan Metzmacher2-5/+221
In the direction from the main process to the job thread, we have: - 'maycancel', which is set when tevent_req_cancel() is called, - 'orphaned' is the job request, tevent_context or pthreadpool_tevent was talloc_free'ed. The job function can consume these by using: /* * return true - if tevent_req_cancel() was called. */ bool pthreadpool_tevent_current_job_canceled(void); /* * return true - if talloc_free() was called on the job request, * tevent_context or pthreadpool_tevent. */ bool pthreadpool_tevent_current_job_orphaned(void); /* * return true if canceled and orphaned are both false. */ bool pthreadpool_tevent_current_job_continue(void); In the other direction we remember the following points in the job execution: - 'started' - set when the job is picked up by a worker thread - 'executed' - set once the job function returned. - 'finished' - set when pthreadpool_tevent_job_signal() is entered - 'dropped' - set when pthreadpool_tevent_job_signal() leaves with orphaned - 'signaled' - set when pthreadpool_tevent_job_signal() leaves normal There're only one side writing each element, either the main process or the job thread. This means we can do the coordination with a full memory barrier using atomic_thread_fence(memory_order_seq_cst). lib/replace provides fallbacks if C11 stdatomic.h is not available. A real pthreadpool requires pthread and atomic_thread_fence() (or an replacement) to be available, otherwise we only have pthreadpool_sync.c. But this should not make a real difference, as at least __sync_synchronize() is availabe since 2005 in gcc. We also require __thread which is available since 2002. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: replace assert_return_code(ret, 0); with assert_int_equal(ret, 0);Stefan Metzmacher1-3/+3
We need to assert the exact value! Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: test pthreadpool_tevent_max_threads() returns the expected resultStefan Metzmacher1-0/+10
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: make sure a pthreadpool is marked as stopped in child processesStefan Metzmacher1-0/+1
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-12pthreadpool: allocate glue->tctx on glue as memory context.Stefan Metzmacher1-1/+1
This means it will go aways together with glue and thte event context. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Stefan Metzmacher <metze@samba.org> Autobuild-Date(master): Thu Jul 12 17:18:01 CEST 2018 on sn-devel-144