diff mbox series

[v10,20/33] scsi: ch: Have scsi-ml retry ch_do_scsi errors

Message ID 20230714213419.95492-21-michael.christie@oracle.com (mailing list archive)
State Changes Requested
Headers show
Series scsi: Allow scsi_execute users to control retries | expand

Commit Message

Mike Christie July 14, 2023, 9:34 p.m. UTC
This has ch_do_scsi have scsi-ml retry errors instead of driving them
itself.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/ch.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

Comments

John Garry July 25, 2023, 10:33 a.m. UTC | #1
On 14/07/2023 22:34, Mike Christie wrote:
> This has ch_do_scsi have scsi-ml retry errors instead of driving them
> itself.
> 
> Signed-off-by: Mike Christie <michael.christie@oracle.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Apart from a small comment, below:
Reviewed-by: John Garry <john.g.garry@oracle.com>

> ---
>   drivers/scsi/ch.c | 21 ++++++++++++---------
>   1 file changed, 12 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
> index 1a998e45978e..8ea498e6eec2 100644
> --- a/drivers/scsi/ch.c
> +++ b/drivers/scsi/ch.c
> @@ -185,16 +185,26 @@ static int
>   ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
>   	   void *buffer, unsigned int buflength, enum req_op op)
>   {
> -	int errno, retries = 0, timeout, result;
> +	int errno, timeout, result;
>   	struct scsi_sense_hdr sshdr;
> +	struct scsi_failure failures[] = {
> +		{
> +			.sense = UNIT_ATTENTION,
> +			.asc = SCMD_FAILURE_ASC_ANY,
> +			.ascq = SCMD_FAILURE_ASCQ_ANY,
> +			.allowed = 3,
> +			.result = SAM_STAT_CHECK_CONDITION,
> +		},
> +		{}
> +	};
>   	const struct scsi_exec_args exec_args = {
>   		.sshdr = &sshdr,
> +		.failures = failures,
>   	};
>   
>   	timeout = (cmd[0] == INITIALIZE_ELEMENT_STATUS)
>   		? timeout_init : timeout_move;
>   
> - retry:
>   	errno = 0;

nit: can errno be init'ed to 0 when declared? Or in an 'else' part of 
the if (scsi_sense_valid()) check?

>   	result = scsi_execute_cmd(ch->device, cmd, op, buffer, buflength,
>   				  timeout * HZ, MAX_RETRIES, &exec_args);
> @@ -204,13 +214,6 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
>   		if (debug)
>   			scsi_print_sense_hdr(ch->device, ch->name, &sshdr);
>   		errno = ch_find_errno(&sshdr);
> -
> -		switch(sshdr.sense_key) {
> -		case UNIT_ATTENTION:
> -			if (retries++ < 3)
> -				goto retry;
> -			break;
> -		}
>   	}
>   	return errno;
>   }
diff mbox series

Patch

diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index 1a998e45978e..8ea498e6eec2 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -185,16 +185,26 @@  static int
 ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
 	   void *buffer, unsigned int buflength, enum req_op op)
 {
-	int errno, retries = 0, timeout, result;
+	int errno, timeout, result;
 	struct scsi_sense_hdr sshdr;
+	struct scsi_failure failures[] = {
+		{
+			.sense = UNIT_ATTENTION,
+			.asc = SCMD_FAILURE_ASC_ANY,
+			.ascq = SCMD_FAILURE_ASCQ_ANY,
+			.allowed = 3,
+			.result = SAM_STAT_CHECK_CONDITION,
+		},
+		{}
+	};
 	const struct scsi_exec_args exec_args = {
 		.sshdr = &sshdr,
+		.failures = failures,
 	};
 
 	timeout = (cmd[0] == INITIALIZE_ELEMENT_STATUS)
 		? timeout_init : timeout_move;
 
- retry:
 	errno = 0;
 	result = scsi_execute_cmd(ch->device, cmd, op, buffer, buflength,
 				  timeout * HZ, MAX_RETRIES, &exec_args);
@@ -204,13 +214,6 @@  ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
 		if (debug)
 			scsi_print_sense_hdr(ch->device, ch->name, &sshdr);
 		errno = ch_find_errno(&sshdr);
-
-		switch(sshdr.sense_key) {
-		case UNIT_ATTENTION:
-			if (retries++ < 3)
-				goto retry;
-			break;
-		}
 	}
 	return errno;
 }