public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: David Disseldorp <ddiss@suse.de>
To: Sergey Samoylenko <s.samoylenko@yadro.com>
Cc: <martin.petersen@oracle.com>, <michael.christie@oracle.com>,
	<bvanassche@acm.org>, <target-devel@vger.kernel.org>,
	<linux-scsi@vger.kernel.org>, <linux@yadro.com>
Subject: Re: [v2 1/2] target: allows backend drivers to fail with specific sense codes
Date: Fri, 30 Jul 2021 18:37:58 +0200	[thread overview]
Message-ID: <20210730183758.6efb3f95@suse.de> (raw)
In-Reply-To: <20210726151646.32631-2-s.samoylenko@yadro.com>

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@oracle.com>.

This looks good and works for me, but I have one comment...

> Cc: Mike Christie <michael.christie@oracle.com>
> Cc: David Disseldorp <ddiss@suse.de>
> [ Moved target_complete_cmd_with_sense() helper to mainline ]
> Signed-off-by: Sergey Samoylenko <s.samoylenko@yadro.com>
> ---
>  drivers/target/target_core_transport.c | 21 ++++++++++++++++++---
>  include/target/target_core_backend.h   |  1 +
>  include/target/target_core_base.h      |  2 ++
>  3 files changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
> index 26ceabe34de5..d2a2892bda9c 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)
> +static void __target_complete_cmd(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,8 +894,22 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
>  
>  	queue_work_on(cpu, target_completion_wq, &cmd->work);
>  }
> +
> +void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
> +{
> +	__target_complete_cmd(cmd, scsi_status, scsi_status ?
> +			      TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE :
> +			      TCM_NO_SENSE);
> +}
>  EXPORT_SYMBOL(target_complete_cmd);
>  
> +void target_complete_cmd_with_sense(struct se_cmd *cmd,
> +				    sense_reason_t sense_reason)
> +{
> +	__target_complete_cmd(cmd, SAM_STAT_CHECK_CONDITION, sense_reason);
> +}
> +EXPORT_SYMBOL(target_complete_cmd_with_sense);
> +

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

  reply	other threads:[~2021-07-30 16:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-26 15:16 [v2 0/2] target: core: Fix sense key for invalid XCOPY request Sergey Samoylenko
2021-07-26 15:16 ` [v2 1/2] target: allows backend drivers to fail with specific sense codes Sergey Samoylenko
2021-07-30 16:37   ` David Disseldorp [this message]
2021-08-02 18:31     ` Sergey Samoylenko
2021-08-03 12:33       ` David Disseldorp
2021-07-26 15:16 ` [v2 2/2] target: core: Fix sense key for invalid XCOPY request Sergey Samoylenko

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=20210730183758.6efb3f95@suse.de \
    --to=ddiss@suse.de \
    --cc=bvanassche@acm.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux@yadro.com \
    --cc=martin.petersen@oracle.com \
    --cc=michael.christie@oracle.com \
    --cc=s.samoylenko@yadro.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