Enable CONFIG_USB_SUSPEND by default or some mobile HD can't be unplugged safely
Hello List,
By default CONFIG_USB_SUSPEND is not enabled and today I got bite by this when I got a new WDC My Book hard drive. I have no way to unplug it safely, according to it's manual, with a kernel that doesn't have CONFIG_USB_SUSPEND=y.
On it's manual read "you should unplug and remove the device only when the light is off." On Linux unmounting it won't turn it's light off and I can feel it's motor is still running. The only way to unplug it properly on a Linux system, as to my knowledge, is to echo suspend' to /sys/bus/usb/devices/$DEV/power/level'. And one has to have CONFIG_USB_SUSPEND=y to do this.
On Windows and Mac OS, safely remove this device' function effectly turns it into suspend' mode, and it's light off.
I'm new in this field and I understood people's concern on enabling autosuspend. As to my understanding, enabling suspend' and enabling autosuspend' should be controlled by two different knobs. I did a quick search in LKML and haven't found specific oppose to enable USB suspend by default, and Debian has started shipping a kernel with it turned on since 2.6.26.
Perhaps we should consider turning it on by default? Thanks!
Signature · 1 line
Li, Yan
PATCH 1/1 enable CONFIG_USB_SUSPEND by default
Some USB devices need to be put into suspend mode before unplugging. Without CONFIG_USB_SUSPEND we have no way to unplug them safely.
--- drivers/usb/core/Kconfig | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
drivers/usb/core/Kconfig +5 -3
@@ -89,18 +89,20 @@ config USB_DYNAMIC_MINORS config USB_SUSPEND bool "USB selective suspend/resume and wakeup" depends on USB && PM + default y help If you say Y here, you can use driver calls or the sysfs "power/level" file to suspend or resume individual USB - peripherals and to enable or disable autosuspend (see - Documentation/usb/power-management.txt for more details). + peripherals and to enable or disable autosuspend. Some USB + devices need to be put into suspend mode before unplugging + (see Documentation/usb/power-management.txt for more details). Also, USB "remote wakeup" signaling is supported, whereby some USB devices (like keyboards and network adapters) can wake up their parent hub. That wakeup cascades up the USB tree, and could wake the system from states like suspend-to-RAM. - If you are unsure about this, say N here. + If you are unsure about this, say Y here. config USB_OTG bool
Signature · 5 lines
1.5.6.5 -- Li, Yan
Quoted 9 lines · Yan Li
Hello List,
By default
CONFIG_USB_SUSPENDis not enabled and today I got bite by this when I got a new WDC My Book hard drive. I have no way to unplug it safely, according to it's manual, with a kernel that doesn't haveCONFIG_USB_SUSPEND=y.On it's manual read "you should unplug and remove the device only when the light is off."
It's not clear whether you should believe this. The manual may have overstated things. Still, better to be safe.
Quoted 8 lines
On Linux unmounting it won't turn it's light off
and I can feel it's motor is still running. The only way to unplug it properly on a Linux system, as to my knowledge, is to echosuspend' to/sys/bus/usb/devices/$DEV/power/level'. And one has to haveCONFIG_USB_SUSPEND=yto do this.On Windows and Mac OS,
safely remove this device' function effectly turns it intosuspend' mode, and it's light off.
Yes -- but they don't suspend the device; instead they disable its upstream port. As far as the device is concerned, there's no difference. However the Linux API doesn't include any way to disable a USB port. Maybe we should add one...
Quoted 3 lines
I'm new in this field and I understood people's concern on enabling autosuspend. As to my understanding,
enabling suspend' andenabling autosuspend' should be controlled by two different knobs.
They are.
Quoted 6 lines
I did a
quick search in LKML and haven't found specific oppose to enable USB suspend by default, and Debian has started shipping a kernel with it turned on since 2.6.26.Perhaps we should consider turning it on by default? Thanks!
That is indeed the next step to take.
Alan Stern
Quoted 14 lines · Yan Li
Hello List,
By default
CONFIG_USB_SUSPENDis not enabled and today I got bite by this when I got a new WDC My Book hard drive. I have no way to unplug it safely, according to it's manual, with a kernel that doesn't haveCONFIG_USB_SUSPEND=y.On it's manual read "you should unplug and remove the device only when the light is off." On Linux unmounting it won't turn it's light off and I can feel it's motor is still running. The only way to unplug it properly on a Linux system, as to my knowledge, is to echo
suspend' to/sys/bus/usb/devices/$DEV/power/level'. And one has to haveCONFIG_USB_SUSPEND=yto do this.
Quoted 2 lines
On Windows and Mac OS,
safely remove this device' function effectly turns it intosuspend' mode, and it's light off.
You have obviously tested only Windows XP, because Vista doesn't cut the power for at least some USB devices. And congratulations for obtaining a Vista-incompatible hard drive (of course, joking).
BTW, does the "eject /dev/$DEV" command help?
Signature · 1 line
Alexander E. Patrakov
Quoted 15 lines · Alexander E. Patrakov
Quoted 14 lines · Yan Li
Hello List,
By default
CONFIG_USB_SUSPENDis not enabled and today I got bite by this when I got a new WDC My Book hard drive. I have no way to unplug it safely, according to it's manual, with a kernel that doesn't haveCONFIG_USB_SUSPEND=y.On it's manual read "you should unplug and remove the device only when the light is off." On Linux unmounting it won't turn it's light off and I can feel it's motor is still running. The only way to unplug it properly on a Linux system, as to my knowledge, is to echo
suspend' to/sys/bus/usb/devices/$DEV/power/level'. And one has to haveCONFIG_USB_SUSPEND=yto do this.
Quoted 5 lines
Quoted 2 lines
On Windows and Mac OS,
safely remove this device' function effectly turns it intosuspend' mode, and it's light off.You have obviously tested only Windows XP, because Vista doesn't cut the power for at least some USB devices.
Yan never said that Windows cuts any power; he only said that the light turns off. This is accomplished by disabling the USB port, not by cutting power.
Quoted 4 lines
And congratulations for obtaining a Vista-incompatible hard drive (of course, joking).
BTW, does the "eject
/dev/$DEV" command help?
I wouldn't expect it to help, since it doesn't disable the port or put the device into suspend mode.
Alan Stern
Quoted 17 lines · Yan Li
Hello List,
By default
CONFIG_USB_SUSPENDis not enabled and today I got bite by this when I got a new WDC My Book hard drive. I have no way to unplug it safely, according to it's manual, with a kernel that doesn't haveCONFIG_USB_SUSPEND=y.On it's manual read "you should unplug and remove the device only when the light is off." On Linux unmounting it won't turn it's light off and I can feel it's motor is still running. The only way to unplug it properly on a Linux system, as to my knowledge, is to echo
suspend' to/sys/bus/usb/devices/$DEV/power/level'. And one has to haveCONFIG_USB_SUSPEND=yto do this.On Windows and Mac OS,
safely remove this device' function effectly turns it intosuspend' mode, and it's light off.
Quoted 8 lines
I'm new in this field and I understood people's concern on enabling autosuspend. As to my understanding,
enabling suspend' andenabling autosuspend' should be controlled by two different knobs. I did a quick search in LKML and haven't found specific oppose to enable USB suspend by default, and Debian has started shipping a kernel with it turned on since 2.6.26.Perhaps we should consider turning it on by default? Thanks!
It's probably not a bad idea. I'm not sure how big of a problem it actually is, though. As long as the filesystem is unmounted before unplug you'll probably be OK (unless you ripped out the cable/power so quickly afterwards that there was still data in the write cache).
Ideally before disconnecting a removable hard drive one should flush the write cache and park the heads (the latter being somewhat important for 2.5" drives in order to avoid emergency head unloads that would reduce the life of the drive). I believe that there's a command one can echo into the sd driver in sysfs somewhere that will trigger this.. Therefore the right sequence would be:
-unmount filesystem
-remove SCSI disk (synchronize cache and stop unit) -suspend SCSI device
Thing is that some USB storage devices don't support both of those commands (I've got a USB-to-IDE enclosure with a Genesys chipset that doesn't translate SCSI START STOP UNIT into an IDE Standby Immediate command as it really should, think it just throws "invalid field in CDB" errors). However if we've done the above we've really done the best we can do..
Quoted 7 lines · Yan Li
Hello List,
By default
CONFIG_USB_SUSPENDis not enabled and today I got bite by this when I got a new WDC My Book hard drive. I have no way to unplug it safely, according to it's manual, with a kernel that doesn't haveCONFIG_USB_SUSPEND=y.
Quoted 6 lines
On it's manual read "you should unplug and remove the device only when the light is off." On Linux unmounting it won't turn it's light off and I can feel it's motor is still running. The only way to unplug it properly on a Linux system, as to my knowledge, is to echo
suspend' to/sys/bus/usb/devices/$DEV/power/level'. And one has to haveCONFIG_USB_SUSPEND=yto do this.
With a WD My Passport drive (2,5"), I need to use sg_start --stop --pc=3 to stop the disk before unplugging it. Maybe this works with your drive, too. This is also required by some Firewire hard disks. Maybe the eject command should be extended to use this method, as it is used also by HAL to eject hotplug devices.
Regards,
Tino
Quoted 6 lines · Alan Stern
Quoted 2 lines · Yan Li
On it's manual read "you should unplug and remove the device only when the light is off."
It's not clear whether you should believe this. The manual may have overstated things. Still, better to be safe.
Yeah, that maybe true. Better to be safe. And we can't tell users just to ignore the warnings on the manual.
Quoted 7 lines
Quoted 2 lines
On Windows and Mac OS,
safely remove this device' function effectly turns it intosuspend' mode, and it's light off.Yes -- but they don't suspend the device; instead they disable its upstream port. As far as the device is concerned, there's no difference. However the Linux API doesn't include any way to disable a USB port. Maybe we should add one...
Definitely.
Quoted 8 lines
Quoted 6 lines
I did a
quick search in LKML and haven't found specific oppose to enable USB suspend by default, and Debian has started shipping a kernel with it turned on since 2.6.26.Perhaps we should consider turning it on by default? Thanks!
That is indeed the next step to take.
Hope to see this happen soon.
Signature · 1 line
Li, Yan
Quoted 7 lines · Alexander E. Patrakov
Quoted 2 lines · Yan Li
On Windows and Mac OS,
safely remove this device' function effectly turns it intosuspend' mode, and it's light off.You have obviously tested only Windows XP, because Vista doesn't cut the power for at least some USB devices. And congratulations for obtaining a Vista-incompatible hard drive (of course, joking).
To be honest I tested neither Windows, I just picked up other Linux user's complaints (pretty much online) who are using both Windows and Linux and thus can compare.
Curiously, is this change in behavior btw XP and Vista another blunder MSFT made?
Quoted 1 line
BTW, does the "eject
/dev/$DEV" command help?
Nope. Unlike iPOD this device doesn't honor eject.
Signature · 1 line
Li, Yan
Quoted 6 lines · Yan Li
To be honest I tested neither Windows, I just picked up other Linux user's complaints (pretty much online) who are using both Windows and Linux and thus can compare.
Curiously, is this change in behavior btw XP and Vista another blunder MSFT made?
I don't know whether it is intentional. I don't have Vista installed on my computer (but had a beta of it on my old computer). However, Google search result for "vista usb flash light" suggests that other people see the change, too.
Signature · 1 line
Alexander E. Patrakov
Quoted 5 lines · Tino Keitel
With a WD My Passport drive (2,5"), I need to use
sg_start--stop --pc=3 to stop the disk before unplugging it. Maybe this works with your drive, too. This is also required by some Firewire hard disks. Maybe the eject command should be extended to use this method, as it is used also by HAL to eject hotplug devices.
Hum... I grepped my hal and hal-info packages but haven't found any scripts using `sg_*'. I'm using hal package 0.5.11-6 from Debian testing.
Now I know 3 methods supposed can be used to shut the device:
1. (Alan Stern said Windows use this) cut the USB port's power
2. send STOP SCSI command to stop it
3. put it into suspend mode
For the 1st method I have no much experience with Windows so I can't verify. But now I doubt it. Since there are many early USB devices that still show light on after you "safely remove" it from Windows. I guess the power is still supplied but the device is send a command to be shutdown or suspended.
For the 2nd and 3rd methods, I don't know which one is better, hope some experts can give advice.
Whatever, I think the suspend mode is a standard USB design and the kernel should support it by default so we should enable CONFIG_USB_SUSPEND.
Signature · 1 line
Li, Yan
Quoted 10 lines · Yan Li
Quoted 5 lines · Tino Keitel
With a WD My Passport drive (2,5"), I need to use
sg_start--stop --pc=3 to stop the disk before unplugging it. Maybe this works with your drive, too. This is also required by some Firewire hard disks. Maybe the eject command should be extended to use this method, as it is used also by HAL to eject hotplug devices.Hum... I grepped my hal and hal-info packages but haven't found any scripts using `sg_*'. I'm using hal package 0.5.11-6 from Debian testing.
HAL uses /usr/bin/eject, which doesn't set the power condition (as sg_start --pc=X does). So eject (and HAL) doesn't work with disks that require to set the power condition.
Just try sg_start --stop --pc=3 /dev/sdX to see if it works for you.
Regards,
Tino
Quoted 10 lines · Yan Li
Now I know 3 methods supposed can be used to shut the device:
1. (Alan Stern said Windows use this) cut the USB port's power
2. send STOP SCSI command to stop it
3. put it into suspend modeFor the 1st method I have no much experience with Windows so I can't verify. But now I doubt it. Since there are many early USB devices that still show light on after you "safely remove" it from Windows. I guess the power is still supplied but the device is send a command to be shutdown or suspended.
Sorry, Alan have not said cut the power'. He said disable the port'.
Signature · 1 line
Li, Yan
Quoted 15 lines · Tino Keitel
Quoted 7 lines · Yan Li
Hello List,
By default
CONFIG_USB_SUSPENDis not enabled and today I got bite by this when I got a new WDC My Book hard drive. I have no way to unplug it safely, according to it's manual, with a kernel that doesn't haveCONFIG_USB_SUSPEND=y.Quoted 6 lines
On it's manual read "you should unplug and remove the device only when the light is off." On Linux unmounting it won't turn it's light off and I can feel it's motor is still running. The only way to unplug it properly on a Linux system, as to my knowledge, is to echo
suspend' to/sys/bus/usb/devices/$DEV/power/level'. And one has to haveCONFIG_USB_SUSPEND=yto do this.
Quoted 5 lines
With a WD My Passport drive (2,5"), I need to use
sg_start--stop --pc=3 to stop the disk before unplugging it. Maybe this works with your drive, too. This is also required by some Firewire hard disks. Maybe the eject command should be extended to use this method, as it is used also by HAL to eject hotplug devices.
..
Incidently, the WD Passport drives support SG_IO,
so things like hdparm and smartctl can work with them as well.
Cheers
Quoted 21 lines · Mark Lord
Quoted 15 lines · Tino Keitel
Quoted 7 lines · Yan Li
Hello List,
By default
CONFIG_USB_SUSPENDis not enabled and today I got bite by this when I got a new WDC My Book hard drive. I have no way to unplug it safely, according to it's manual, with a kernel that doesn't haveCONFIG_USB_SUSPEND=y.Quoted 6 lines
On it's manual read "you should unplug and remove the device only when the light is off." On Linux unmounting it won't turn it's light off and I can feel it's motor is still running. The only way to unplug it properly on a Linux system, as to my knowledge, is to echo
suspend' to/sys/bus/usb/devices/$DEV/power/level'. And one has to haveCONFIG_USB_SUSPEND=yto do this.Quoted 5 lines
With a WD My Passport drive (2,5"), I need to use
sg_start--stop --pc=3 to stop the disk before unplugging it. Maybe this works with your drive, too. This is also required by some Firewire hard disks. Maybe the eject command should be extended to use this method, as it is used also by HAL to eject hotplug devices.
Quoted 4 lines
..
Incidently, the WD Passport drives support
SG_IO,
so things like hdparm and smartctl can work with them as well.
..
s/SG_IO/SG_IO+SAT/
Quoted 2 lines · Yan Li
Now I know 3 methods supposed can be used to shut the device:
1. (Alan Stern said Windows use this) cut the USB port's power
I said no such thing! In fact, I said exactly the opposite: Windows does _not_ cut the port's power. Instead it disables the port.
Quoted 1 line
2. send STOP SCSI command to stop it
Note that this is different. The START-STOP command is used to spin-up or spin-down a disk. It does not affect the state of the data link.
Quoted 1 line
3. put it into suspend mode
As far as the device is concerned, there is essentially no difference between 1 and 3. When the device's upstream port is disabled, the device must go into suspend mode.
The best approach is to send a SYNCHRONIZE CACHE command followed by START-STOP (if the device supports it), and then to disable or suspend the port. In Linux, those two commands will be sent automatically if you unbind the device from usb-storage. The suspend has to be done manually unless you have set up a udev rule (or something equivalent) to enable autosuspend for the device. Of course, this requires CONFIG_USB_SUSPEND.
Alan Stern
Quoted 1 line · Mark Lord
Mark Lord wrote:
[...]
Quoted 5 lines
Quoted 2 lines
Incidently, the WD Passport drives support
SG_IO,
so things like hdparm and smartctl can work with them as well...
s/SG_IO/SG_IO+SAT/
The issue I noticed with the WD Passport drives is that the hard disk won't spin down with /usr/bin/eject, which is used by HAL if the user ejects the device (i.e. via his desktop environment). The WD Passport drives need to be set into a sleep power condition. Something like "sg_start --pc=3 /dev/sdX" needs to be used in this case.
I just checked hdparm -Y, and this works too.
Regards,
Tino
Quoted 7 lines · Tino Keitel
The issue I noticed with the WD Passport drives is that the hard disk won't spin down with
/usr/bin/eject, which is used by HAL if the user ejects the device (i.e. via his desktop environment). The WD Passport drives need to be set into a sleep power condition. Something like "sg_start--pc=3/dev/sdX" needs to be used in this case.I just checked hdparm -Y, and this works too.
STOP SCSI command spins down the drive but the device is still `on'.
The only way I found on Linux to shut down it's power is to put it into `suspend' mode.
Signature · 1 line
Li, Yan
Quoted 5 lines · Alan Stern
Quoted 2 lines
Now I know 3 methods supposed can be used to shut the device:
1. (Alan Stern said Windows use this) cut the USB port's powerI said no such thing! In fact, I said exactly the opposite: Windows does _not_ cut the port's power. Instead it disables the port.
Sorry, my mistake.
Quoted 7 lines
The best approach is to send a SYNCHRONIZE CACHE command followed by START-STOP (if the device supports it), and then to disable or suspend the port. In Linux, those two commands will be sent automatically if you unbind the device from usb-storage. The suspend has to be done manually unless you have set up a udev rule (or something equivalent) to enable autosuspend for the device. Of course, this requires
CONFIG_USB_SUSPEND.
Quite clear, thanks.
Signature · 1 line
Li, Yan