From: 胡连勤 <hulianqin@vivo.com>
To: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <mkp@kernel.org>,
Bart Van Assche <bvanassche@acm.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Alan Stern <stern@rowland.harvard.edu>
Cc: "Christoph Hellwig" <hch@lst.de>, "Jens Axboe" <axboe@kernel.dk>,
"Hannes Reinecke" <hare@suse.de>,
"Mike Christie" <michael.christie@oracle.com>,
"Damien Le Moal" <dlemoal@kernel.org>,
"John Garry" <john.g.garry@oracle.com>,
"Shin'ichiro Kawasaki" <shinichiro.kawasaki@wdc.com>,
"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"usb-storage@lists.one-eyed-alien.net"
<usb-storage@lists.one-eyed-alien.net>,
"stable@vger.kernel.org" <stable@vger.kernel.org>,
胡连勤 <hulianqin@vivo.com>
Subject: [PATCH v5 2/2] usb: storage: set surprise_removal flag on physical removal
Date: Fri, 9 Oct 2026 11:31:42 +0000 [thread overview]
Message-ID: <TYUPR06MB621711053AB2B701FECC73FED2922@TYUPR06MB6217.apcprd06.prod.outlook.com> (raw)
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
next reply other threads:[~2026-10-09 11:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 11:31 胡连勤 [this message]
2026-11-20 11:49 ` Greg Kroah-Hartman
2026-11-20 12:31 ` 答复: " 胡连勤
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=TYUPR06MB621711053AB2B701FECC73FED2922@TYUPR06MB6217.apcprd06.prod.outlook.com \
--to=hulianqin@vivo.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=dlemoal@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=john.g.garry@oracle.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=michael.christie@oracle.com \
--cc=mkp@kernel.org \
--cc=shinichiro.kawasaki@wdc.com \
--cc=stable@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=usb-storage@lists.one-eyed-alien.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®