From patchwork Thu Jun 1 06:57:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 9758757 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7829760390 for ; Thu, 1 Jun 2017 06:57:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68A5628451 for ; Thu, 1 Jun 2017 06:57:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D327284F9; Thu, 1 Jun 2017 06:57:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.9 required=2.0 tests=BAYES_00,HEXHASH_WORD, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBDE2284F9 for ; Thu, 1 Jun 2017 06:57:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751118AbdFAG5S (ORCPT ); Thu, 1 Jun 2017 02:57:18 -0400 Received: from verein.lst.de ([213.95.11.211]:44549 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751053AbdFAG5R (ORCPT ); Thu, 1 Jun 2017 02:57:17 -0400 Received: by newverein.lst.de (Postfix, from userid 2407) id A194968B7F; Thu, 1 Jun 2017 08:57:15 +0200 (CEST) Date: Thu, 1 Jun 2017 08:57:15 +0200 From: Christoph Hellwig To: "Nicholas A. Bellinger" Cc: target-devel , linux-scsi , lkml , Christoph Hellwig , Mike Christie , Hannes Reinecke Subject: Re: [PATCH] target: Avoid target_shutdown_sessions loop during queue_depth change Message-ID: <20170601065715.GA17147@lst.de> References: <1496300046-21234-1-git-send-email-nab@linux-iscsi.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1496300046-21234-1-git-send-email-nab@linux-iscsi.org> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP How about this slightly easier to read version? --- From 75276cd521ccecba244c1ee6c1100e27518c628d Mon Sep 17 00:00:00 2001 From: Nicholas Bellinger 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 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 Cc: Mike Christie Cc: Hannes Reinecke Signed-off-by: Nicholas Bellinger --- 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); /*