Blame SOURCES/lib-zfcp-hbaapi-2.1-HBA_FreeLibrary.patch

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