rgw/posix: Fix race condition in Inotify causing segfault
Fixed a race condition in the Inotify class where the ev_loop() thread
and caller threads (add_watch/remove_watch) were accessing the
wd_callback_map and wd_remove_map hash maps without synchronization.
This caused a segfault during hash table operations when one thread
was reading from the map while another was modifying it, leading to
iterator invalidation and memory corruption.
Backtrace from the crash:
Frame 5: file::listing::Inotify::ev_loop()+0x190
Frame 4: ankerl::unordered_dense::v3_1_0::detail::table::find()
Crash: Memory access violation during WatchRecord lookup
The fix adds:
- A mutex (map_mutex) to protect both hash maps
- Lock guards in add_watch() and remove_watch() during map modifications
- Lock guard in ev_loop() with proper copying of watch record data to
avoid holding the lock during callbacks and prevent use-after-free
See https://jenkins.ceph.com/job/ceph-pull-requests/169774/testReport/junit/projectroot.src.test/rgw/unittest_rgw_posix_driver/