[PATCH 05/13] scsi: alua: Add scsi_alua_tur()

John Garry posted 13 patches 2 weeks, 6 days ago
[PATCH 05/13] scsi: alua: Add scsi_alua_tur()
Posted by John Garry 2 weeks, 6 days ago
Add same as alua_tur() from scsi_dh_alua.c

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/scsi/scsi_alua.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/scsi/scsi_alua.c b/drivers/scsi/scsi_alua.c
index 1045885f74169..d8825ad7a1672 100644
--- a/drivers/scsi/scsi_alua.c
+++ b/drivers/scsi/scsi_alua.c
@@ -40,6 +40,32 @@ static struct workqueue_struct *kalua_wq;
 #define ALUA_RTPG_DELAY_MSECS		5
 #define ALUA_RTPG_RETRY_DELAY		2
 
+/*
+ * alua_tur - Send a TEST UNIT READY
+ * @sdev: device to which the TEST UNIT READY command should be send
+ *
+ * Send a TEST UNIT READY to @sdev to figure out the device state
+ * Returns SCSI_DH_RETRY if the sense code is NOT READY/ALUA TRANSITIONING,
+ * SCSI_DH_OK if no error occurred, and SCSI_DH_IO otherwise.
+ */
+__maybe_unused
+static int scsi_alua_tur(struct scsi_device *sdev)
+{
+	struct scsi_sense_hdr sense_hdr;
+	int retval;
+
+	retval = scsi_test_unit_ready(sdev, ALUA_FAILOVER_TIMEOUT * HZ,
+				      ALUA_FAILOVER_RETRIES, &sense_hdr);
+	if ((sense_hdr.sense_key == NOT_READY ||
+	     sense_hdr.sense_key == UNIT_ATTENTION) &&
+	    sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x0a)
+		return -EAGAIN;//SCSI_DH_RETRY;
+	else if (retval)
+		return -EIO;//SCSI_DH_IO;
+	else
+		return 0;//SCSI_DH_OK;
+}
+
 /*
  * submit_rtpg - Issue a REPORT TARGET GROUP STATES command
  * @sdev: sdev the command should be sent to
-- 
2.43.5
Re: [PATCH 05/13] scsi: alua: Add scsi_alua_tur()
Posted by Hannes Reinecke 2 weeks, 5 days ago
On 3/17/26 13:06, John Garry wrote:
> Add same as alua_tur() from scsi_dh_alua.c
> 
> Signed-off-by: John Garry <john.g.garry@oracle.com>
> ---
>   drivers/scsi/scsi_alua.c | 26 ++++++++++++++++++++++++++
>   1 file changed, 26 insertions(+)
> 
> diff --git a/drivers/scsi/scsi_alua.c b/drivers/scsi/scsi_alua.c
> index 1045885f74169..d8825ad7a1672 100644
> --- a/drivers/scsi/scsi_alua.c
> +++ b/drivers/scsi/scsi_alua.c
> @@ -40,6 +40,32 @@ static struct workqueue_struct *kalua_wq;
>   #define ALUA_RTPG_DELAY_MSECS		5
>   #define ALUA_RTPG_RETRY_DELAY		2
>   
> +/*
> + * alua_tur - Send a TEST UNIT READY
> + * @sdev: device to which the TEST UNIT READY command should be send
> + *
> + * Send a TEST UNIT READY to @sdev to figure out the device state
> + * Returns SCSI_DH_RETRY if the sense code is NOT READY/ALUA TRANSITIONING,
> + * SCSI_DH_OK if no error occurred, and SCSI_DH_IO otherwise.
> + */
> +__maybe_unused
> +static int scsi_alua_tur(struct scsi_device *sdev)
> +{
> +	struct scsi_sense_hdr sense_hdr;
> +	int retval;
> +
> +	retval = scsi_test_unit_ready(sdev, ALUA_FAILOVER_TIMEOUT * HZ,
> +				      ALUA_FAILOVER_RETRIES, &sense_hdr);
> +	if ((sense_hdr.sense_key == NOT_READY ||
> +	     sense_hdr.sense_key == UNIT_ATTENTION) &&
> +	    sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x0a)
> +		return -EAGAIN;//SCSI_DH_RETRY;
> +	else if (retval)
> +		return -EIO;//SCSI_DH_IO;
> +	else
> +		return 0;//SCSI_DH_OK;
> +}
> +
>   /*
>    * submit_rtpg - Issue a REPORT TARGET GROUP STATES command
>    * @sdev: sdev the command should be sent to

???
And this function is useful _why_?
We're just sending a normal 'TEST UNIT READY', it has nothing to
do with ALUA. Why do we have a special function here?

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Re: [PATCH 05/13] scsi: alua: Add scsi_alua_tur()
Posted by John Garry 2 weeks ago
On 18/03/2026 07:54, Hannes Reinecke wrote:
>>   /*
>>    * submit_rtpg - Issue a REPORT TARGET GROUP STATES command
>>    * @sdev: sdev the command should be sent to
> 
> ???
> And this function is useful _why_?
> We're just sending a normal 'TEST UNIT READY', it has nothing to
> do with ALUA. Why do we have a special function here?

This is used in the STPG code, and I added the STPG code to scsi_alua.c

Thanks,
John
Re: [PATCH 05/13] scsi: alua: Add scsi_alua_tur()
Posted by John Garry 1 week, 6 days ago
On 23/03/2026 13:42, John Garry wrote:
> On 18/03/2026 07:54, Hannes Reinecke wrote:
>>>   /*
>>>    * submit_rtpg - Issue a REPORT TARGET GROUP STATES command
>>>    * @sdev: sdev the command should be sent to
>>
>> ???
>> And this function is useful _why_?
>> We're just sending a normal 'TEST UNIT READY', it has nothing to
>> do with ALUA. Why do we have a special function here?
> 
> This is used in the STPG code, and I added the STPG code to scsi_alua.c

I meant to say that this is used in RTPG code from the following:


commit 9d2c30395213166e0b5614fe97576a789864e5de
Author: Hannes Reinecke <hare@suse.de>
Date:   Fri Feb 19 09:17:15 2016 +0100

     scsi_dh_alua: Send TEST UNIT READY to poll for transitioning

     Sending a 'REPORT TARGET PORT GROUP' command is a costly operation,
     as the array has to gather information about all ports.
     So instead of using RTPG to poll for a status update when a port
     is in transitioning we should be sending a TEST UNIT READY, and
     wait for the sense code to report success.