Re: Host drivers and conversion of SCSI to the driver model

Christoph Hellwig
2003-06-27T09:48:57Z

On Mon, Jun 23, 2003 at 10:57:22AM -0400, Alan Stern wrote:
> 2. More importantly, the current organization of the code has a
> serious problem. The SCSI core does not modify the host driver when the
> reference count for either shost->class_dev or shost->host_gendev drops to
> 0.

The host driver shouldn't know.

> Without knowing that, it is unsafe for the driver ever to deallocate a
> private host data structure, since a user process may continue to hold a
> reference to an open attribute file indefinitely, even after
> scsi_unregister() has returned.

Right, And this issue has been discussed on netdev for a long time.
The solution that they came up with and I plan to implement in scsi
aswell as soon as their code actually shows up is to have a mark this
device gone function that makes the struct device never call back
into driver code.

If you think a bit about this this is what's really needed - even with
your notification you'd still have module unload races. With the above
fix you can just free your private data in your ->remove method
(or wherever you want) after you marked the struct device / class_device
gone and be sure it'll never be used again.

Of course for this to fully work with scsi we need a proper
scsi_set_host_offline..