failover fixes for scsi_dh_alua
cover failover fixes for scsi_dh_alua
Here are 3 fixes we came up with at SUSE to fix problems we encountered in multipath failover tests. Feedback welcome.
Best regards,
Martin
Hannes Reinecke (2):
scsi_dh_alua: Do not modify the interval value for retries
scsi_dh_alua: Do not retry for unmapped device
Martin Wilck (1):
scsi_dh_alua: do not call BUG_ON when updating port group
drivers/scsi/device_handler/scsi_dh_alua.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
Signature · 1 line
2.12.2
PATCH 1/3 scsi_dh_alua: Do not modify the interval value for retries
From: Hannes Reinecke <[email protected]>
We shouldn't modify the interval value, as the struct is accessed from different devices and hence we might end up scheduling too early.
--- drivers/scsi/device_handler/scsi_dh_alua.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/scsi/device_handler/scsi_dh_alua.c +2 -5
@@ -681,7 +681,6 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)case SCSI_ACCESS_STATE_TRANSITIONING :if (time_before (jiffies, pg->expiry)) {/* State transition, retry */ - pg->interval =2 ; err =SCSI_DH_RETRY ; }else {struct alua_dh_data *h;
@@ -836,11 +835,9 @@ static void alua_rtpg_work(struct work_struct *work)spin_lock_irqsave (&pg->lock, flags);if (err ==SCSI_DH_RETRY || pg->flags &ALUA_PG_RUN_RTPG ) { pg->flags |=ALUA_PG_RUN_RTPG ; - pg->interval =0 ; pg->flags &= ~ALUA_PG_RUNNING ;spin_unlock_irqrestore (&pg->lock, flags); -queue_delayed_work (alua_wq, &pg->rtpg_work, - pg->interval *HZ ); +queue_delayed_work (alua_wq, &pg->rtpg_work,0 );return ; } }
@@ -886,7 +883,7 @@ static bool alua_rtpg_queue(struct alua_port_group *pg, force = true; }if (pg->rtpg_sdev ==NULL ) { - pg->interval =0 ; + pg->interval =2 ; pg->flags |=ALUA_PG_RUN_RTPG ;kref_get (&pg->kref); pg->rtpg_sdev = sdev;
Signature · 1 line
2.12.2
PATCH 2/3 scsi_dh_alua: Do not retry for unmapped device
In reply to Martin WilckFrom: Hannes Reinecke <[email protected]>
If a device becomes unmapped on the target we should be returning SCSI_DH_DEV_OFFLINED.
--- drivers/scsi/device_handler/scsi_dh_alua.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/scsi/device_handler/scsi_dh_alua.c +6 -3
@@ -522,7 +522,7 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)struct alua_port_group *tmp_pg;int len, k, off, valid_states =0 , bufflen =ALUA_RTPG_SIZE ;unsigned char *desc, *buff; -unsigned err, retval; +unsigned err =SCSI_DH_OK , retval;unsigned int tpg_desc_tbl_off;unsigned char orig_transition_tmo;unsigned long flags;
@@ -541,7 +541,6 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)return SCSI_DH_DEV_TEMP_BUSY ; retry: - err =0 ; retval =submit_rtpg (sdev, buff, bufflen, &sense_hdr, pg->flags);if (retval) {
@@ -569,6 +568,7 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) pg->flags |=ALUA_RTPG_EXT_HDR_UNSUPP ; goto retry; } + err =SCSI_DH_IO ;/* * Retry on ALUA state transition or if any * UNIT ATTENTION occurred.
@@ -576,6 +576,9 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)if (sense_hdr.sense_key ==NOT_READY && sense_hdr.asc ==0x04 && sense_hdr.ascq ==0x0a ) err =SCSI_DH_RETRY ; +if (sense_hdr.sense_key ==ILLEGAL_REQUEST && + sense_hdr.asc ==0x25 && sense_hdr.ascq ==0x00 ) + err =SCSI_DH_DEV_OFFLINED ;else if (sense_hdr.sense_key ==UNIT_ATTENTION ) err =SCSI_DH_RETRY ; if (err == SCSI_DH_RETRY &&
@@ -591,7 +594,7 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)scsi_print_sense_hdr (sdev,ALUA_DH_NAME , &sense_hdr);kfree (buff); pg->expiry =0 ; -return SCSI_DH_IO ; +return err; } len =get_unaligned_be32 (&buff[0 ]) +4 ;
Signature · 1 line
2.12.2
PATCH 3/3 scsi_dh_alua: do not call BUG_ON when updating port group
In reply to Martin Wilckalua_rtpg() can race with alua_bus_detach(). The assertion that alua_dh_data *h->sdev must be non-NULL is not guaranteed because alua_bus_detach sets this field to NULL before removing the entry from the port group's dh_list.
This happens when a device is about to be removed, so don't BUG out but continue silently.
--- drivers/scsi/device_handler/scsi_dh_alua.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/scsi/device_handler/scsi_dh_alua.c +9 -4
@@ -652,9 +652,13 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)rcu_read_lock ();list_for_each_entry_rcu (h, &tmp_pg->dh_list, node) { -/* h->sdev should always be valid */ -BUG_ON (!h->sdev); - h->sdev->access_state = desc[0 ]; +/* +* We might be racing with +* alua_bus_detach here +*/ +if (h->sdev) + h->sdev->access_state = + desc[0 ]; }rcu_read_unlock (); }
@@ -694,7 +698,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) pg->expiry =0 ;rcu_read_lock ();list_for_each_entry_rcu (h, &pg->dh_list, node) { -BUG_ON (!h->sdev); +if (!h->sdev) +continue ; h->sdev->access_state = (pg->state &SCSI_ACCESS_STATE_MASK );if (pg->pref)
Signature · 1 line
2.12.2
Re: [PATCH 1/3] scsi_dh_alua: Do not modify the interval value for retries
In reply to Martin Wilckdrivers/scsi/device_handler/scsi_dh_alua.c static bool alua_rtpg_queue(struct alua_port_group *pg, · line 889
Quoted 9 lines · Martin Wilck
drivers/scsi/device_handler/scsi_dh_alua.c +1
-1@@ -886,7 +883,7 @@ static bool alua_rtpg_queue(struct alua_port_group *pg, force = true; }if (pg->rtpg_sdev ==NULL ) { - pg->interval =0 ; + pg->interval =2 ; pg->flags |=ALUA_PG_RUN_RTPG ;kref_get (&pg->kref); pg->rtpg_sdev = sdev;
Hello Hannes and Martin,
Why is .interval initialized in alua_rtpg_queue() instead of in alua_alloc_pg()? I think initializing it in alua_alloc_pg() would make more clear that .interval is constant.
Thanks,
Bart.
Re: [PATCH 2/3] scsi_dh_alua: Do not retry for unmapped device
In reply to Martin WilckQuoted 7 lines · Martin Wilck
From: Hannes Reinecke <[email protected]>
If a device becomes unmapped on the target we should be returning
SCSI_DH_DEV_OFFLINED.Signed-off-by Hannes Reinecke <[email protected]>Reviewed-by Martin Wilck <[email protected]>
Hello Hannes and Martin,
Have you considered to add "Cc: stable" to this patch and other patches in this series?
drivers/scsi/device_handler/scsi_dh_alua.c static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) · line 583
Quoted 12 lines
drivers/scsi/device_handler/scsi_dh_alua.c +3
-0* Retry on ALUA state transition or if any * UNIT ATTENTION occurred. @@ -576,6 +576,9 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)if (sense_hdr.sense_key ==NOT_READY && sense_hdr.asc ==0x04 && sense_hdr.ascq ==0x0a ) err =SCSI_DH_RETRY ; +if (sense_hdr.sense_key ==ILLEGAL_REQUEST && + sense_hdr.asc ==0x25 && sense_hdr.ascq ==0x00 ) + err =SCSI_DH_DEV_OFFLINED ;else if (sense_hdr.sense_key ==UNIT_ATTENTION ) err =SCSI_DH_RETRY ;
Please be consistent in the code that checks the sense codes - either use "else if" for the test that has been added or changed the existing "else if" into "if". Otherwise this patch looks fine to me.
Thanks,
Bart.
Re: [PATCH 1/3] scsi_dh_alua: Do not modify the interval value for retries
In reply to Bart Van AsscheQuoted 14 lines · Bart Van Assche
Quoted 10 lines · Martin Wilck
drivers/scsi/device_handler/scsi_dh_alua.c +1
-1@@ -886,7 +883,7 @@ static bool alua_rtpg_queue(structalua_port_group *pg, force = true; } if (pg->rtpg_sdev == NULL) { - pg->interval =0 ; + pg->interval =2 ; pg->flags |= ALUA_PG_RUN_RTPG; kref_get(&pg->kref);
pg->rtpg_sdev= sdev;Hello Hannes and Martin,
Quoted 3 lines
Why is .interval initialized in
alua_rtpg_queue()instead of inalua_alloc_pg()? I think initializing it inalua_alloc_pg()would make more clear that .interval is constant.
Thinking about it - since "interval" has now become a global constant, we might as well declare it as a constant rather than carrying in around in the alua_port_group struct.
It's kind of funny how this evolved from a geometric series via an arithmetic series (bc97f4bb) and a per port-group variable with just two values (03197b61) to a global constant ... an example of kernel code gradually getting simpler over time :-)
However: 03197b61 ("scsi_dh_alua: Use workqueue for RTPG") has removed the progression sort of silently. It was still present in Hannes's first version of the patch (http://marc.info/?l=linux-scsi&m=1391160640
32031&w=2) but seems to have been dropped in later versions:
@@ -546,23 +593,26 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
switch (pg->state) {
case TPGS_STATE_TRANSITIONING:
- if (time_before(jiffies, expiry)) {
+ if (time_before(jiffies, pg->expiry)) {
/* State transition, retry */
- interval += 2000;
- msleep(interval);
- goto retry;
+ pg->interval = 2;
+ err = SCSI_DH_RETRY;
+ } else {
+ /* Transitioning time exceeded, set port to standby */
+ err = SCSI_DH_IO;
+ pg->state = TPGS_STATE_STANDBY;
+ pg->expiry = 0;Can someone confirm that using a constant value here is sufficient?
Martin
Signature · 3 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg)
Re: [PATCH 2/3] scsi_dh_alua: Do not retry for unmapped device
In reply to Bart Van AsscheHi Bart,
Quoted 6 lines · Bart Van Assche
Quoted 5 lines · Martin Wilck
From: Hannes Reinecke <[email protected]>
If a device becomes unmapped on the target we should be returning
SCSI_DH_DEV_OFFLINED.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Hannes Reinecke <[email protected]>Reviewed-by Martin Wilck <[email protected]>Hello Hannes and Martin,
Have you considered to add "Cc: stable" to this patch and other patches in
this series?
Sorry, I forgot. But a v2 will be necessary anyway as it seems.
Regards
Martin
Signature · 3 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg)
Re: [PATCH 3/3] scsi_dh_alua: do not call BUG_ON when updating port group
In reply to Martin WilckQuoted 11 lines · Martin Wilck
drivers/scsi/device_handler/scsi_dh_alua.c +0
-3@@ -652,9 +652,13 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)rcu_read_lock ();list_for_each_entry_rcu (h, &tmp_pg->dh_list, node) { -/* h->sdev should always be valid */ -BUG_ON (!h->sdev); - h->sdev->access_state = desc[0 ];
drivers/scsi/device_handler/scsi_dh_alua.c static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) · line 664
Quoted 10 lines
drivers/scsi/device_handler/scsi_dh_alua.c +7
-0+/* +* We might be racing with +* alua_bus_detach here +*/ +if (h->sdev) + h->sdev->access_state = + desc[0 ]; }rcu_read_unlock (); }
Hello Hannes and Martin,
What will happen if h->sdev is cleared after it has been tested and before it is dereferenced? Additionally, even if h->sdev would be cached, can the following sequence of events happen?
* alua_rtpg() tests h->sdev.
* alua_bus_detach() clears h->sdev.
* h->sdev is freed.
* alua_rtpg() dereferences h->sdev.
Thanks,
Bart.
Re: [PATCH 1/3] scsi_dh_alua: Do not modify the interval value for retries
In reply to Bart Van AsscheQuoted 13 lines · Bart Van Assche
drivers/scsi/device_handler/scsi_dh_alua.c static bool alua_rtpg_queue(struct alua_port_group *pg, · line 889
Quoted 9 lines · Martin Wilck
drivers/scsi/device_handler/scsi_dh_alua.c +1
-1@@ -886,7 +883,7 @@ static bool alua_rtpg_queue(struct alua_port_group *pg, force = true; }if (pg->rtpg_sdev ==NULL ) { - pg->interval =0 ; + pg->interval =2 ; pg->flags |=ALUA_PG_RUN_RTPG ;kref_get (&pg->kref); pg->rtpg_sdev = sdev;Hello Hannes and Martin,
Quoted 4 lines
Why is .interval initialized in
alua_rtpg_queue()instead of inalua_alloc_pg()? I think initializing it inalua_alloc_pg()would make more clear that .interval is constant.
Yes, valid point.
Will be doing so.
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)