From patchwork Mon Nov 7 18:22:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 9415729 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 796866022E for ; Mon, 7 Nov 2016 18:23:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7409D28A4B for ; Mon, 7 Nov 2016 18:23:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68F8528C71; Mon, 7 Nov 2016 18:23:54 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 705DA28A4B for ; Mon, 7 Nov 2016 18:23:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932674AbcKGSXH (ORCPT ); Mon, 7 Nov 2016 13:23:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48264 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932720AbcKGSXF (ORCPT ); Mon, 7 Nov 2016 13:23:05 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B77EDC0467D0; Mon, 7 Nov 2016 18:22:20 +0000 (UTC) Received: from straylight.hirudinean.org.com (ovpn-116-167.phx2.redhat.com [10.3.116.167]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uA7IMKwO017673; Mon, 7 Nov 2016 13:22:20 -0500 From: Chris Leech To: , , lduncan@suse.com Subject: iscsi: make mutex for target scanning and unbinding per-session Date: Mon, 7 Nov 2016 10:22:00 -0800 Message-Id: <1478542920-24460-1-git-send-email-cleech@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 07 Nov 2016 18:22:20 +0000 (UTC) Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently the iSCSI transport class synchronises target scanning and unbinding with a host level mutex. For multi-session hosts (offloading iSCSI HBAs) connecting to storage arrays that may implement one target-per-lun, this can result in the target scan work for hundreds of sessions being serialized behind a single mutex. With slow enough response times, this can cause scan requests initiated from userspace to block on the mutex long enough to trigger 120 sec hung task warnings. I can't see any reason not to move this to a session level mutex and let the target scans run in parallel, speeding up connecting to a large number of targets. Note that as iscsi_tcp creates a virtual host for each session, software iSCSI is effectively doing this already. Signed-off-by: Chris Leech --- drivers/scsi/scsi_transport_iscsi.c | 19 ++++++------------- include/scsi/scsi_transport_iscsi.h | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index 42bca61..83c90fa 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -1568,7 +1568,6 @@ static int iscsi_setup_host(struct transport_container *tc, struct device *dev, memset(ihost, 0, sizeof(*ihost)); atomic_set(&ihost->nr_scans, 0); - mutex_init(&ihost->mutex); iscsi_bsg_host_add(shost, ihost); /* ignore any bsg add error - we just can't do sgio */ @@ -1789,8 +1788,6 @@ static int iscsi_user_scan_session(struct device *dev, void *data) { struct iscsi_scan_data *scan_data = data; struct iscsi_cls_session *session; - struct Scsi_Host *shost; - struct iscsi_cls_host *ihost; unsigned long flags; unsigned int id; @@ -1801,10 +1798,7 @@ static int iscsi_user_scan_session(struct device *dev, void *data) ISCSI_DBG_TRANS_SESSION(session, "Scanning session\n"); - shost = iscsi_session_to_shost(session); - ihost = shost->shost_data; - - mutex_lock(&ihost->mutex); + mutex_lock(&session->mutex); spin_lock_irqsave(&session->lock, flags); if (session->state != ISCSI_SESSION_LOGGED_IN) { spin_unlock_irqrestore(&session->lock, flags); @@ -1823,7 +1817,7 @@ static int iscsi_user_scan_session(struct device *dev, void *data) } user_scan_exit: - mutex_unlock(&ihost->mutex); + mutex_unlock(&session->mutex); ISCSI_DBG_TRANS_SESSION(session, "Completed session scan\n"); return 0; } @@ -2001,26 +1995,24 @@ static void __iscsi_unbind_session(struct work_struct *work) struct iscsi_cls_session *session = container_of(work, struct iscsi_cls_session, unbind_work); - struct Scsi_Host *shost = iscsi_session_to_shost(session); - struct iscsi_cls_host *ihost = shost->shost_data; unsigned long flags; unsigned int target_id; ISCSI_DBG_TRANS_SESSION(session, "Unbinding session\n"); /* Prevent new scans and make sure scanning is not in progress */ - mutex_lock(&ihost->mutex); + mutex_lock(&session->mutex); spin_lock_irqsave(&session->lock, flags); if (session->target_id == ISCSI_MAX_TARGET) { spin_unlock_irqrestore(&session->lock, flags); - mutex_unlock(&ihost->mutex); + mutex_unlock(&session->mutex); return; } target_id = session->target_id; session->target_id = ISCSI_MAX_TARGET; spin_unlock_irqrestore(&session->lock, flags); - mutex_unlock(&ihost->mutex); + mutex_unlock(&session->mutex); if (session->ida_used) ida_simple_remove(&iscsi_sess_ida, target_id); @@ -2053,6 +2045,7 @@ iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport, INIT_WORK(&session->unbind_work, __iscsi_unbind_session); INIT_WORK(&session->scan_work, iscsi_scan_session); spin_lock_init(&session->lock); + mutex_init(&session->mutex); /* this is released in the dev's release function */ scsi_host_get(shost); diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h index 6183d20..acf9d9d 100644 --- a/include/scsi/scsi_transport_iscsi.h +++ b/include/scsi/scsi_transport_iscsi.h @@ -238,6 +238,7 @@ struct iscsi_cls_session { struct work_struct unblock_work; struct work_struct scan_work; struct work_struct unbind_work; + struct mutex mutex; /* recovery fields */ int recovery_tmo; @@ -272,7 +273,6 @@ struct iscsi_cls_session { struct iscsi_cls_host { atomic_t nr_scans; - struct mutex mutex; struct request_queue *bsg_q; uint32_t port_speed; uint32_t port_state;