]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/commit
MFC r237328 (by ken) for recently merged scsi_enc.c:
authormav <mav@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Thu, 21 Feb 2013 18:56:09 +0000 (18:56 +0000)
committermav <mav@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Thu, 21 Feb 2013 18:56:09 +0000 (18:56 +0000)
commitd81cf0a3f36273cd775362dbd4c37189460477e1
treef9ade4939c0b7783fafa392a2ca870125da9d9b8
parenta44d2e3f248a55f7bf58c1e230721b8051309043
MFC r237328 (by ken) for recently merged scsi_enc.c:

Fix several reference counting and object lifetime issues between
the pass(4) and enc(4) drivers and devfs.

The pass(4) driver uses the destroy_dev_sched() routine to
schedule its device node for destruction in a separate thread
context.  It does this because the passcleanup() routine can get
called indirectly from the passclose() routine, and that would
cause a deadlock if the close routine tried to destroy its own
device node.

In any case, once a particular passthrough driver number, e.g.
pass3, is destroyed, CAM considers that unit number (3 in this
case) available for reuse.

The problem is that devfs may not be done cleaning up the previous
instance of pass3, and will panic if isn't done cleaning up the
previous instance.

The solution is to get a callback from devfs when the device node
is removed, and make sure we hold a reference to the peripheral
until that happens.

Testing exposed some other cases where we have reference counting
issues, and those were also fixed in the pass(4) driver.

cam_periph.c: In camperiphfree(), reorder some of the operations.

The peripheral destructor needs to be called before
the peripheral is removed from the peripheral is
removed from the list.  This is because once we
remove the peripheral from the list, and drop the
topology lock, the peripheral number may be reused.
But if the destructor hasn't been called yet, there
may still be resources hanging around (like devfs
nodes) that haven't been fully cleaned up.

cam_xpt.c: Add an argument to xpt_remove_periph() to indicate
whether the topology lock is already held.

scsi_enc.c: Acquire an extra reference to the peripheral during
registration, and release it once we get a callback
from devfs indicating that the device node is gone.

Call destroy_dev_sched_cb() in enc_oninvalidate()
instead of calling destroy_dev() in the cleanup
routine.

scsi_pass.c: Add reference counting to handle peripheral and
devfs object lifetime issues.

Add a reference to the peripheral and the devfs
node in the peripheral registration.

Don't attempt to add a physical path alias if the
peripheral has been marked invalid.

Release the devfs reference once the initial
physical path alias taskqueue run has completed.

Schedule devfs node destruction in the
passoninvalidate(), and release our peripheral
reference in a new routine, passdevgonecb() once
the devfs node is gone.  This allows the peripheral
to fully go away, and the peripheral destructor,
passcleanup(), will get called.

git-svn-id: svn://svn.freebsd.org/base/stable/9@247114 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
sys/cam/scsi/scsi_enc.c