scsi_forget_host() and scsi_remove_device()

Alan Stern
2003-07-03T20:47:55Z

There's a real problem about the way scsi_forget_host() calls
scsi_remove_device() for each device on the host's bus. The problem is
that scsi_remove_device() unregisters the device in sysfs, which unbinds
the device's driver. This happens immediately, without waiting for the
reference count to be 0. So if the device is open (mounted, for example)
when the host is unplugged, the filesystem will have a dangling reference
to the unbound driver. Of course this will most likely cause a segfault
when the user attempts to unmount the device.

I don't know what the right way is to attack this problem, or what you're
planning to do about it. One approach would be somehow to prevent any new
references to the device from being created while waiting for all the
existing references to go away. But that doesn't seem feasible.

How are you going to address this problem?

Alan Stern