Linux block layer
 help / color / mirror / Atom feed
* [PATCH v5 2/2] usb: storage: set surprise_removal flag on physical removal
@ 2026-10-09 11:31 胡连勤
  2026-11-20 11:49 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: 胡连勤 @ 2026-10-09 11:31 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen, Bart Van Assche,
	Greg Kroah-Hartman, Alan Stern
  Cc: Christoph Hellwig, Jens Axboe, Hannes Reinecke, Mike Christie,
	Damien Le Moal, John Garry, Shin'ichiro Kawasaki,
	linux-scsi@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	usb-storage@lists.one-eyed-alien.net, stable@vger.kernel.org,
	胡连勤

Set the surprise_removal flag in struct Scsi_Host when the USB device
state is USB_STATE_NOTATTACHED, indicating the device has been
physically removed and cannot handle I/O.

This flag is checked by sd_remove() (added in the previous patch) to
skip sync_filesystem() during surprise removal, avoiding a hang waiting
for I/O that can never complete.

For orderly removal (e.g. rmmod, sysfs unbind) the USB device state is
not NOTATTACHED, so the flag is not set and sync proceeds normally,
preserving dirty data writeback.

Signed-off-by: Lianqin Hu <hulianqin@vivo.com>
---
 drivers/usb/storage/usb.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 064c7fc8e368..f6c81f7ff9f1 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -930,6 +930,9 @@ static void quiesce_and_remove_host(struct us_data *us)
 	if (us->pusb_dev->state == USB_STATE_NOTATTACHED) {
 		set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
 		wake_up(&us->delay_wait);
+
+		/* Device is physically gone, cannot handle I/O */
+		host->surprise_removal = 1;
 	}
 
 	/*
-- 
2.48.1


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

* Re: [PATCH v5 2/2] usb: storage: set surprise_removal flag on physical removal
  2026-10-09 11:31 [PATCH v5 2/2] usb: storage: set surprise_removal flag on physical removal 胡连勤
@ 2026-11-20 11:49 ` Greg Kroah-Hartman
  2026-11-20 12:31   ` 答复: " 胡连勤
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-20 11:49 UTC (permalink / raw)
  To: 胡连勤
  Cc: James E.J. Bottomley, Martin K. Petersen, Bart Van Assche,
	Alan Stern, Christoph Hellwig, Jens Axboe, Hannes Reinecke,
	Mike Christie, Damien Le Moal, John Garry,
	Shin'ichiro Kawasaki, linux-scsi@vger.kernel.org,
	linux-usb@vger.kernel.org, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	usb-storage@lists.one-eyed-alien.net, stable@vger.kernel.org

On Fri, Oct 09, 2026 at 11:31:42AM +0000, 胡连勤 wrote:
> Set the surprise_removal flag in struct Scsi_Host when the USB device
> state is USB_STATE_NOTATTACHED, indicating the device has been
> physically removed and cannot handle I/O.
> 
> This flag is checked by sd_remove() (added in the previous patch) to
> skip sync_filesystem() during surprise removal, avoiding a hang waiting
> for I/O that can never complete.

There is no previous patch.

> For orderly removal (e.g. rmmod, sysfs unbind) the USB device state is
> not NOTATTACHED, so the flag is not set and sync proceeds normally,
> preserving dirty data writeback.
> 
> Signed-off-by: Lianqin Hu <hulianqin@vivo.com>

Does not match the From: line :(

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

* 答复: [PATCH v5 2/2] usb: storage: set surprise_removal flag on physical removal
  2026-11-20 11:49 ` Greg Kroah-Hartman
@ 2026-11-20 12:31   ` 胡连勤
  0 siblings, 0 replies; 3+ messages in thread
From: 胡连勤 @ 2026-11-20 12:31 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: James E.J. Bottomley, Martin K. Petersen, Bart Van Assche,
	Alan Stern, Christoph Hellwig, Jens Axboe, Hannes Reinecke,
	Mike Christie, Damien Le Moal, John Garry,
	Shin'ichiro Kawasaki, linux-scsi@vger.kernel.org,
	linux-usb@vger.kernel.org, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	usb-storage@lists.one-eyed-alien.net, stable@vger.kernel.org

Hi Greg,

> > Set the surprise_removal flag in struct Scsi_Host when the USB device
> > state is USB_STATE_NOTATTACHED, indicating the device has been
> > physically removed and cannot handle I/O.
> >
> > This flag is checked by sd_remove() (added in the previous patch) to
> > skip sync_filesystem() during surprise removal, avoiding a hang waiting
> > for I/O that can never complete.
> 
> There is no previous patch.
> 
> > For orderly removal (e.g. rmmod, sysfs unbind) the USB device state is
> > not NOTATTACHED, so the flag is not set and sync proceeds normally,
> > preserving dirty data writeback.
> >
> > Signed-off-by: Lianqin Hu <hulianqin@vivo.com>
> 
> Does not match the From: line :(

Thanks for the review. Apologies for the issues:

1. Missing previous patch
Patch v5 1/2 was sent separately to the SCSI list:
https://lore.kernel.org/all/TYUPR06MB6217DD31B1B3CD09E431CC12D2922@TYUPR06MB6217.apcprd06.prod.outlook.com/

I should have sent both patches together as a series with a cover
letter. My mistake.

2. From: / Signed-off-by mismatch
The From: header shows my Chinese name while Signed-off-by: uses the
English transliteration. I'll ensure they match in future submissions.

3. This patch is superseded
The issue has already been fixed by Bart Van Assche's patch, which was
merged upstream:

scsi: sd: Mark the disk dead if runtime resume fails in sd_remove()
https://lore.kernel.org/all/2c0c76d70f0fe197932836b9bcf8496095135d1b.1792446921.git.bvanassche@acm.org/

Bart's solution is cleaner — it calls blk_mark_disk_dead() directly in
sd_remove() when scsi_autopm_get_device() fails, without needing a new
surprise_removal flag.

Thanks,
Lianqin

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

end of thread, other threads:[~2026-11-20 12:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-09 11:31 [PATCH v5 2/2] usb: storage: set surprise_removal flag on physical removal 胡连勤
2026-11-20 11:49 ` Greg Kroah-Hartman
2026-11-20 12:31   ` 答复: " 胡连勤

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