Date: Tue, 27 Mar 2007 15:47:26 GMT From: Scott Long <scottl@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 116657 for review Message-ID: <200703271547.l2RFlQiJ004661@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=116657 Change 116657 by scottl@scottl-x64 on 2007/03/27 15:46:52 Convert the CD driver to using callouts. Lock the global list of changers. Affected files ... .. //depot/projects/scottl-camlock/src/sys/cam/scsi/scsi_cd.c#11 edit Differences ... ==== //depot/projects/scottl-camlock/src/sys/cam/scsi/scsi_cd.c#11 (text+ko) ==== @@ -70,6 +70,7 @@ #include <cam/cam_periph.h> #include <cam/cam_xpt_periph.h> #include <cam/cam_queue.h> +#include <cam/cam_sim.h> #include <cam/scsi/scsi_message.h> #include <cam/scsi/scsi_da.h> @@ -290,9 +291,6 @@ PERIPHDRIVER_DECLARE(cd, cddriver); - -static int num_changers; - #ifndef CHANGER_MIN_BUSY_SECONDS #define CHANGER_MIN_BUSY_SECONDS 5 #endif @@ -319,22 +317,26 @@ struct camq devq; struct timeval start_time; struct cd_softc *cur_device; - struct callout_handle short_handle; - struct callout_handle long_handle; + struct callout short_handle; + struct callout long_handle; volatile cd_changer_flags flags; STAILQ_ENTRY(cdchanger) changer_links; STAILQ_HEAD(chdevlist, cd_softc) chluns; }; +static struct mtx changerq_mtx; static STAILQ_HEAD(changerlist, cdchanger) changerq; +static int num_changers; - static void cdinit(void) { cam_status status; struct cam_path *path; + mtx_init(&changerq_mtx, "cdchangerq", "SCSI CD Changer List", MTX_DEF); + STAILQ_INIT(&changerq); + /* * Install a global async callback. This callback will * receive async callbacks like "new device found". @@ -456,8 +458,7 @@ * be any bogus pointer references there. */ if (softc->changer->flags & CHANGER_SHORT_TMOUT_SCHED) { - untimeout(cdshorttimeout, softc->changer, - softc->changer->short_handle); + callout_stop(&softc->changer->short_handle); softc->changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED; } softc->changer->devq.qfrozen_cnt--; @@ -478,22 +479,22 @@ * it won't hurt to check and see if there are any left. */ if (softc->changer->flags & CHANGER_TIMEOUT_SCHED) { - untimeout(cdrunchangerqueue, softc->changer, - softc->changer->long_handle); + callout_stop(&softc->changer->long_handle); softc->changer->flags &= ~CHANGER_TIMEOUT_SCHED; } if (softc->changer->flags & CHANGER_SHORT_TMOUT_SCHED) { - untimeout(cdshorttimeout, softc->changer, - softc->changer->short_handle); + callout_stop(&softc->changer->short_handle); softc->changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED; } + mtx_lock(&changerq_mtx); STAILQ_REMOVE(&changerq, softc->changer, cdchanger, changer_links); + num_changers--; + mtx_unlock(&changerq_mtx); xpt_print(periph->path, "removing changer entry\n"); free(softc->changer, M_DEVBUF); - num_changers--; } disk_destroy(softc->disk); free(softc, M_DEVBUF); @@ -787,13 +788,11 @@ /* Set the changer flag in the current device's softc */ softc->flags |= CD_FLAG_CHANGER; - if (num_changers == 0) - STAILQ_INIT(&changerq); - /* * Now, look around for an existing changer device with the * same path and target ID as the current device. */ + mtx_lock(&changerq_mtx); for (found = 0, nchanger = (struct cdchanger *)STAILQ_FIRST(&changerq); nchanger != NULL; @@ -804,6 +803,7 @@ break; } } + mtx_unlock(&changerq_mtx); /* * If we found a matching entry, just add this device to @@ -909,8 +909,6 @@ goto cdregisterexit; } - num_changers++; - nchanger->path_id = cgd->ccb_h.path_id; nchanger->target_id = cgd->ccb_h.target_id; @@ -919,8 +917,16 @@ STAILQ_INIT(&nchanger->chluns); + callout_init_mtx(&nchanger->long_handle, + periph->sim->mtx, 0); + callout_init_mtx(&nchanger->short_handle, + periph->sim->mtx, 0); + + mtx_lock(&changerq_mtx); + num_changers++; STAILQ_INSERT_TAIL(&changerq, nchanger, changer_links); + mtx_unlock(&changerq_mtx); /* * Create a path with lun id 0, and see if we can @@ -1186,9 +1192,9 @@ changer->cur_device->bufs_left = changer->cur_device->outstanding_cmds; if (called_from_timeout) { - changer->long_handle = - timeout(cdrunchangerqueue, changer, - changer_max_busy_seconds * hz); + callout_reset(&changer->long_handle, + changer_max_busy_seconds * hz, + cdrunchangerqueue, changer); changer->flags |= CHANGER_TIMEOUT_SCHED; } splx(s); @@ -1233,12 +1239,12 @@ * ones so this device gets its full time quantum. */ if (changer->flags & CHANGER_TIMEOUT_SCHED) { - untimeout(cdrunchangerqueue, changer, changer->long_handle); + callout_stop(&changer->long_handle); changer->flags &= ~CHANGER_TIMEOUT_SCHED; } if (changer->flags & CHANGER_SHORT_TMOUT_SCHED) { - untimeout(cdshorttimeout, changer, changer->short_handle); + callout_stop(&changer->short_handle); changer->flags &= ~CHANGER_SHORT_TMOUT_SCHED; } @@ -1304,18 +1310,18 @@ * and schedule our timeouts. */ if ((changer->flags & CHANGER_TIMEOUT_SCHED) == 0) { - changer->long_handle = - timeout(cdrunchangerqueue, changer, - changer_max_busy_seconds * hz); + callout_reset(&changer->long_handle, + changer_max_busy_seconds * hz, + cdrunchangerqueue, changer); changer->flags |= CHANGER_TIMEOUT_SCHED; } else printf("cdchangerschedule: already have a long" " timeout!\n"); if ((changer->flags & CHANGER_SHORT_TMOUT_SCHED) == 0) { - changer->short_handle = - timeout(cdshorttimeout, changer, - changer_min_busy_seconds * hz); + callout_reset(&changer->short_handle, + changer_min_busy_seconds * hz, + cdshorttimeout, changer); changer->flags |= CHANGER_SHORT_TMOUT_SCHED; } else printf("cdchangerschedule: already have a short "
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200703271547.l2RFlQiJ004661>