[stgt] [PATCH] iscsi: clean up pthread properly

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Tue Jun 8 13:05:06 CEST 2010


This is for the pthread branch.

=
From: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
Subject: [PATCH] iscsi: clean up pthread properly

Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
---
 usr/iscsi/iscsid.h |    1 +
 usr/iscsi/target.c |   14 +++++++++++++-
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/usr/iscsi/iscsid.h b/usr/iscsi/iscsid.h
index 8158e63..91e40d6 100644
--- a/usr/iscsi/iscsid.h
+++ b/usr/iscsi/iscsid.h
@@ -249,6 +249,7 @@ struct iscsi_target {
 	struct list_head events_list;
 
 	struct bs_finish bsfin;
+	int stop_pthread;
 };
 
 enum task_flags {
diff --git a/usr/iscsi/target.c b/usr/iscsi/target.c
index a32667c..3b3eecc 100644
--- a/usr/iscsi/target.c
+++ b/usr/iscsi/target.c
@@ -255,6 +255,15 @@ void iscsi_target_destroy(int tid)
 	}
 
 	list_del(&target->tlist);
+
+	if (target->bsfin.thread) {
+		target->stop_pthread = 1;
+		pthread_kill(target->bsfin.thread, SIGUSR2);
+
+		pthread_join(target->bsfin.thread, NULL);
+		pthread_mutex_destroy(&target->bsfin.finished_lock);
+	}
+
 	close(target->efd);
 	free(target);
 	isns_target_deregister(tgt_targetname(tid));
@@ -291,7 +300,10 @@ retry:
 		}
 	}
 
-	goto retry;
+	if (!t->stop_pthread)
+		goto retry;
+
+	pthread_exit(NULL);
 }
 
 int iscsi_target_create(struct target *t)
-- 
1.6.5

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list