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