From patchwork Fri Mar 27 08:04:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 6103911 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A382F9F399 for ; Fri, 27 Mar 2015 08:06:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 66326203FB for ; Fri, 27 Mar 2015 08:06:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 004F5203E5 for ; Fri, 27 Mar 2015 08:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752912AbbC0IGL (ORCPT ); Fri, 27 Mar 2015 04:06:11 -0400 Received: from mail-oi0-f46.google.com ([209.85.218.46]:34586 "EHLO mail-oi0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752971AbbC0IGE (ORCPT ); Fri, 27 Mar 2015 04:06:04 -0400 Received: by oigz129 with SMTP id z129so25137482oig.1 for ; Fri, 27 Mar 2015 01:06:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Wk7MtFr283+1CcpiMQw9hmxPPcYcVLQO6FGb/FGXQCA=; b=fCbxg1rTPf4I5dHMfFWKWgf698F5w22Wyy8s6ARYuih3MCsGP4PPZF+UtUQqgqSoLr A2u2qqgKiBfTL7W0pQCGC4GW1WiI3+1wkO6TBj6gVbFxww07+DkDedEMEatKAuzOQh3X M2GPKo7CzlAJUUzVKl43x7YfJO9RViXjPxLYRhVT/3GzM2Z2ASYx1QTAToUrfTUHOThI Rv16bfuB996mXIWDMEhMiDaz2NgBbWsG2cdKaLrSLsuW35ixp49tGw7rRIRz3LifJDjP GWeO7JbYeXnSEkYWtHcvpunP8Qc9Lr0+2Wwk0r6aiEVHOnrf6FykxsH3H3d0bwa48WG9 7K/g== X-Gm-Message-State: ALoCoQnbIlPT0JP7ECdfe46icpnNnyPkX2Sn0kDRl77R/JS9Gdu30IbPT94rQH+F4Wo/jsdvVbq0 X-Received: by 10.202.68.70 with SMTP id r67mr14391320oia.66.1427443563920; Fri, 27 Mar 2015 01:06:03 -0700 (PDT) Received: from localhost.localdomain (mail.linux-iscsi.org. [67.23.28.174]) by mx.google.com with ESMTPSA id h4sm711520obr.18.2015.03.27.01.06.03 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 27 Mar 2015 01:06:03 -0700 (PDT) From: "Nicholas A. Bellinger" To: target-devel Cc: linux-scsi , Hannes Reinecke , Christoph Hellwig , Sagi Grimberg , Nicholas Bellinger Subject: [RFC 03/22] target/device: Convert se_node_acl->device_list access to RCU reader Date: Fri, 27 Mar 2015 08:04:53 +0000 Message-Id: <1427443512-8925-4-git-send-email-nab@daterainc.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1427443512-8925-1-git-send-email-nab@daterainc.com> References: <1427443512-8925-1-git-send-email-nab@daterainc.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Nicholas Bellinger This patch converts various target_core_device.c to RCU reader path to extract deve->mapped_lun before rcu_read_unlock() ahead of invoking core_disable_device_list_for_node() to trigger subsequent RCU updater code. It includes core_free_device_list_for_node(), core_clear_lun_from_tpg(), core_clear_initiator_node_from_tpg(), and core_update_device_list_access() updates. Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Sagi Grimberg Signed-off-by: Nicholas Bellinger --- drivers/target/target_core_device.c | 52 +++++++++++++++++++------------------ drivers/target/target_core_tpg.c | 22 ++++++++-------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index 9385e16..1053a2d 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -257,32 +257,33 @@ int core_free_device_list_for_node( { struct se_dev_entry *deve; struct se_lun *lun; - u32 i; + u32 i, mapped_lun; - if (!nacl->device_list) + if (!nacl->lun_entry_hlist) return 0; - spin_lock_irq(&nacl->device_list_lock); for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { - deve = nacl->device_list[i]; + rcu_read_lock(); + deve = rcu_dereference(nacl->lun_entry_hlist[i]); - if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) + if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) { + rcu_read_unlock(); continue; - + } if (!deve->se_lun) { pr_err("%s device entries device pointer is" " NULL, but Initiator has access.\n", tpg->se_tpg_tfo->get_fabric_name()); + rcu_read_unlock(); continue; } lun = deve->se_lun; + mapped_lun = deve->mapped_lun; + rcu_read_unlock(); - spin_unlock_irq(&nacl->device_list_lock); - core_disable_device_list_for_node(lun, NULL, deve->mapped_lun, - TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg); - spin_lock_irq(&nacl->device_list_lock); + core_disable_device_list_for_node(lun, NULL, mapped_lun, + TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg); } - spin_unlock_irq(&nacl->device_list_lock); array_free(nacl->lun_entry_hlist, TRANSPORT_MAX_LUNS_PER_TPG); nacl->lun_entry_hlist = NULL; @@ -297,8 +298,8 @@ void core_update_device_list_access( { struct se_dev_entry *deve; - spin_lock_irq(&nacl->device_list_lock); - deve = nacl->device_list[mapped_lun]; + spin_lock_irq(&nacl->lun_entry_lock); + deve = rcu_dereference(nacl->lun_entry_hlist[mapped_lun]); if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) { deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY; deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE; @@ -306,7 +307,9 @@ void core_update_device_list_access( deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE; deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY; } - spin_unlock_irq(&nacl->device_list_lock); + spin_unlock_irq(&nacl->lun_entry_lock); + + synchronize_rcu(); } /* core_enable_device_list_for_node(): @@ -442,26 +445,25 @@ void core_clear_lun_from_tpg(struct se_lun *lun, struct se_portal_group *tpg) { struct se_node_acl *nacl; struct se_dev_entry *deve; - u32 i; + u32 i, mapped_lun; spin_lock_irq(&tpg->acl_node_lock); list_for_each_entry(nacl, &tpg->acl_node_list, acl_list) { spin_unlock_irq(&tpg->acl_node_lock); - spin_lock_irq(&nacl->device_list_lock); for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { - deve = nacl->device_list[i]; - if (lun != deve->se_lun) + rcu_read_lock(); + deve = rcu_dereference(nacl->lun_entry_hlist[i]); + if (!deve || lun != deve->se_lun) { + rcu_read_unlock(); continue; - spin_unlock_irq(&nacl->device_list_lock); - - core_disable_device_list_for_node(lun, NULL, - deve->mapped_lun, TRANSPORT_LUNFLAGS_NO_ACCESS, - nacl, tpg); + } + mapped_lun = deve->mapped_lun; + rcu_read_unlock(); - spin_lock_irq(&nacl->device_list_lock); + core_disable_device_list_for_node(lun, NULL, mapped_lun, + TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg); } - spin_unlock_irq(&nacl->device_list_lock); spin_lock_irq(&tpg->acl_node_lock); } diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c index b2fdba5..15a683b 100644 --- a/drivers/target/target_core_tpg.c +++ b/drivers/target/target_core_tpg.c @@ -55,32 +55,32 @@ static void core_clear_initiator_node_from_tpg( struct se_node_acl *nacl, struct se_portal_group *tpg) { - int i; struct se_dev_entry *deve; struct se_lun *lun; + u32 i, mapped_lun; - spin_lock_irq(&nacl->device_list_lock); for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { - deve = nacl->device_list[i]; + rcu_read_lock(); + deve = rcu_dereference(nacl->lun_entry_hlist[i]); - if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) + if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) { + rcu_read_unlock(); continue; - + } if (!deve->se_lun) { pr_err("%s device entries device pointer is" " NULL, but Initiator has access.\n", tpg->se_tpg_tfo->get_fabric_name()); + rcu_read_unlock(); continue; } - lun = deve->se_lun; - spin_unlock_irq(&nacl->device_list_lock); - core_disable_device_list_for_node(lun, NULL, deve->mapped_lun, - TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg); + mapped_lun = deve->mapped_lun; + rcu_read_unlock(); - spin_lock_irq(&nacl->device_list_lock); + core_disable_device_list_for_node(lun, NULL, mapped_lun, + TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg); } - spin_unlock_irq(&nacl->device_list_lock); } /* __core_tpg_get_initiator_node_acl():