From patchwork Tue May 12 09:25:26 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: 6386941 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 08A6E9F32B for ; Tue, 12 May 2015 09:37:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E88BF2025B for ; Tue, 12 May 2015 09:37:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6FEDD20220 for ; Tue, 12 May 2015 09:37:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932277AbbELJhM (ORCPT ); Tue, 12 May 2015 05:37:12 -0400 Received: from mail-ob0-f182.google.com ([209.85.214.182]:35651 "EHLO mail-ob0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932351AbbELJ2A (ORCPT ); Tue, 12 May 2015 05:28:00 -0400 Received: by obcus9 with SMTP id us9so896253obc.2 for ; Tue, 12 May 2015 02:28:00 -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=McAXNxez16oyrAEBKDQjtdZ0qSv+7mhZCE2kS2ShXL8=; b=DDLbbKJV1BGI8JqSyXOwteATE8ED8SpmVwbcXz8ZQfAUp+1ank6t3DNdSrpvR25Un3 /TC/wS/trc8ldQHReWIGfET+laJZ9CpGZwrS7msmZNA0wJj20LQ5HSvTrQju6E9VN09h asN8W0AV94ZAxB2cYaYuHFZg4Es2L8dtRqLxlpSwtdO1Bxy7QUbYUjn5crBVmE81n6Bi CG7YPVtmR0AYHfkjKdf6ODdLv+R5HjTcaSF4AcicZAMK0vpxe4Z8rXfyv/WShpyrGuWo 9EhHU6kwyxuXBaD20I9fAbOggd/8GYMtU5IY1KBigxq6iCumHnDj7SndqTVmzdLwVSFQ d9fw== X-Gm-Message-State: ALoCoQn6yWLhQAl9JuHWyj8/HSs78NcfgUNeb/+RTIJELSDIs+JC9gkAAVROP8bDIL3utnxiDAwQ X-Received: by 10.60.131.170 with SMTP id on10mr11334308oeb.44.1431422880299; Tue, 12 May 2015 02:28:00 -0700 (PDT) Received: from localhost.localdomain (mail.linux-iscsi.org. [67.23.28.174]) by mx.google.com with ESMTPSA id z133sm10658470oif.14.2015.05.12.02.27.59 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 12 May 2015 02:27:59 -0700 (PDT) From: "Nicholas A. Bellinger" To: target-devel Cc: linux-scsi , linux-kernel , Hannes Reinecke , Christoph Hellwig , Sagi Grimberg , Nicholas Bellinger Subject: [PATCH 02/12] target: Convert REPORT_LUN + MODE_SENSE to RCU reader Date: Tue, 12 May 2015 09:25:26 +0000 Message-Id: <1431422736-29125-3-git-send-email-nab@daterainc.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1431422736-29125-1-git-send-email-nab@daterainc.com> References: <1431422736-29125-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 locks for se_node_acl->lun_entry_hlist access. Also convert the MODE_SENSE special case in pscsi_transport_complete() Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Sagi Grimberg Signed-off-by: Nicholas Bellinger --- drivers/target/target_core_pscsi.c | 17 +++++++++++++++-- drivers/target/target_core_spc.c | 27 ++++++++++++++++++--------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index f6c954c..9fcdcc0 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -47,6 +47,7 @@ #include #include "target_core_alua.h" +#include "target_core_internal.h" #include "target_core_pscsi.h" #define ISPRINT(a) ((a >= ' ') && (a <= '~')) @@ -634,12 +635,24 @@ static void pscsi_transport_complete(struct se_cmd *cmd, struct scatterlist *sg, * Hack to make sure that Write-Protect modepage is set if R/O mode is * forced. */ - if (!cmd->se_deve || !cmd->data_length) + if (!cmd->data_length) goto after_mode_sense; if (((cdb[0] == MODE_SENSE) || (cdb[0] == MODE_SENSE_10)) && (status_byte(result) << 1) == SAM_STAT_GOOD) { - if (cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) { + struct se_session *sess = cmd->se_sess; + struct se_node_acl *nacl = sess->se_node_acl; + struct se_dev_entry *deve; + u32 lun = cmd->orig_fe_lun; + bool read_only = true; + + rcu_read_lock(); + deve = target_nacl_find_deve(nacl, lun); + if (deve) + read_only = (deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY); + rcu_read_unlock(); + + if (read_only) { unsigned char *buf; buf = transport_kmap_data_sg(cmd); diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index 78c0b40..d256243 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -969,6 +969,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); @@ -981,6 +983,7 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd) int length = 0; int ret; int i; + bool read_only = true; memset(buf, 0, SE_MODE_PAGE_BUF); @@ -990,10 +993,14 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd) */ length = ten ? 3 : 2; + rcu_read_lock(); + deve = target_nacl_find_deve(sess->se_node_acl, cmd->orig_fe_lun); + if (deve) + 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); /* @@ -1211,8 +1218,9 @@ sense_reason_t spc_emulate_report_luns(struct se_cmd *cmd) { struct se_dev_entry *deve; struct se_session *sess = cmd->se_sess; + struct se_node_acl *nacl = sess->se_node_acl; unsigned char *buf; - u32 lun_count = 0, offset = 8, i; + u32 lun_count = 0, offset = 8, mapped_lun; if (cmd->data_length < 16) { pr_warn("REPORT LUNS allocation length %u too small\n", @@ -1235,11 +1243,12 @@ 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]; + rcu_read_lock(); + hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) { if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) continue; + + mapped_lun = deve->mapped_lun; /* * We determine the correct LUN LIST LENGTH even once we * have reached the initial allocation length. @@ -1249,10 +1258,10 @@ 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); + rcu_read_unlock(); /* * See SPC3 r07, page 159.