* [PATCH] target: Avoid target_shutdown_sessions loop during queue_depth change
@ 2017-06-01 6:54 Nicholas A. Bellinger
2017-06-01 6:57 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Nicholas A. Bellinger @ 2017-06-01 6:54 UTC (permalink / raw)
To: target-devel
Cc: linux-scsi, lkml, Nicholas Bellinger, Christoph Hellwig,
Mike Christie, Hannes Reinecke
From: Nicholas Bellinger <nab@linux-iscsi.org>
When target_shutdown_sessions() is invoked to shutdown all active
sessions associated with a se_node_acl when se_node_acl->queue_depth
is changed via core_tpg_set_initiator_node_queue_depth(), it's
possible that new connections reconnect immediately after explicit
shutdown occurs via target_shutdown_sessions().
Which means it's possible for the newly reconnected session with
the proper queue_depth can be shutdown multiple times when
target_shutdown_sessions() loops to drain all active sessions
for all cases.
This was regression was introduced by:
commit bc6e6bb470eda42f44bcac96c261cff1216577b3
Author: Christoph Hellwig <hch@lst.de>
Date: Mon May 2 15:45:19 2016 +0200
target: consolidate and fix session shutdown
To avoid this case, instead move sessions into a local list and
avoid draining the same session multiple times when invoked via
core_tpg_set_initiator_node_queue_depth(), but still loop during
normal se_node_acl delete until all associated sessions have
been shutdown.
Cc: Christoph Hellwig <hch@lst.de>
Cc: Mike Christie <mchristi@redhat.com>
Cc: Hannes Reinecke <hare@suse.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
drivers/target/target_core_tpg.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c
index 310d9e5..7a7c2b5 100644
--- a/drivers/target/target_core_tpg.c
+++ b/drivers/target/target_core_tpg.c
@@ -336,10 +336,11 @@ struct se_node_acl *core_tpg_add_initiator_node_acl(
return acl;
}
-static void target_shutdown_sessions(struct se_node_acl *acl)
+static void target_shutdown_sessions(struct se_node_acl *acl, bool do_restart)
{
struct se_session *sess;
unsigned long flags;
+ LIST_HEAD(tmp_list);
restart:
spin_lock_irqsave(&acl->nacl_sess_lock, flags);
@@ -347,14 +348,22 @@ static void target_shutdown_sessions(struct se_node_acl *acl)
if (sess->sess_tearing_down)
continue;
+ list_move_tail(&sess->sess_acl_list, &tmp_list);
+ }
+ spin_unlock_irqrestore(&acl->nacl_sess_lock, flags);
+
+ if (list_empty(&tmp_list))
+ return;
+
+ list_for_each_entry(sess, &tmp_list, sess_acl_list) {
list_del_init(&sess->sess_acl_list);
- spin_unlock_irqrestore(&acl->nacl_sess_lock, flags);
if (acl->se_tpg->se_tpg_tfo->close_session)
acl->se_tpg->se_tpg_tfo->close_session(sess);
- goto restart;
}
- spin_unlock_irqrestore(&acl->nacl_sess_lock, flags);
+
+ if (do_restart)
+ goto restart;
}
void core_tpg_del_initiator_node_acl(struct se_node_acl *acl)
@@ -367,7 +376,7 @@ void core_tpg_del_initiator_node_acl(struct se_node_acl *acl)
list_del(&acl->acl_list);
mutex_unlock(&tpg->acl_node_mutex);
- target_shutdown_sessions(acl);
+ target_shutdown_sessions(acl, true);
target_put_nacl(acl);
/*
@@ -414,7 +423,7 @@ int core_tpg_set_initiator_node_queue_depth(
/*
* Shutdown all pending sessions to force session reinstatement.
*/
- target_shutdown_sessions(acl);
+ target_shutdown_sessions(acl, false);
pr_debug("Successfully changed queue depth to: %d for Initiator"
" Node: %s on %s Target Portal Group: %u\n", acl->queue_depth,
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] target: Avoid target_shutdown_sessions loop during queue_depth change
2017-06-01 6:54 [PATCH] target: Avoid target_shutdown_sessions loop during queue_depth change Nicholas A. Bellinger
@ 2017-06-01 6:57 ` Christoph Hellwig
2017-06-01 7:04 ` Nicholas A. Bellinger
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2017-06-01 6:57 UTC (permalink / raw)
To: Nicholas A. Bellinger
Cc: target-devel, linux-scsi, lkml, Christoph Hellwig, Mike Christie,
Hannes Reinecke
How about this slightly easier to read version?
---
>From 75276cd521ccecba244c1ee6c1100e27518c628d Mon Sep 17 00:00:00 2001
From: Nicholas Bellinger <nab@linux-iscsi.org>
Date: Thu, 1 Jun 2017 06:54:06 +0000
Subject: target: Avoid target_shutdown_sessions loop during queue_depth change
When target_shutdown_sessions() is invoked to shutdown all active
sessions associated with a se_node_acl when se_node_acl->queue_depth
is changed via core_tpg_set_initiator_node_queue_depth(), it's
possible that new connections reconnect immediately after explicit
shutdown occurs via target_shutdown_sessions().
Which means it's possible for the newly reconnected session with
the proper queue_depth can be shutdown multiple times when
target_shutdown_sessions() loops to drain all active sessions
for all cases.
This was regression was introduced by:
commit bc6e6bb470eda42f44bcac96c261cff1216577b3
Author: Christoph Hellwig <hch@lst.de>
Date: Mon May 2 15:45:19 2016 +0200
target: consolidate and fix session shutdown
To avoid this case, instead move sessions into a local list and
avoid draining the same session multiple times when invoked via
core_tpg_set_initiator_node_queue_depth(), but still loop during
normal se_node_acl delete until all associated sessions have
been shutdown.
Cc: Christoph Hellwig <hch@lst.de>
Cc: Mike Christie <mchristi@redhat.com>
Cc: Hannes Reinecke <hare@suse.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
drivers/target/target_core_tpg.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c
index 310d9e55c6eb..74893acb8b5e 100644
--- a/drivers/target/target_core_tpg.c
+++ b/drivers/target/target_core_tpg.c
@@ -336,25 +336,32 @@ struct se_node_acl *core_tpg_add_initiator_node_acl(
return acl;
}
-static void target_shutdown_sessions(struct se_node_acl *acl)
+static bool target_shutdown_sessions(struct se_node_acl *acl)
{
struct se_session *sess;
unsigned long flags;
+ LIST_HEAD(tmp_list);
-restart:
spin_lock_irqsave(&acl->nacl_sess_lock, flags);
list_for_each_entry(sess, &acl->acl_sess_list, sess_acl_list) {
if (sess->sess_tearing_down)
continue;
+ list_move_tail(&sess->sess_acl_list, &tmp_list);
+ }
+ spin_unlock_irqrestore(&acl->nacl_sess_lock, flags);
+
+ if (list_empty(&tmp_list))
+ return true;
+
+ list_for_each_entry(sess, &tmp_list, sess_acl_list) {
list_del_init(&sess->sess_acl_list);
- spin_unlock_irqrestore(&acl->nacl_sess_lock, flags);
if (acl->se_tpg->se_tpg_tfo->close_session)
acl->se_tpg->se_tpg_tfo->close_session(sess);
- goto restart;
}
- spin_unlock_irqrestore(&acl->nacl_sess_lock, flags);
+
+ return false;
}
void core_tpg_del_initiator_node_acl(struct se_node_acl *acl)
@@ -367,7 +374,8 @@ void core_tpg_del_initiator_node_acl(struct se_node_acl *acl)
list_del(&acl->acl_list);
mutex_unlock(&tpg->acl_node_mutex);
- target_shutdown_sessions(acl);
+ while (!target_shutdown_sessions(acl))
+ ;
target_put_nacl(acl);
/*
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-06-01 7:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-01 6:54 [PATCH] target: Avoid target_shutdown_sessions loop during queue_depth change Nicholas A. Bellinger
2017-06-01 6:57 ` Christoph Hellwig
2017-06-01 7:04 ` Nicholas A. Bellinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox