Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9c58b7dd authored by Roland Dreier's avatar Roland Dreier Committed by Nicholas Bellinger
Browse files

target: Simplify fabric sense data length handling



Every fabric driver has to supply a se_tfo->set_fabric_sense_len()
method, just so iSCSI can return an offset of 2.  However, every fabric
driver is already allocating a sense buffer and passing it into the
target core, either via transport_init_se_cmd() or target_submit_cmd().

So instead of having iSCSI pass the start of its sense buffer into the
core and then later tell the core to skip the first 2 bytes, it seems
easier for iSCSI just to do the offset of 2 when it passes the sense
buffer into the core.  Then we can drop the se_tfo->set_fabric_sense_len()
everywhere, and just add a couple of lines of code to iSCSI to set the
sense data length to the beginning of the buffer right before it sends
it over the network.

(nab: Remove .set_fabric_sense_len usage from tcm_qla2xxx_npiv_ops +
      change transport_get_sense_buffer to follow v3.6-rc6 code w/o
      ->set_fabric_sense_len usage)

Signed-off-by: default avatarRoland Dreier <roland@purestorage.com>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 2ed772b7
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -402,7 +402,6 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
	buf += "	.queue_data_in			= " + fabric_mod_name + "_queue_data_in,\n"
	buf += "	.queue_status			= " + fabric_mod_name + "_queue_status,\n"
	buf += "	.queue_tm_rsp			= " + fabric_mod_name + "_queue_tm_rsp,\n"
	buf += "	.set_fabric_sense_len		= " + fabric_mod_name + "_set_fabric_sense_len,\n"
	buf += "	.is_state_remove		= " + fabric_mod_name + "_is_state_remove,\n"
	buf += "	/*\n"
	buf += "	 * Setup function pointers for generic logic in target_core_fabric_configfs.c\n"
@@ -905,13 +904,6 @@ def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):
			buf += "}\n\n"
			bufi += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n"

		if re.search('set_fabric_sense_len\)\(', fo):
			buf += "u16 " + fabric_mod_name + "_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length)\n"
			buf += "{\n"
			buf += "	return 0;\n"
			buf += "}\n\n"
			bufi += "u16 " + fabric_mod_name + "_set_fabric_sense_len(struct se_cmd *, u32);\n"

		if re.search('is_state_remove\)\(', fo):
			buf += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *se_cmd)\n"
			buf += "{\n"
+0 −6
Original line number Diff line number Diff line
@@ -3564,11 +3564,6 @@ static int srpt_get_tcm_cmd_state(struct se_cmd *se_cmd)
	return srpt_get_cmd_state(ioctx);
}

static u16 srpt_set_fabric_sense_len(struct se_cmd *cmd, u32 sense_length)
{
	return 0;
}

/**
 * srpt_parse_i_port_id() - Parse an initiator port ID.
 * @name: ASCII representation of a 128-bit initiator port ID.
@@ -3948,7 +3943,6 @@ static struct target_core_fabric_ops srpt_template = {
	.queue_data_in			= srpt_queue_response,
	.queue_status			= srpt_queue_status,
	.queue_tm_rsp			= srpt_queue_response,
	.set_fabric_sense_len		= srpt_set_fabric_sense_len,
	/*
	 * Setup function pointers for generic logic in
	 * target_core_fabric_configfs.c
+0 −8
Original line number Diff line number Diff line
@@ -735,12 +735,6 @@ static int tcm_qla2xxx_queue_tm_rsp(struct se_cmd *se_cmd)
	return 0;
}

static u16 tcm_qla2xxx_set_fabric_sense_len(struct se_cmd *se_cmd,
					u32 sense_length)
{
	return 0;
}

/* Local pointer to allocated TCM configfs fabric module */
struct target_fabric_configfs *tcm_qla2xxx_fabric_configfs;
struct target_fabric_configfs *tcm_qla2xxx_npiv_fabric_configfs;
@@ -1686,7 +1680,6 @@ static struct target_core_fabric_ops tcm_qla2xxx_ops = {
	.queue_data_in			= tcm_qla2xxx_queue_data_in,
	.queue_status			= tcm_qla2xxx_queue_status,
	.queue_tm_rsp			= tcm_qla2xxx_queue_tm_rsp,
	.set_fabric_sense_len		= tcm_qla2xxx_set_fabric_sense_len,
	/*
	 * Setup function pointers for generic logic in
	 * target_core_fabric_configfs.c
@@ -1734,7 +1727,6 @@ static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
	.queue_data_in			= tcm_qla2xxx_queue_data_in,
	.queue_status			= tcm_qla2xxx_queue_status,
	.queue_tm_rsp			= tcm_qla2xxx_queue_tm_rsp,
	.set_fabric_sense_len		= tcm_qla2xxx_set_fabric_sense_len,
	/*
	 * Setup function pointers for generic logic in
	 * target_core_fabric_configfs.c
+8 −5
Original line number Diff line number Diff line
@@ -953,7 +953,7 @@ static int iscsit_handle_scsi_cmd(
	 */
	transport_init_se_cmd(&cmd->se_cmd, &lio_target_fabric_configfs->tf_ops,
			conn->sess->se_sess, hdr->data_length, cmd->data_direction,
			sam_task_attr, &cmd->sense_buffer[0]);
			sam_task_attr, cmd->sense_buffer + 2);

	pr_debug("Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x,"
		" ExpXferLen: %u, Length: %u, CID: %hu\n", hdr->itt,
@@ -1700,7 +1700,7 @@ static int iscsit_handle_task_mgt_cmd(
		transport_init_se_cmd(&cmd->se_cmd,
				      &lio_target_fabric_configfs->tf_ops,
				      conn->sess->se_sess, 0, DMA_NONE,
				      MSG_SIMPLE_TAG, &cmd->sense_buffer[0]);
				      MSG_SIMPLE_TAG, cmd->sense_buffer + 2);

		switch (function) {
		case ISCSI_TM_FUNC_ABORT_TASK:
@@ -3092,15 +3092,18 @@ static int iscsit_send_status(
	if (cmd->se_cmd.sense_buffer &&
	   ((cmd->se_cmd.se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) ||
	    (cmd->se_cmd.se_cmd_flags & SCF_EMULATED_TASK_SENSE))) {
		put_unaligned_be16(cmd->se_cmd.scsi_sense_length, cmd->sense_buffer);
		cmd->se_cmd.scsi_sense_length += sizeof (__be16);

		padding		= -(cmd->se_cmd.scsi_sense_length) & 3;
		hton24(hdr->dlength, cmd->se_cmd.scsi_sense_length);
		iov[iov_count].iov_base	= cmd->se_cmd.sense_buffer;
		iov[iov_count].iov_base	= cmd->sense_buffer;
		iov[iov_count++].iov_len =
				(cmd->se_cmd.scsi_sense_length + padding);
		tx_size += cmd->se_cmd.scsi_sense_length;

		if (padding) {
			memset(cmd->se_cmd.sense_buffer +
			memset(cmd->sense_buffer +
				cmd->se_cmd.scsi_sense_length, 0, padding);
			tx_size += padding;
			pr_debug("Adding %u bytes of padding to"
@@ -3109,7 +3112,7 @@ static int iscsit_send_status(

		if (conn->conn_ops->DataDigest) {
			iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
				cmd->se_cmd.sense_buffer,
				cmd->sense_buffer,
				(cmd->se_cmd.scsi_sense_length + padding),
				0, NULL, (u8 *)&cmd->data_crc);

+0 −16
Original line number Diff line number Diff line
@@ -1542,21 +1542,6 @@ static int lio_queue_status(struct se_cmd *se_cmd)
	return 0;
}

static u16 lio_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length)
{
	unsigned char *buffer = se_cmd->sense_buffer;
	/*
	 * From RFC-3720 10.4.7.  Data Segment - Sense and Response Data Segment
	 * 16-bit SenseLength.
	 */
	buffer[0] = ((sense_length >> 8) & 0xff);
	buffer[1] = (sense_length & 0xff);
	/*
	 * Return two byte offset into allocated sense_buffer.
	 */
	return 2;
}

static int lio_queue_tm_rsp(struct se_cmd *se_cmd)
{
	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
@@ -1740,7 +1725,6 @@ int iscsi_target_register_configfs(void)
	fabric->tf_ops.queue_data_in = &lio_queue_data_in;
	fabric->tf_ops.queue_status = &lio_queue_status;
	fabric->tf_ops.queue_tm_rsp = &lio_queue_tm_rsp;
	fabric->tf_ops.set_fabric_sense_len = &lio_set_fabric_sense_len;
	/*
	 * Setup function pointers for generic logic in target_core_fabric_configfs.c
	 */
Loading