diff options
Diffstat (limited to 'lib/libgeom')
-rw-r--r-- | lib/libgeom/Makefile | 25 | ||||
-rw-r--r-- | lib/libgeom/geom_getxml.c | 66 | ||||
-rw-r--r-- | lib/libgeom/geom_stats.c | 185 | ||||
-rw-r--r-- | lib/libgeom/geom_xml2tree.c | 428 | ||||
-rw-r--r-- | lib/libgeom/libgeom.3 | 117 | ||||
-rw-r--r-- | lib/libgeom/libgeom.h | 129 |
6 files changed, 950 insertions, 0 deletions
diff --git a/lib/libgeom/Makefile b/lib/libgeom/Makefile new file mode 100644 index 0000000..120919d --- /dev/null +++ b/lib/libgeom/Makefile @@ -0,0 +1,25 @@ +# $FreeBSD$ + +LIB= geom +SRCS+= geom_getxml.c +SRCS+= geom_stats.c +SRCS+= geom_xml2tree.c +INCS= libgeom.h + +CFLAGS += -I${.CURDIR} + +WARNS?= 3 + +MAN= libgeom.3 + +MLINKS+= \ + libgeom.3 geom_stats_open.3 \ + libgeom.3 geom_stats_close.3 \ + libgeom.3 geom_stats_resync.3 \ + libgeom.3 geom_stats_snapshot_get.3 \ + libgeom.3 geom_stats_snapshot_free.3 \ + libgeom.3 geom_stats_snapshot_timestamp.3 \ + libgeom.3 geom_stats_snapshot_reset.3 \ + libgeom.3 geom_stats_snapshot_next.3 + +.include <bsd.lib.mk> diff --git a/lib/libgeom/geom_getxml.c b/lib/libgeom/geom_getxml.c new file mode 100644 index 0000000..fbc9cb8 --- /dev/null +++ b/lib/libgeom/geom_getxml.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2003 Poul-Henning Kamp + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include <sys/types.h> +#include <sys/sysctl.h> +#include <stdlib.h> +#include <string.h> +#include "libgeom.h" + +char * +geom_getxml() +{ + char *p; + size_t l; + int i; + + l = 1024 * 1024; /* Start big, realloc back */ + p = malloc(l); + if (p) { + i = sysctlbyname("kern.geom.confxml", p, &l, NULL, 0); + if (i == 0) { + p = realloc(p, strlen(p) + 1); + return (p); + } + free(p); + } + l = 0; + i = sysctlbyname("kern.geom.confxml", p, &l, NULL, 0); + if (i != 0) + return (NULL); + p = malloc(l + 4096); + i = sysctlbyname("kern.geom.confxml", p, &l, NULL, 0); + if (i == 0) { + p = realloc(p, strlen(p) + 1); + return (p); + } + return (NULL); +} diff --git a/lib/libgeom/geom_stats.c b/lib/libgeom/geom_stats.c new file mode 100644 index 0000000..9f9faf2 --- /dev/null +++ b/lib/libgeom/geom_stats.c @@ -0,0 +1,185 @@ +/*- + * Copyright (c) 2003 Poul-Henning Kamp + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include <paths.h> +#include <errno.h> +#include <fcntl.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <libgeom.h> + +#include <sys/mman.h> +#include <sys/time.h> +#include <sys/types.h> + +#include <geom/geom_stats.h> + +/************************************************************/ +static uint npages, pagesize, spp; +static int statsfd = -1; +static u_char *statp; + +void +geom_stats_close(void) +{ + if (statsfd == -1) + return; + munmap(statp, npages *pagesize); + statp = NULL; + close (statsfd); + statsfd = -1; +} + +void +geom_stats_resync(void) +{ + void *p; + + if (statsfd == -1) + return; + for (;;) { + p = mmap(statp, (npages + 1) * pagesize, + PROT_READ, 0, statsfd, 0); + if (p == MAP_FAILED) + break; + else + statp = p; + npages++; + } +} + +int +geom_stats_open(void) +{ + int error; + void *p; + + if (statsfd != -1) + return (EBUSY); + statsfd = open(_PATH_DEV GEOM_STATS_DEVICE, O_RDONLY); + if (statsfd < 0) + return (errno); + pagesize = getpagesize(); + spp = pagesize / sizeof(struct g_stat); + p = mmap(NULL, pagesize, PROT_READ, 0, statsfd, 0); + if (p == MAP_FAILED) { + error = errno; + close(statsfd); + statsfd = -1; + errno = error; + return (error); + } + statp = p; + npages = 1; + geom_stats_resync(); + return (0); +} + +struct snapshot { + u_char *ptr; + uint pages; + uint pagesize; + uint perpage; + struct timespec time; + /* used by getnext: */ + uint u, v; +}; + +void * +geom_stats_snapshot_get(void) +{ + struct snapshot *sp; + + sp = malloc(sizeof *sp); + if (sp == NULL) + return (NULL); + memset(sp, 0, sizeof *sp); + sp->ptr = malloc(pagesize * npages); + if (sp->ptr == NULL) { + free(sp); + return (NULL); + } + memset(sp->ptr, 0, pagesize * npages); /* page in, cache */ + clock_gettime(CLOCK_REALTIME, &sp->time); + memset(sp->ptr, 0, pagesize * npages); /* page in, cache */ + memcpy(sp->ptr, statp, pagesize * npages); + sp->pages = npages; + sp->perpage = spp; + sp->pagesize = pagesize; + return (sp); +} + +void +geom_stats_snapshot_free(void *arg) +{ + struct snapshot *sp; + + sp = arg; + free(sp->ptr); + free(sp); +} + +void +geom_stats_snapshot_timestamp(void *arg, struct timespec *tp) +{ + struct snapshot *sp; + + sp = arg; + *tp = sp->time; +} + +void +geom_stats_snapshot_reset(void *arg) +{ + struct snapshot *sp; + + sp = arg; + sp->u = sp->v = 0; +} + +struct g_stat * +geom_stats_snapshot_next(void *arg) +{ + struct g_stat *gsp; + struct snapshot *sp; + + sp = arg; + gsp = (struct g_stat *) + (sp->ptr + sp->u * pagesize + sp->v * sizeof *gsp); + if (++sp->v >= sp->perpage) { + if (++sp->u >= sp->pages) + return (NULL); + else + sp->v = 0; + } + return (gsp); +} diff --git a/lib/libgeom/geom_xml2tree.c b/lib/libgeom/geom_xml2tree.c new file mode 100644 index 0000000..277dda6 --- /dev/null +++ b/lib/libgeom/geom_xml2tree.c @@ -0,0 +1,428 @@ +/*- + * Copyright (c) 2003 Poul-Henning Kamp + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include <stdio.h> +#include <inttypes.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <fcntl.h> +#include <ctype.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/queue.h> +#include <sys/sbuf.h> +#include <sys/sysctl.h> +#include <err.h> +#include <bsdxml.h> +#include <libgeom.h> + +struct mystate { + struct gmesh *mesh; + struct gclass *class; + struct ggeom *geom; + struct gprovider *provider; + struct gconsumer *consumer; + int level; + struct sbuf *sbuf[20]; + struct gconf *config; + int nident; +}; + +static void +StartElement(void *userData, const char *name, const char **attr) +{ + struct mystate *mt; + void *id; + void *ref; + int i; + + mt = userData; + mt->level++; + mt->sbuf[mt->level] = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + id = NULL; + for (i = 0; attr[i] != NULL; i += 2) { + if (!strcmp(attr[i], "id")) { + id = (void *)strtoul(attr[i + 1], NULL, 0); + mt->nident++; + } else if (!strcmp(attr[i], "ref")) { + ref = (void *)strtoul(attr[i + 1], NULL, 0); + } else + printf("%*.*s[%s = %s]\n", + mt->level + 1, mt->level + 1, "", + attr[i], attr[i + 1]); + } + 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); + 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); + return; + } + if (!strcmp(name, "class") && mt->geom != NULL) { + mt->geom->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); + return; + } + if (!strcmp(name, "geom") && mt->consumer != NULL) { + mt->consumer->geom = ref; + return; + } + if (!strcmp(name, "provider") && mt->consumer != NULL) { + mt->consumer->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); + return; + } + if (!strcmp(name, "geom") && mt->provider != NULL) { + mt->provider->geom = ref; + return; + } + if (!strcmp(name, "config")) { + if (mt->provider != NULL) { + mt->config = &mt->provider->config; + return; + } + if (mt->consumer != NULL) { + mt->config = &mt->consumer->config; + return; + } + if (mt->geom != NULL) { + mt->config = &mt->geom->config; + return; + } + if (mt->class != NULL) { + mt->config = &mt->class->config; + return; + } + } +} + +static void +EndElement(void *userData, const char *name) +{ + struct mystate *mt; + struct gconfig *gc; + char *p; + + mt = userData; + sbuf_finish(mt->sbuf[mt->level]); + p = strdup(sbuf_data(mt->sbuf[mt->level])); + sbuf_delete(mt->sbuf[mt->level]); + mt->sbuf[mt->level] = NULL; + mt->level--; + if (strlen(p) == 0) { + free(p); + p = NULL; + } + + if (!strcmp(name, "name")) { + if (mt->provider != NULL) { + mt->provider->name = p; + return; + } else if (mt->geom != NULL) { + mt->geom->name = p; + return; + } else if (mt->class != NULL) { + mt->class->name = p; + return; + } + } + if (!strcmp(name, "rank") && mt->geom != NULL) { + mt->geom->rank = strtoul(p, NULL, 0); + free(p); + return; + } + if (!strcmp(name, "mode") && mt->provider != NULL) { + mt->provider->mode = p; + return; + } + if (!strcmp(name, "mode") && mt->consumer != NULL) { + mt->consumer->mode = p; + return; + } + if (!strcmp(name, "mediasize") && mt->provider != NULL) { + mt->provider->mediasize = strtoumax(p, NULL, 0); + free(p); + return; + } + if (!strcmp(name, "sectorsize") && mt->provider != NULL) { + mt->provider->sectorsize = strtoul(p, NULL, 0); + free(p); + return; + } + + if (!strcmp(name, "config")) { + mt->config = NULL; + return; + } + + if (mt->config != NULL) { + gc = calloc(sizeof *gc, 1); + gc->name = strdup(name); + gc->val = p; + LIST_INSERT_HEAD(mt->config, gc, config); + return; + } + + if (p != NULL) { +printf("<<<%s>>>\n", p); + free(p); + } + + if (!strcmp(name, "consumer") && mt->consumer != NULL) { + mt->consumer = NULL; + return; + } + if (!strcmp(name, "provider") && mt->provider != NULL) { + mt->provider = NULL; + return; + } + if (!strcmp(name, "geom") && mt->consumer != NULL) { + return; + } + if (!strcmp(name, "geom") && mt->provider != NULL) { + return; + } + if (!strcmp(name, "geom") && mt->geom != NULL) { + mt->geom = NULL; + return; + } + if (!strcmp(name, "class") && mt->geom != NULL) { + return; + } + if (!strcmp(name, "class") && mt->class != NULL) { + mt->class = NULL; + return; + } +} + +static void +CharData(void *userData , const XML_Char *s , int len) +{ + struct mystate *mt; + const char *b, *e; + + mt = userData; + + b = s; + e = s + len - 1; + while (isspace(*b) && b < e) + b++; + while (isspace(*e) && e > b) + e--; + if (e != b || (*b && !isspace(*b))) + sbuf_bcat(mt->sbuf[mt->level], b, e - b + 1); +} + +struct gident * +geom_lookupid(struct gmesh *gmp, void *id) +{ + struct gident *gip; + + for (gip = gmp->ident; gip->id != NULL; gip++) + if (gip->id == id) + return (gip); + return (NULL); +} + +int +geom_xml2tree(struct gmesh *gmp, char *p) +{ + XML_Parser parser; + struct mystate *mt; + struct gclass *cl; + struct ggeom *ge; + struct gprovider *pr; + struct gconsumer *co; + int i; + + memset(gmp, 0, sizeof *gmp); + LIST_INIT(&gmp->class); + parser = XML_ParserCreate(NULL); + mt = calloc(1, sizeof *mt); + if (mt == NULL) + return (ENOMEM); + mt->mesh = gmp; + XML_SetUserData(parser, mt); + XML_SetElementHandler(parser, StartElement, EndElement); + XML_SetCharacterDataHandler(parser, CharData); + i = XML_Parse(parser, p, strlen(p), 1); + if (i != 1) + return (-1); + XML_ParserFree(parser); + gmp->ident = calloc(sizeof *gmp->ident, mt->nident + 1); + if (gmp->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; + i++; + LIST_FOREACH(ge, &cl->geom, geom) { + gmp->ident[i].id = ge->id; + gmp->ident[i].ptr = ge; + gmp->ident[i].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; + i++; + } + LIST_FOREACH(co, &ge->consumer, consumer) { + gmp->ident[i].id = co->id; + gmp->ident[i].ptr = co; + gmp->ident[i].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(co, &ge->consumer, consumer) { + co->geom = geom_lookupid(gmp, co->geom)->ptr; + if (co->provider != NULL) + co->provider = + geom_lookupid(gmp, co->provider)->ptr; + } + } + } + return (0); +} + +int +geom_gettree(struct gmesh *gmp) +{ + char *p; + int error; + + p = geom_getxml(); + error = geom_xml2tree(gmp, p); + free(p); + return (error); +} + +static void +delete_config(struct gconf *gp) +{ + struct gconfig *cf; + + for (;;) { + cf = LIST_FIRST(gp); + if (cf == NULL) + return; + LIST_REMOVE(cf, config); + free(cf->name); + free(cf->val); + free(cf); + } +} + +void +geom_deletetree(struct gmesh *gmp) +{ + struct gclass *cl; + struct ggeom *ge; + struct gprovider *pr; + struct gconsumer *co; + + free(gmp->ident); + gmp->ident = NULL; + for (;;) { + cl = LIST_FIRST(&gmp->class); + if (cl == NULL) + break; + LIST_REMOVE(cl, class); + delete_config(&cl->config); + if (cl->name) free(cl->name); + for (;;) { + ge = LIST_FIRST(&cl->geom); + if (ge == NULL) + break; + LIST_REMOVE(ge, geom); + delete_config(&ge->config); + if (ge->name) free(ge->name); + for (;;) { + pr = LIST_FIRST(&ge->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); + free(pr); + } + for (;;) { + co = LIST_FIRST(&ge->consumer); + if (co == NULL) + break; + LIST_REMOVE(co, consumer); + delete_config(&co->config); + if (co->mode) free(co->mode); + free(co); + } + free(ge); + } + free(cl); + } +} diff --git a/lib/libgeom/libgeom.3 b/lib/libgeom/libgeom.3 new file mode 100644 index 0000000..78622a0 --- /dev/null +++ b/lib/libgeom/libgeom.3 @@ -0,0 +1,117 @@ +.\" Copyright (c) 2003 Poul-Henning Kamp +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The names of the authors may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd February 8, 2003 +.Dt LIBGEOM 3 +.Os +.Sh NAME +.Nm geom_stats_open , +.Nm geom_stats_close , +.Nm geom_stats_resync , +.Nm geom_stats_snapshot_get , +.Nm geom_stats_snapshot_free , +.Nm geom_stats_snapshot_timestamp , +.Nm geom_stats_snapshot_reset , +.Nm geom_stats_snapshot_next +.Nd userland API library for kernel GEOM subsystem +.Sh LIBRARY +.Lb libgeom +.Sh SYNOPSIS +.In libgeom.h +.Ss "Statistics functions" +.Ft void +.Fn geom_stats_close void +.Ft int +.Fn geom_stats_open void +.Ft void +.Fn geom_stats_resync void +.Ft void * +.Fn geom_stats_snapshot_get void +.Ft void +.Fn geom_stats_snapshot_free "void *arg" +.Ft void +.Fn geom_stats_snapshot_timestamp "void *arg" "struct timespec *tp" +.Ft void +.Fn geom_stats_snapshot_reset "void *arg" +.Ft struct g_stat * +.Fn geom_stats_snapshot_next "void *arg" +.Sh DESCRIPTION +.Nm Libgeom +is the library which contains the official and publicized API for +interacting with the GEOM subsystem in the kernel. +.Ss "Statistics functions" +GEOM collects statistics data for all consumers and providers, but does +not perform any normalization or presentation on the raw data, this is +left as an excercize for user-land presentation utilities. +.Pp +The +.Fn geom_stats_open +and +.Fn geom_stats_close +functions opens and closes the necessary pathways to access the raw +statistics information in the kernel. These functions are likely to +open one or more files and cache the filedescriptors locally. +.Fn geom_stats_open +returns zero on success, and sets errno if not. +.Pp +The +.Fn geom_stats_resync +function will check if more statistics collection points have been +added in the kernel since +.Fn geom_stats_open +or the previous call to +.Fn geom_stats_resync . +.Pp +.Fn geom_stats_snapshot_get +will aquire a snapshot of the raw data from the kernel and while a +reasonable effort is made to make this snapshot as atomic and consistent +as possible, no guarantee is given that it will actually be so. +The snapshot must be freed again using the +.Fn geom_stats_snapshot_free +function. +.Fn geom_stats_snapshot_get +returns NULL on failure. +.Pp +.Fn geom_stats_snapshot_timestamp +provides access to the timestamp aquired in the snapshot. +.Pp +.Fn geom_stats_snapshot_reset +and +.Fn geom_stats_snapshot_next +provides an iterator over the statistics slots in the snapshot. +.Fn geom_stats_snapshot_reset +forces the internal pointer in the snapshot back to before the first item. +.Fn geom_stats_snapshot_next +returns the next item and NULL if there are no more items in the snapshot. +.Sh AUTHORS +.An Poul-Henning Kamp Aq phk@FreeBSD.org +.Sh HISTORY +.Nm geom +library appeard in +.Fx 5.1 . diff --git a/lib/libgeom/libgeom.h b/lib/libgeom/libgeom.h new file mode 100644 index 0000000..130ac36 --- /dev/null +++ b/lib/libgeom/libgeom.h @@ -0,0 +1,129 @@ +/*- + * Copyright (c) 2003 Poul-Henning Kamp + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _LIBGEOM_H_ +#define _LIBGEOM_H_ + +#include <sys/queue.h> +#include <sys/time.h> +#include <geom/geom_stats.h> + +void geom_stats_close(void); +void geom_stats_resync(void); +int geom_stats_open(void); +void *geom_stats_snapshot_get(void); +void geom_stats_snapshot_free(void *arg); +void geom_stats_snapshot_timestamp(void *arg, struct timespec *tp); +void geom_stats_snapshot_reset(void *arg); +struct g_stat *geom_stats_snapshot_next(void *arg); + +char *geom_getxml(void); + +/* geom_xml2tree.c */ + +/* + * These structs are used to build the tree based on the XML. + * they're named as the kernel variant without the first '_'. + */ + +struct gclass; +struct ggeom; +struct gconsumer; +struct gprovider; + +LIST_HEAD(gconf, gconfig); + +struct gident { + void *id; + void *ptr; + enum { ISCLASS, + ISGEOM, + ISPROVIDER, + ISCONSUMER } what; +}; + +struct gmesh { + LIST_HEAD(, gclass) class; + struct gident *ident; +}; + +struct gconfig { + LIST_ENTRY(gconfig) config; + char *name; + char *val; +}; + +struct gclass { + void *id; + char *name; + LIST_ENTRY(gclass) class; + LIST_HEAD(, ggeom) geom; + struct gconf 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; +}; + +struct gconsumer { + void *id; + struct ggeom *geom; + LIST_ENTRY(gconsumer) consumer; + struct gprovider *provider; + LIST_ENTRY(gconsumer) consumers; + char *mode; + struct gconf 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; +}; + +struct gident * geom_lookupid(struct gmesh *gmp, void *id); +int geom_xml2tree(struct gmesh *gmp, char *p); +int geom_gettree(struct gmesh *gmp); +void geom_deletetree(struct gmesh *gmp); + +#endif /* _LIBGEOM_H_ */ |