Skip to contentSkip to conversation

scsi: scsi_dh_alua: use device timeout instead of constant

PATCH New Brian Bunker 2 participants 4 messages Mar 25 – Mar 27 SCSI

lore
Share & tools
lore
#0 lore raw

v2 cover scsi: scsi_dh_alua: use device timeout instead of constant

This patch changes the ALUA device handler to use the SCSI device's configured timeout (rq_timeout) instead of the hardcoded 60-second ALUA_FAILOVER_TIMEOUT constant. This allows administrators to control ALUA-related timeouts via the standard SCSI device timeout sysfs interface (/sys/block/sdX/device/timeout).

Changes in v2:
- Added READ_ONCE() when accessing sdev->request_queue->rq_timeout since this value can be modified dynamically by userspace via sysfs
- Added fallback to ALUA_FAILOVER_TIMEOUT if rq_timeout is 0, using the ?: operator, to handle any edge cases where the timeout might be uninitialized (though sysfs store functions reject 0)
- Retained ALUA_FAILOVER_TIMEOUT constant as the fallback value

Regarding dynamic changes to rq_timeout: this is acceptable because each SCSI command reads the current timeout when issued. If an admin changes the timeout mid-operation, subsequent commands will use the new value. This is actually desirable as it allows administrators to adjust timeouts on the fly during problematic failovers without reloading modules.

Brian Bunker (1):
scsi: scsi_dh_alua: use the device timeout rather than a constant

 drivers/scsi/device_handler/scsi_dh_alua.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw

PATCH v2 1/1 scsi: scsi_dh_alua: use the device timeout rather than a constant

Instead of using a constant for timeouts, use the timeout of the SCSI device itself. There are reasons why someone might want to extend the SCSI timeout and having the constant out of sync can lead to early timeouts.

---
 drivers/scsi/device_handler/scsi_dh_alua.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/scsi/device_handler/scsi_dh_alua.c +7 -5
index efb08b9b145a..a4ee67109548 100644
@@ -143,7 +143,7 @@ static int submit_rtpg(struct scsi_device *sdev, unsigned char *buff,
 	put_unaligned_be32(bufflen, &cdb[6]);
 
 	return scsi_execute_cmd(sdev, cdb, opf, buff, bufflen,
-				ALUA_FAILOVER_TIMEOUT * HZ,
+				READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ,
 				ALUA_FAILOVER_RETRIES, &exec_args);
 }
 
@@ -178,7 +178,7 @@ static int submit_stpg(struct scsi_device *sdev, int group_id,
 	put_unaligned_be32(stpg_len, &cdb[6]);
 
 	return scsi_execute_cmd(sdev, cdb, opf, stpg_data,
-				stpg_len, ALUA_FAILOVER_TIMEOUT * HZ,
+				stpg_len, READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ,
 				ALUA_FAILOVER_RETRIES, &exec_args);
 }
 
@@ -512,7 +512,7 @@ static int alua_tur(struct scsi_device *sdev)
 	struct scsi_sense_hdr sense_hdr;
 	int retval;
 
-	retval = scsi_test_unit_ready(sdev, ALUA_FAILOVER_TIMEOUT * HZ,
+	retval = scsi_test_unit_ready(sdev, READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ,
 				      ALUA_FAILOVER_RETRIES, &sense_hdr);
 	if ((sense_hdr.sense_key == NOT_READY ||
 	     sense_hdr.sense_key == UNIT_ATTENTION) &&
@@ -552,7 +552,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
 	valid_states_old = pg->valid_states;
 
 	if (!pg->expiry) {
-		unsigned long transition_tmo = ALUA_FAILOVER_TIMEOUT * HZ;
+		unsigned long transition_tmo = min(READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ,
+						   (unsigned long)U8_MAX * HZ);
 
 		if (pg->transition_tmo)
 			transition_tmo = pg->transition_tmo * HZ;
@@ -664,7 +665,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
 	if ((buff[4] & RTPG_FMT_MASK) == RTPG_FMT_EXT_HDR && buff[5] != 0)
 		pg->transition_tmo = buff[5];
 	else
-		pg->transition_tmo = ALUA_FAILOVER_TIMEOUT;
+		pg->transition_tmo = min((READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ) / HZ,
+					 (unsigned long)U8_MAX);
 
 	if (orig_transition_tmo != pg->transition_tmo) {
 		sdev_printk(KERN_INFO, sdev,
Signature · 1 line
2.50.1 (Apple Git-155)
#2 lore raw

Re: [PATCH v2] scsi: scsi_dh_alua: use the device timeout rather than a constant

Quoted 54 lines · Brian Bunker

Instead of using a constant for timeouts, use the timeout of the SCSI device itself. There are reasons why someone might want to extend the SCSI timeout and having the constant out of sync can lead to early timeouts.

---
  drivers/scsi/device_handler/scsi_dh_alua.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
drivers/scsi/device_handler/scsi_dh_alua.c +5 -4
index efb08b9b145a..a4ee67109548 100644
@@ -143,7 +143,7 @@ static int submit_rtpg(struct scsi_device *sdev, unsigned char *buff,
  	put_unaligned_be32(bufflen, &cdb[6]);
 
  	return scsi_execute_cmd(sdev, cdb, opf, buff, bufflen,
-				ALUA_FAILOVER_TIMEOUT * HZ,
+				READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ,
  				ALUA_FAILOVER_RETRIES, &exec_args);
  }
 
@@ -178,7 +178,7 @@ static int submit_stpg(struct scsi_device *sdev, int group_id,
  	put_unaligned_be32(stpg_len, &cdb[6]);
 
  	return scsi_execute_cmd(sdev, cdb, opf, stpg_data,
-				stpg_len, ALUA_FAILOVER_TIMEOUT * HZ,
+				stpg_len, READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ,
  				ALUA_FAILOVER_RETRIES, &exec_args);
  }
 
@@ -512,7 +512,7 @@ static int alua_tur(struct scsi_device *sdev)
  	struct scsi_sense_hdr sense_hdr;
  	int retval;
 
-	retval = scsi_test_unit_ready(sdev, ALUA_FAILOVER_TIMEOUT * HZ,
+	retval = scsi_test_unit_ready(sdev, READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ,
  				      ALUA_FAILOVER_RETRIES, &sense_hdr);
  	if ((sense_hdr.sense_key == NOT_READY ||
  	     sense_hdr.sense_key == UNIT_ATTENTION) &&
@@ -552,7 +552,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
  	valid_states_old = pg->valid_states;
 
  	if (!pg->expiry) {
-		unsigned long transition_tmo = ALUA_FAILOVER_TIMEOUT * HZ;
+		unsigned long transition_tmo = min(READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ,
+						   (unsigned long)U8_MAX * HZ);
 
  		if (pg->transition_tmo)
  			transition_tmo = pg->transition_tmo * HZ;

drivers/scsi/device_handler/scsi_dh_alua.c static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) · line 672

Quoted 9 lines
drivers/scsi/device_handler/scsi_dh_alua.c +2 -1
@@ -664,7 +665,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
  	if ((buff[4] & RTPG_FMT_MASK) == RTPG_FMT_EXT_HDR && buff[5] != 0)
  		pg->transition_tmo = buff[5];
  	else
-		pg->transition_tmo = ALUA_FAILOVER_TIMEOUT;
+		pg->transition_tmo = min((READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ) / HZ,
+					 (unsigned long)U8_MAX);
 
  	if (orig_transition_tmo != pg->transition_tmo) {
  		sdev_printk(KERN_INFO, sdev,

Weelll ... The transition timeout is _vastly_ different from the device command timeout. While the latter tends to be rather small (ie in the seconds range), the former can take _really_ long time. Ask you competitors, they regularly require tens of _minuntes_ here.

Having is settable is a good idea, but not to the command timeout.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                               +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
#3 lore raw

Re: [PATCH v2] scsi: scsi_dh_alua: use the device timeout rather than a constant

Quoted 71 lines · Hannes Reinecke
Quoted 54 lines · Brian Bunker

Instead of using a constant for timeouts, use the timeout of the SCSI device itself. There are reasons why someone might want to extend the SCSI timeout and having the constant out of sync can lead to early timeouts.

---
  drivers/scsi/device_handler/scsi_dh_alua.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
drivers/scsi/device_handler/scsi_dh_alua.c +5 -4
index efb08b9b145a..a4ee67109548 100644
@@ -143,7 +143,7 @@ static int submit_rtpg(struct scsi_device *sdev, unsigned char *buff,
      put_unaligned_be32(bufflen, &cdb[6]);
 
      return scsi_execute_cmd(sdev, cdb, opf, buff, bufflen,
-                             ALUA_FAILOVER_TIMEOUT * HZ,
+                             READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ,
                              ALUA_FAILOVER_RETRIES, &exec_args);
  }
 
@@ -178,7 +178,7 @@ static int submit_stpg(struct scsi_device *sdev, int group_id,
      put_unaligned_be32(stpg_len, &cdb[6]);
 
      return scsi_execute_cmd(sdev, cdb, opf, stpg_data,
-                             stpg_len, ALUA_FAILOVER_TIMEOUT * HZ,
+                             stpg_len, READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ,
                              ALUA_FAILOVER_RETRIES, &exec_args);
  }
 
@@ -512,7 +512,7 @@ static int alua_tur(struct scsi_device *sdev)
      struct scsi_sense_hdr sense_hdr;
      int retval;
 
-     retval = scsi_test_unit_ready(sdev, ALUA_FAILOVER_TIMEOUT * HZ,
+     retval = scsi_test_unit_ready(sdev, READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ,
                                    ALUA_FAILOVER_RETRIES, &sense_hdr);
      if ((sense_hdr.sense_key == NOT_READY ||
           sense_hdr.sense_key == UNIT_ATTENTION) &&
@@ -552,7 +552,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
      valid_states_old = pg->valid_states;
 
      if (!pg->expiry) {
-             unsigned long transition_tmo = ALUA_FAILOVER_TIMEOUT * HZ;
+             unsigned long transition_tmo = min(READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ,
+                                                (unsigned long)U8_MAX * HZ);
 
              if (pg->transition_tmo)
                      transition_tmo = pg->transition_tmo * HZ;

drivers/scsi/device_handler/scsi_dh_alua.c static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) · line 672

Quoted 9 lines
drivers/scsi/device_handler/scsi_dh_alua.c +2 -1
@@ -664,7 +665,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
      if ((buff[4] & RTPG_FMT_MASK) == RTPG_FMT_EXT_HDR && buff[5] != 0)
              pg->transition_tmo = buff[5];
      else
-             pg->transition_tmo = ALUA_FAILOVER_TIMEOUT;
+             pg->transition_tmo = min((READ_ONCE(sdev->request_queue->rq_timeout) ?: ALUA_FAILOVER_TIMEOUT * HZ) / HZ,
+                                      (unsigned long)U8_MAX);
 
      if (orig_transition_tmo != pg->transition_tmo) {
              sdev_printk(KERN_INFO, sdev,

Weelll ... The transition timeout is _vastly_ different from the device command timeout. While the latter tends to be rather small (ie in the seconds range), the former can take _really_ long time.
Ask you competitors, they regularly require tens of _minuntes_ here.

Quoted 1 line

Having is settable is a good idea, but not to the command timeout.

The SCSI path timeout represents a contract between the initiator and the target. Storage vendors provide recommended path timeout values for their arrays as a best practice, and administrators are expected to configure these values accordingly. This timeout value reflects what the target vendor has determined is the appropriate maximum time to wait for any operation on that path, accounting for the target's internal processing, failover capabilities, and expected behavior under various conditions.

When the implicit transition timeout honors this same path timeout, it simply extends that existing contract to cover ALUA state transitions. The target vendor
whoever recommended a 30-second or 60-second path timeout did so with full knowledge of their array's behavior, including how long implicit transitions might
take. If their array requires longer transitions than the recommended path timeout allows, that is a deficiency in their recommendation, not in the use
of it as a default.

The SCSI SPC specification itself constrains the implicit transition timeout to a single byte in the RTPG extended header, limiting it to 255 seconds. The
kernel's data structure reflects this with an unsigned char for transition_tmo. If the
specification authors believed implicit transitions could legitimately require tens of
minutes, they would have allocated more than one byte for this field. Beyond the spec and
data structure constraints, when the implicit transition timer expires the port group
state is forced to STANDBY and new commands fail immediately. Supporting tens of minutes is not
possible with the current implementation regardless of the default chosen. Using the path timeout as the default creates consistency with the broader timeout contract that already exists between the initiator and the target, rather than
introducing a separate arbitrary value that may conflict with the administrator's I/O expectations
behavior on that path.

Quoted 9 lines

Cheers,

Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
[email protected] +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

Thanks,
Brian

Signature · 3 lines
Brian Bunker
PURE Storage, Inc.
[email protected]