Change the registration of magic spaces so it does its own memory management.

Sponsored by: DARPA & NAI Labs.
This commit is contained in:
Poul-Henning Kamp 2002-06-05 20:30:36 +00:00
parent 4b683fb224
commit 678735da39
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=97887
5 changed files with 42 additions and 35 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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;
int i;
struct g_magicspaces *msps;
struct g_magicspace *msp, *msp2;
/* KASSERT gp->magicspaces != NULL */
/* KASSERT index < gp->magicspaces->nmagic */
msp = &gp->magicspaces->magicspace[index];
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;

View File

@ -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);