freebsd-nq/sys/cam/scsi
Kenneth D. Merry ea37f51942 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.

MFC after:	3 days
Sponsored by:	Spectra Logic
2012-06-20 17:08:00 +00:00
..
scsi_all.c One more major cam_periph_error() rewrite to improve error handling and 2012-06-09 13:07:44 +00:00
scsi_all.h One more major cam_periph_error() rewrite to improve error handling and 2012-06-09 13:07:44 +00:00
scsi_cd.c Remove never used CD/DA_FLAG_TAGGED_QUEUING flags. 2012-06-18 12:45:35 +00:00
scsi_cd.h
scsi_ch.c Work around a race condition in devfs by changing the way closes 2012-05-27 06:11:09 +00:00
scsi_ch.h - fix duplicate "a a" in some comments 2011-11-13 17:06:33 +00:00
scsi_da.c Remove never used CD/DA_FLAG_TAGGED_QUEUING flags. 2012-06-18 12:45:35 +00:00
scsi_da.h Add the CAM Target Layer (CTL). 2012-01-12 00:34:33 +00:00
scsi_dvcfg.h
scsi_enc_internal.h MFprojects/zfsd: 2012-05-24 14:07:44 +00:00
scsi_enc_safte.c MFprojects/zfsd: 2012-05-24 14:07:44 +00:00
scsi_enc_ses.c MFprojects/zfsd: 2012-05-24 14:07:44 +00:00
scsi_enc.c Fix several reference counting and object lifetime issues between 2012-06-20 17:08:00 +00:00
scsi_enc.h MFprojects/zfsd: 2012-05-24 14:07:44 +00:00
scsi_iu.h
scsi_low_pisa.c
scsi_low_pisa.h
scsi_low.c Mark MALLOC_DEFINEs static that have no corresponding MALLOC_DECLAREs. 2011-11-07 06:44:47 +00:00
scsi_low.h
scsi_message.h
scsi_pass.c Fix several reference counting and object lifetime issues between 2012-06-20 17:08:00 +00:00
scsi_pass.h
scsi_pt.c Tune and add some missing CAM_DEBUG() points for better consistency. 2012-06-05 09:45:42 +00:00
scsi_pt.h
scsi_sa.c To make CAM debugging easier, compile in some debug flags (CAM_DEBUG_INFO, 2012-06-07 10:05:51 +00:00
scsi_sa.h
scsi_ses.h MFprojects/zfsd: 2012-05-24 14:07:44 +00:00
scsi_sg.c Work around a race condition in devfs by changing the way closes 2012-05-27 06:11:09 +00:00
scsi_sg.h
scsi_targ_bh.c Add the CAM Target Layer (CTL). 2012-01-12 00:34:33 +00:00
scsi_target.c To make CAM debugging easier, compile in some debug flags (CAM_DEBUG_INFO, 2012-06-07 10:05:51 +00:00
scsi_targetio.h
scsi_xpt.c One more major cam_periph_error() rewrite to improve error handling and 2012-06-09 13:07:44 +00:00
smp_all.c Add Serial Management Protocol (SMP) passthrough support to CAM. 2010-11-30 22:39:46 +00:00
smp_all.h Add Serial Management Protocol (SMP) passthrough support to CAM. 2010-11-30 22:39:46 +00:00