Re: Linux Virtual SCSI HBAs and Virtual disks

James Bottomley
2007-01-22T18:07:30Z

On Mon, 2007-01-22 at 17:47 +0100, Stefan Richter wrote:
> As I wrote before, deal with it like with hot-unplug. A kernel driver
> cannot prevent the user from pulling a cable.

This is exactly the correct advice.

The hotplug model requires that you own a reference on the resources you
want to access. When you're done, you release the reference and the
last person to drop the reference causes the object to be freed.

For scsi_hosts, every open device keeps a reference on the host, so the
way do destroy one is to do a scsi_remove_host() which releases your
interest in the host object, but keeps it around long enough to tidy up
after it. For physical drivers, your queuecommand() routine may still
be required to handle the odd stray command after the removal notice has
been issued, however, by and large SCSI begins rejecting I/O to the
devices higher up. When the last device is closed, it will release the
last reference to the host and trigger final cleanup.

James