Description: zfcp-hbaapi: Fix crash on HBA_FreeLibrary call. Symptom: zfcp_ping segmentation fault without any online adapters. Problem: Segmentation fault happens on libzfcphbaapi if it build as vendor library at this time when SNIA HBAAPI performs dlclose of zfcp-hbaapi after clean-up function HBA_FreeLibrary. zfcp-hbaapi has missing the event thread clean-up. Solution: zfcp-hbaapi event thread cleanup has been coded using pthread_cancel and pthread_join in HBA_FreeLibrary function. Problem-ID: 72524 --- lib-zfcp-hbaapi-2.1/vlib.c | 16 ++++++++++++++++ lib-zfcp-hbaapi-2.1/vlib.h | 2 ++ lib-zfcp-hbaapi-2.1/vlib_events.c | 4 +--- 3 files changed, 19 insertions(+), 3 deletions(-) --- a/lib-zfcp-hbaapi-2.1/vlib.c +++ b/lib-zfcp-hbaapi-2.1/vlib.c @@ -169,6 +169,7 @@ HBA_STATUS HBA_LoadLibrary(void) */ HBA_STATUS HBA_FreeLibrary(void) { + void *res; VLIB_MUTEX_LOCK(&vlib_data.mutex); if (!vlib_data.isLoaded) { @@ -183,6 +184,21 @@ HBA_STATUS HBA_FreeLibrary(void) } vlib_data.unloading = 1; + if (pthread_cancel(vlib_data.id) != 0) { + VLIB_MUTEX_UNLOCK(&vlib_data.mutex); + return HBA_STATUS_ERROR; + } + + if (pthread_join(vlib_data.id, &res) != 0) { + VLIB_MUTEX_UNLOCK(&vlib_data.mutex); + return HBA_STATUS_ERROR; + } + + if (res != PTHREAD_CANCELED) { + VLIB_MUTEX_UNLOCK(&vlib_data.mutex); + return HBA_STATUS_ERROR; + } + closeAllAdapters(); vlib_data.isLoaded = 0; --- a/lib-zfcp-hbaapi-2.1/vlib.h +++ b/lib-zfcp-hbaapi-2.1/vlib.h @@ -494,6 +494,8 @@ struct vlib_data { struct block adapters; /**< @brief List of adapters In fact this is the anchor of the library's repository. */ + pthread_t id; /**< @brief Pthread ID of event + handling thread*/ pthread_mutex_t mutex; /**< @brief Protects this structure */ }; --- a/lib-zfcp-hbaapi-2.1/vlib_events.c +++ b/lib-zfcp-hbaapi-2.1/vlib_events.c @@ -241,7 +241,5 @@ void cleanup_event_thread() void start_event_thread() { - pthread_t id; - - pthread_create(&id, NULL, &establish_listener, NULL); + pthread_create(&vlib_data.id, NULL, &establish_listener, NULL); }