]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
UBUNTU: SAUCE: Return TCMU-generated sense data to fabric module
authorMichael Cyr <mikecyr@us.ibm.com>
Fri, 26 Aug 2016 19:06:45 +0000 (14:06 -0500)
committerTim Gardner <tim.gardner@canonical.com>
Mon, 20 Feb 2017 03:57:58 +0000 (20:57 -0700)
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: Michael Cyr <mikecyr@linux.vnet.ibm.com>
Reviewed-by: Andy Grover <agrover@redhat.com>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
drivers/target/target_core_user.c

index 8041710b697298ec7073c4e5910849bd1a154703..30e610d4a1bfa3441cf87f3a81cae07f34b0b9ea 100644 (file)
@@ -159,6 +159,14 @@ static struct genl_family tcmu_genl_family __ro_after_init = {
        .netnsok = true,
 };
 
+/* 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;
@@ -578,9 +586,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);
                free_data_area(udev, cmd);
        } else if (se_cmd->se_cmd_flags & SCF_BIDI) {
                DECLARE_BITMAP(bitmap, DATA_BLOCK_BITS);
@@ -683,6 +693,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;
 
@@ -1136,6 +1148,17 @@ tcmu_parse_cdb(struct se_cmd *cmd)
        return passthrough_parse_cdb(cmd, tcmu_queue_cmd);
 }
 
+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,
@@ -1146,6 +1169,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,