Make libgeom usable by C++ programs:

- Add DECL wrappers to libgeom.h.
- Rename structure members in libgeom.h to use a lg_ prefix for member
  names.  This is required because a few structures had members named
  'class' which made g++ very unhappy.
- Catch gstat(8) and gconcat(8) up to these API changes.

Reviewed by:	phk
This commit is contained in:
jhb 2004-03-09 21:14:18 +00:00
parent dc5da5f8f7
commit 01eed200f9
4 changed files with 163 additions and 149 deletions

View File

@ -70,6 +70,7 @@ StartElement(void *userData, const char *name, const char **attr)
mt->level++;
mt->sbuf[mt->level] = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
id = NULL;
ref = NULL;
for (i = 0; attr[i] != NULL; i += 2) {
if (!strcmp(attr[i], "id")) {
id = (void *)strtoul(attr[i + 1], NULL, 0);
@ -83,67 +84,69 @@ StartElement(void *userData, const char *name, const char **attr)
}
if (!strcmp(name, "class") && mt->class == NULL) {
mt->class = calloc(1, sizeof *mt->class);
mt->class->id = id;
LIST_INSERT_HEAD(&mt->mesh->class, mt->class, class);
LIST_INIT(&mt->class->geom);
LIST_INIT(&mt->class->config);
mt->class->lg_id = id;
LIST_INSERT_HEAD(&mt->mesh->lg_class, mt->class, lg_class);
LIST_INIT(&mt->class->lg_geom);
LIST_INIT(&mt->class->lg_config);
return;
}
if (!strcmp(name, "geom") && mt->geom == NULL) {
mt->geom = calloc(1, sizeof *mt->geom);
mt->geom->id = id;
LIST_INSERT_HEAD(&mt->class->geom, mt->geom, geom);
LIST_INIT(&mt->geom->provider);
LIST_INIT(&mt->geom->consumer);
LIST_INIT(&mt->geom->config);
mt->geom->lg_id = id;
LIST_INSERT_HEAD(&mt->class->lg_geom, mt->geom, lg_geom);
LIST_INIT(&mt->geom->lg_provider);
LIST_INIT(&mt->geom->lg_consumer);
LIST_INIT(&mt->geom->lg_config);
return;
}
if (!strcmp(name, "class") && mt->geom != NULL) {
mt->geom->class = ref;
mt->geom->lg_class = ref;
return;
}
if (!strcmp(name, "consumer") && mt->consumer == NULL) {
mt->consumer = calloc(1, sizeof *mt->consumer);
mt->consumer->id = id;
LIST_INSERT_HEAD(&mt->geom->consumer, mt->consumer, consumer);
LIST_INIT(&mt->consumer->config);
mt->consumer->lg_id = id;
LIST_INSERT_HEAD(&mt->geom->lg_consumer, mt->consumer,
lg_consumer);
LIST_INIT(&mt->consumer->lg_config);
return;
}
if (!strcmp(name, "geom") && mt->consumer != NULL) {
mt->consumer->geom = ref;
mt->consumer->lg_geom = ref;
return;
}
if (!strcmp(name, "provider") && mt->consumer != NULL) {
mt->consumer->provider = ref;
mt->consumer->lg_provider = ref;
return;
}
if (!strcmp(name, "provider") && mt->provider == NULL) {
mt->provider = calloc(1, sizeof *mt->provider);
mt->provider->id = id;
LIST_INSERT_HEAD(&mt->geom->provider, mt->provider, provider);
LIST_INIT(&mt->provider->consumers);
LIST_INIT(&mt->provider->config);
mt->provider->lg_id = id;
LIST_INSERT_HEAD(&mt->geom->lg_provider, mt->provider,
lg_provider);
LIST_INIT(&mt->provider->lg_consumers);
LIST_INIT(&mt->provider->lg_config);
return;
}
if (!strcmp(name, "geom") && mt->provider != NULL) {
mt->provider->geom = ref;
mt->provider->lg_geom = ref;
return;
}
if (!strcmp(name, "config")) {
if (mt->provider != NULL) {
mt->config = &mt->provider->config;
mt->config = &mt->provider->lg_config;
return;
}
if (mt->consumer != NULL) {
mt->config = &mt->consumer->config;
mt->config = &mt->consumer->lg_config;
return;
}
if (mt->geom != NULL) {
mt->config = &mt->geom->config;
mt->config = &mt->geom->lg_config;
return;
}
if (mt->class != NULL) {
mt->config = &mt->class->config;
mt->config = &mt->class->lg_config;
return;
}
}
@ -169,36 +172,36 @@ EndElement(void *userData, const char *name)
if (!strcmp(name, "name")) {
if (mt->provider != NULL) {
mt->provider->name = p;
mt->provider->lg_name = p;
return;
} else if (mt->geom != NULL) {
mt->geom->name = p;
mt->geom->lg_name = p;
return;
} else if (mt->class != NULL) {
mt->class->name = p;
mt->class->lg_name = p;
return;
}
}
if (!strcmp(name, "rank") && mt->geom != NULL) {
mt->geom->rank = strtoul(p, NULL, 0);
mt->geom->lg_rank = strtoul(p, NULL, 0);
free(p);
return;
}
if (!strcmp(name, "mode") && mt->provider != NULL) {
mt->provider->mode = p;
mt->provider->lg_mode = p;
return;
}
if (!strcmp(name, "mode") && mt->consumer != NULL) {
mt->consumer->mode = p;
mt->consumer->lg_mode = p;
return;
}
if (!strcmp(name, "mediasize") && mt->provider != NULL) {
mt->provider->mediasize = strtoumax(p, NULL, 0);
mt->provider->lg_mediasize = strtoumax(p, NULL, 0);
free(p);
return;
}
if (!strcmp(name, "sectorsize") && mt->provider != NULL) {
mt->provider->sectorsize = strtoul(p, NULL, 0);
mt->provider->lg_sectorsize = strtoul(p, NULL, 0);
free(p);
return;
}
@ -210,9 +213,9 @@ EndElement(void *userData, const char *name)
if (mt->config != NULL) {
gc = calloc(sizeof *gc, 1);
gc->name = strdup(name);
gc->val = p;
LIST_INSERT_HEAD(mt->config, gc, config);
gc->lg_name = strdup(name);
gc->lg_val = p;
LIST_INSERT_HEAD(mt->config, gc, lg_config);
return;
}
@ -271,8 +274,8 @@ geom_lookupid(struct gmesh *gmp, const void *id)
{
struct gident *gip;
for (gip = gmp->ident; gip->id != NULL; gip++)
if (gip->id == id)
for (gip = gmp->lg_ident; gip->lg_id != NULL; gip++)
if (gip->lg_id == id)
return (gip);
return (NULL);
}
@ -289,7 +292,7 @@ geom_xml2tree(struct gmesh *gmp, char *p)
int i;
memset(gmp, 0, sizeof *gmp);
LIST_INIT(&gmp->class);
LIST_INIT(&gmp->lg_class);
parser = XML_ParserCreate(NULL);
mt = calloc(1, sizeof *mt);
if (mt == NULL)
@ -302,51 +305,55 @@ geom_xml2tree(struct gmesh *gmp, char *p)
if (i != 1)
return (-1);
XML_ParserFree(parser);
gmp->ident = calloc(sizeof *gmp->ident, mt->nident + 1);
if (gmp->ident == NULL)
gmp->lg_ident = calloc(sizeof *gmp->lg_ident, mt->nident + 1);
if (gmp->lg_ident == NULL)
return (ENOMEM);
free(mt);
i = 0;
/* Collect all identifiers */
LIST_FOREACH(cl, &gmp->class, class) {
gmp->ident[i].id = cl->id;
gmp->ident[i].ptr = cl;
gmp->ident[i].what = ISCLASS;
LIST_FOREACH(cl, &gmp->lg_class, lg_class) {
gmp->lg_ident[i].lg_id = cl->lg_id;
gmp->lg_ident[i].lg_ptr = cl;
gmp->lg_ident[i].lg_what = ISCLASS;
i++;
LIST_FOREACH(ge, &cl->geom, geom) {
gmp->ident[i].id = ge->id;
gmp->ident[i].ptr = ge;
gmp->ident[i].what = ISGEOM;
LIST_FOREACH(ge, &cl->lg_geom, lg_geom) {
gmp->lg_ident[i].lg_id = ge->lg_id;
gmp->lg_ident[i].lg_ptr = ge;
gmp->lg_ident[i].lg_what = ISGEOM;
i++;
LIST_FOREACH(pr, &ge->provider, provider) {
gmp->ident[i].id = pr->id;
gmp->ident[i].ptr = pr;
gmp->ident[i].what = ISPROVIDER;
LIST_FOREACH(pr, &ge->lg_provider, lg_provider) {
gmp->lg_ident[i].lg_id = pr->lg_id;
gmp->lg_ident[i].lg_ptr = pr;
gmp->lg_ident[i].lg_what = ISPROVIDER;
i++;
}
LIST_FOREACH(co, &ge->consumer, consumer) {
gmp->ident[i].id = co->id;
gmp->ident[i].ptr = co;
gmp->ident[i].what = ISCONSUMER;
LIST_FOREACH(co, &ge->lg_consumer, lg_consumer) {
gmp->lg_ident[i].lg_id = co->lg_id;
gmp->lg_ident[i].lg_ptr = co;
gmp->lg_ident[i].lg_what = ISCONSUMER;
i++;
}
}
}
/* Substitute all identifiers */
LIST_FOREACH(cl, &gmp->class, class) {
LIST_FOREACH(ge, &cl->geom, geom) {
ge->class = geom_lookupid(gmp, ge->class)->ptr;
LIST_FOREACH(pr, &ge->provider, provider) {
pr->geom = geom_lookupid(gmp, pr->geom)->ptr;
LIST_FOREACH(cl, &gmp->lg_class, lg_class) {
LIST_FOREACH(ge, &cl->lg_geom, lg_geom) {
ge->lg_class =
geom_lookupid(gmp, ge->lg_class)->lg_ptr;
LIST_FOREACH(pr, &ge->lg_provider, lg_provider) {
pr->lg_geom =
geom_lookupid(gmp, pr->lg_geom)->lg_ptr;
}
LIST_FOREACH(co, &ge->consumer, consumer) {
co->geom = geom_lookupid(gmp, co->geom)->ptr;
if (co->provider != NULL) {
co->provider =
geom_lookupid(gmp, co->provider)->ptr;
LIST_FOREACH(co, &ge->lg_consumer, lg_consumer) {
co->lg_geom =
geom_lookupid(gmp, co->lg_geom)->lg_ptr;
if (co->lg_provider != NULL) {
co->lg_provider =
geom_lookupid(gmp,
co->lg_provider)->lg_ptr;
LIST_INSERT_HEAD(
&co->provider->consumers,
co, consumers);
&co->lg_provider->lg_consumers,
co, lg_consumers);
}
}
}
@ -375,9 +382,9 @@ delete_config(struct gconf *gp)
cf = LIST_FIRST(gp);
if (cf == NULL)
return;
LIST_REMOVE(cf, config);
free(cf->name);
free(cf->val);
LIST_REMOVE(cf, lg_config);
free(cf->lg_name);
free(cf->lg_val);
free(cf);
}
}
@ -390,39 +397,39 @@ geom_deletetree(struct gmesh *gmp)
struct gprovider *pr;
struct gconsumer *co;
free(gmp->ident);
gmp->ident = NULL;
free(gmp->lg_ident);
gmp->lg_ident = NULL;
for (;;) {
cl = LIST_FIRST(&gmp->class);
cl = LIST_FIRST(&gmp->lg_class);
if (cl == NULL)
break;
LIST_REMOVE(cl, class);
delete_config(&cl->config);
if (cl->name) free(cl->name);
LIST_REMOVE(cl, lg_class);
delete_config(&cl->lg_config);
if (cl->lg_name) free(cl->lg_name);
for (;;) {
ge = LIST_FIRST(&cl->geom);
ge = LIST_FIRST(&cl->lg_geom);
if (ge == NULL)
break;
LIST_REMOVE(ge, geom);
delete_config(&ge->config);
if (ge->name) free(ge->name);
LIST_REMOVE(ge, lg_geom);
delete_config(&ge->lg_config);
if (ge->lg_name) free(ge->lg_name);
for (;;) {
pr = LIST_FIRST(&ge->provider);
pr = LIST_FIRST(&ge->lg_provider);
if (pr == NULL)
break;
LIST_REMOVE(pr, provider);
delete_config(&pr->config);
if (pr->name) free(pr->name);
if (pr->mode) free(pr->mode);
LIST_REMOVE(pr, lg_provider);
delete_config(&pr->lg_config);
if (pr->lg_name) free(pr->lg_name);
if (pr->lg_mode) free(pr->lg_mode);
free(pr);
}
for (;;) {
co = LIST_FIRST(&ge->consumer);
co = LIST_FIRST(&ge->lg_consumer);
if (co == NULL)
break;
LIST_REMOVE(co, consumer);
delete_config(&co->config);
if (co->mode) free(co->mode);
LIST_REMOVE(co, lg_consumer);
delete_config(&co->lg_config);
if (co->lg_mode) free(co->lg_mode);
free(co);
}
free(ge);

View File

@ -31,11 +31,15 @@
#ifndef _LIBGEOM_H_
#define _LIBGEOM_H_
#include <sys/cdefs.h>
#include <sys/queue.h>
#include <sys/time.h>
#include <geom/geom_ctl.h>
__BEGIN_DECLS
void geom_stats_close(void);
void geom_stats_resync(void);
int geom_stats_open(void);
@ -62,64 +66,64 @@ struct gprovider;
LIST_HEAD(gconf, gconfig);
struct gident {
void *id;
void *ptr;
void *lg_id;
void *lg_ptr;
enum { ISCLASS,
ISGEOM,
ISPROVIDER,
ISCONSUMER } what;
ISCONSUMER } lg_what;
};
struct gmesh {
LIST_HEAD(, gclass) class;
struct gident *ident;
LIST_HEAD(, gclass) lg_class;
struct gident *lg_ident;
};
struct gconfig {
LIST_ENTRY(gconfig) config;
char *name;
char *val;
LIST_ENTRY(gconfig) lg_config;
char *lg_name;
char *lg_val;
};
struct gclass {
void *id;
char *name;
LIST_ENTRY(gclass) class;
LIST_HEAD(, ggeom) geom;
struct gconf config;
void *lg_id;
char *lg_name;
LIST_ENTRY(gclass) lg_class;
LIST_HEAD(, ggeom) lg_geom;
struct gconf lg_config;
};
struct ggeom {
void *id;
struct gclass *class;
char *name;
u_int rank;
LIST_ENTRY(ggeom) geom;
LIST_HEAD(, gconsumer) consumer;
LIST_HEAD(, gprovider) provider;
struct gconf config;
void *lg_id;
struct gclass *lg_class;
char *lg_name;
u_int lg_rank;
LIST_ENTRY(ggeom) lg_geom;
LIST_HEAD(, gconsumer) lg_consumer;
LIST_HEAD(, gprovider) lg_provider;
struct gconf lg_config;
};
struct gconsumer {
void *id;
struct ggeom *geom;
LIST_ENTRY(gconsumer) consumer;
struct gprovider *provider;
LIST_ENTRY(gconsumer) consumers;
char *mode;
struct gconf config;
void *lg_id;
struct ggeom *lg_geom;
LIST_ENTRY(gconsumer) lg_consumer;
struct gprovider *lg_provider;
LIST_ENTRY(gconsumer) lg_consumers;
char *lg_mode;
struct gconf lg_config;
};
struct gprovider {
void *id;
char *name;
struct ggeom *geom;
LIST_ENTRY(gprovider) provider;
LIST_HEAD(, gconsumer) consumers;
char *mode;
off_t mediasize;
u_int sectorsize;
struct gconf config;
void *lg_id;
char *lg_name;
struct ggeom *lg_geom;
LIST_ENTRY(gprovider) lg_provider;
LIST_HEAD(, gconsumer) lg_consumers;
char *lg_mode;
off_t lg_mediasize;
u_int lg_sectorsize;
struct gconf lg_config;
};
struct gident * geom_lookupid(struct gmesh *gmp, const void *id);
@ -140,4 +144,6 @@ const char *gctl_issue(struct gctl_req *req);
void gctl_ro_param(struct gctl_req *req, const char *name, int len, const void* val);
void gctl_rw_param(struct gctl_req *req, const char *name, int len, void* val);
__END_DECLS
#endif /* _LIBGEOM_H_ */

View File

@ -379,8 +379,8 @@ find_class(struct gmesh *mesh, const char *name)
{
struct gclass *class;
LIST_FOREACH(class, &mesh->class, class) {
if (strcmp(class->name, name) == 0)
LIST_FOREACH(class, &mesh->lg_class, lg_class) {
if (strcmp(class->lg_name, name) == 0)
return (class);
}
@ -392,9 +392,9 @@ get_conf(struct ggeom *gp, const char *name)
{
struct gconfig *conf;
LIST_FOREACH(conf, &gp->config, config) {
if (strcmp(conf->name, name) == 0)
return (conf->val);
LIST_FOREACH(conf, &gp->lg_config, lg_config) {
if (strcmp(conf->lg_name, name) == 0)
return (conf->lg_val);
}
return (NULL);
@ -406,19 +406,19 @@ show_config(struct ggeom *gp)
struct gprovider *pp;
struct gconsumer *cp;
pp = LIST_FIRST(&gp->provider);
pp = LIST_FIRST(&gp->lg_provider);
if (pp == NULL)
return;
printf(" NAME: %s\n", pp->name);
printf(" NAME: %s\n", pp->lg_name);
printf(" id: %s\n", get_conf(gp, "id"));
printf(" type: %s\n", get_conf(gp, "type"));
printf(" mediasize: %jd\n", pp->mediasize);
printf("sectorsize: %u\n", pp->sectorsize);
printf(" mode: %s\n", pp->mode);
printf(" mediasize: %jd\n", pp->lg_mediasize);
printf("sectorsize: %u\n", pp->lg_sectorsize);
printf(" mode: %s\n", pp->lg_mode);
printf(" providers:");
LIST_FOREACH(cp, &gp->consumer, consumer) {
printf(" %s", cp->provider->name);
LIST_FOREACH(cp, &gp->lg_consumer, lg_consumer) {
printf(" %s", cp->lg_provider->lg_name);
}
printf("\n");
}
@ -441,7 +441,7 @@ concat_list(void)
exit(EXIT_SUCCESS);
}
LIST_FOREACH(gp, &class->geom, geom) {
LIST_FOREACH(gp, &class->lg_geom, lg_geom) {
show_config(gp);
}

View File

@ -162,7 +162,8 @@ main(int argc, char **argv)
}
if (gid == NULL)
continue;
if (gid != NULL && gid->what == ISCONSUMER && !flag_c)
if (gid != NULL && gid->lg_what == ISCONSUMER &&
!flag_c)
continue;
if (gsp->sequence0 != gsp->sequence1) {
printw("*\n");
@ -213,15 +214,15 @@ main(int argc, char **argv)
printw("|");
if (gid == NULL) {
printw(" ??");
} else if (gid->what == ISPROVIDER) {
pp = gid->ptr;
printw(" %s", pp->name);
} else if (gid->what == ISCONSUMER) {
cp = gid->ptr;
} else if (gid->lg_what == ISPROVIDER) {
pp = gid->lg_ptr;
printw(" %s", pp->lg_name);
} else if (gid->lg_what == ISCONSUMER) {
cp = gid->lg_ptr;
printw(" %s/%s/%s",
cp->geom->class->name,
cp->geom->name,
cp->provider->name);
cp->lg_geom->lg_class->lg_name,
cp->lg_geom->lg_name,
cp->lg_provider->lg_name);
}
clrtoeol();
printw("\n");