RE: [v2 1/2] target: allows backend drivers to fail with specific sense codes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi David,
Sorry for the long answer.

> Hi Sergey,
>
> On Mon, 26 Jul 2021 18:16:45 +0300, Sergey Samoylenko wrote:
>
>> Currently, backend drivers can fail IO with
>> SAM_STAT_CHECK_CONDITION which gets us
>> TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE. The patch adds
>> a new helper that allows backend drivers to fail with
>> specific sense codes.
>> 
>> This is based on a patch from Mike Christie <michael.christie@xxxxxxxxxx>.
>
> This looks good and works for me, but I have one comment...
>
> It's a little unclear from the function prototype that this actually
> fails the command with SAM_STAT_CHECK_CONDITION. I could imagine people
> erroneously calling target_complete_cmd_with_sense(cmd, TCM_NO_SENSE)
> and expecting success.
> I think it might be a bit clearer if you just export
> __target_complete_cmd() as target_complete_cmd_with_sense() with all
> three parameters and leave it up to the caller to flag
> CHECK_CONDITION.
>
> Cheers, David

David, am I getting the idea right?

We want to get something like this:
-----------------------------------------------------------------------------------
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 7e35eddd9eb7..6dbfba7f16a6 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -736,8 +736,7 @@ static void target_complete_failure_work(struct work_struct *work)
 {
        struct se_cmd *cmd = container_of(work, struct se_cmd, work);

-       transport_generic_request_failure(cmd,
-                       TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE);
+       transport_generic_request_failure(cmd, cmd->sense_reason);
 }

 /*
@@ -855,7 +854,8 @@ static bool target_cmd_interrupted(struct se_cmd *cmd)
 }

 /* May be called from interrupt context so must not sleep. */
-void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
+void target_complete_cmd_with_sense(struct se_cmd *cmd, u8 scsi_status,
+                                   sense_reason_t sense_reason)
 {
        struct se_wwn *wwn = cmd->se_sess->se_tpg->se_tpg_wwn;
        int success, cpu;
@@ -865,6 +865,7 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
                return;

        cmd->scsi_status = scsi_status;
+       cmd->sense_reason = sense_reason;

        spin_lock_irqsave(&cmd->t_state_lock, flags);
        switch (cmd->scsi_status) {
@@ -893,6 +894,14 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)

        queue_work_on(cpu, target_completion_wq, &cmd->work);
 }
+EXPORT_SYMBOL(target_complete_cmd_with_sense);
+
+void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
+{
+       target_complete_cmd_with_sense(cmd, scsi_status, scsi_status ?
+                             TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE :
+                             TCM_NO_SENSE);
+}
 EXPORT_SYMBOL(target_complete_cmd);

 void target_set_cmd_data_length(struct se_cmd *cmd, int length)
-----------------------------------------------------------------------------------

Then we use it as follows:
-----------------------------------------------------------------------------------
diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c
index 0f1319336f3e..1b4faafedb1a 100644
--- a/drivers/target/target_core_xcopy.c
+++ b/drivers/target/target_core_xcopy.c
@@ -674,12 +674,16 @@ static void target_xcopy_do_work(struct work_struct *work)
...
err_free:
        kfree(xop);
-       /*
-        * Don't override an error scsi status if it has already been set
-        */
-       if (ec_cmd->scsi_status == SAM_STAT_GOOD) {
-               pr_warn_ratelimited("target_xcopy_do_work: rc: %d, Setting X-COPY"
-                       " CHECK_CONDITION -> sending response\n", rc);
-               ec_cmd->scsi_status = SAM_STAT_CHECK_CONDITION;
-       }
-       target_complete_cmd(ec_cmd, ec_cmd->scsi_status);
+       pr_warn_ratelimited("target_xcopy_do_work: rc: %d, sense: %u,"
+               " XCOPY operation failed\n", rc, sense_rc);
+       target_complete_cmd_with_sense(ec_cmd, SAM_STAT_CHECK_CONDITION, sense_rc);
 }
-----------------------------------------------------------------------------------

Best regards,
Sergey




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux