diff --git a/sys/cam/scsi/scsi_cd.c b/sys/cam/scsi/scsi_cd.c --- a/sys/cam/scsi/scsi_cd.c +++ b/sys/cam/scsi/scsi_cd.c @@ -262,7 +262,7 @@ static int cdgetpagesize(int page_num); static void cdprevent(struct cam_periph *periph, int action); static void cdmediaprobedone(struct cam_periph *periph); -static int cdcheckmedia(struct cam_periph *periph, int do_wait); +static int cdcheckmedia(struct cam_periph *periph, bool do_wait); #if 0 static int cdsize(struct cam_periph *periph, uint32_t *size); #endif @@ -773,7 +773,7 @@ * if we don't have media, but then we don't allow anything but the * CDIOCEJECT/CDIOCCLOSE ioctls if there is no media. */ - cdcheckmedia(periph, /*do_wait*/ 1); + cdcheckmedia(periph, /*do_wait*/ true); CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("leaving cdopen\n")); cam_periph_unhold(periph); @@ -879,7 +879,7 @@ * check first. The I/O will get executed after the media check. */ if ((softc->flags & CD_FLAG_VALID_MEDIA) == 0) - cdcheckmedia(periph, /*do_wait*/ 0); + cdcheckmedia(periph, /*do_wait*/ false); else xpt_schedule(periph, CAM_PRIORITY_NORMAL); @@ -1781,7 +1781,7 @@ && ((cmd != CDIOCCLOSE) && (cmd != CDIOCEJECT)) && (IOCGROUP(cmd) == 'c')) { - error = cdcheckmedia(periph, /*do_wait*/ 1); + error = cdcheckmedia(periph, /*do_wait*/ true); if (error != 0) { cam_periph_unhold(periph); cam_periph_unlock(periph); @@ -2674,6 +2674,7 @@ softc->flags &= ~CD_FLAG_MEDIA_WAIT; wakeup(&softc->toc); } + cam_periph_release_locked(periph); } /* @@ -2682,7 +2683,7 @@ */ static int -cdcheckmedia(struct cam_periph *periph, int do_wait) +cdcheckmedia(struct cam_periph *periph, bool do_wait) { struct cd_softc *softc; int error; @@ -2691,31 +2692,29 @@ softc = (struct cd_softc *)periph->softc; error = 0; - if ((do_wait != 0) - && ((softc->flags & CD_FLAG_MEDIA_WAIT) == 0)) { + /* Released by cdmediaprobedone(). */ + error = cam_periph_acquire(periph); + if (error != 0) + return (error); + + if (do_wait) softc->flags |= CD_FLAG_MEDIA_WAIT; - } if ((softc->flags & CD_FLAG_MEDIA_SCAN_ACT) == 0) { softc->state = CD_STATE_MEDIA_PREVENT; softc->flags |= CD_FLAG_MEDIA_SCAN_ACT; xpt_schedule(periph, CAM_PRIORITY_NORMAL); } - - if (do_wait == 0) - goto bailout; + if (!do_wait) + return (0); error = msleep(&softc->toc, cam_periph_mtx(periph), PRIBIO,"cdmedia",0); - if (error != 0) - goto bailout; - /* * Check to see whether we have a valid size from the media. We * may or may not have a valid TOC. */ - if ((softc->flags & CD_FLAG_VALID_MEDIA) == 0) + if (error == 0 && (softc->flags & CD_FLAG_VALID_MEDIA) == 0) error = EINVAL; -bailout: return (error); }