Skip to contentSkip to conversation

usb: storage: add shutdown function for usb storage driver

PATCH In review Meng Li 4 participants 12 messages Oct 23, 2023 – Oct 25, 2023

Subsystems (2)
lore
Share & tools
lore

Meng Li

author
#0 lore raw

PATCH 1/1 usb: storage: add shutdown function for usb storage driver

On ls1043/ls1046 rdb platform, if a PCIe-USB host controller is installed, and an USB disk is also installed on the PCIe card, when executing "reboot -f" to reset the board, there will be below error reported:
usb 2-2: device not accepting address 2, error -108
This issue is introduced by linux-yocto commit 837547b64a34("driver: net:
dpaa: release resource when executing kexec") that cause to spend more time on shutdown operation. So, the 2 platforms with DPAA are not reset immediately after executing force reboot command. Moreover, the usb-storage thread is still in active status, there is still control data transferred between USB disk and PCIe host controller. But now the shutdown callback of usb pci driver had been invoked to stop the PCIe host controller completely. In this situation, the data transferring failed and report error. Therefore, add shutdown function used to disconnect the usb mass storage device to avoid data transferring under the stopped status of PCIe device.

---
 drivers/usb/storage/usb.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/usb/storage/usb.c +10 -0
index ed7c6ad96a74..e076d7e3784f 100644
@@ -1142,6 +1142,15 @@ static int storage_probe(struct usb_interface *intf,
 	return result;
 }
 
+static void usb_stor_shutdown(struct device *dev)
+{
+	struct usb_driver *driver = to_usb_driver(dev->driver);
+	struct usb_interface *intf = to_usb_interface(dev);
+
+	if (driver->disconnect)
+		driver->disconnect(intf);
+}
+
 static struct usb_driver usb_storage_driver = {
 	.name =		DRV_NAME,
 	.probe =	storage_probe,
@@ -1151,6 +1160,7 @@ static struct usb_driver usb_storage_driver = {
 	.reset_resume =	usb_stor_reset_resume,
 	.pre_reset =	usb_stor_pre_reset,
 	.post_reset =	usb_stor_post_reset,
+	.drvwrap.driver.shutdown = usb_stor_shutdown,
 	.id_table =	usb_storage_usb_ids,
 	.supports_autosuspend = 1,
 	.soft_unbind =	1,
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 4 lines · Meng Li

On ls1043/ls1046 rdb platform, if a PCIe-USB host controller is installed, and an USB disk is also installed on the PCIe card, when executing "reboot -f" to reset the board, there will be below error reported:
usb 2-2: device not accepting address 2, error -108

Do you mean that this error occurs after the system has rebooted? Or do you mean that the error is reported while the reboot is taking place?

That "device not accepting address" error message is generated by the USB core, not by the usb-storage driver. How will changing usb-storage help fix the problem?

Quoted 8 lines

This issue is introduced by linux-yocto commit 837547b64a34("driver: net:
dpaa: release resource when executing kexec") that cause to spend more time on shutdown operation. So, the 2 platforms with DPAA are not reset immediately after executing force reboot command. Moreover, the usb-storage thread is still in active status, there is still control data transferred between USB disk and PCIe host controller. But now the shutdown callback of usb pci driver had been invoked to stop the PCIe host controller completely. In this situation, the data transferring failed and report error.

That's _supposed_ to happen. By design, the "reboot -f" command is meant to carry out an immediate reboot, without using the init system, unmounting filesystems, or doing other cleanup operations.

If you want a clean reboot with no errors, don't use the "-f" option.

Quoted 3 lines

Therefore, add shutdown function
used to disconnect the usb mass storage device to avoid data transferring under the stopped status of PCIe device.

I don't see how this will fix the problems associated with a forced reboot. How is preventing data from being transferred any better than getting an error when you do try to transfer it?

Quoted 26 lines
---
 drivers/usb/storage/usb.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/usb/storage/usb.c +9 -0
index ed7c6ad96a74..e076d7e3784f 100644
@@ -1142,6 +1142,15 @@ static int storage_probe(struct usb_interface *intf,
 	return result;
 }
 
+static void usb_stor_shutdown(struct device *dev)
+{
+	struct usb_driver *driver = to_usb_driver(dev->driver);
+	struct usb_interface *intf = to_usb_interface(dev);
+
+	if (driver->disconnect)
+		driver->disconnect(intf);
+}
+
 static struct usb_driver usb_storage_driver = {
 	.name =		DRV_NAME,
 	.probe =	storage_probe,

drivers/usb/storage/usb.c static struct usb_driver usb_storage_driver = { · line 1163

Quoted 4 lines
drivers/usb/storage/usb.c +1 -0
@@ -1151,6 +1160,7 @@ static struct usb_driver usb_storage_driver = {
 	.reset_resume =	usb_stor_reset_resume,
 	.pre_reset =	usb_stor_pre_reset,
 	.post_reset =	usb_stor_post_reset,
+	.drvwrap.driver.shutdown = usb_stor_shutdown,

This definitely looks like a layering violation. If devices are to be disconnected during a system shutdown, the USB core should take care of it. Not the individual device drivers.

What will happen if you make this change to usb-storage? In a little while you'll want to do the same thing to the uas driver. And then the usbhid driver. And the usb serial drivers. And so on...

This does not seem like the best solution to whatever problem you want to solve.

drivers/usb/storage/usb.c static struct usb_driver usb_storage_driver = { · line 1166

Quoted 3 lines
drivers/usb/storage/usb.c +0 -0
 	.id_table =	usb_storage_usb_ids,
 	.supports_autosuspend = 1,
 	.soft_unbind =	1,

Alan Stern

author
#2 lore raw
Quoted 15 lines

-----Original Message-----
From: Alan Stern <[email protected]>
Sent: Tuesday, October 24, 2023 3:12 AM
To: Li, Meng <[email protected]>
Cc: [email protected]; [email protected]; usb- [email protected]; [email protected]
Subject: Re: [PATCH] usb: storage: add shutdown function for usb storage driver

CAUTION: This email comes from a non Wind River email account! Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 9 lines
Quoted 4 lines · Meng Li

On ls1043/ls1046 rdb platform, if a PCIe-USB host controller is installed, and an USB disk is also installed on the PCIe card, when executing "reboot -f" to reset the board, there will be below error reported:
usb 2-2: device not accepting address 2, error -108

Do you mean that this error occurs after the system has rebooted? Or do you mean that the error is reported while the reboot is taking place?

Understand why you ask me to clarify the time of reporting error.
Only when the reboot action is taking place, there is error reported, and then system reset normally, and there is no error in the boot log of the next time. So, I am not sure whether it is meaningful and worth to fix this issue or not.

Quoted 4 lines

That "device not accepting address" error message is generated by the USB core, not by the usb-storage driver. How will changing usb-storage help fix the problem?

I add an WARN_ON() in USB core code
Call trace as below:

 hub_port_init+0xae0/0xcf0
 usb_reset_and_verify_device+0xe8/0x3e4
 usb_reset_device+0x118/0x24c
 usb_stor_port_reset+0x70/0x80
 usb_stor_invoke_transport+0x234/0x530
 usb_stor_transparent_scsi_command+0x18/0x24
 usb_stor_control_thread+0x158/0x25c
 kthread+0x120/0x124
 ret_from_fork+0x10/0x20
Quoted 8 lines
Quoted 8 lines

This issue is introduced by linux-yocto commit 837547b64a34("driver: net:
dpaa: release resource when executing kexec") that cause to spend more time on shutdown operation. So, the 2 platforms with DPAA are not reset immediately after executing force reboot command. Moreover, the usb-storage thread is still in active status, there is still control data transferred between USB disk and PCIe host controller. But now the shutdown callback of usb pci driver had been invoked to stop the PCIe host controller completely. In this situation, the data transferring failed

Quoted 6 lines

and report error.

That's _supposed_ to happen. By design, the "reboot -f" command is meant to carry out an immediate reboot, without using the init system, unmounting filesystems, or doing other cleanup operations.

As my above said, I understand what you mean. I also thought over what you said.
I am not sure, but I still sent patch to upstream community, and want to get some suggest from more authoritative maintainer.

Quoted 2 lines

If you want a clean reboot with no errors, don't use the "-f" option.

There is also error report even if I use command "reboot"

Quoted 8 lines
Quoted 3 lines

Therefore, add shutdown function
used to disconnect the usb mass storage device to avoid data transferring under the stopped status of PCIe device.

I don't see how this will fix the problems associated with a forced reboot. How is preventing data from being transferred any better than getting an error when you do try to transfer it?

After adding the mass storage shutdown function usb_stor_shutdown(), it will release resource with bellow call logic. usb_stor_shutdown()->usb_stor_disconnect->usb_stor_release_resources()
in the usb_stor_release_resources(), usb_stor_control_thread thread() is stopped, and there will no control data transferring.

Quoted 25 lines

drivers/usb/storage/usb.c static int storage_probe(struct usb_interface

Quoted 10 lines
---
 drivers/usb/storage/usb.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/usb/storage/usb.c +0 -0
index ed7c6ad96a74..e076d7e3784f 100644
@@ -1142,6 +1142,15 @@ static int storage_probe(struct usb_interface

*intf,

Quoted 14 lines
drivers/usb/storage/usb.c +7 -0
      return result;
 }
 
+static void usb_stor_shutdown(struct device *dev) {
+     struct usb_driver *driver = to_usb_driver(dev->driver);
+     struct usb_interface *intf = to_usb_interface(dev);
+
+     if (driver->disconnect)
+             driver->disconnect(intf); }
+
 static struct usb_driver usb_storage_driver = {
      .name =         DRV_NAME,
      .probe =        storage_probe,
@@ -1151,6 +1160,7 @@ static struct usb_driver usb_storage_driver = {
Quoted 9 lines

drivers/usb/storage/usb.c static struct usb_driver usb_storage_driver = { · line 1163

Quoted 4 lines
drivers/usb/storage/usb.c +1 -0
      .reset_resume = usb_stor_reset_resume,
      .pre_reset =    usb_stor_pre_reset,
      .post_reset =   usb_stor_post_reset,
+     .drvwrap.driver.shutdown = usb_stor_shutdown,

This definitely looks like a layering violation. If devices are to be disconnected during a system shutdown, the USB core should take care of it. Not the individual device drivers.

It looks like a little uncomfortably indeed.

Quoted 4 lines

What will happen if you make this change to usb-storage? In a little while you'll want to do the same thing to the uas driver. And then the usbhid driver. And the usb serial drivers. And so on...

I add the shutdown callback refer to uas driver that has the similar shutdown function.
About the usb serial driver, there has been serial_port_shutdown() function at a more reasonable location. I am able to test all the cases with PCIe to USB card, so I am not sure whether there is also the same issue with other drivers.

Quoted 2 lines

This does not seem like the best solution to whatever problem you want to solve.

Maybe. But this issue is caused by usb_stor_control_thread() thread that is in the use mass storage driver.
So, I would like to fixed it only in use mass storage driver.
Based on my current understanding of usb code, I don't know whether there is a unified usb core interface that can fix this issue of all the usb driver. I don't have ability to touch use core code that has so widespread influence.

Thanks,
LImeng

Quoted 6 lines

drivers/usb/storage/usb.c static struct usb_driver usb_storage_driver = { · line 1166

Quoted 4 lines
drivers/usb/storage/usb.c +0 -0
      .id_table =     usb_storage_usb_ids,
      .supports_autosuspend = 1,
      .soft_unbind =  1,

Alan Stern

maintainer
#3 lore raw
Quoted 26 lines · Meng
Quoted 19 lines

-----Original Message-----
From: Alan Stern <[email protected]>

Quoted 5 lines · Meng Li

On ls1043/ls1046 rdb platform, if a PCIe-USB host controller is installed, and an USB disk is also installed on the PCIe card, when executing "reboot -f" to reset the board, there will be below error reported:
usb 2-2: device not accepting address 2, error -108

Quoted 8 lines

This issue is introduced by linux-yocto commit 837547b64a34("driver: net:
dpaa: release resource when executing kexec") that cause to spend more time on shutdown operation. So, the 2 platforms with DPAA are not reset immediately after executing force reboot command. Moreover, the usb-storage thread is still in active status, there is still control data transferred between USB disk and PCIe host controller. But now the shutdown callback of usb pci driver had been invoked to stop the PCIe host controller completely. In this situation, the data transferring failed

Quoted 6 lines

and report error.

That's _supposed_ to happen. By design, the "reboot -f" command is meant to carry out an immediate reboot, without using the init system, unmounting filesystems, or doing other cleanup operations.

Quoted 7 lines

As my above said, I understand what you mean. I also thought over what you said.
I am not sure, but I still sent patch to upstream community, and want to get some suggest from more authoritative maintainer.

Quoted 2 lines

If you want a clean reboot with no errors, don't use the "-f" option.

There is also error report even if I use command "reboot"

Okay, that's a different matter. In fact, I don't know what is supposed to happen during a clean reboot.

Greg, do you know? Should we take the time to disconnect all the USB devices during a system shutdown? What happens with non-USB disk drives? Or other removable devices?

Alan Stern

#4 lore raw
Quoted 30 lines · Alan Stern
Quoted 29 lines · Meng
Quoted 19 lines

-----Original Message-----
From: Alan Stern <[email protected]>

Quoted 5 lines · Meng Li

On ls1043/ls1046 rdb platform, if a PCIe-USB host controller is installed, and an USB disk is also installed on the PCIe card, when executing "reboot -f" to reset the board, there will be below error reported:
usb 2-2: device not accepting address 2, error -108

Quoted 8 lines

This issue is introduced by linux-yocto commit 837547b64a34("driver: net:
dpaa: release resource when executing kexec") that cause to spend more time on shutdown operation. So, the 2 platforms with DPAA are not reset immediately after executing force reboot command. Moreover, the usb-storage thread is still in active status, there is still control data transferred between USB disk and PCIe host controller. But now the shutdown callback of usb pci driver had been invoked to stop the PCIe host controller completely. In this situation, the data transferring failed

Quoted 6 lines

and report error.

That's _supposed_ to happen. By design, the "reboot -f" command is meant to carry out an immediate reboot, without using the init system, unmounting filesystems, or doing other cleanup operations.

As my above said, I understand what you mean. I also thought over what you said.
I am not sure, but I still sent patch to upstream community, and want to get some suggest from more authoritative maintainer.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

If you want a clean reboot with no errors, don't use the "-f" option.

There is also error report even if I use command "reboot"

Okay, that's a different matter. In fact, I don't know what is supposed to happen during a clean reboot.

Define "clean" :)

reboot is a system thing that happens before the reboot syscall happens. So which are we talking nabout here?

Quoted 2 lines

Greg, do you know? Should we take the time to disconnect all the USB devices during a system shutdown?

In the past we have not. And if we switch to do so, we might get some complaints as we would now delaying the shutdown process to be longer than before.

Quoted 1 line

What happens with non-USB disk drives? Or other removable devices?

It would have to come from "above" in the device tree, so does the PCI or platform bus say that they should be shut down and their child devices?

thanks,

greg k-h

maintainer
#5 lore raw
Quoted 5 lines · On Tue, Oct 24, 2023 at 05:45:40PM +0200, [email protected] wrote:
Quoted 2 lines · Alan Stern

Okay, that's a different matter. In fact, I don't know what is supposed to happen during a clean reboot.

Define "clean" :)

In this case, I mean what happens when you give the "reboot" command.

Quoted 9 lines

reboot is a system thing that happens before the reboot syscall happens. So which are we talking nabout here?

Quoted 2 lines

Greg, do you know? Should we take the time to disconnect all the USB devices during a system shutdown?

In the past we have not. And if we switch to do so, we might get some complaints as we would now delaying the shutdown process to be longer than before.

Yes, that's what I'm afraid of.

Quoted 5 lines
Quoted 1 line

What happens with non-USB disk drives? Or other removable devices?

It would have to come from "above" in the device tree, so does the PCI or platform bus say that they should be shut down and their child devices?

Well, the PCI layer invokes the HCD's ->shutdown callback. But the usb-storage driver and usbcore don't know this has happened, so they start logging errors because they are suddenly unable to communicate with a USB drive. Meng Li is unhappy about these error messages.

Adding a shutdown callback of sorts to usb-storage allows the driver to know that it shouldn't communicate with the drive any more, which prevents the error message from appearing. That's what this patch does.

But that's all it does. Basically it creates a layering violation just to prevent some error messages from showing up in the system log during a shutdown or reboot. The question is whether we want to do this at all, and if we do, shouldn't it be handled at the usbcore level rather than just within usb-storage?

Alan Stern

#6 lore raw
Quoted 8 lines · Alan Stern
Quoted 5 lines · On Tue, Oct 24, 2023 at 05:45:40PM +0200, [email protected] wrote:
Quoted 2 lines · Alan Stern

Okay, that's a different matter. In fact, I don't know what is supposed to happen during a clean reboot.

Define "clean" :)

In this case, I mean what happens when you give the "reboot" command.

That's a userspace binary/script/whatever that can do loads of different things not involving the kernel, so it all depends on the user's system as to what will happen here.

Many "good" userspace implementation of reboot will go and sync and unmount all mounted disks in the correct order, before the kernel is told to reboot.

All we can do in the kernel is act on the reboot system call.

So perhaps the original poster here can see why his userspace isn't correctly shutting down their storage devices?

Quoted 27 lines
Quoted 9 lines

reboot is a system thing that happens before the reboot syscall happens. So which are we talking nabout here?

Quoted 2 lines

Greg, do you know? Should we take the time to disconnect all the USB devices during a system shutdown?

In the past we have not. And if we switch to do so, we might get some complaints as we would now delaying the shutdown process to be longer than before.

Yes, that's what I'm afraid of.

Quoted 5 lines
Quoted 1 line

What happens with non-USB disk drives? Or other removable devices?

It would have to come from "above" in the device tree, so does the PCI or platform bus say that they should be shut down and their child devices?

Well, the PCI layer invokes the HCD's ->shutdown callback. But the usb-storage driver and usbcore don't know this has happened, so they start logging errors because they are suddenly unable to communicate with a USB drive. Meng Li is unhappy about these error messages.

Adding a shutdown callback of sorts to usb-storage allows the driver to know that it shouldn't communicate with the drive any more, which prevents the error message from appearing. That's what this patch does.

Quoted 5 lines

But that's all it does. Basically it creates a layering violation just to prevent some error messages from showing up in the system log during a shutdown or reboot. The question is whether we want to do this at all, and if we do, shouldn't it be handled at the usbcore level rather than just within usb-storage?

We should do this within the usb core if we care about it, but why did the USB device suddenly go away before the USB storage driver was told about it? That feels like something else is pulling the power on the device that is out-of-band here.

thanks,

greg k-h

maintainer
#7 lore raw
Quoted 10 lines · On Tue, Oct 24, 2023 at 07:11:31PM +0200, [email protected] wrote:
Quoted 8 lines · Alan Stern
Quoted 5 lines · On Tue, Oct 24, 2023 at 05:45:40PM +0200, [email protected] wrote:
Quoted 2 lines · Alan Stern

Okay, that's a different matter. In fact, I don't know what is supposed to happen during a clean reboot.

Define "clean" :)

In this case, I mean what happens when you give the "reboot" command.

Quoted 7 lines

That's a userspace binary/script/whatever that can do loads of different things not involving the kernel, so it all depends on the user's system as to what will happen here.

Many "good" userspace implementation of reboot will go and sync and unmount all mounted disks in the correct order, before the kernel is told to reboot.

Even if the filesystems are unmounted, the kernel will still probe the drive periodically (once every few seconds) if it claims to have removable media. Failure of those probes won't hurt anything, but it is likely to generate an error message. I don't know if that's what's happening in this case, though.

Quoted 4 lines

All we can do in the kernel is act on the reboot system call.

So perhaps the original poster here can see why his userspace isn't correctly shutting down their storage devices?

Meng, can you do this? Maybe you can fix the problem by adding a script to be executed by the "reboot" command. If the script writes to the "remove" attribute file in the drive's sysfs directory, that will unbind usb-storage from the device. It should give the same result as your patch, for clean reboots. It won't help "reboot -f", though.

Quoted 21 lines
Quoted 15 lines
Quoted 5 lines
Quoted 1 line

What happens with non-USB disk drives? Or other removable devices?

It would have to come from "above" in the device tree, so does the PCI or platform bus say that they should be shut down and their child devices?

Well, the PCI layer invokes the HCD's ->shutdown callback. But the usb-storage driver and usbcore don't know this has happened, so they start logging errors because they are suddenly unable to communicate with a USB drive. Meng Li is unhappy about these error messages.

Adding a shutdown callback of sorts to usb-storage allows the driver to know that it shouldn't communicate with the drive any more, which prevents the error message from appearing. That's what this patch does.

Quoted 5 lines

But that's all it does. Basically it creates a layering violation just to prevent some error messages from showing up in the system log during a shutdown or reboot. The question is whether we want to do this at all, and if we do, shouldn't it be handled at the usbcore level rather than just within usb-storage?

Quoted 4 lines

We should do this within the usb core if we care about it, but why did the USB device suddenly go away before the USB storage driver was told about it? That feels like something else is pulling the power on the device that is out-of-band here.

The device went away because the HCD shut down the host controller, thereby stopping all USB communication. The usb-storage driver wasn't informed because this all happened inside the HCD's PCI ->shutdown callback. HCD shutdown doesn't do anything to the USB bus -- in particular, it doesn't remove the root hub or anything else -- it just turns off the host controller.

Since USB class-device drivers don't have ->shutdown callbacks (there is no shutdown() method in struct usb_driver), they don't know what's going on while a shutdown or reboot is in progress. All they see is a bunch of errors.

Alan Stern

author
#8 lore raw
Quoted 43 lines

-----Original Message-----
From: Alan Stern <[email protected]>
Sent: Wednesday, October 25, 2023 3:23 AM
To: [email protected]
Cc: Li, Meng <[email protected]>; [email protected]; usb- [email protected]; [email protected]
Subject: Re: [PATCH] usb: storage: add shutdown function for usb storage driver

CAUTION: This email comes from a non Wind River email account! Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 2 lines · On Tue, Oct 24, 2023 at 07:11:31PM +0200, [email protected] wrote:
Quoted 1 line · Alan Stern

On Tue, Oct 24, 2023 at 05:45:40PM +0200, [email protected]

Quoted 8 lines · wrote:
Quoted 7 lines
Quoted 5 lines · Alan Stern
Quoted 2 lines

Okay, that's a different matter. In fact, I don't know what is supposed to happen during a clean reboot.

Define "clean" :)

In this case, I mean what happens when you give the "reboot" command.

Quoted 7 lines

That's a userspace binary/script/whatever that can do loads of different things not involving the kernel, so it all depends on the user's system as to what will happen here.

Many "good" userspace implementation of reboot will go and sync and unmount all mounted disks in the correct order, before the kernel is told to reboot.

Even if the filesystems are unmounted, the kernel will still probe the drive periodically (once every few seconds) if it claims to have removable media. Failure of those probes won't hurt anything, but it is likely to generate an error message. I don't know if that's what's happening in this case, though.

Quoted 2 lines

All we can do in the kernel is act on the reboot system call.

Quoted 9 lines
Quoted 2 lines

So perhaps the original poster here can see why his userspace isn't correctly shutting down their storage devices?

Meng, can you do this? Maybe you can fix the problem by adding a script to be executed by the "reboot" command. If the script writes to the "remove" attribute file in the drive's sysfs directory, that will unbind usb-storage from the device. It should give the same result as your patch, for clean reboots. It won't help "reboot -f", though.

Ok! Got it.
In fact, the reported error is not critical one. In my real work environment, there is not the error because there is not PCIe-TO-USB card installed on board.
The issue is reported to me from our tester who used the PCIe-TO-USB card to test the PCIe feature, not test USB feature.
I am ok to NAK this patch. The primary intention of sending this patch is to raise up the discussion about whether shutdown function should be added for usb mass storage driver, and I have got what I want.

Thanks,
Limeng

Quoted 37 lines
Quoted 21 lines
Quoted 15 lines
Quoted 5 lines
Quoted 1 line

What happens with non-USB disk drives? Or other removable devices?

It would have to come from "above" in the device tree, so does the PCI or platform bus say that they should be shut down and their child devices?

Well, the PCI layer invokes the HCD's ->shutdown callback. But the usb-storage driver and usbcore don't know this has happened, so they start logging errors because they are suddenly unable to communicate with a USB drive. Meng Li is unhappy about these error messages.

Adding a shutdown callback of sorts to usb-storage allows the driver to know that it shouldn't communicate with the drive any more, which prevents the error message from appearing. That's what this patch does.

Quoted 5 lines

But that's all it does. Basically it creates a layering violation just to prevent some error messages from showing up in the system log during a shutdown or reboot. The question is whether we want to do this at all, and if we do, shouldn't it be handled at the usbcore level rather than just within usb-storage?

Quoted 4 lines

We should do this within the usb core if we care about it, but why did the USB device suddenly go away before the USB storage driver was told about it? That feels like something else is pulling the power on the device that is out-of-band here.

The device went away because the HCD shut down the host controller, thereby stopping all USB communication. The usb-storage driver wasn't informed because this all happened inside the HCD's PCI ->shutdown callback. HCD shutdown doesn't do anything to the USB bus -- in particular, it doesn't remove the root hub or anything else -- it just turns off the host controller.

Since USB class-device drivers don't have ->shutdown callbacks (there is no shutdown() method in struct usb_driver), they don't know what's going on while a shutdown or reboot is in progress. All they see is a bunch of errors.

Alan Stern

maintainer
#9 lore raw
Quoted 3 lines · Meng

In fact, the reported error is not critical one. In my real work environment, there is not the error because there is not PCIe-TO-USB card installed on board.
The issue is reported to me from our tester who used the PCIe-TO-USB card to test the PCIe feature, not test USB feature.
I am ok to NAK this patch. The primary intention of sending this patch is to raise up the discussion about whether shutdown function should be added for usb mass storage driver, and I have got what I want.

All right, then we will consider the issue closed. Thanks.

Alan Stern

#10 lore raw
In reply to Alan Stern
Quoted 4 lines · Alan Stern

Since USB class-device drivers don't have ->shutdown callbacks (there is no shutdown() method in struct usb_driver), they don't know what's going on while a shutdown or reboot is in progress. All they see is a bunch of errors.

Does this solve the issue? You'd have to flush the cache on the SCSI device further down in the tree, if you want this done properly.

Regards
Oliver

maintainer
#11 lore raw
Quoted 8 lines · Oliver Neukum
Quoted 4 lines · Alan Stern

Since USB class-device drivers don't have ->shutdown callbacks (there is no shutdown() method in struct usb_driver), they don't know what's going on while a shutdown or reboot is in progress. All they see is a bunch of errors.

Does this solve the issue? You'd have to flush the cache on the SCSI device further down in the tree, if you want this done properly.

Depends on what issue you're talking about. The purpose of the proposed patch was not to make sure that the reboot happens cleanly; it was to prevent certain error messages from showing up in the system log.

Besides, Meng Li has decided to withdraw the patch submission.

Alan Stern