Re: "Safely remove hardware" for USB

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2009-09-28 at 21:24 +0200, Oliver Neukum wrote:
> > to the "remove" attribute.
> 
> If this is the only way to correctly use the attribute why not make the
> attribute do what needs to be done to be correct?

For a disk, here's what I do now

 1. unmount/sync/detach all partitions/filesystems on the device
    - e.g. unmount fs'es, tear down raid etc.
    - when this is done, the block device for the device shouldn't
      return EBUSY - e.g. nothing is mounted, nothing is holding
      the partitions and so on
 2. send SCSI SYNCHRONIZE CACHE to the device
 3. send SCSI STOP UNIT to the device
 4. unbind the usb-storage driver from the interface in question
 5. write to the new 'remove' file in sysfs
    - right now I do 'echo suspend > $sysfs/power/level' and that
      only works for some devices - hence why I asked Alan for this
      new feature

There's also some policy here, right now I do step 5. only if the device
has a single USB interface. 

Also, there might cases where you don't want to send STOP UNIT just
because you unbind the usb-storage driver (since that might mean that
the device needs a power cycle to power up again) - for example, you
might want to bind 'ub' or another driver for the mass storage
interface.

Moving all this into the kernel when writing to the new 'remove' file
could probably be done but seems like a lot of work (you'd get rid of
some (theoretical) races in 1.-5., though). And I'd need to do this from
user space anyway since I'd like the "safely remove hardware" feature to
work for other drivers/buses/interconnects (FWIW, the other interesting
case is an ATA device (typicall cd-rom drive) in an Ultrabay on a
Thinkpad laptop).

Thanks,
David


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux