Straighten up the geom.ctl config interface definitions.

Sponsored by:	DARPA & NAI Labs
This commit is contained in:
Poul-Henning Kamp 2002-11-06 20:05:15 +00:00
parent a7a1238911
commit e6e142398f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=106518
4 changed files with 84 additions and 46 deletions

View File

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

View File

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

View File

@ -151,32 +151,11 @@ g_ctl_start(struct bio *bp)
* All the stuff above is really just needed to get to the stuff below
*/
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;

View File

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