linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nicholas A. Bellinger" <nab@daterainc.com>
To: target-devel <target-devel@vger.kernel.org>
Cc: linux-scsi <linux-scsi@vger.kernel.org>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Sagi Grimberg <sagig@mellanox.com>,
	Quinn Tran <quinn.tran@qlogic.com>,
	Nicholas Bellinger <nab@linux-iscsi.org>,
	Christoph Hellwig <hch@lst.de>,
	Doug Gilbert <dgilbert@interlog.com>
Subject: [PATCH-v2 02/15] target: Add protected fabric + unprotected device support
Date: Mon, 30 Mar 2015 03:28:11 +0000	[thread overview]
Message-ID: <1427686104-14231-3-git-send-email-nab@daterainc.com> (raw)
In-Reply-To: <1427686104-14231-1-git-send-email-nab@daterainc.com>

From: Nicholas Bellinger <nab@linux-iscsi.org>

This patch adds a new target_core_fabric_ops callback for allowing fabric
drivers to expose a TPG attribute for signaling when a T10-PI protected
fabric wants to function with an un-protected device without T10-PI.

This specifically is to allow LIO to perform WRITE_STRIP + READ_INSERT
operations when functioning with non T10-PI enabled devices, seperate
from any available hw offloads the fabric supports.

This is done using a new se_sess->sess_prot_type that is set at fabric
session creation time based upon the TPG attribute.  It currently cannot
be changed for individual sessions after initial creation.

Also, update existing target_core_sbc.c code to honor sess_prot_type when
setting up cmd->prot_op + cmd->prot_type assignments.

Cc: Martin Petersen <martin.petersen@oracle.com>
Cc: Sagi Grimberg <sagig@mellanox.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Doug Gilbert <dgilbert@interlog.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
 drivers/target/target_core_sbc.c       | 44 +++++++++++++++++++++++++---------
 drivers/target/target_core_transport.c |  8 +++++++
 include/target/target_core_base.h      |  1 +
 include/target/target_core_fabric.h    |  8 +++++++
 4 files changed, 50 insertions(+), 11 deletions(-)

diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index 95a7a74..5b3564a 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -581,12 +581,13 @@ sbc_compare_and_write(struct se_cmd *cmd)
 }
 
 static int
-sbc_set_prot_op_checks(u8 protect, enum target_prot_type prot_type,
+sbc_set_prot_op_checks(u8 protect, bool fabric_prot, enum target_prot_type prot_type,
 		       bool is_write, struct se_cmd *cmd)
 {
 	if (is_write) {
-		cmd->prot_op = protect ? TARGET_PROT_DOUT_PASS :
-					 TARGET_PROT_DOUT_INSERT;
+		cmd->prot_op = fabric_prot ? TARGET_PROT_DOUT_STRIP :
+			       protect ? TARGET_PROT_DOUT_PASS :
+			       TARGET_PROT_DOUT_INSERT;
 		switch (protect) {
 		case 0x0:
 		case 0x3:
@@ -610,8 +611,9 @@ sbc_set_prot_op_checks(u8 protect, enum target_prot_type prot_type,
 			return -EINVAL;
 		}
 	} else {
-		cmd->prot_op = protect ? TARGET_PROT_DIN_PASS :
-					 TARGET_PROT_DIN_STRIP;
+		cmd->prot_op = fabric_prot ? TARGET_PROT_DIN_INSERT :
+			       protect ? TARGET_PROT_DIN_PASS :
+			       TARGET_PROT_DIN_STRIP;
 		switch (protect) {
 		case 0x0:
 		case 0x1:
@@ -644,11 +646,15 @@ sbc_check_prot(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb,
 	       u32 sectors, bool is_write)
 {
 	u8 protect = cdb[1] >> 5;
+	int sp_ops = cmd->se_sess->sup_prot_ops;
+	int pi_prot_type = dev->dev_attrib.pi_prot_type;
+	bool fabric_prot = false;
 
 	if (!cmd->t_prot_sg || !cmd->t_prot_nents) {
-		if (protect && !dev->dev_attrib.pi_prot_type) {
-			pr_err("CDB contains protect bit, but device does not"
-			       " advertise PROTECT=1 feature bit\n");
+		if (protect &&
+		    !dev->dev_attrib.pi_prot_type && !cmd->se_sess->sess_prot_type) {
+			pr_err("CDB contains protect bit, but device + fabric does"
+			       " not advertise PROTECT=1 feature bit\n");
 			return TCM_INVALID_CDB_FIELD;
 		}
 		if (cmd->prot_pto)
@@ -669,15 +675,28 @@ sbc_check_prot(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb,
 		cmd->reftag_seed = cmd->t_task_lba;
 		break;
 	case TARGET_DIF_TYPE0_PROT:
+		/*
+		 * See if the fabric supports T10-PI, and the session has been
+		 * configured to allow export PROTECT=1 feature bit with backend
+		 * devices that don't support T10-PI.
+		 */
+		fabric_prot = is_write ?
+			      (sp_ops & (TARGET_PROT_DOUT_PASS | TARGET_PROT_DOUT_STRIP)) :
+			      (sp_ops & (TARGET_PROT_DIN_PASS | TARGET_PROT_DIN_INSERT));
+
+		if (fabric_prot && cmd->se_sess->sess_prot_type) {
+			pi_prot_type = cmd->se_sess->sess_prot_type;
+			break;
+		}
+		/* Fallthrough */
 	default:
 		return TCM_NO_SENSE;
 	}
 
-	if (sbc_set_prot_op_checks(protect, dev->dev_attrib.pi_prot_type,
-				   is_write, cmd))
+	if (sbc_set_prot_op_checks(protect, fabric_prot, pi_prot_type, is_write, cmd))
 		return TCM_INVALID_CDB_FIELD;
 
-	cmd->prot_type = dev->dev_attrib.pi_prot_type;
+	cmd->prot_type = pi_prot_type;
 	cmd->prot_length = dev->prot_length * sectors;
 
 	/**
@@ -1231,6 +1250,9 @@ sbc_dif_copy_prot(struct se_cmd *cmd, unsigned int sectors, bool read,
 	unsigned int i, len, left;
 	unsigned int offset = sg_off;
 
+	if (!sg)
+		return;
+
 	left = sectors * dev->prot_length;
 
 	for_each_sg(cmd->t_prot_sg, psg, cmd->t_prot_nents, i) {
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 4a00ed5..aef989e 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -322,11 +322,19 @@ void __transport_register_session(
 	struct se_session *se_sess,
 	void *fabric_sess_ptr)
 {
+	struct target_core_fabric_ops *tfo = se_tpg->se_tpg_tfo;
 	unsigned char buf[PR_REG_ISID_LEN];
 
 	se_sess->se_tpg = se_tpg;
 	se_sess->fabric_sess_ptr = fabric_sess_ptr;
 	/*
+	 * Determine if fabric allows for T10-PI feature bits to be exposed
+	 * to initiators for device backends with !dev->dev_attrib.pi_prot_type
+	 */
+	if (tfo->tpg_check_prot_fabric_only)
+		se_sess->sess_prot_type = tfo->tpg_check_prot_fabric_only(se_tpg);
+
+	/*
 	 * Used by struct se_node_acl's under ConfigFS to locate active se_session-t
 	 *
 	 * Only set for struct se_session's that will actually be moving I/O.
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index 672150b..fe25a78 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -616,6 +616,7 @@ struct se_session {
 	unsigned		sess_tearing_down:1;
 	u64			sess_bin_isid;
 	enum target_prot_op	sup_prot_ops;
+	enum target_prot_type	sess_prot_type;
 	struct se_node_acl	*se_node_acl;
 	struct se_portal_group *se_tpg;
 	void			*fabric_sess_ptr;
diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h
index 2f4a250..c93cfdf 100644
--- a/include/target/target_core_fabric.h
+++ b/include/target/target_core_fabric.h
@@ -27,6 +27,14 @@ struct target_core_fabric_ops {
 	 * inquiry response
 	 */
 	int (*tpg_check_demo_mode_login_only)(struct se_portal_group *);
+	/*
+	 * Optionally used as a configfs tunable to determine when
+	 * target-core should signal the PROTECT=1 feature bit for
+	 * backends that don't support T10-PI, so that either fabric
+	 * HW offload or target-core emulation performs the associated
+	 * WRITE_STRIP and READ_INSERT operations.
+	 */
+	int (*tpg_check_prot_fabric_only)(struct se_portal_group *);
 	struct se_node_acl *(*tpg_alloc_fabric_acl)(
 					struct se_portal_group *);
 	void (*tpg_release_fabric_acl)(struct se_portal_group *,
-- 
1.9.1


  parent reply	other threads:[~2015-03-30  3:29 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-30  3:28 [PATCH-v2 00/15] target: Add WRITE_STRIP + READ_INSERT support Nicholas A. Bellinger
2015-03-30  3:28 ` [PATCH-v2 01/15] target: Convert DIF emulation to use cmd->prot_type Nicholas A. Bellinger
2015-03-30  7:38   ` Sagi Grimberg
2015-04-07 23:22   ` Martin K. Petersen
2015-03-30  3:28 ` Nicholas A. Bellinger [this message]
2015-03-30  7:51   ` [PATCH-v2 02/15] target: Add protected fabric + unprotected device support Sagi Grimberg
2015-04-01  5:49     ` Nicholas A. Bellinger
2015-04-01  9:04       ` Sagi Grimberg
2015-04-02  4:40         ` Nicholas A. Bellinger
2015-04-07 23:27   ` Martin K. Petersen
2015-04-08  7:40     ` Nicholas A. Bellinger
2015-04-09 21:45       ` Martin K. Petersen
2015-04-10 18:59         ` Nicholas A. Bellinger
2015-04-13 10:11           ` Sagi Grimberg
2015-04-14  1:15           ` Martin K. Petersen
2015-03-30  3:28 ` [PATCH-v2 03/15] target: Update SPC/SBC emulation for sess_prot_type Nicholas A. Bellinger
2015-03-30  7:53   ` Sagi Grimberg
2015-04-07 23:28   ` Martin K. Petersen
2015-03-30  3:28 ` [PATCH-v2 04/15] target: Move cmd->prot_op check into target_check_write_prot Nicholas A. Bellinger
2015-03-30  7:57   ` Sagi Grimberg
2015-04-01  5:54     ` Nicholas A. Bellinger
2015-04-07 23:30       ` Martin K. Petersen
2015-03-30  3:28 ` [PATCH-v2 05/15] target: Add internal WRITE_STRIP support Nicholas A. Bellinger
2015-03-30  8:01   ` Sagi Grimberg
2015-04-01  5:59     ` Nicholas A. Bellinger
2015-04-07 23:32   ` Martin K. Petersen
2015-03-30  3:28 ` [PATCH-v2 06/15] target: Move cmd->prot_op check into target_check_read_prot Nicholas A. Bellinger
2015-03-30  8:02   ` Sagi Grimberg
2015-04-01  6:03     ` Nicholas A. Bellinger
2015-04-07 23:33   ` Martin K. Petersen
2015-03-30  3:28 ` [PATCH-v2 07/15] target: Add internal READ_INSERT support Nicholas A. Bellinger
2015-04-07 23:34   ` Martin K. Petersen
2015-03-30  3:28 ` [PATCH-v2 08/15] target/file: Add checks for backend DIF emulation Nicholas A. Bellinger
2015-03-30  8:05   ` Sagi Grimberg
2015-03-30  3:28 ` [PATCH-v2 09/15] target/iblock: " Nicholas A. Bellinger
2015-03-30  3:28 ` [PATCH-v2 10/15] target/rd: " Nicholas A. Bellinger
2015-03-30  3:28 ` [PATCH-v2 11/15] loopback: Add fabric_prot_type attribute support Nicholas A. Bellinger
2015-03-30  8:07   ` Sagi Grimberg
2015-04-01  6:22     ` Nicholas A. Bellinger
2015-03-30  3:28 ` [PATCH-v2 12/15] vhost/scsi: " Nicholas A. Bellinger
2015-03-30  3:28 ` [PATCH-v2 13/15] tcm_qla2xxx: Set TARGET_PROT_ALL for sup_prot_ops Nicholas A. Bellinger
2015-03-30  3:28 ` [PATCH-v2 14/15] tcm_qla2xxx: Add fabric_prot_type attribute support Nicholas A. Bellinger
2015-03-30  3:28 ` [PATCH-v2 15/15] iscsi/iser-target: " Nicholas A. Bellinger
2015-03-30  8:11   ` Sagi Grimberg
2015-04-01  6:27     ` Nicholas A. Bellinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1427686104-14231-3-git-send-email-nab@daterainc.com \
    --to=nab@daterainc.com \
    --cc=dgilbert@interlog.com \
    --cc=hch@lst.de \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=nab@linux-iscsi.org \
    --cc=quinn.tran@qlogic.com \
    --cc=sagig@mellanox.com \
    --cc=target-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).