Commit 3c93830a authored by Michael Cyr's avatar Michael Cyr Committed by Tim Gardner

UBUNTU: SAUCE: Return TCMU-generated sense data to fabric module

BugLink: http://bugs.launchpad.net/bugs/1615665

If an error status is passed to target_complete_cmd, then by default it
queues the command to target_complete_failure_work, which will generate
Logical Unit Communication Failure sense data, overwriting any sense data
already set in the command.  This means that any sense data returned by
TCMU does not get returned to the fabric module.

This change implements a transport_complete function for target-user which
will set the SCF_TRANSPORT_TASK_SENSE flag if we have valid sense data,
which will cause target_complete_cmd to queue the command to
target_complete_ok_work instead of target_complete_failure_work.
Signed-off-by: default avatarMichael Cyr <mikecyr@linux.vnet.ibm.com>
Reviewed-by: default avatarAndy Grover <agrover@redhat.com>
Signed-off-by: default avatarTim Gardner <tim.gardner@canonical.com>

 Conflicts:
	drivers/target/target_core_user.c
Signed-off-by: default avatarTim Gardner <tim.gardner@canonical.com>
Acked-by: default avatarBrad Figg <brad.figg@canonical.com>
Acked-by: default avatarKamal Mostafa <kamal@canonical.com>
parent 5afee347
......@@ -154,6 +154,14 @@ static struct genl_family tcmu_genl_family = {
.n_mcgrps = ARRAY_SIZE(tcmu_mcgrps),
};
/* Sense Key = 2 (Not Ready)
* ASC/ASCQ = 0x0800 (Logical Unit Communication Failure)
*/
static const char lu_comm_failure_sense[18] = {
0x70, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x0a,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00 };
static struct tcmu_cmd *tcmu_alloc_cmd(struct se_cmd *se_cmd)
{
struct se_device *se_dev = se_cmd->se_dev;
......@@ -540,9 +548,11 @@ static void tcmu_handle_completion(struct tcmu_cmd *cmd, struct tcmu_cmd_entry *
pr_warn("TCMU: Userspace set UNKNOWN_OP flag on se_cmd %p\n",
cmd->se_cmd);
entry->rsp.scsi_status = SAM_STAT_CHECK_CONDITION;
memcpy(se_cmd->sense_buffer, lu_comm_failure_sense,
sizeof(lu_comm_failure_sense));
} else if (entry->rsp.scsi_status == SAM_STAT_CHECK_CONDITION) {
memcpy(se_cmd->sense_buffer, entry->rsp.sense_buffer,
se_cmd->scsi_sense_length);
TRANSPORT_SENSE_BUFFER);
UPDATE_HEAD(udev->data_tail, cmd->data_length, udev->data_size);
} else if (se_cmd->se_cmd_flags & SCF_BIDI) {
......@@ -642,6 +652,8 @@ static int tcmu_check_expired_cmd(int id, void *p, void *data)
return 0;
set_bit(TCMU_CMD_BIT_EXPIRED, &cmd->flags);
memcpy(cmd->se_cmd->sense_buffer, lu_comm_failure_sense,
sizeof(lu_comm_failure_sense));
target_complete_cmd(cmd->se_cmd, SAM_STAT_CHECK_CONDITION);
cmd->se_cmd = NULL;
......@@ -1099,6 +1111,17 @@ tcmu_parse_cdb(struct se_cmd *cmd)
return passthrough_parse_cdb(cmd, tcmu_pass_op);
}
static void tcmu_transport_complete(struct se_cmd *cmd, struct scatterlist *sg,
unsigned char *sense_buffer)
{
if (cmd->scsi_status == SAM_STAT_CHECK_CONDITION)
/* Setting this flag will prevent target_complete_cmd from
* calling target_complete_failure_work, which would overwrite
* the sense data we already set.
*/
cmd->se_cmd_flags |= SCF_TRANSPORT_TASK_SENSE;
}
static const struct target_backend_ops tcmu_ops = {
.name = "user",
.owner = THIS_MODULE,
......@@ -1109,6 +1132,7 @@ static const struct target_backend_ops tcmu_ops = {
.configure_device = tcmu_configure_device,
.free_device = tcmu_free_device,
.parse_cdb = tcmu_parse_cdb,
.transport_complete = tcmu_transport_complete,
.set_configfs_dev_params = tcmu_set_configfs_dev_params,
.show_configfs_dev_params = tcmu_show_configfs_dev_params,
.get_device_type = sbc_get_device_type,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment