public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] MegaRAID SAS: Raidcard hotswap wouldn't work if the device's fd is held in userspace
@ 2017-04-28  9:43 Zhou Zhengping
  2017-04-28 13:34 ` Hannes Reinecke
  2017-04-29 18:11 ` [PATCH]scsi: megaraid_sas: fix raid card hotswap failure Zhou Zhengping
  0 siblings, 2 replies; 4+ messages in thread
From: Zhou Zhengping @ 2017-04-28  9:43 UTC (permalink / raw)
  To: linux-scsi; +Cc: Zhou Zhengping

    When a scsi_device is unpluged from scsi controller, if the
scsi_device is still be used by application layer,it won't be
released until users release it. In this case, scsi_device_remove just set
the scsi_device's state to be SDEV_DEL. But if you plug the disk
just before the old scsi_device is released, then there will be two
scsi_device structures in scsi_host->__devices. when the next unpluging
event happens,some low-level drivers will check whether the scsi_device
has been added to host (for example, the megaraid sas series controller)
by calling scsi_device_lookup(call __scsi_device_lookup) in function
megasas_aen_polling.__scsi_device_lookup will return the first scsi_device.
Because its state is SDEV_DEL, the scsi_device_lookup will return NULL finally,
making the low-level driver assume that the scsi_device has been
removed,and won't call scsi_device_remove,which will lead the
failure of hot swap.

Signed-off-by: Zhou Zhengping <johnzzpcrystal@gmail.com>
Tested-and-reported-by: Zeng Rujia <ZengRujia@sangfor.com.cn>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=195607
---
 drivers/scsi/scsi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 61c82a3..b455619 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -1262,6 +1262,8 @@ struct scsi_device *__scsi_device_lookup(struct Scsi_Host *shost,
 	struct scsi_device *sdev;
 
 	list_for_each_entry(sdev, &shost->__devices, siblings) {
+		if (sdev->sdev_state == SDEV_DEL)
+			continue;
 		if (sdev->channel == channel && sdev->id == id &&
 				sdev->lun ==lun)
 			return sdev;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] MegaRAID SAS: Raidcard hotswap wouldn't work if the device's fd is held in userspace
  2017-04-28  9:43 [PATCH] MegaRAID SAS: Raidcard hotswap wouldn't work if the device's fd is held in userspace Zhou Zhengping
@ 2017-04-28 13:34 ` Hannes Reinecke
  2017-04-29 18:11 ` [PATCH]scsi: megaraid_sas: fix raid card hotswap failure Zhou Zhengping
  1 sibling, 0 replies; 4+ messages in thread
From: Hannes Reinecke @ 2017-04-28 13:34 UTC (permalink / raw)
  To: Zhou Zhengping, linux-scsi

On 04/28/2017 11:43 AM, Zhou Zhengping wrote:
>     When a scsi_device is unpluged from scsi controller, if the
> scsi_device is still be used by application layer,it won't be
> released until users release it. In this case, scsi_device_remove just set
> the scsi_device's state to be SDEV_DEL. But if you plug the disk
> just before the old scsi_device is released, then there will be two
> scsi_device structures in scsi_host->__devices. when the next unpluging
> event happens,some low-level drivers will check whether the scsi_device
> has been added to host (for example, the megaraid sas series controller)
> by calling scsi_device_lookup(call __scsi_device_lookup) in function
> megasas_aen_polling.__scsi_device_lookup will return the first scsi_device.
> Because its state is SDEV_DEL, the scsi_device_lookup will return NULL finally,
> making the low-level driver assume that the scsi_device has been
> removed,and won't call scsi_device_remove,which will lead the
> failure of hot swap.
> 
> Signed-off-by: Zhou Zhengping <johnzzpcrystal@gmail.com>
> Tested-and-reported-by: Zeng Rujia <ZengRujia@sangfor.com.cn>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=195607
> ---
>  drivers/scsi/scsi.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
> index 61c82a3..b455619 100644
> --- a/drivers/scsi/scsi.c
> +++ b/drivers/scsi/scsi.c
> @@ -1262,6 +1262,8 @@ struct scsi_device *__scsi_device_lookup(struct Scsi_Host *shost,
>  	struct scsi_device *sdev;
>  
>  	list_for_each_entry(sdev, &shost->__devices, siblings) {
> +		if (sdev->sdev_state == SDEV_DEL)
> +			continue;
>  		if (sdev->channel == channel && sdev->id == id &&
>  				sdev->lun ==lun)
>  			return sdev;
> 
Actually this is a similar to 2aeef605aa0 ("[SCSI] Skip deleted devices
in __scsi_device_lookup_by_target()")
Well spotted.

Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare@suse.de			               +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)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH]scsi: megaraid_sas: fix raid card hotswap failure
  2017-04-28  9:43 [PATCH] MegaRAID SAS: Raidcard hotswap wouldn't work if the device's fd is held in userspace Zhou Zhengping
  2017-04-28 13:34 ` Hannes Reinecke
@ 2017-04-29 18:11 ` Zhou Zhengping
  2017-05-09  1:38   ` Martin K. Petersen
  1 sibling, 1 reply; 4+ messages in thread
From: Zhou Zhengping @ 2017-04-29 18:11 UTC (permalink / raw)
  To: linux-scsi; +Cc: hare, James.Bottomley, Zhou Zhengping

    When a scsi_device is unpluged from scsi controller, if the
scsi_device is still be used by application layer,it won't be
released until users release it. In this case, scsi_device_remove just
set the scsi_device's state to be SDEV_DEL. But if you plug the disk
just before the old scsi_device is released, then there will be two
scsi_device structures in scsi_host->__devices. when the next unpluging
event happens,some low-level drivers will check whether the scsi_device
has been added to host (for example, the megaraid sas series controller)
by calling scsi_device_lookup(call __scsi_device_lookup) in function
megasas_aen_polling.__scsi_device_lookup will return the first scsi_device.
Because its state is SDEV_DEL, the scsi_device_lookup will return NULL
finally, making the low-level driver assume that the scsi_device has been
removed,and won't call scsi_device_remove,which will lead the
failure of hot swap.

Signed-off-by: Zhou Zhengping <johnzzpcrystal@gmail.com>
Tested-and-reported-by: Zeng Rujia <ZengRujia@sangfor.com.cn>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=195607
Reviewed-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/scsi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 7bfbcfa..61cdd99 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -763,6 +763,8 @@ struct scsi_device *__scsi_device_lookup(struct Scsi_Host *shost,
 	struct scsi_device *sdev;
 
 	list_for_each_entry(sdev, &shost->__devices, siblings) {
+		if (sdev->sdev_state == SDEV_DEL)
+			continue;
 		if (sdev->channel == channel && sdev->id == id &&
 				sdev->lun ==lun)
 			return sdev;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH]scsi: megaraid_sas: fix raid card hotswap failure
  2017-04-29 18:11 ` [PATCH]scsi: megaraid_sas: fix raid card hotswap failure Zhou Zhengping
@ 2017-05-09  1:38   ` Martin K. Petersen
  0 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2017-05-09  1:38 UTC (permalink / raw)
  To: Zhou Zhengping; +Cc: linux-scsi, hare, James.Bottomley


Zhou,

> When a scsi_device is unpluged from scsi controller, if the
> scsi_device is still be used by application layer,it won't be released
> until users release it. In this case, scsi_device_remove just set the
> scsi_device's state to be SDEV_DEL. But if you plug the disk just
> before the old scsi_device is released, then there will be two
> scsi_device structures in scsi_host->__devices. when the next
> unpluging event happens,some low-level drivers will check whether the
> scsi_device has been added to host (for example, the megaraid sas
> series controller) by calling scsi_device_lookup(call
> __scsi_device_lookup) in function
> megasas_aen_polling.__scsi_device_lookup will return the first
> scsi_device.  Because its state is SDEV_DEL, the scsi_device_lookup
> will return NULL finally, making the low-level driver assume that the
> scsi_device has been removed,and won't call scsi_device_remove,which
> will lead the failure of hot swap.

Applied to 4.12/scsi-fixes. Thank you!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-05-09  1:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-28  9:43 [PATCH] MegaRAID SAS: Raidcard hotswap wouldn't work if the device's fd is held in userspace Zhou Zhengping
2017-04-28 13:34 ` Hannes Reinecke
2017-04-29 18:11 ` [PATCH]scsi: megaraid_sas: fix raid card hotswap failure Zhou Zhengping
2017-05-09  1:38   ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox