From 4474209781bef424993cc72afcc9e14183b6f1e2 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 21 Apr 2019 19:03:53 +0000 Subject: [PATCH 1/2] scst: Remove disabled code from scst_unregister_target() git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8267 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_main.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index 3154c9c75..0ef9db751 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -550,11 +550,13 @@ out_free_tgt: } EXPORT_SYMBOL(scst_register_target); -/* - * scst_unregister_target() - unregister target. +/** + * scst_unregister_target() - unregister a target + * @tgt: Target to be unregistered. * - * It is supposed that no attempts to create new sessions for this - * target will be done in a race with this function. + * The caller is responsible for unregistration of all sessions associated + * with @tgt. Additionally, the caller must guarantee that no new sessions + * will be associated with @tgt while this function is in progress. */ void scst_unregister_target(struct scst_tgt *tgt) { @@ -575,28 +577,6 @@ void scst_unregister_target(struct scst_tgt *tgt) tgt->tgtt->release(tgt); TRACE_DBG("%s", "Target driver's release() returned"); -#if 0 /* Looks not needed. For scst_local it's bad, see this commit log message */ - mutex_lock(&scst_mutex); -again: - { - struct scst_session *sess; - - list_for_each_entry(sess, &tgt->sess_list, sess_list_entry) { - if (sess->shut_phase == SCST_SESS_SPH_READY) { - /* - * Sometimes it's hard for target driver to - * track all its sessions, so let's help it. - */ - mutex_unlock(&scst_mutex); - scst_unregister_session(sess, 0, NULL); - mutex_lock(&scst_mutex); - goto again; - } - } - } - mutex_unlock(&scst_mutex); -#endif - /* * Testing tgt->sysfs_sess_list below without holding scst_mutex * is safe, because: From a61b47415cf1e6630c0177f2badb31bc5b86f62c Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 21 Apr 2019 19:05:28 +0000 Subject: [PATCH 2/2] scst: Make scst_unregister_target() show which sessions it is waiting for git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8268 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_main.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index 0ef9db751..ff3c4f12f 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -590,7 +590,19 @@ void scst_unregister_target(struct scst_tgt *tgt) * object. */ TRACE_DBG("%s", "Waiting for sessions shutdown"); - wait_event(tgt->unreg_waitQ, list_empty(&tgt->sysfs_sess_list)); + while (!wait_event_timeout(tgt->unreg_waitQ, + list_empty(&tgt->sysfs_sess_list), 60 * HZ)) { + struct scst_session *sess; + + mutex_lock(&scst_mutex); + list_for_each_entry(sess, &tgt->sess_list, sess_list_entry) { + PRINT_INFO("Still waiting for session %s/%s; state %ld; refcnt %#lx", + tgt->tgt_name, sess->sess_name, + sess->shut_phase, + atomic_long_read(&sess->refcnt.count)); + } + mutex_unlock(&scst_mutex); + } TRACE_DBG("%s", "wait_event() returned"); res = scst_suspend_activity(SCST_SUSPEND_TIMEOUT_UNLIMITED);