From: Bart Van Assche <bvanassche@acm.org>
To: Mike Christie <michael.christie@oracle.com>,
jgross@suse.com, njavali@marvell.com, pbonzini@redhat.com,
jasowang@redhat.com, mst@redhat.com, stefanha@redhat.com,
oneukum@suse.com, manoj@linux.ibm.com, mrochs@linux.ibm.com,
ukrishn@linux.ibm.com, martin.petersen@oracle.com,
linux-scsi@vger.kernel.org,
james.bottomley@hansenpartnership.com
Subject: Re: [PATCH 08/10] scsi: Add error codes for internal scsi-ml use.
Date: Tue, 9 Aug 2022 13:13:27 -0700 [thread overview]
Message-ID: <67db6828-0e1b-83ad-9c4e-1fbd736e39b4@acm.org> (raw)
In-Reply-To: <20220804034100.121125-9-michael.christie@oracle.com>
On 8/3/22 20:40, Mike Christie wrote:
> If a driver returns:
>
> DID_TARGET_FAILURE
> DID_NEXUS_FAILURE
> DID_ALLOC_FAILURE
> DID_MEDIUM_ERROR
>
> we hit a couple bugs:
>
> 1. The SCSI error handler runs because scsi_decide_disposition has no
> case statements for them and we return FAILED.
>
> 2. For SG IO the userspace app gets a success status instead of failed,
> because scsi_result_to_blk_status clears those errors.
>
> This patch adds a new internal error code byte for use by scsi-ml. It
> will be used instead of the above error codes, so we don't have to play
> that clearing the host code game in scsi_result_to_blk_status and
> drivers cannot accidentally use them.
>
> The next patch will then remove the internal users of the above codes and
> convert us to use the new ones.
>
> Signed-off-by: Mike Christie <michael.christie@oracle.com>
> ---
> drivers/scsi/scsi_error.c | 5 +++++
> drivers/scsi/scsi_lib.c | 22 ++++++++++++++++++++++
> drivers/scsi/scsi_priv.h | 11 +++++++++++
> 3 files changed, 38 insertions(+)
>
> diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
> index 947d98a0565f..4adadd3fb410 100644
> --- a/drivers/scsi/scsi_error.c
> +++ b/drivers/scsi/scsi_error.c
> @@ -514,6 +514,11 @@ static void scsi_report_sense(struct scsi_device *sdev,
> }
> }
>
> +static inline void set_scsi_ml_byte(struct scsi_cmnd *cmd, u8 status)
> +{
> + cmd->result = (cmd->result & 0xffff00ff) | (status << 8);
> +}
> +
> /**
> * scsi_check_sense - Examine scsi cmd sense
> * @scmd: Cmd to have sense checked.
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index 2aca0a838ca5..eaf4865a2cb6 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -576,6 +576,11 @@ static bool scsi_end_request(struct request *req, blk_status_t error,
> return false;
> }
>
> +static inline u8 get_scsi_ml_byte(int result)
> +{
> + return (result >> 8) & 0xff;
> +}
> +
> /**
> * scsi_result_to_blk_status - translate a SCSI result code into blk_status_t
> * @cmd: SCSI command
> @@ -586,6 +591,23 @@ static bool scsi_end_request(struct request *req, blk_status_t error,
> */
> static blk_status_t scsi_result_to_blk_status(struct scsi_cmnd *cmd, int result)
> {
> + /*
> + * Check the scsi-ml byte first in case we converted a host or status
> + * byte.
> + */
> + switch (get_scsi_ml_byte(result)) {
> + case SCSIML_STAT_OK:
> + break;
> + case SCSIML_STAT_RESV_CONFLICT:
> + return BLK_STS_NEXUS;
> + case SCSIML_STAT_SPACE_ALLOC:
> + return BLK_STS_NOSPC;
> + case SCSIML_STAT_MED_ERROR:
> + return BLK_STS_MEDIUM;
> + case SCSIML_STAT_TGT_FAILURE:
> + return BLK_STS_TARGET;
> + }
> +
> switch (host_byte(result)) {
> case DID_OK:
> if (scsi_status_is_good(result))
> diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
> index 5c4786310a31..9d2d32bf0171 100644
> --- a/drivers/scsi/scsi_priv.h
> +++ b/drivers/scsi/scsi_priv.h
> @@ -18,6 +18,17 @@ struct scsi_nl_hdr;
>
> #define SCSI_CMD_RETRIES_NO_LIMIT -1
>
> +/*
> + * Error codes used by scsi-ml internally. These must not be used by drivers.
> + */
> +enum scsi_ml_status {
> + SCSIML_STAT_OK = 0x00,
> + SCSIML_STAT_RESV_CONFLICT = 0x01, /* Reservation conflict */
> + SCSIML_STAT_SPACE_ALLOC = 0x02, /* Space allocation on the dev failed */
> + SCSIML_STAT_MED_ERROR = 0x03, /* Medium error */
> + SCSIML_STAT_TGT_FAILURE = 0x04, /* Permanent target failure */
> +};
How about changing "SPACE_ALLOC" into "ENOSPC"?
Anyway:
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
next prev parent reply other threads:[~2022-08-09 20:13 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-04 3:40 [PATCH 00/10] scsi: Fix internal host code use Mike Christie
2022-08-04 3:40 ` [PATCH 01/10] scsi: xen: Drop use of internal host codes Mike Christie
2022-08-04 6:18 ` Juergen Gross
2022-08-04 16:28 ` Mike Christie
2022-08-04 17:00 ` Juergen Gross
2022-08-04 3:40 ` [PATCH 02/10] scsi: storvsc: Drop DID_TARGET_FAILURE use Mike Christie
2022-08-04 3:40 ` [PATCH 03/10] scsi: uas: " Mike Christie
2022-08-04 18:59 ` Mike Christie
2022-08-04 21:07 ` Hans de Goede
2022-08-04 3:40 ` [PATCH 04/10] scsi: virtio_scsi: " Mike Christie
2022-08-04 18:25 ` Paolo Bonzini
2022-08-09 19:40 ` Michael S. Tsirkin
2022-08-04 3:40 ` [PATCH 05/10] scsi: virtio_scsi: Drop DID_NEXUS_FAILURE use Mike Christie
2022-08-04 18:25 ` Paolo Bonzini
2022-08-09 19:40 ` Michael S. Tsirkin
2022-08-04 3:40 ` [PATCH 06/10] scsi: qla2xxx: Drop DID_TARGET_FAILURE use Mike Christie
2022-08-04 3:40 ` [PATCH 07/10] scsi: cxlflash: Drop DID_ALLOC_FAILURE use Mike Christie
2022-08-04 3:40 ` [PATCH 08/10] scsi: Add error codes for internal scsi-ml use Mike Christie
2022-08-09 20:13 ` Bart Van Assche [this message]
2022-08-10 3:18 ` Mike Christie
2022-08-04 3:40 ` [PATCH 09/10] scsi: Convert scsi_decide_disposition to use SCSIML_STAT Mike Christie
2022-08-09 20:14 ` Bart Van Assche
2022-08-04 3:41 ` [PATCH 10/10] scsi: Remove useless host error codes Mike Christie
2022-08-09 20:08 ` Bart Van Assche
2022-08-04 6:55 ` [PATCH 00/10] scsi: Fix internal host code use Oliver Neukum
2022-08-04 17:04 ` Mike Christie
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=67db6828-0e1b-83ad-9c4e-1fbd736e39b4@acm.org \
--to=bvanassche@acm.org \
--cc=james.bottomley@hansenpartnership.com \
--cc=jasowang@redhat.com \
--cc=jgross@suse.com \
--cc=linux-scsi@vger.kernel.org \
--cc=manoj@linux.ibm.com \
--cc=martin.petersen@oracle.com \
--cc=michael.christie@oracle.com \
--cc=mrochs@linux.ibm.com \
--cc=mst@redhat.com \
--cc=njavali@marvell.com \
--cc=oneukum@suse.com \
--cc=pbonzini@redhat.com \
--cc=stefanha@redhat.com \
--cc=ukrishn@linux.ibm.com \
/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