--- sys/cam/cam_periph.c.orig +++ sys/cam/cam_periph.c @@ -290,7 +290,7 @@ } void -cam_periph_release(struct cam_periph *periph) +cam_periph_release_locked(struct cam_periph *periph) { if (periph == NULL) @@ -302,7 +302,21 @@ camperiphfree(periph); } xpt_unlock_buses(); +} + +void +cam_periph_release(struct cam_periph *periph) +{ + struct cam_sim *sim; + if (periph == NULL) + return; + + sim = periph->sim; + mtx_assert(sim->mtx, MA_NOTOWNED); + mtx_lock(sim->mtx); + cam_periph_release_locked(periph); + mtx_unlock(sim->mtx); } int @@ -330,7 +344,7 @@ while ((periph->flags & CAM_PERIPH_LOCKED) != 0) { periph->flags |= CAM_PERIPH_LOCK_WANTED; if ((error = msleep(periph, mtx, priority, "caplck", 0)) != 0) { - cam_periph_release(periph); + cam_periph_release_locked(periph); return (error); } } @@ -351,7 +365,7 @@ wakeup(periph); } - cam_periph_release(periph); + cam_periph_release_locked(periph); } /* --- sys/cam/cam_periph.h.orig +++ sys/cam/cam_periph.h @@ -141,6 +141,7 @@ struct cam_periph *cam_periph_find(struct cam_path *path, char *name); cam_status cam_periph_acquire(struct cam_periph *periph); void cam_periph_release(struct cam_periph *periph); +void cam_periph_release_locked(struct cam_periph *periph); int cam_periph_hold(struct cam_periph *periph, int priority); void cam_periph_unhold(struct cam_periph *periph); void cam_periph_invalidate(struct cam_periph *periph); --- sys/cam/cam_xpt.c.orig +++ sys/cam/cam_xpt.c @@ -6314,7 +6314,7 @@ xpt_done(done_ccb); if (TAILQ_FIRST(&softc->request_ccbs) == NULL) { cam_periph_invalidate(periph); - cam_periph_release(periph); + cam_periph_release_locked(periph); } else { probeschedule(periph); } --- sys/cam/scsi/scsi_da.c.orig +++ sys/cam/scsi/scsi_da.c @@ -772,8 +772,8 @@ softc->flags &= ~DA_FLAG_OPEN; cam_periph_unhold(periph); + cam_periph_unlock(periph); cam_periph_release(periph); - cam_periph_unlock(periph); return (0); }