Index: sys/dev/scsipi/scsipi_base.c =================================================================== RCS file: /cvsroot/src/sys/dev/scsipi/scsipi_base.c,v retrieving revision 1.175 diff -u -p -r1.175 scsipi_base.c --- sys/dev/scsipi/scsipi_base.c 22 Dec 2016 11:19:21 -0000 1.175 +++ sys/dev/scsipi/scsipi_base.c 3 Jan 2017 07:32:42 -0000 @@ -493,6 +498,12 @@ scsipi_get_xs(struct scsipi_periph *peri periph->periph_flags &= ~PERIPH_RECOVERY_ACTIVE; } else periph->periph_active--; + KASSERT(mutex_owned(chan_mtx(periph->periph_channel))); + if (periph->periph_active == 0 && + (periph->periph_flags & PERIPH_WAITDRAIN) != 0) { + periph->periph_flags &= ~PERIPH_WAITDRAIN; + cv_broadcast(periph_cv_active(periph)); + } if (lock) mutex_exit(chan_mtx(periph->periph_channel)); scsipi_printaddr(periph); @@ -535,6 +549,8 @@ scsipi_put_xs(struct scsipi_xfer *xs) SC_DEBUG(periph, SCSIPI_DB3, ("scsipi_free_xs\n")); + KASSERT(mutex_owned(chan_mtx(periph->periph_channel))); + TAILQ_REMOVE(&periph->periph_xferq, xs, device_q); callout_destroy(&xs->xs_callout); pool_put(&scsipi_xfer_pool, xs); @@ -682,8 +688,10 @@ scsipi_periph_thaw_locked(struct scsipi_ } #endif if (periph->periph_qfreeze == 0 && - (periph->periph_flags & PERIPH_WAITING) != 0) + (periph->periph_flags & PERIPH_WAITING) != 0) { + periph->periph_flags &= ~PERIPH_WAITING; cv_broadcast(periph_cv_periph(periph)); + } } void @@ -767,6 +775,7 @@ scsipi_kill_pending(struct scsipi_periph { struct scsipi_channel *chan = periph->periph_channel; + KASSERT(mutex_owned(chan_mtx(chan))); (*chan->chan_bustype->bustype_kill_pending)(periph); while (periph->periph_active != 0) { periph->periph_flags |= PERIPH_WAITDRAIN; @@ -1587,10 +1596,12 @@ scsipi_complete(struct scsipi_xfer *xs) */ mo.mo_target = periph->periph_target; mo.mo_lun = periph->periph_lun; + mutex_enter(chan_mtx(chan)); if (periph->periph_active < periph->periph_openings) mo.mo_openings = periph->periph_active - 1; else mo.mo_openings = periph->periph_openings - 1; + mutex_exit(chan_mtx(chan)); #ifdef DIAGNOSTIC if (mo.mo_openings < 0) { scsipi_printaddr(periph); @@ -2158,9 +2169,9 @@ scsipi_completion_thread(void *arg) scsipi_adapter_request(chan, ADAPTER_REQ_GROW_RESOURCES, NULL); scsipi_channel_thaw(chan, 1); - if (chan->chan_tflags & SCSIPI_CHANT_GROWRES) - kpause("scsizzz", FALSE, hz/10, NULL); mutex_enter(chan_mtx(chan)); + if (chan->chan_tflags & SCSIPI_CHANT_GROWRES) + kpause("scsizzz", FALSE, hz/10, chan_mtx(chan)); continue; } if (chan->chan_tflags & SCSIPI_CHANT_KICK) {