Move access and orphan member functions from class to geom.
Sponsored by: DARPA & NAI Labs
This commit is contained in:
parent
a2f4e30c8c
commit
07d77fc610
@ -57,7 +57,6 @@ struct thread;
|
||||
struct bio;
|
||||
struct sbuf;
|
||||
|
||||
#define G_CLASS_INITSTUFF { 0, 0 }, { 0 }, 0
|
||||
|
||||
typedef struct g_geom * g_create_geom_t (struct g_class *mp,
|
||||
struct g_provider *pp, char *name);
|
||||
@ -81,20 +80,22 @@ typedef void g_dumpconf_t (struct sbuf *, char *indent, struct g_geom *,
|
||||
* one common g_class and so on.
|
||||
* Certain operations are instantiated on the class, most notably the
|
||||
* taste and create_geom functions.
|
||||
* XXX: should access and orphan go into g_geom ?
|
||||
* XXX: would g_class be a better and less confusing name ?
|
||||
*/
|
||||
struct g_class {
|
||||
char *name;
|
||||
g_taste_t *taste;
|
||||
g_access_t *access;
|
||||
g_orphan_t *orphan;
|
||||
g_create_geom_t *create_geom;
|
||||
/*
|
||||
* The remaning elements are private and classes should use
|
||||
* the G_CLASS_INITSTUFF macro to initialize them.
|
||||
*/
|
||||
LIST_ENTRY(g_class) class;
|
||||
LIST_HEAD(,g_geom) geom;
|
||||
struct g_event *event;
|
||||
};
|
||||
|
||||
#define G_CLASS_INITSTUFF { 0, 0 }, { 0 }, 0
|
||||
|
||||
/*
|
||||
* The g_geom is an instance of a g_class.
|
||||
*/
|
||||
@ -109,6 +110,8 @@ struct g_geom {
|
||||
g_start_t *start;
|
||||
g_spoiled_t *spoiled;
|
||||
g_dumpconf_t *dumpconf;
|
||||
g_access_t *access;
|
||||
g_orphan_t *orphan;
|
||||
void *softc;
|
||||
struct g_event *event;
|
||||
unsigned flags;
|
||||
@ -205,6 +208,7 @@ void g_std_spoiled(struct g_consumer *cp);
|
||||
struct bio * g_clone_bio(struct bio *);
|
||||
void g_destroy_bio(struct bio *);
|
||||
void g_io_deliver(struct bio *bp);
|
||||
void g_io_fail(struct bio *bp, int error);
|
||||
int g_io_getattr(char *attr, struct g_consumer *cp, int *len, void *ptr);
|
||||
void g_io_request(struct bio *bp, struct g_consumer *cp);
|
||||
int g_io_setattr(char *attr, struct g_consumer *cp, int len, void *ptr);
|
||||
|
@ -425,8 +425,6 @@ g_bsd_taste(struct g_class *mp, struct g_provider *pp, int flags)
|
||||
static struct g_class g_bsd_class = {
|
||||
BSD_CLASS_NAME,
|
||||
g_bsd_taste,
|
||||
g_slice_access,
|
||||
g_slice_orphan,
|
||||
NULL,
|
||||
G_CLASS_INITSTUFF
|
||||
};
|
||||
|
@ -80,8 +80,6 @@ static struct g_class g_dev_class = {
|
||||
"DEV-class",
|
||||
g_dev_taste,
|
||||
NULL,
|
||||
g_dev_orphan,
|
||||
NULL,
|
||||
G_CLASS_INITSTUFF
|
||||
};
|
||||
|
||||
@ -140,6 +138,7 @@ g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused)
|
||||
if (cp->geom->class == mp)
|
||||
return (NULL);
|
||||
gp = g_new_geomf(mp, pp->name);
|
||||
gp->orphan = g_dev_orphan;
|
||||
cp = g_new_consumer(gp);
|
||||
g_attach(cp, pp);
|
||||
error = g_access_rel(cp, 1, 0, 0);
|
||||
|
@ -59,11 +59,8 @@ static g_access_t g_disk_access;
|
||||
struct g_class g_disk_class = {
|
||||
"DISK-class",
|
||||
NULL,
|
||||
g_disk_access,
|
||||
NULL,
|
||||
NULL,
|
||||
{ 0, 0 },
|
||||
{ 0 }
|
||||
G_CLASS_INITSTUFF
|
||||
};
|
||||
|
||||
static int
|
||||
@ -193,6 +190,7 @@ disk_create(int unit, struct disk *dp, int flags, struct cdevsw *cdevsw, struct
|
||||
g_topology_lock();
|
||||
gp = g_new_geomf(&g_disk_class, "%s%d", cdevsw->d_name, unit);
|
||||
gp->start = g_disk_start;
|
||||
gp->access = g_disk_access;
|
||||
gp->softc = dp;
|
||||
dp->d_softc = gp;
|
||||
pp = g_new_providerf(gp, "%s", gp->name);
|
||||
|
@ -123,10 +123,10 @@ g_orphan_register(struct g_provider *pp)
|
||||
cp = LIST_FIRST(&pp->consumers);
|
||||
while (cp != NULL) {
|
||||
cp2 = LIST_NEXT(cp, consumers);
|
||||
KASSERT(cp->geom->class->orphan != NULL,
|
||||
("class %s has no orphan, geom %s",
|
||||
cp->geom->class->name, cp->geom->name));
|
||||
cp->geom->class->orphan(cp);
|
||||
KASSERT(cp->geom->orphan != NULL,
|
||||
("geom %s has no orphan, class %s",
|
||||
cp->geom->name, cp->geom->class->name));
|
||||
cp->geom->orphan(cp);
|
||||
cp = cp2;
|
||||
}
|
||||
}
|
||||
|
@ -244,8 +244,6 @@ g_mbr_taste(struct g_class *mp, struct g_provider *pp, int insist)
|
||||
static struct g_class g_mbr_class = {
|
||||
MBR_CLASS_NAME,
|
||||
g_mbr_taste,
|
||||
g_slice_access,
|
||||
g_slice_orphan,
|
||||
NULL,
|
||||
G_CLASS_INITSTUFF
|
||||
};
|
||||
@ -382,8 +380,6 @@ g_mbrext_taste(struct g_class *mp, struct g_provider *pp, int insist __unused)
|
||||
static struct g_class g_mbrext_class = {
|
||||
MBREXT_CLASS_NAME,
|
||||
g_mbrext_taste,
|
||||
g_slice_access,
|
||||
g_slice_orphan,
|
||||
NULL,
|
||||
G_CLASS_INITSTUFF
|
||||
};
|
||||
|
@ -180,8 +180,6 @@ g_pc98_taste(struct g_class *mp, struct g_provider *pp, int flags)
|
||||
static struct g_class g_pc98_class = {
|
||||
PC98_CLASS_NAME,
|
||||
g_pc98_taste,
|
||||
g_slice_access,
|
||||
g_slice_orphan,
|
||||
NULL,
|
||||
G_CLASS_INITSTUFF
|
||||
};
|
||||
|
@ -60,6 +60,10 @@
|
||||
#include <geom/geom_slice.h>
|
||||
#include <machine/stdarg.h>
|
||||
|
||||
static g_orphan_t g_slice_orphan;
|
||||
static g_access_t g_slice_access;
|
||||
static g_start_t g_slice_start;
|
||||
|
||||
struct g_slicer *
|
||||
g_slice_init(unsigned nslice, unsigned scsize)
|
||||
{
|
||||
@ -72,7 +76,7 @@ g_slice_init(unsigned nslice, unsigned scsize)
|
||||
return (gsp);
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
g_slice_access(struct g_provider *pp, int dr, int dw, int de)
|
||||
{
|
||||
int error, i;
|
||||
@ -114,7 +118,7 @@ g_slice_access(struct g_provider *pp, int dr, int dw, int de)
|
||||
return (error);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
g_slice_start(struct bio *bp)
|
||||
{
|
||||
struct bio *bp2;
|
||||
@ -226,6 +230,8 @@ g_slice_new(struct g_class *mp, int slices, struct g_provider *pp, struct g_cons
|
||||
gp = g_new_geomf(mp, "%s", pp->name);
|
||||
gsp = g_slice_init(slices, extra);
|
||||
gsp->start = start;
|
||||
gp->access = g_slice_access;
|
||||
gp->orphan = g_slice_orphan;
|
||||
gp->softc = gsp;
|
||||
gp->start = g_slice_start;
|
||||
gp->spoiled = g_std_spoiled;
|
||||
@ -246,7 +252,7 @@ g_slice_new(struct g_class *mp, int slices, struct g_provider *pp, struct g_cons
|
||||
return (gp);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
g_slice_orphan(struct g_consumer *cp)
|
||||
{
|
||||
struct g_geom *gp;
|
||||
|
@ -50,11 +50,8 @@ struct g_slicer {
|
||||
g_slice_start_t *start;
|
||||
};
|
||||
|
||||
g_orphan_t g_slice_orphan;
|
||||
struct g_slicer * g_slice_init(unsigned nslice, unsigned scsize);
|
||||
int g_slice_access(struct g_provider *pp, int dr, int dw, int de);
|
||||
void g_slice_start(struct bio *bp);
|
||||
void g_slice_dumpconf(struct sbuf *sb, char *indent, struct g_geom *gp, struct g_consumer *cp __unused, struct g_provider *pp);
|
||||
g_dumpconf_t g_slice_dumpconf;
|
||||
struct g_provider * g_slice_addslice(struct g_geom *gp, int index, off_t offset, off_t length, char *fmt, ...);
|
||||
struct g_geom * g_slice_new(struct g_class *mp, int slices, struct g_provider *pp, struct g_consumer **cpp, void *extrap, int extra, g_slice_start_t *start);
|
||||
|
||||
|
@ -136,8 +136,9 @@ g_new_consumer(struct g_geom *gp)
|
||||
struct g_consumer *cp;
|
||||
|
||||
g_topology_assert();
|
||||
KASSERT(gp->class->orphan != NULL,
|
||||
("g_new_consumer on class(%s) without orphan", gp->class->name));
|
||||
KASSERT(gp->orphan != NULL,
|
||||
("g_new_consumer on geom(%s) (class %s) without orphan",
|
||||
gp->name, gp->class->name));
|
||||
|
||||
cp = g_malloc(sizeof *cp, M_WAITOK | M_ZERO);
|
||||
cp->geom = gp;
|
||||
@ -378,7 +379,7 @@ g_access_rel(struct g_consumer *cp, int dcr, int dcw, int dce)
|
||||
KASSERT(cp->acr + dcr >= 0, ("access resulting in negative acr"));
|
||||
KASSERT(cp->acw + dcw >= 0, ("access resulting in negative acw"));
|
||||
KASSERT(cp->ace + dce >= 0, ("access resulting in negative ace"));
|
||||
KASSERT(pp->geom->class->access != NULL, ("NULL class->access"));
|
||||
KASSERT(pp->geom->access != NULL, ("NULL geom->access"));
|
||||
|
||||
/*
|
||||
* If our class cares about being spoiled, and we have been, we
|
||||
@ -431,7 +432,7 @@ g_access_rel(struct g_consumer *cp, int dcr, int dcw, int dce)
|
||||
else if (pp->acw != 0 && pp->acw == -dcw && !(pp->geom->flags & G_GEOM_WITHER))
|
||||
g_post_event(EV_NEW_PROVIDER, NULL, NULL, pp, NULL);
|
||||
|
||||
error = pp->geom->class->access(pp, dcr, dcw, dce);
|
||||
error = pp->geom->access(pp, dcr, dcw, dce);
|
||||
if (!error) {
|
||||
pp->acr += dcr;
|
||||
pp->acw += dcw;
|
||||
|
@ -187,8 +187,6 @@ g_sunlabel_taste(struct g_class *mp, struct g_provider *pp, int flags)
|
||||
static struct g_class g_sunlabel_class = {
|
||||
SUNLABEL_CLASS_NAME,
|
||||
g_sunlabel_taste,
|
||||
g_slice_access,
|
||||
g_slice_orphan,
|
||||
NULL,
|
||||
G_CLASS_INITSTUFF
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user