diff options
author | phk <phk@FreeBSD.org> | 2002-11-06 20:05:15 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2002-11-06 20:05:15 +0000 |
commit | ad8a01f928d22e6bb9907a478104c5f787c254c1 (patch) | |
tree | 8020852f2d71d6d028e8de130696a3b08a3f9cd9 | |
parent | fd412ae82b5e378696c60be23a09910141b9f96d (diff) | |
download | FreeBSD-src-ad8a01f928d22e6bb9907a478104c5f787c254c1.zip FreeBSD-src-ad8a01f928d22e6bb9907a478104c5f787c254c1.tar.gz |
Straighten up the geom.ctl config interface definitions.
Sponsored by: DARPA & NAI Labs
-rw-r--r-- | sys/geom/bde/g_bde.c | 10 | ||||
-rw-r--r-- | sys/geom/geom.h | 80 | ||||
-rw-r--r-- | sys/geom/geom_ctl.c | 38 | ||||
-rw-r--r-- | sys/geom/geom_subr.c | 2 |
4 files changed, 84 insertions, 46 deletions
diff --git a/sys/geom/bde/g_bde.c b/sys/geom/bde/g_bde.c index 234c6e6..85df347 100644 --- a/sys/geom/bde/g_bde.c +++ b/sys/geom/bde/g_bde.c @@ -120,7 +120,7 @@ g_bde_access(struct g_provider *pp, int dr, int dw, int de) } static int -g_bde_create(struct g_createargs *ga) +g_bde_config(struct g_configargs *ga) { struct g_geom *gp; struct g_consumer *cp; @@ -131,10 +131,10 @@ g_bde_create(struct g_createargs *ga) off_t mediasize; struct g_bde_softc *sc; - g_trace(G_T_TOPOLOGY, "g_bde_create(%d)", ga->flag); + g_trace(G_T_TOPOLOGY, "g_bde_config(%d)", ga->flag); g_topology_assert(); gp = NULL; - if (ga->flag == 1) { + if (ga->flag == GCFG_DISMANTLE) { /* * Orderly dettachment. */ @@ -185,7 +185,7 @@ g_bde_create(struct g_createargs *ga) return (0); } - if (ga->flag != 0) + if (ga->flag != GCFG_CREATE) return (EOPNOTSUPP); if (ga->provider == NULL) @@ -271,7 +271,7 @@ g_bde_create(struct g_createargs *ga) static struct g_class g_bde_class = { BDE_CLASS_NAME, NULL, - g_bde_create, + g_bde_config, G_CLASS_INITIALIZER }; diff --git a/sys/geom/geom.h b/sys/geom/geom.h index 14a5e6f..df21e31 100644 --- a/sys/geom/geom.h +++ b/sys/geom/geom.h @@ -61,9 +61,9 @@ struct g_event; struct thread; struct bio; struct sbuf; -struct g_createargs; +struct g_configargs; -typedef int g_create_geom_t (struct g_createargs *ca); +typedef int g_config_t (struct g_configargs *ca); typedef struct g_geom * g_taste_t (struct g_class *, struct g_provider *, int flags); #define G_TF_NORMAL 0 @@ -83,12 +83,12 @@ typedef void g_dumpconf_t (struct sbuf *, char *indent, struct g_geom *, * all BSD disklabel handlers share one g_class, all MBR handlers share * one common g_class and so on. * Certain operations are instantiated on the class, most notably the - * taste and create_geom functions. + * taste and config_geom functions. */ struct g_class { char *name; g_taste_t *taste; - g_create_geom_t *create_geom; + g_config_t *config; /* * The remaning elements are private and classes should use * the G_CLASS_INITIALIZER macro to initialize them. @@ -333,13 +333,11 @@ extern struct sx topology_lock; * IOCTLS for talking to the geom.ctl device. */ -struct geomgetconf { - char *ptr; - u_int len; -}; -#define GEOMGETCONF _IOW('G', 0, struct geomgetconf) - -struct g_createargs { +/* + * This is the structure used internally in the kernel, it is created and + * populated by geom_ctl.c. + */ +struct g_configargs { /* Valid on call */ struct g_class *class; struct g_geom *geom; @@ -349,6 +347,9 @@ struct g_createargs { void *ptr; }; +/* + * This is the structure used to communicate with userland. + */ struct geomconfiggeom { /* Valid on call */ struct geomidorname class; @@ -357,10 +358,65 @@ struct geomconfiggeom { u_int flag; u_int len; void *ptr; - /* Valid on return */ }; + #define GEOMCONFIGGEOM _IOW('G', 0, struct geomconfiggeom) +#define GCFG_GENERIC0 0x00000000 + /* + * Generic requests suitable for all classes. + */ +#define GCFG_CLASS0 0x10000000 + /* + * Class specific verbs. Allocations in this part of the numberspace + * can only be done after review and approval of phk@FreeBSD.org. + * All allocations in this space will be listed in this file. + */ +#define GCFG_PRIVATE0 0x20000000 + /* + * Lowest allocation for private flag definitions. + * If you define you own private "verbs", please express them in + * your code as (GCFG_PRIVATE0 + somenumber), where somenumber is + * a magic number in the range [0x0 ... 0xfffffff] chosen the way + * magic numbers are chosen. Such allocation SHALL NOT be listed + * here but SHOULD be listed in some suitable .h file. + */ +#define GCFG_RESERVED0 0x30000000 +#define GCFG_RESERVEDN 0xffffffff + /* + * This area is reserved for the future. + */ + +#define GCFG_CREATE (GCFG_GENERIC0 + 0x0) + /* + * Request geom construction. + * ptr/len is class-specific. + */ +#define GCFG_DISMANTLE (GCFG_GENERIC0 + 0x1) + /* + * Request orderly geom dismantling. + * ptr/len is class-specific. + */ + + +struct gcfg_magicrw { + off_t offset; + u_int len; +}; + +#define GCFG_MAGICREAD (GCFG_GENERIC0 + 0x100) + /* + * Read of magic spaces. + * ptr/len is gcfgmagicrw structure followed by bufferspace + * for data to be read. + */ +#define GCFG_MAGICWRITE (GCFG_GENERIC0 + 0x101) + /* + * Write of magic spaces. + * as above, only the other way. + */ + + /* geom_enc.c */ uint16_t g_dec_be2(const u_char *p); uint32_t g_dec_be4(const u_char *p); diff --git a/sys/geom/geom_ctl.c b/sys/geom/geom_ctl.c index 1ae88fb..48bac22 100644 --- a/sys/geom/geom_ctl.c +++ b/sys/geom/geom_ctl.c @@ -152,31 +152,10 @@ g_ctl_start(struct bio *bp) */ static int -g_ctl_ioctl_getconf(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td) -{ - struct geomgetconf *gcp; - struct sbuf *sb; - int error; - u_int l; - - gcp = (struct geomgetconf *)data; - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); - sbuf_clear(sb); - g_confxml(sb); - l = sbuf_len(sb) + 1; - if (l > gcp->len) - error = ENOMEM; - else - error = copyout(sbuf_data(sb), gcp->ptr, l); - sbuf_delete(sb); - return(error); -} - -static int g_ctl_ioctl_configgeom(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td) { struct geomconfiggeom *gcp; - struct g_createargs ga; + struct g_configargs ga; int error; error = 0; @@ -185,7 +164,7 @@ g_ctl_ioctl_configgeom(dev_t dev, u_long cmd, caddr_t data, int fflag, struct th ga.class = g_idclass(&gcp->class); if (ga.class == NULL) return (EINVAL); - if (ga.class->create_geom == NULL) + if (ga.class->config == NULL) return (EOPNOTSUPP); ga.geom = g_idgeom(&gcp->geom); ga.provider = g_idprovider(&gcp->provider); @@ -196,10 +175,16 @@ g_ctl_ioctl_configgeom(dev_t dev, u_long cmd, caddr_t data, int fflag, struct th ga.ptr = NULL; } else { ga.ptr = g_malloc(gcp->len, M_WAITOK); - copyin(gcp->ptr, ga.ptr, gcp->len); + error = copyin(gcp->ptr, ga.ptr, gcp->len); + if (error) { + g_free(ga.ptr); + return (error); + } } ga.flag = gcp->flag; - error = ga.class->create_geom(&ga); + error = ga.class->config(&ga); + if (gcp->len != 0) + copyout(ga.ptr, gcp->ptr, gcp->len); /* Ignore error */ gcp->class.u.id = (uintptr_t)ga.class; gcp->class.len = 0; gcp->geom.u.id = (uintptr_t)ga.geom; @@ -217,9 +202,6 @@ g_ctl_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td) DROP_GIANT(); g_topology_lock(); switch(cmd) { - case GEOMGETCONF: - error = g_ctl_ioctl_getconf(dev, cmd, data, fflag, td); - break; case GEOMCONFIGGEOM: error = g_ctl_ioctl_configgeom(dev, cmd, data, fflag, td); break; diff --git a/sys/geom/geom_subr.c b/sys/geom/geom_subr.c index e134fd9..96f3b61e 100644 --- a/sys/geom/geom_subr.c +++ b/sys/geom/geom_subr.c @@ -591,7 +591,7 @@ g_insert_geom(char *class, struct g_consumer *cp) mp = g_class_by_name(class); if (mp == NULL) return (NULL); - if (mp->create_geom == NULL) + if (mp->config == NULL) return (NULL); pp = cp->provider; gp = mp->taste(mp, pp, G_TF_TRANSPARENT); |