Skip to contentSkip to conversation

scsi: scsh_dh_alua use the device timeout rather than a constant

PATCH Superseded Brian Bunker 3 participants 3 messages Feb 24 – Mar 23 SCSI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: scsh_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 reaasons 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..7f11acf714ad 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,
+				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, 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, 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(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((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.52.0
#1 lore raw
Quoted 5 lines

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

Hannes: Please opine...

Signature · 1 line
Martin K. Petersen
#2 lore raw
In reply to Brian Bunker
Quoted 2 lines · Brian Bunker

Instead of using a constant for timeouts, use the timeout of the SCSI device itself. There are reaasons why someone might want to extend

reasons

Quoted 14 lines

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 +0 -0
index efb08b9b145a..7f11acf714ad 100644

drivers/scsi/device_handler/scsi_dh_alua.c static int submit_rtpg(struct scsi_device *sdev, unsigned char *buff, · line 146

Quoted 5 lines
drivers/scsi/device_handler/scsi_dh_alua.c +1 -1
@@ -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,
+				sdev->request_queue->rq_timeout ?: ALUA_FAILOVER_TIMEOUT * HZ,

is sdev->request_queue->rq_timeout == 0 even ever valid? In queue_io_timeout_store() and sdev_store_timeout(), a timeout of 0 is rejected.

Also, sdev->request_queue->rq_timeout can change dynamically by userspace control - is that ok for these changes?

And, finally, READ_ONCE should be use for accessing sdev->request_queue->rq_timeout

Quoted 41 lines
drivers/scsi/device_handler/scsi_dh_alua.c +6 -4
  				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, 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, 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(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((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,