From patchwork Fri Mar 27 08:04:56 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: 6103941 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 5EBE79F399 for ; Fri, 27 Mar 2015 08:06:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1F691203E5 for ; Fri, 27 Mar 2015 08:06:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 488012041E for ; Fri, 27 Mar 2015 08:06:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753240AbbC0IG1 (ORCPT ); Fri, 27 Mar 2015 04:06:27 -0400 Received: from mail-ob0-f174.google.com ([209.85.214.174]:34310 "EHLO mail-ob0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753327AbbC0IGK (ORCPT ); Fri, 27 Mar 2015 04:06:10 -0400 Received: by obbgh1 with SMTP id gh1so3224266obb.1 for ; Fri, 27 Mar 2015 01:06:09 -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=KF1XyDSO7cpbG9pwsOCXLhkpkCp4Mi95w3v9RIchDNs=; b=BG+GxUnTNjhVBIPgyv8mKcFITncV5HMltxlbi/auaqZ3fRa960YrsAmCAQ7aoJyjTq KvYec53LixYt3tKpOVRkhJInpnyw58ruuhSB98FopPTZbWrCz740VKElQhFqm2hUXnrA +mkkk38X8NrHJvpBP87oaGnNNB7a2IyDpHm3FrHZ+uTrWeCEcXpVi9NPevjeyngcyJLZ gIHbB0rjWmSTg7BhJbOFYrvC3p0KwHiVfutmtxd0bDgBC0DSxvPLw9DO+OiQGllkcUgr odn9d6C60g5EZTWT131RZwLQO4lNuYWWApOTPkld04cqgyAX5jX6OtV97Kj5uJqlrKNt gZZA== X-Gm-Message-State: ALoCoQnAnRpd9MQ2B4E5kHzQrTPQQeA0/msoscw6uWphwlywkXJu4lp7qPMThpW4cD0wX/znfkbT X-Received: by 10.60.174.19 with SMTP id bo19mr15307988oec.5.1427443569072; Fri, 27 Mar 2015 01:06:09 -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.08 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 27 Mar 2015 01:06:08 -0700 (PDT) From: "Nicholas A. Bellinger" To: target-devel Cc: linux-scsi , Hannes Reinecke , Christoph Hellwig , Sagi Grimberg , Nicholas Bellinger Subject: [RFC 06/22] target/spc: Convert REPORT_LUN + MODE_SENSE to RCU reader Date: Fri, 27 Mar 2015 08:04:56 +0000 Message-Id: <1427443512-8925-7-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 SPC emulation for REPORT_LUN + MODE_SENSE to use RCU read path macros for se_node_acl->lun_entry_hlist[] access. Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Sagi Grimberg Signed-off-by: Nicholas Bellinger --- drivers/target/target_core_spc.c | 28 ++++++++++++++++++---------- include/target/target_core_base.h | 1 - 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index 5b6a0af..12cb045 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -986,6 +986,8 @@ static int spc_modesense_long_blockdesc(unsigned char *buf, u64 blocks, u32 bloc static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd) { struct se_device *dev = cmd->se_dev; + struct se_dev_entry *deve; + struct se_session *sess = cmd->se_sess; char *cdb = cmd->t_task_cdb; unsigned char buf[SE_MODE_PAGE_BUF], *rbuf; int type = dev->transport->get_device_type(dev); @@ -998,6 +1000,7 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd) int length = 0; int ret; int i; + bool read_only; memset(buf, 0, SE_MODE_PAGE_BUF); @@ -1007,10 +1010,13 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd) */ length = ten ? 3 : 2; + rcu_read_lock(); + deve = rcu_dereference(sess->se_node_acl->lun_entry_hlist[cmd->orig_fe_lun]); + read_only = (deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY); + rcu_read_unlock(); + /* DEVICE-SPECIFIC PARAMETER */ - if ((cmd->se_lun->lun_access & TRANSPORT_LUNFLAGS_READ_ONLY) || - (cmd->se_deve && - (cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY))) + if ((cmd->se_lun->lun_access & TRANSPORT_LUNFLAGS_READ_ONLY) || read_only) spc_modesense_write_protect(&buf[length], type); if ((spc_check_dev_wce(dev)) && @@ -1225,7 +1231,7 @@ sense_reason_t spc_emulate_report_luns(struct se_cmd *cmd) struct se_dev_entry *deve; struct se_session *sess = cmd->se_sess; unsigned char *buf; - u32 lun_count = 0, offset = 8, i; + u32 lun_count = 0, offset = 8, i, mapped_lun; if (cmd->data_length < 16) { pr_warn("REPORT LUNS allocation length %u too small\n", @@ -1248,11 +1254,15 @@ sense_reason_t spc_emulate_report_luns(struct se_cmd *cmd) goto done; } - spin_lock_irq(&sess->se_node_acl->device_list_lock); for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { - deve = sess->se_node_acl->device_list[i]; - if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) + rcu_read_lock(); + deve = rcu_dereference(sess->se_node_acl->lun_entry_hlist[i]); + if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) { + rcu_read_unlock(); continue; + } + mapped_lun = deve->mapped_lun; + rcu_read_unlock(); /* * We determine the correct LUN LIST LENGTH even once we * have reached the initial allocation length. @@ -1262,11 +1272,9 @@ sense_reason_t spc_emulate_report_luns(struct se_cmd *cmd) if ((offset + 8) > cmd->data_length) continue; - int_to_scsilun(deve->mapped_lun, (struct scsi_lun *)&buf[offset]); + int_to_scsilun(mapped_lun, (struct scsi_lun *)&buf[offset]); offset += 8; } - spin_unlock_irq(&sess->se_node_acl->device_list_lock); - /* * See SPC3 r07, page 159. */ diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 06ecd7b..a826e6f 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -512,7 +512,6 @@ struct se_cmd { struct list_head se_delayed_node; struct list_head se_qf_node; struct se_device *se_dev; - struct se_dev_entry *se_deve; struct se_lun *se_lun; /* Only used for internal passthrough and legacy TCM fabric modules */ struct se_session *se_sess;