From owner-svn-src-all@FreeBSD.ORG Thu Aug 15 20:00:33 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 364EB759; Thu, 15 Aug 2013 20:00:33 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 148A8265B; Thu, 15 Aug 2013 20:00:33 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7FK0W1D088017; Thu, 15 Aug 2013 20:00:32 GMT (envelope-from trasz@svn.freebsd.org) Received: (from trasz@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r7FK0WQ6088016; Thu, 15 Aug 2013 20:00:32 GMT (envelope-from trasz@svn.freebsd.org) Message-Id: <201308152000.r7FK0WQ6088016@svn.freebsd.org> From: Edward Tomasz Napierala Date: Thu, 15 Aug 2013 20:00:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r254378 - head/sys/cam/ctl X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Aug 2013 20:00:33 -0000 Author: trasz Date: Thu Aug 15 20:00:32 2013 New Revision: 254378 URL: http://svnweb.freebsd.org/changeset/base/254378 Log: Turn comments about locking into actual lock assertions. Reviewed by: ken Tested by: ken MFC after: 1 month Modified: head/sys/cam/ctl/ctl.c Modified: head/sys/cam/ctl/ctl.c ============================================================================== --- head/sys/cam/ctl/ctl.c Thu Aug 15 19:46:31 2013 (r254377) +++ head/sys/cam/ctl/ctl.c Thu Aug 15 20:00:32 2013 (r254378) @@ -1070,9 +1070,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 @@ -1088,10 +1090,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"); @@ -1372,7 +1376,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) @@ -1381,6 +1384,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); @@ -1404,7 +1409,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) @@ -1414,6 +1418,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) @@ -1970,7 +1976,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 @@ -1982,6 +1987,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)) { @@ -3395,12 +3402,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); @@ -3412,12 +3419,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); @@ -3426,12 +3433,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); @@ -3443,14 +3450,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, @@ -4392,7 +4398,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. */ @@ -4409,6 +4414,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); @@ -9772,7 +9779,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. */ @@ -9783,6 +9789,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 @@ -9823,13 +9831,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 @@ -10893,8 +10902,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. */ @@ -10903,6 +10910,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); @@ -11204,14 +11213,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; /* @@ -11281,14 +11289,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 @@ -12134,8 +12141,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) @@ -12144,6 +12149,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