From acbabe3d916d763a0bb13e7df876cac61ca5b160 Mon Sep 17 00:00:00 2001 From: Xiubo Li Date: Fri, 26 Jul 2019 12:34:52 +0800 Subject: event: rename event_XXX with gf_ prefixed I hit one crash issue when using the libgfapi. In the libgfapi it will call glfs_poller() --> event_dispatch() in file api/src/glfs.c:721, and the event_dispatch() is defined by libgluster locally, the problem is the name of event_dispatch() is the extremly the same with the one from libevent package form the OS. For example, if a executable program Foo, which will also use and link the libevent and the libgfapi at the same time, I can hit the crash, like: kernel: glfs_glfspoll[68486]: segfault at 1c0 ip 00007fef006fd2b8 sp 00007feeeaffce30 error 4 in libevent-2.0.so.5.1.9[7fef006ed000+46000] The link for Foo is: lib_foo_LADD = -levent $(GFAPI_LIBS) It will crash. This is because the glfs_poller() is calling the event_dispatch() from the libevent, not the libglsuter. The gfapi link info : GFAPI_LIBS = -lacl -lgfapi -lglusterfs -lgfrpc -lgfxdr -luuid If I link Foo like: lib_foo_LADD = $(GFAPI_LIBS) -levent It will works well without any problem. And if Foo call one private lib, such as handler_glfs.so, and the handler_glfs.so will link the GFAPI_LIBS directly, while the Foo won't and it will dlopen(handler_glfs.so), then the crash will be hit everytime. The link info will be: foo_LADD = -levent libhandler_glfs_LIBADD = $(GFAPI_LIBS) I can avoid the crash temporarily by linking the GFAPI_LIBS in Foo too like: foo_LADD = $(GFAPI_LIBS) -levent libhandler_glfs_LIBADD = $(GFAPI_LIBS) But this is ugly since the Foo won't use any APIs from the GFAPI_LIBS. And in some cases when the --as-needed link option is added(on many dists it is added as default), then the crash is back again, the above workaround won't work. Backport of: > https://review.gluster.org/#/c/glusterfs/+/23110/ > Change-Id: I38f0200b941bd1cff4bf3066fca2fc1f9a5263aa > Fixes: #699 > Signed-off-by: Xiubo Li Change-Id: I38f0200b941bd1cff4bf3066fca2fc1f9a5263aa updates: bz#1740519 Signed-off-by: Xiubo Li (cherry picked from commit 799edc73c3d4f694c365c6a7c27c9ab8eed5f260) --- libglusterfs/src/event.c | 37 ++++++++++++++++++----------------- libglusterfs/src/glusterfs/gf-event.h | 25 +++++++++++------------ libglusterfs/src/libglusterfs.sym | 20 +++++++++---------- 3 files changed, 42 insertions(+), 40 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/event.c b/libglusterfs/src/event.c index 35a2f5c896f..235128b6044 100644 --- a/libglusterfs/src/event.c +++ b/libglusterfs/src/event.c @@ -22,7 +22,7 @@ #include "glusterfs/syscall.h" struct event_pool * -event_pool_new(int count, int eventthreadcount) +gf_event_pool_new(int count, int eventthreadcount) { struct event_pool *event_pool = NULL; extern struct event_ops event_ops_poll; @@ -51,8 +51,9 @@ event_pool_new(int count, int eventthreadcount) } int -event_register(struct event_pool *event_pool, int fd, event_handler_t handler, - void *data, int poll_in, int poll_out, char notify_poller_death) +gf_event_register(struct event_pool *event_pool, int fd, + event_handler_t handler, void *data, int poll_in, + int poll_out, char notify_poller_death) { int ret = -1; @@ -65,7 +66,7 @@ out: } int -event_unregister(struct event_pool *event_pool, int fd, int idx) +gf_event_unregister(struct event_pool *event_pool, int fd, int idx) { int ret = -1; @@ -78,7 +79,7 @@ out: } int -event_unregister_close(struct event_pool *event_pool, int fd, int idx) +gf_event_unregister_close(struct event_pool *event_pool, int fd, int idx) { int ret = -1; @@ -91,8 +92,8 @@ out: } int -event_select_on(struct event_pool *event_pool, int fd, int idx_hint, - int poll_in, int poll_out) +gf_event_select_on(struct event_pool *event_pool, int fd, int idx_hint, + int poll_in, int poll_out) { int ret = -1; @@ -105,7 +106,7 @@ out: } int -event_dispatch(struct event_pool *event_pool) +gf_event_dispatch(struct event_pool *event_pool) { int ret = -1; @@ -120,7 +121,7 @@ out: } int -event_reconfigure_threads(struct event_pool *event_pool, int value) +gf_event_reconfigure_threads(struct event_pool *event_pool, int value) { int ret = -1; @@ -134,7 +135,7 @@ out: } int -event_pool_destroy(struct event_pool *event_pool) +gf_event_pool_destroy(struct event_pool *event_pool) { int ret = -1; int destroy = 0, activethreadcount = 0; @@ -175,13 +176,13 @@ poller_destroy_handler(int fd, int idx, int gen, void *data, int poll_out, } out: - event_handled(destroy->pool, fd, idx, gen); + gf_event_handled(destroy->pool, fd, idx, gen); return; } /* This function destroys all the poller threads. - * Note: to be called before event_pool_destroy is called. + * Note: to be called before gf_event_pool_destroy is called. * The order in which cleaning is performed: * - Register a pipe fd(this is for waking threads in poll()/epoll_wait()) * - Set the destroy mode, which this no new event registration will succeed @@ -192,7 +193,7 @@ out: * threads are destroyed) */ int -event_dispatch_destroy(struct event_pool *event_pool) +gf_event_dispatch_destroy(struct event_pool *event_pool) { int ret = -1, threadcount = 0; int fd[2] = {-1}; @@ -230,8 +231,8 @@ event_dispatch_destroy(struct event_pool *event_pool) /* From the main thread register an event on the pipe fd[0], */ - idx = event_register(event_pool, fd[0], poller_destroy_handler, &data, 1, 0, - 0); + idx = gf_event_register(event_pool, fd[0], poller_destroy_handler, &data, 1, + 0, 0); if (idx < 0) goto out; @@ -245,7 +246,7 @@ event_dispatch_destroy(struct event_pool *event_pool) } pthread_mutex_unlock(&event_pool->mutex); - ret = event_reconfigure_threads(event_pool, 0); + ret = gf_event_reconfigure_threads(event_pool, 0); if (ret < 0) goto out; @@ -280,7 +281,7 @@ event_dispatch_destroy(struct event_pool *event_pool) } pthread_mutex_unlock(&event_pool->mutex); - ret = event_unregister(event_pool, fd[0], idx); + ret = gf_event_unregister(event_pool, fd[0], idx); out: if (fd[0] != -1) @@ -292,7 +293,7 @@ out: } int -event_handled(struct event_pool *event_pool, int fd, int idx, int gen) +gf_event_handled(struct event_pool *event_pool, int fd, int idx, int gen) { int ret = 0; diff --git a/libglusterfs/src/glusterfs/gf-event.h b/libglusterfs/src/glusterfs/gf-event.h index 0305194d712..c0f05e7c83b 100644 --- a/libglusterfs/src/glusterfs/gf-event.h +++ b/libglusterfs/src/glusterfs/gf-event.h @@ -110,26 +110,27 @@ struct event_ops { }; struct event_pool * -event_pool_new(int count, int eventthreadcount); +gf_event_pool_new(int count, int eventthreadcount); int -event_select_on(struct event_pool *event_pool, int fd, int idx, int poll_in, - int poll_out); +gf_event_select_on(struct event_pool *event_pool, int fd, int idx, int poll_in, + int poll_out); int -event_register(struct event_pool *event_pool, int fd, event_handler_t handler, - void *data, int poll_in, int poll_out, char notify_poller_death); +gf_event_register(struct event_pool *event_pool, int fd, + event_handler_t handler, void *data, int poll_in, + int poll_out, char notify_poller_death); int -event_unregister(struct event_pool *event_pool, int fd, int idx); +gf_event_unregister(struct event_pool *event_pool, int fd, int idx); int -event_unregister_close(struct event_pool *event_pool, int fd, int idx); +gf_event_unregister_close(struct event_pool *event_pool, int fd, int idx); int -event_dispatch(struct event_pool *event_pool); +gf_event_dispatch(struct event_pool *event_pool); int -event_reconfigure_threads(struct event_pool *event_pool, int value); +gf_event_reconfigure_threads(struct event_pool *event_pool, int value); int -event_pool_destroy(struct event_pool *event_pool); +gf_event_pool_destroy(struct event_pool *event_pool); int -event_dispatch_destroy(struct event_pool *event_pool); +gf_event_dispatch_destroy(struct event_pool *event_pool); int -event_handled(struct event_pool *event_pool, int fd, int idx, int gen); +gf_event_handled(struct event_pool *event_pool, int fd, int idx, int gen); #endif /* _GF_EVENT_H_ */ diff --git a/libglusterfs/src/libglusterfs.sym b/libglusterfs/src/libglusterfs.sym index 60b3f317cc8..92f05946176 100644 --- a/libglusterfs/src/libglusterfs.sym +++ b/libglusterfs/src/libglusterfs.sym @@ -438,16 +438,16 @@ eh_dump eh_new eh_save_history entry_copy -event_dispatch -event_dispatch_destroy -event_handled -event_pool_destroy -event_pool_new -event_reconfigure_threads -event_register -event_select_on -event_unregister -event_unregister_close +gf_event_dispatch +gf_event_dispatch_destroy +gf_event_handled +gf_event_pool_destroy +gf_event_pool_new +gf_event_reconfigure_threads +gf_event_register +gf_event_select_on +gf_event_unregister +gf_event_unregister_close fd_anonymous fd_anonymous_with_flags fd_bind -- cgit