svn commit: r258223 - stable/9/sys/cam/ctl

Alexander Motin mav at FreeBSD.org
Sat Nov 16 15:34:12 UTC 2013


Author: mav
Date: Sat Nov 16 15:34:11 2013
New Revision: 258223
URL: http://svnweb.freebsd.org/changeset/base/258223

Log:
  MFC r254378 (by trasz):
  Turn comments about locking into actual lock assertions.

Modified:
  stable/9/sys/cam/ctl/ctl.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/cam/ctl/ctl.c
==============================================================================
--- stable/9/sys/cam/ctl/ctl.c	Sat Nov 16 15:26:56 2013	(r258222)
+++ stable/9/sys/cam/ctl/ctl.c	Sat Nov 16 15:34:11 2013	(r258223)
@@ -1078,9 +1078,11 @@ ctl_init(void)
 	softc->emergency_pool = emergency_pool;
 	softc->othersc_pool = other_pool;
 
+	mtx_lock(&softc->ctl_lock);
 	ctl_pool_acquire(internal_pool);
 	ctl_pool_acquire(emergency_pool);
 	ctl_pool_acquire(other_pool);
+	mtx_unlock(&softc->ctl_lock);
 
 	/*
 	 * We used to allocate a processor LUN here.  The new scheme is to
@@ -1096,10 +1098,12 @@ ctl_init(void)
 			 "ctl_thrd");
 	if (error != 0) {
 		printf("error creating CTL work thread!\n");
+		mtx_lock(&softc->ctl_lock);
 		ctl_free_lun(lun);
 		ctl_pool_free(softc, internal_pool);
 		ctl_pool_free(softc, emergency_pool);
 		ctl_pool_free(softc, other_pool);
+		mtx_unlock(&softc->ctl_lock);
 		return (error);
 	}
 	printf("ctl: CAM Target Layer loaded\n");
@@ -1380,7 +1384,6 @@ ctl_ioctl_offline(void *arg)
 /*
  * Remove an initiator by port number and initiator ID.
  * Returns 0 for success, 1 for failure.
- * Assumes the caller does NOT hold the CTL lock.
  */
 int
 ctl_remove_initiator(int32_t targ_port, uint32_t iid)
@@ -1389,6 +1392,8 @@ ctl_remove_initiator(int32_t targ_port, 
 
 	softc = control_softc;
 
+	mtx_assert(&softc->ctl_lock, MA_NOTOWNED);
+
 	if ((targ_port < 0)
 	 || (targ_port > CTL_MAX_PORTS)) {
 		printf("%s: invalid port number %d\n", __func__, targ_port);
@@ -1412,7 +1417,6 @@ ctl_remove_initiator(int32_t targ_port, 
 /*
  * Add an initiator to the initiator map.
  * Returns 0 for success, 1 for failure.
- * Assumes the caller does NOT hold the CTL lock.
  */
 int
 ctl_add_initiator(uint64_t wwpn, int32_t targ_port, uint32_t iid)
@@ -1422,6 +1426,8 @@ ctl_add_initiator(uint64_t wwpn, int32_t
 
 	softc = control_softc;
 
+	mtx_assert(&softc->ctl_lock, MA_NOTOWNED);
+
 	retval = 0;
 
 	if ((targ_port < 0)
@@ -1978,7 +1984,6 @@ ctl_ioctl_bbrread_callback(void *arg, st
 }
 
 /*
- * Must be called with the ctl_lock held.
  * Returns 0 for success, errno for failure.
  */
 static int
@@ -1990,6 +1995,8 @@ ctl_ioctl_fill_ooa(struct ctl_lun *lun, 
 
 	retval = 0;
 
+	mtx_assert(&control_softc->ctl_lock, MA_OWNED);
+
 	for (io = (union ctl_io *)TAILQ_FIRST(&lun->ooa_queue); (io != NULL);
 	     (*cur_fill_num)++, io = (union ctl_io *)TAILQ_NEXT(&io->io_hdr,
 	     ooa_links)) {
@@ -3403,12 +3410,12 @@ bailout:
 	return (retval);
 }
 
-/*
- * Caller must hold ctl_softc->ctl_lock.
- */
 int
 ctl_pool_acquire(struct ctl_io_pool *pool)
 {
+
+	mtx_assert(&control_softc->ctl_lock, MA_OWNED);
+
 	if (pool == NULL)
 		return (-EINVAL);
 
@@ -3420,12 +3427,12 @@ ctl_pool_acquire(struct ctl_io_pool *poo
 	return (0);
 }
 
-/*
- * Caller must hold ctl_softc->ctl_lock.
- */
 int
 ctl_pool_invalidate(struct ctl_io_pool *pool)
 {
+
+	mtx_assert(&control_softc->ctl_lock, MA_OWNED);
+
 	if (pool == NULL)
 		return (-EINVAL);
 
@@ -3434,12 +3441,12 @@ ctl_pool_invalidate(struct ctl_io_pool *
 	return (0);
 }
 
-/*
- * Caller must hold ctl_softc->ctl_lock.
- */
 int
 ctl_pool_release(struct ctl_io_pool *pool)
 {
+
+	mtx_assert(&control_softc->ctl_lock, MA_OWNED);
+
 	if (pool == NULL)
 		return (-EINVAL);
 
@@ -3451,14 +3458,13 @@ ctl_pool_release(struct ctl_io_pool *poo
 	return (0);
 }
 
-/*
- * Must be called with ctl_softc->ctl_lock held.
- */
 void
 ctl_pool_free(struct ctl_softc *ctl_softc, struct ctl_io_pool *pool)
 {
 	union ctl_io *cur_io, *next_io;
 
+	mtx_assert(&ctl_softc->ctl_lock, MA_OWNED);
+
 	for (cur_io = (union ctl_io *)STAILQ_FIRST(&pool->free_queue);
 	     cur_io != NULL; cur_io = next_io) {
 		next_io = (union ctl_io *)STAILQ_NEXT(&cur_io->io_hdr,
@@ -4400,7 +4406,6 @@ ctl_alloc_lun(struct ctl_softc *ctl_soft
 /*
  * Delete a LUN.
  * Assumptions:
- * - caller holds ctl_softc->ctl_lock.
  * - LUN has already been marked invalid and any pending I/O has been taken
  *   care of.
  */
@@ -4417,6 +4422,8 @@ ctl_free_lun(struct ctl_lun *lun)
 
 	softc = lun->ctl_softc;
 
+	mtx_assert(&softc->ctl_lock, MA_OWNED);
+
 	STAILQ_REMOVE(&softc->lun_list, lun, ctl_lun, links);
 
 	ctl_clear_mask(softc->ctl_lun_mask, lun->lun);
@@ -9780,7 +9787,6 @@ ctl_check_for_blockage(union ctl_io *pen
 /*
  * Check for blockage or overlaps against the OOA (Order Of Arrival) queue.
  * Assumptions:
- * - caller holds ctl_lock
  * - pending_io is generally either incoming, or on the blocked queue
  * - starting I/O is the I/O we want to start the check with.
  */
@@ -9791,6 +9797,8 @@ ctl_check_ooa(struct ctl_lun *lun, union
 	union ctl_io *ooa_io;
 	ctl_action action;
 
+	mtx_assert(&control_softc->ctl_lock, MA_OWNED);
+
 	/*
 	 * Run back along the OOA queue, starting with the current
 	 * blocked I/O and going through every I/O before it on the
@@ -9831,13 +9839,14 @@ ctl_check_ooa(struct ctl_lun *lun, union
  * Assumptions:
  * - An I/O has just completed, and has been removed from the per-LUN OOA
  *   queue, so some items on the blocked queue may now be unblocked.
- * - The caller holds ctl_softc->ctl_lock
  */
 static int
 ctl_check_blocked(struct ctl_lun *lun)
 {
 	union ctl_io *cur_blocked, *next_blocked;
 
+	mtx_assert(&control_softc->ctl_lock, MA_OWNED);
+
 	/*
 	 * Run forward from the head of the blocked queue, checking each
 	 * entry against the I/Os prior to it on the OOA queue to see if
@@ -10901,8 +10910,6 @@ bailout:
 }
 
 /*
- * Assumptions:  caller holds ctl_softc->ctl_lock
- *
  * This routine cannot block!  It must be callable from an interrupt
  * handler as well as from the work thread.
  */
@@ -10911,6 +10918,8 @@ ctl_run_task_queue(struct ctl_softc *ctl
 {
 	union ctl_io *io, *next_io;
 
+	mtx_assert(&ctl_softc->ctl_lock, MA_OWNED);
+
 	CTL_DEBUG_PRINT(("ctl_run_task_queue\n"));
 
 	for (io = (union ctl_io *)STAILQ_FIRST(&ctl_softc->task_queue);
@@ -11212,14 +11221,13 @@ ctl_cmd_pattern_match(struct ctl_scsiio 
 	return (filtered_pattern);
 }
 
-/*
- * Called with the CTL lock held.
- */
 static void
 ctl_inject_error(struct ctl_lun *lun, union ctl_io *io)
 {
 	struct ctl_error_desc *desc, *desc2;
 
+	mtx_assert(&control_softc->ctl_lock, MA_OWNED);
+
 	STAILQ_FOREACH_SAFE(desc, &lun->error_list, links, desc2) {
 		ctl_lun_error_pattern pattern;
 		/*
@@ -11289,14 +11297,13 @@ ctl_datamove_timer_wakeup(void *arg)
 }
 #endif /* CTL_IO_DELAY */
 
-/*
- * Assumption:  caller does NOT hold ctl_lock
- */
 void
 ctl_datamove(union ctl_io *io)
 {
 	void (*fe_datamove)(union ctl_io *io);
 
+	mtx_assert(&control_softc->ctl_lock, MA_NOTOWNED);
+
 	CTL_DEBUG_PRINT(("ctl_datamove\n"));
 
 #ifdef CTL_TIME_IO
@@ -12142,8 +12149,6 @@ ctl_datamove_remote_read(union ctl_io *i
  * first.  Once that is complete, the data gets DMAed into the remote
  * controller's memory.  For reads, we DMA from the remote controller's
  * memory into our memory first, and then move it out to the FETD.
- *
- * Should be called without the ctl_lock held.
  */
 static void
 ctl_datamove_remote(union ctl_io *io)
@@ -12152,6 +12157,8 @@ ctl_datamove_remote(union ctl_io *io)
 
 	softc = control_softc;
 
+	mtx_assert(&softc->ctl_lock, MA_NOTOWNED);
+
 	/*
 	 * Note that we look for an aborted I/O here, but don't do some of
 	 * the other checks that ctl_datamove() normally does.  We don't


More information about the svn-src-stable-9 mailing list