Index: sys/ktr.h =================================================================== RCS file: /usr/repo/src/sys/sys/ktr.h,v retrieving revision 1.32 diff -u -p -r1.32 ktr.h --- sys/ktr.h 11 Jun 2005 00:40:27 -0000 1.32 +++ sys/ktr.h 31 Aug 2005 08:49:12 -0000 @@ -70,7 +70,8 @@ #define KTR_CRITICAL 0x10000000 /* Critical sections */ #define KTR_SCHED 0x20000000 /* Machine parsed sched info. */ #define KTR_BUF 0x40000000 /* Buffer cache */ -#define KTR_ALL 0x7fffffff +#define KTR_MDTMP 0x80000000 /* md(4) (temporary). */ +#define KTR_ALL 0xffffffff /* * Trace classes which can be assigned to particular use at compile time Index: dev/md/md.c =================================================================== RCS file: /usr/repo/src/sys/dev/md/md.c,v retrieving revision 1.154 diff -u -p -r1.154 md.c --- dev/md/md.c 17 Aug 2005 01:24:55 -0000 1.154 +++ dev/md/md.c 31 Aug 2005 10:03:23 -0000 @@ -112,6 +112,8 @@ static g_access_t g_md_access; static int mdunits; static struct cdev *status_dev = 0; +static struct mtx md_mtx; +MTX_SYSINIT(md_mtx, &md_mtx, "md", MTX_DEF); static d_ioctl_t mdctlioctl; @@ -708,44 +710,53 @@ mdfind(int unit) { struct md_s *sc; - /* XXX: LOCK(unique unit numbers) */ + mtx_lock(&md_mtx); LIST_FOREACH(sc, &md_softc_list, list) { if (sc->unit == unit) break; } - /* XXX: UNLOCK(unique unit numbers) */ + mtx_unlock(&md_mtx); return (sc); } static struct md_s * mdnew(int unit) { - struct md_s *sc; + struct md_s *sc, *sc2; int error, max = -1; - /* XXX: LOCK(unique unit numbers) */ - LIST_FOREACH(sc, &md_softc_list, list) { - if (sc->unit == unit) { - /* XXX: UNLOCK(unique unit numbers) */ + sc = (struct md_s *)malloc(sizeof *sc, M_MD, M_WAITOK | M_ZERO); + bioq_init(&sc->bio_queue); + mtx_init(&sc->queue_mtx, "md bio queue", NULL, MTX_DEF); + CTR2(KTR_MDTMP, "%s(): mtx_init(%p)", __func__, &sc->queue_mtx); + mtx_lock(&md_mtx); + LIST_FOREACH(sc2, &md_softc_list, list) { + if (sc2->unit == unit) { + mtx_unlock(&md_mtx); + CTR2(KTR_MDTMP, "%s(): mtx_destroy(%p)", __func__, &sc->queue_mtx); + mtx_destroy(&sc->queue_mtx); + free(sc, M_MD); return (NULL); } - if (sc->unit > max) - max = sc->unit; + if (sc2->unit > max) + max = sc2->unit; } if (unit == -1) unit = max + 1; - sc = (struct md_s *)malloc(sizeof *sc, M_MD, M_WAITOK | M_ZERO); sc->unit = unit; - bioq_init(&sc->bio_queue); - mtx_init(&sc->queue_mtx, "md bio queue", NULL, MTX_DEF); sprintf(sc->name, "md%d", unit); + LIST_INSERT_HEAD(&md_softc_list, sc, list); + mtx_unlock(&md_mtx); error = kthread_create(md_kthread, sc, &sc->procp, 0, 0,"%s", sc->name); if (error != 0) { + mtx_lock(&md_mtx); + LIST_REMOVE(sc, list); + mtx_unlock(&md_mtx); + CTR2(KTR_MDTMP, "%s(): mtx_destroy(%p)", __func__, &sc->queue_mtx); + mtx_destroy(&sc->queue_mtx); free(sc, M_MD); return (NULL); } - LIST_INSERT_HEAD(&md_softc_list, sc, list); - /* XXX: UNLOCK(unique unit numbers) */ return (sc); } @@ -932,6 +943,7 @@ mddestroy(struct md_s *sc, struct thread GIANT_REQUIRED; + CTR2(KTR_MDTMP, "%s(): mtx_destroy(%p)", __func__, &sc->queue_mtx); mtx_destroy(&sc->queue_mtx); if (sc->gp) { sc->gp->softc = NULL; @@ -955,9 +967,9 @@ mddestroy(struct md_s *sc, struct thread if (sc->uma) uma_zdestroy(sc->uma); - /* XXX: LOCK(unique unit numbers) */ + mtx_lock(&md_mtx); LIST_REMOVE(sc, list); - /* XXX: UNLOCK(unique unit numbers) */ + mtx_unlock(&md_mtx); free(sc, M_MD); return (0); } @@ -1061,14 +1073,14 @@ mdctlioctl(struct cdev *dev, u_long cmd, default: return (EINVAL); } - if (mdio->md_options & MD_AUTOUNIT) { + if (mdio->md_options & MD_AUTOUNIT) sc = mdnew(-1); - mdio->md_unit = sc->unit; - } else { + else sc = mdnew(mdio->md_unit); - if (sc == NULL) - return (EBUSY); - } + if (sc == NULL) + return (EBUSY); + if (mdio->md_options & MD_AUTOUNIT) + mdio->md_unit = sc->unit; sc->type = mdio->md_type; sc->mediasize = mdio->md_mediasize; if (mdio->md_sectorsize == 0)