freebsd-dev/lib/libgeom/libgeom.3

259 lines
7.1 KiB
Groff
Raw Normal View History

.\" 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$
.\"
2004-07-01 18:20:57 +00:00
.Dd March 7, 2004
.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 ,
.Nm gctl_get_handle ,
.Nm gctl_ro_param ,
.Nm gctl_rw_param ,
.Nm gctl_issue ,
.Nm gctl_free ,
.Nm gctl_dump
.Nd userland API library for kernel GEOM subsystem
.Sh LIBRARY
.Lb libgeom
.Sh SYNOPSIS
.In libgeom.h
2003-02-24 22:53:26 +00:00
.Ss "Statistics Functions"
.Ft void
.Fn geom_stats_close void
.Ft int
.Fn geom_stats_open void
.Ft void
.Fn geom_stats_resync void
2003-02-24 22:53:26 +00:00
.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"
2003-02-24 22:53:26 +00:00
.Ft "struct g_stat *"
.Fn geom_stats_snapshot_next "void *arg"
.Ss "Control Functions"
.Ft "struct gctl_req *"
.Fn gctl_get_handle "void"
.Ft void
.Fn gctl_ro_param "struct gctl_req *req" "const char *name" "int len" "const void *value"
.Ft void
.Fn gctl_rw_param "struct gctl_req *req" "const char *name" "int len" "void *value"
.Ft "const char *"
.Fn gctl_issue "struct gctl_req *req"
.Ft void
.Fn gctl_free "struct gctl_req *req"
.Ft void
.Fn gctl_dump "struct gctl_req *req" "FILE *f"
.Sh DESCRIPTION
2003-02-24 22:53:26 +00:00
The
.Nm geom
library contains the official and publicized API for
interacting with the GEOM subsystem in the kernel.
2003-02-24 22:53:26 +00:00
.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
2003-02-24 22:53:26 +00:00
and
.Fn geom_stats_close
2003-02-24 22:53:26 +00:00
functions open and close 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 file descriptors locally.
2003-06-18 19:43:17 +00:00
The
.Fn geom_stats_open
2003-06-18 19:43:17 +00:00
function returns zero on success, and sets
2003-02-24 22:53:26 +00:00
.Va 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
2003-02-24 22:53:26 +00:00
The
.Fn geom_stats_snapshot_get
2003-02-24 22:53:26 +00:00
function
will acquire 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.
2003-06-18 19:43:17 +00:00
The
.Fn geom_stats_snapshot_get
2003-06-18 19:43:17 +00:00
function returns
2003-02-24 22:53:26 +00:00
.Dv NULL
on failure.
.Pp
2003-02-24 22:53:26 +00:00
The
.Fn geom_stats_snapshot_timestamp
2003-02-24 22:53:26 +00:00
function
provides access to the timestamp acquired in the snapshot.
.Pp
2003-02-24 22:53:26 +00:00
The
.Fn geom_stats_snapshot_reset
and
.Fn geom_stats_snapshot_next
2003-02-24 22:53:26 +00:00
functions
provide an iterator over the statistics slots in the snapshot.
The
.Fn geom_stats_snapshot_reset
2003-02-24 22:53:26 +00:00
function
forces the internal pointer in the snapshot back to before the first item.
2003-02-24 22:53:26 +00:00
The
.Fn geom_stats_snapshot_next
2003-02-24 22:53:26 +00:00
function
returns the next item, and
.Dv NULL
if there are no more items in the snapshot.
.Ss "Control Functions"
The
.Fn gctl_*
2004-07-01 18:20:57 +00:00
functions are used to send requests to GEOM classes.
In order for a GEOM
class to actually be able to receive these requests, it must have defined a
"ctlreq" method.
.Pp
A
2004-07-01 18:20:57 +00:00
.Vt "struct gctl_req *" ,
obtained with
.Fn gctl_get_handle ,
can hold any number of parameters, which must be added to it with
.Fn gctl_ro_param
(for read-only parameters) or
.Fn gctl_rw_param
(for read/write parameters).
.Pp
Both
.Fn gctl_ro_param
and
.Fn gctl_rw_param
take a string
2004-07-01 18:20:57 +00:00
.Fa name ,
which is used to identify the parameter, and a
2004-07-01 18:20:57 +00:00
.Fa value ,
which contains, in the read-only case, the data to be passed to the
GEOM class, or, in the read/write case, a pointer to preallocated memory
that the GEOM class should fill with the desired data.
If
.Fa len
is negative, it is assumed that
2004-07-01 18:20:57 +00:00
.Fa value
is an
.Tn ASCII
string and the actual length is taken from the string length of
.Fa value ;
otherwise it must hold the size of
2004-07-01 18:20:57 +00:00
.Fa value .
.Pp
A parameter with a
2004-07-01 18:20:57 +00:00
.Fa name
containing the string
.Qq Li class
is mandatory for each request, and the
corresponding
2004-07-01 18:20:57 +00:00
.Fa value
must hold the name of the GEOM class where the request should be sent to.
.Pp
Also mandatory for each request is a parameter with a
2004-07-01 18:20:57 +00:00
.Fa name
called
.Qq Li verb ,
and the corresponding
.Fa value
needs to hold the command string that the GEOM class should react upon.
.Pp
Once all desired parameters are filled in, the request must be sent to
the GEOM subsystem with
.Fn gctl_issue ,
2004-07-01 18:20:57 +00:00
which returns
.Dv NULL
on success, or a string containing the error message
on failure.
.Pp
After the request is finished, the allocated memory should be released with
.Fn gctl_free .
.Pp
2004-07-01 18:20:57 +00:00
The
.Fn gctl_dump
2004-07-01 18:20:57 +00:00
function
can be used to format the contents of
2004-07-01 18:20:57 +00:00
.Fa req
to the open file handle pointed to by
2004-07-01 18:20:57 +00:00
.Fa f ,
for debugging purposes.
.Pp
Error handling for the control functions is postponed until the call
2004-07-01 18:20:57 +00:00
to
.Fn gctl_issue ,
which returns
.Dv NULL
on success, or an error message corresponding to the
first error which happened.
.Sh EXAMPLES
2004-07-01 18:20:57 +00:00
Create a request that is to be sent to the CCD class, and tell
it to destroy a specific geom:
.Bd -literal -offset indent
H = gctl_get_handle();
gctl_ro_param(H, "verb", -1, "destroy geom");
gctl_ro_param(H, "class", -1, "CCD");
sprintf(buf, "ccd%d", ccd);
gctl_ro_param(H, "geom", -1, buf);
errstr = gctl_issue(H);
if (errstr != NULL)
2004-07-01 18:20:57 +00:00
err(1, "could not destroy ccd: %s", errstr);
gctl_free(H);
.Ed
.Sh SEE ALSO
2004-07-01 18:20:57 +00:00
.Pa http://ezine.daemonnews.org/200308/blueprints.html
.Sh HISTORY
2003-02-24 22:53:26 +00:00
The
.Nm geom
2003-02-24 22:53:26 +00:00
library appeared in
.Fx 5.1 .
.Sh AUTHORS
.An Poul-Henning Kamp Aq phk@FreeBSD.org
.An Lukas Ertl Aq le@FreeBSD.org