From patchwork Fri Nov 3 23:20:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10041363 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 5689B602D8 for ; Fri, 3 Nov 2017 23:21:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48911283AF for ; Fri, 3 Nov 2017 23:21:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D70C29A19; Fri, 3 Nov 2017 23:21:08 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 3009C283AF for ; Fri, 3 Nov 2017 23:21:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752127AbdKCXVF (ORCPT ); Fri, 3 Nov 2017 19:21:05 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:41264 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752515AbdKCXVB (ORCPT ); Fri, 3 Nov 2017 19:21:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1509751262; x=1541287262; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=IR0bW309d/TVleC44oqHMecJMrCvG2OPgifC7T9Pyog=; b=oTA2Hw9zBjM26HOjSVwwSXDfdR+7HmN0QEDtWRc+Wo1N7htcfBgtnAqH OgRz6Ho9ao8GhieZd1UGB9rFHRvtmSG8BpW2zCT9R6I293x9oPnvzdKaM 6JcdV+1JxXYPtx7FtzpJZ2l71W5OGGK0u8gKKtmgZazQeOlVsTApCfq3g U2VtHj0bAns3Pq473OrMwG5CO5DHLnHKGzl241G85Pm7h1FNVKwpSV62R q9B2TOWQxT+mkJmj939g3qF97kHwtRPBeAEXz2N/mTm5jYPOugh0jcRbt lfVD1zThBh8jVq5zpCMZxV+ieb6NL4TmSmxU5XLCKHo4tCYrH7HM2vJha Q==; X-IronPort-AV: E=Sophos;i="5.44,339,1505750400"; d="scan'208";a="61365173" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 04 Nov 2017 07:21:01 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 03 Nov 2017 16:19:03 -0700 Received: from unknown (HELO MILHUBIP04.sdcorp.global.sandisk.com) ([10.177.9.97]) by uls-op-cesaip02.wdc.com with ESMTP; 03 Nov 2017 16:21:01 -0700 Received: from milsmgip12.sandisk.com (10.177.9.6) by MILHUBIP04.sdcorp.global.sandisk.com (10.177.9.97) with Microsoft SMTP Server id 14.3.319.2; Fri, 3 Nov 2017 16:20:59 -0700 X-AuditID: 0ab1095a-d99e3980000146e4-be-59fcf9db5000 Received: from thinkpad-bart.int.fusionio.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id 78.33.18148.BD9FCF95; Fri, 3 Nov 2017 16:20:59 -0700 (PDT) From: Bart Van Assche To: Doug Ledford CC: , Mike Marciniszyn , Bart Van Assche Subject: [PATCH 4/5] IB/srpt: Wait until channel release has finished during module unload Date: Fri, 3 Nov 2017 16:20:55 -0700 Message-ID: <20171103232056.30614-5-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171103232056.30614-1-bart.vanassche@wdc.com> References: <20171103232056.30614-1-bart.vanassche@wdc.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFJMWRmVeSWpSXmKPExsXCtZGTTff2zz+RBodmyVhc+vOF0eLl+Q+s Fs8O9bJYbPjfyO7A4rF4z0smj/f7rrJ5fN4k59F+oJspgCWKyyYlNSezLLVI3y6BK6Nn4XmW guviFV/eP2ZsYNwn3MXIySEhYCLxa+IExi5GLg4hgZWMEueP3GEFSbAJ6EmcmrePCcQWEVCT 2PRqETuIzSxQLXF1z3RGEFtYIEri05aZbF2MHBwsAqoSu8+ngIR5Bawlbpy/wwwxX15i7dt7 jCAlnAI2EudnioOEhYBKltxsYJ3AyL2AkWEVo1huZk5xbnpmgaGRXnFiXkpmcbZecn7uJkaI 76N2MF6faH6IkYmDU6qB0bih9eQ23tzcqqIexxlWvK7L2Z3bI2cn1fbITrjlcePwf4X8G3aH V/B43DpiuSG2ruTfLJZKJXbNhGVWPQs/a/nHJH9tfHBEavLN2b6l2TUtJcpzbm15deNMlNN9 T87lIal+37qX1p7aqHXE3cEz9fVH/Vfiaqt9hByNatzz8kx69Nfva/6kxFKckWioxVxUnAgA CCqEQa0BAAA= MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce the helper function srpt_set_enabled(). Protect sport->enabled changes with sdev->mutex. Makes configfs writes into 'enabled' wait until all channel resources have been freed. Wait until channel release has finished during kernel module unload. Signed-off-by: Bart Van Assche --- drivers/infiniband/ulp/srpt/ib_srpt.c | 43 ++++++++++++++++------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c index 1aeb8d6ae6d9..ca602eb50078 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -1821,19 +1821,31 @@ static bool srpt_disconnect_ch_sync(struct srpt_rdma_ch *ch) return wait; } -static void __srpt_close_all_ch(struct srpt_device *sdev) +static void srpt_set_enabled(struct srpt_port *sport, bool enabled) + __must_hold(&sdev->mutex) { + struct srpt_device *sdev = sport->sdev; struct srpt_rdma_ch *ch; lockdep_assert_held(&sdev->mutex); + if (sport->enabled == enabled) + return; + sport->enabled = enabled; + if (sport->enabled) + return; + +again: list_for_each_entry(ch, &sdev->rch_list, list) { - if (srpt_disconnect_ch(ch) >= 0) - pr_info("Closing channel %s-%d because target %s has been disabled\n", - ch->sess_name, ch->qp->qp_num, - sdev->device->name); - srpt_close_ch(ch); + if (ch->sport == sport) { + pr_info("%s: closing channel %s-%d\n", + sdev->device->name, ch->sess_name, + ch->qp->qp_num); + if (srpt_disconnect_ch_sync(ch)) + goto again; + } } + } static void srpt_free_ch(struct kref *kref) @@ -2496,8 +2508,7 @@ static int srpt_release_sdev(struct srpt_device *sdev) mutex_lock(&sdev->mutex); for (i = 0; i < ARRAY_SIZE(sdev->port); i++) - sdev->port[i].enabled = false; - __srpt_close_all_ch(sdev); + srpt_set_enabled(&sdev->port[i], false); mutex_unlock(&sdev->mutex); res = wait_event_interruptible(sdev->ch_releaseQ, @@ -3083,7 +3094,6 @@ static ssize_t srpt_tpg_enable_store(struct config_item *item, struct se_portal_group *se_tpg = to_tpg(item); struct srpt_port *sport = srpt_tpg_to_sport(se_tpg); struct srpt_device *sdev = sport->sdev; - struct srpt_rdma_ch *ch; unsigned long tmp; int ret; @@ -3097,24 +3107,11 @@ static ssize_t srpt_tpg_enable_store(struct config_item *item, pr_err("Illegal value for srpt_tpg_store_enable: %lu\n", tmp); return -EINVAL; } - if (sport->enabled == tmp) - goto out; - sport->enabled = tmp; - if (sport->enabled) - goto out; mutex_lock(&sdev->mutex); - list_for_each_entry(ch, &sdev->rch_list, list) { - if (ch->sport == sport) { - pr_debug("%s: ch %p %s-%d\n", __func__, ch, - ch->sess_name, ch->qp->qp_num); - srpt_disconnect_ch(ch); - srpt_close_ch(ch); - } - } + srpt_set_enabled(sport, tmp); mutex_unlock(&sdev->mutex); -out: return count; }