FreeBSD/sys/cam/ctl/ctl.c
/*
 * The LUN should always be set.  The I/O is optional, and is used to
 * distinguish between I/Os sent by this initiator, and by other
 * initiators.  We set unit attention for initiators other than this one.
 * SAM-3 is vague on this point.  It does say that a unit attention should
 * be established for other initiators when a LUN is reset (see section
 * 5.7.3), but it doesn't specifically say that the unit attention should
 * be established for this particular initiator when a LUN is reset.  Here
 * is the relevant text, from SAM-3 rev 8:
 *
 * 5.7.2 When a SCSI initiator port aborts its own tasks
 *
 * When a SCSI initiator port causes its own task(s) to be aborted, no
 * notification that the task(s) have been aborted shall be returned to
 * the SCSI initiator port other than the completion response for the
 * command or task management function action that caused the task(s) to
 * be aborted and notification(s) associated with related effects of the
 * action (e.g., a reset unit attention condition).
 *
 * XXX KDM for now, we're setting unit attention for all initiators.
 */
The LUN should always be set.  The I/O is optional, and is used to
distinguish between I/Os sent by this initiator, and by other
initiators.  We set unit attention for initiators other than this one.
SAM-3 is vague on this point.  It does say that a unit attention should
be established for other initiators when a LUN is reset (see section
5.7.3), but it doesn't specifically say that the unit attention should
be established for this particular initiator when a LUN is reset.  Here
is the relevant text, from SAM-3 rev 8.

5.7.2 When a SCSI initiator port aborts its own tasks

When a SCSI initiator port causes its own task(s) to be aborted, no
notification that the task(s) have been aborted shall be returned to
the SCSI initiator port other than the completion response for the
command or task management function action that caused the task(s) to
be aborted and notification(s) associated with related effects of the
action .

XXX KDM for now, we're setting unit attention for all initiators.
The LUN should always be set . The I / O is optional and is used to distinguish between I / Os sent by this initiator and by other initiators . We set unit attention for initiators other than this one . SAM - 3 is vague on this point . It does say that a unit attention should be established for other initiators when a LUN is reset ( see section 5 . 7 . 3 ) but it doesn ' t specifically say that the unit attention should be established for this particular initiator when a LUN is reset . Here is the relevant text from SAM - 3 rev 8 . 5 . 7 . 2 When a SCSI initiator port aborts its own tasks When a SCSI initiator port causes its own task ( s ) to be aborted no notification that the task ( s ) have been aborted shall be returned to the SCSI initiator port other than the completion response for the command or task management function action that caused the task ( s ) to be aborted and notification ( s ) associated with related effects of the action . XXX KDM for now we ' re setting unit attention for all initiators .
static int
ctl_do_lun_reset(struct ctl_lun *lun, union ctl_io *io, ctl_ua_type ua_type)
{
	union ctl_io *xio;
#if 0
	uint32_t initidx;
#endif
	int i;
	mtx_lock(&lun->lun_lock);
	for (xio = (union ctl_io *)TAILQ_FIRST(&lun->ooa_queue); xio != NULL;
	     xio = (union ctl_io *)TAILQ_NEXT(&xio->io_hdr, ooa_links)) {
		xio->io_hdr.flags |= CTL_FLAG_ABORT | CTL_FLAG_ABORT_STATUS;
	}
#if 0
	initidx = ctl_get_initindex(&io->io_hdr.nexus);
	ctl_est_ua_all(lun, initidx, ua_type);
#else
	ctl_est_ua_all(lun, -1, ua_type);
#endif
	lun->flags &= ~CTL_LUN_RESERVED;
#ifdef CTL_WITH_CA
	for (i = 0; i < CTL_MAX_INITIATORS; i++)
		ctl_clear_mask(lun->have_ca, i);
#endif
	lun->prevent_count = 0;
	for (i = 0; i < CTL_MAX_INITIATORS; i++)
		ctl_clear_mask(lun->prevent, i);
	mtx_unlock(&lun->lun_lock);
	return (0);
}
static int ctl_do_lun_reset ( struct ctl_lun * lun , union ctl_io * io , ctl_ua_type ua_type ) { union ctl_io * xio ; #if 0 uint32_t initidx ; #endif int i ; mtx_lock ( & lun -> lun_lock ) ; for ( xio = ( union ctl_io * ) TAILQ_FIRST ( & lun -> ooa_queue ) ; xio != NULL ; xio = ( union ctl_io * ) TAILQ_NEXT ( & xio -> io_hdr , ooa_links ) ) { xio -> io_hdr . flags |= CTL_FLAG_ABORT | CTL_FLAG_ABORT_STATUS ; } #if 0 initidx = ctl_get_initindex ( & io -> io_hdr . nexus ) ; ctl_est_ua_all ( lun , initidx , ua_type ) ; #else ctl_est_ua_all ( lun , -1 , ua_type ) ; #endif lun -> flags &= ~ CTL_LUN_RESERVED ; #ifdef CTL_WITH_CA for ( i = 0 ; i < CTL_MAX_INITIATORS ; i ++ ) ctl_clear_mask ( lun -> have_ca , i ) ; #endif lun -> prevent_count = 0 ; for ( i = 0 ; i < CTL_MAX_INITIATORS ; i ++ ) ctl_clear_mask ( lun -> prevent , i ) ; mtx_unlock ( & lun -> lun_lock ) ; return ( 0 ) ; }
The LUN should always be set.
The LUN should always be set .
/*
	 * Run through the OOA queue and abort each I/O.
	 */ /*
	 * This version sets unit attention for every
	 */ /*
	 * A reset (any kind, really) clears reservations established with
	 * RESERVE/RELEASE.  It does not clear reservations established
	 * with PERSISTENT RESERVE OUT, but we don't support that at the
	 * moment anyway.  See SPC-2, section 5.6.  SPC-3 doesn't address
	 * reservations made with the RESERVE/RELEASE commands, because
	 * those commands are obsolete in SPC-3.
	 */