diff options
author | phk <phk@FreeBSD.org> | 2002-06-05 20:30:36 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2002-06-05 20:30:36 +0000 |
commit | 7f7b291518b00d350eb19be5613ba5f44dea5db9 (patch) | |
tree | c00bb36b848696cccd66b1b04a81cc487a607ec9 /sys/geom | |
parent | 93f29d8926acf7a0ce2ceaaef0c39ad3f11172c7 (diff) | |
download | FreeBSD-src-7f7b291518b00d350eb19be5613ba5f44dea5db9.zip FreeBSD-src-7f7b291518b00d350eb19be5613ba5f44dea5db9.tar.gz |
Change the registration of magic spaces so it does its own memory management.
Sponsored by: DARPA & NAI Labs.
Diffstat (limited to 'sys/geom')
-rw-r--r-- | sys/geom/geom.h | 4 | ||||
-rw-r--r-- | sys/geom/geom_bsd.c | 16 | ||||
-rw-r--r-- | sys/geom/geom_mbr.c | 7 | ||||
-rw-r--r-- | sys/geom/geom_subr.c | 49 | ||||
-rw-r--r-- | sys/geom/geom_sunlabel.c | 3 |
5 files changed, 43 insertions, 36 deletions
diff --git a/sys/geom/geom.h b/sys/geom/geom.h index 8fdf07d..665a992 100644 --- a/sys/geom/geom.h +++ b/sys/geom/geom.h @@ -197,6 +197,7 @@ struct g_magicspaces { uintptr_t geom_id; char class[8]; uint nmagic; + uint nspace; struct g_magicspace *magicspace; }; @@ -223,7 +224,7 @@ void g_silence(void); int g_access_abs(struct g_consumer *cp, int read, int write, int exclusive); int g_access_rel(struct g_consumer *cp, int read, int write, int exclusive); void g_add_class(struct g_class *mp); -int g_add_magicspace(struct g_geom *gp, u_int index, const char *name, off_t start, u_int len, u_int flags); +int g_add_magicspace(struct g_geom *gp, const char *name, off_t start, u_int len, u_int flags); int g_attach(struct g_consumer *cp, struct g_provider *pp); struct g_geom *g_create_geomf(char *class, struct g_provider *, char *fmt, ...); void g_destroy_consumer(struct g_consumer *cp); @@ -239,7 +240,6 @@ int g_haveattr_off_t(struct bio *bp, char *attribute, off_t val); struct g_geom * g_insert_geom(char *class, struct g_consumer *cp); struct g_consumer * g_new_consumer(struct g_geom *gp); struct g_geom * g_new_geomf(struct g_class *mp, char *fmt, ...); -int g_new_magicspaces(struct g_geom *gp, int nspaces); struct g_provider * g_new_providerf(struct g_geom *gp, char *fmt, ...); void g_sanity(void *ptr); void g_spoil(struct g_provider *pp, struct g_consumer *cp); diff --git a/sys/geom/geom_bsd.c b/sys/geom/geom_bsd.c index 3e5ed6f..77f4214 100644 --- a/sys/geom/geom_bsd.c +++ b/sys/geom/geom_bsd.c @@ -339,19 +339,17 @@ g_bsd_taste(struct g_class *mp, struct g_provider *pp, int flags) } error = g_bsd_try(gsp, cp, secsize, ms, secsize); if (!error) { - g_new_magicspaces(gp, 4); - g_add_magicspace(gp, 0, "boot1", 0, 512, 0); - g_add_magicspace(gp, 1, "label", 512, 276, 0); - g_add_magicspace(gp, 2, "fill0", 748, 236, 0); - g_add_magicspace(gp, 3, "boot2", 1024, 7168, 0); + g_add_magicspace(gp, "boot1", 0, 512, 0); + g_add_magicspace(gp, "label", 512, 276, 0); + g_add_magicspace(gp, "fill0", 748, 236, 0); + g_add_magicspace(gp, "boot2", 1024, 7168, 0); } if (error) { error = g_bsd_try(gsp, cp, secsize, ms, 64); if (!error) { - g_new_magicspaces(gp, 3); - g_add_magicspace(gp, 0, "fill0", 0, 64, 0); - g_add_magicspace(gp, 1, "label", 64, 276, 0); - g_add_magicspace(gp, 2, "fill1", 340, 172, 0); + g_add_magicspace(gp, "fill0", 0, 64, 0); + g_add_magicspace(gp, "label", 64, 276, 0); + g_add_magicspace(gp, "fill1", 340, 172, 0); } } if (error) diff --git a/sys/geom/geom_mbr.c b/sys/geom/geom_mbr.c index 9e8e8cd..90ebaff 100644 --- a/sys/geom/geom_mbr.c +++ b/sys/geom/geom_mbr.c @@ -251,10 +251,9 @@ g_mbr_taste(struct g_class *mp, struct g_provider *pp, int insist) g_topology_lock(); error = g_access_rel(cp, -1, 0, 0); if (npart > 0) { - g_new_magicspaces(gp, 3); - g_add_magicspace(gp, 0, "boot", 0, DOSPARTOFF, 0); - g_add_magicspace(gp, 1, "mbr", DOSPARTOFF, 4 * 16, 0); - g_add_magicspace(gp, 2, "signature", 510, 2, 0); + g_add_magicspace(gp, "boot", 0, DOSPARTOFF, 0); + g_add_magicspace(gp, "mbr", DOSPARTOFF, 4 * 16, 0); + g_add_magicspace(gp, "magic", 510, 2, 0); LIST_FOREACH(pp, &gp->provider, provider) g_error_provider(pp, 0); return (gp); diff --git a/sys/geom/geom_subr.c b/sys/geom/geom_subr.c index 1b2dc2e..570c113 100644 --- a/sys/geom/geom_subr.c +++ b/sys/geom/geom_subr.c @@ -114,28 +114,39 @@ g_new_geomf(struct g_class *mp, char *fmt, ...) return (gp); } -int -g_new_magicspaces(struct g_geom *gp, int nspaces) -{ - gp->magicspaces = g_malloc(sizeof *gp->magicspaces, M_WAITOK | M_ZERO); - gp->magicspaces->magicspace = - g_malloc(sizeof *gp->magicspaces->magicspace * nspaces, - M_WAITOK | M_ZERO); - gp->magicspaces->geom_id = (uintptr_t)gp; - strncpy(gp->magicspaces->class, gp->class->name, - sizeof gp->magicspaces->class); - gp->magicspaces->nmagic = nspaces; - return (0); -} +/* + * Add a magic space to a geom. There is no locking here because nobody + * should be modifying these except the geom itself during configuration, + * so it cannot go away while we fiddling it. + * For now, no provision exists for removing magic spaces or for changing + * them on the fly. + */ int -g_add_magicspace(struct g_geom *gp, u_int index, const char *name, off_t start, u_int len, u_int flags) +g_add_magicspace(struct g_geom *gp, const char *name, off_t start, u_int len, u_int flags) { - struct g_magicspace *msp; - - /* KASSERT gp->magicspaces != NULL */ - /* KASSERT index < gp->magicspaces->nmagic */ - msp = &gp->magicspaces->magicspace[index]; + int i; + struct g_magicspaces *msps; + struct g_magicspace *msp, *msp2; + + if (gp->magicspaces == NULL) { + msps = g_malloc(sizeof *gp->magicspaces, M_WAITOK | M_ZERO); + msps->geom_id = (uintptr_t)gp; + strncpy(msps->class, gp->class->name, sizeof msps->class); + gp->magicspaces = msps; + } + msps = gp->magicspaces; + if (msps->nmagic >= msps->nspace) { + i = msps->nspace + 1; + msp = g_malloc(sizeof(*msp) * i, M_WAITOK | M_ZERO); + bcopy(msps->magicspace, msp, sizeof(*msp) * msps->nmagic); + msp2 = msps->magicspace; + msps->magicspace = msp; + if (msp2 != NULL) + g_free(msp2); + msps->nspace = i; + } + msp = &msps->magicspace[msps->nmagic++]; strncpy(msp->name, name, sizeof msp->name); msp->offset = start; msp->len = len; diff --git a/sys/geom/geom_sunlabel.c b/sys/geom/geom_sunlabel.c index 6171ac8..7d5f98a 100644 --- a/sys/geom/geom_sunlabel.c +++ b/sys/geom/geom_sunlabel.c @@ -180,8 +180,7 @@ g_sunlabel_taste(struct g_class *mp, struct g_provider *pp, int flags) g_topology_lock(); error = g_access_rel(cp, -1, 0, 0); if (npart > 0) { - g_new_magicspaces(gp, 1); - g_add_magicspace(gp, 0, "label", 0, 512, 0); + g_add_magicspace(gp, "label", 0, 512, 0); return (gp); } g_std_spoiled(cp); |