xref: /freebsd/lib/libgeom/libgeom.3 (revision 5e5bfe775762511630afddae75a68bb98204e1c2)
1e13db587SPoul-Henning Kamp.\" Copyright (c) 2003 Poul-Henning Kamp
2e13db587SPoul-Henning Kamp.\" All rights reserved.
3e13db587SPoul-Henning Kamp.\"
4e13db587SPoul-Henning Kamp.\" Redistribution and use in source and binary forms, with or without
5e13db587SPoul-Henning Kamp.\" modification, are permitted provided that the following conditions
6e13db587SPoul-Henning Kamp.\" are met:
7e13db587SPoul-Henning Kamp.\" 1. Redistributions of source code must retain the above copyright
8e13db587SPoul-Henning Kamp.\"    notice, this list of conditions and the following disclaimer.
9e13db587SPoul-Henning Kamp.\" 2. Redistributions in binary form must reproduce the above copyright
10e13db587SPoul-Henning Kamp.\"    notice, this list of conditions and the following disclaimer in the
11e13db587SPoul-Henning Kamp.\"    documentation and/or other materials provided with the distribution.
12e13db587SPoul-Henning Kamp.\" 3. The names of the authors may not be used to endorse or promote
13e13db587SPoul-Henning Kamp.\"    products derived from this software without specific prior written
14e13db587SPoul-Henning Kamp.\"    permission.
15e13db587SPoul-Henning Kamp.\"
16e13db587SPoul-Henning Kamp.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17e13db587SPoul-Henning Kamp.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18e13db587SPoul-Henning Kamp.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19e13db587SPoul-Henning Kamp.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20e13db587SPoul-Henning Kamp.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21e13db587SPoul-Henning Kamp.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22e13db587SPoul-Henning Kamp.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23e13db587SPoul-Henning Kamp.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24e13db587SPoul-Henning Kamp.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25e13db587SPoul-Henning Kamp.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26e13db587SPoul-Henning Kamp.\" SUCH DAMAGE.
27e13db587SPoul-Henning Kamp.\"
28e13db587SPoul-Henning Kamp.\" $FreeBSD$
29e13db587SPoul-Henning Kamp.\"
30e13db587SPoul-Henning Kamp.Dd February 8, 2003
31e13db587SPoul-Henning Kamp.Dt LIBGEOM 3
32e13db587SPoul-Henning Kamp.Os
33e13db587SPoul-Henning Kamp.Sh NAME
34e13db587SPoul-Henning Kamp.Nm geom_stats_open ,
35e13db587SPoul-Henning Kamp.Nm geom_stats_close ,
36e13db587SPoul-Henning Kamp.Nm geom_stats_resync ,
37e13db587SPoul-Henning Kamp.Nm geom_stats_snapshot_get ,
38e13db587SPoul-Henning Kamp.Nm geom_stats_snapshot_free ,
39e13db587SPoul-Henning Kamp.Nm geom_stats_snapshot_timestamp ,
40e13db587SPoul-Henning Kamp.Nm geom_stats_snapshot_reset ,
415e5bfe77SPoul-Henning Kamp.Nm geom_stats_snapshot_next ,
425e5bfe77SPoul-Henning Kamp.Nm gctl_get_handle ,
435e5bfe77SPoul-Henning Kamp.Nm gctl_ro_param ,
445e5bfe77SPoul-Henning Kamp.Nm gctl_rw_param ,
455e5bfe77SPoul-Henning Kamp.Nm gctl_issue ,
465e5bfe77SPoul-Henning Kamp.Nm gctl_free ,
475e5bfe77SPoul-Henning Kamp.Nm gctl_dump
483fe5cc64SAlexey Zelkin.Nd userland API library for kernel GEOM subsystem
49e13db587SPoul-Henning Kamp.Sh LIBRARY
503fe5cc64SAlexey Zelkin.Lb libgeom
51e13db587SPoul-Henning Kamp.Sh SYNOPSIS
52e13db587SPoul-Henning Kamp.In libgeom.h
53ace5be68SRuslan Ermilov.Ss "Statistics Functions"
54e13db587SPoul-Henning Kamp.Ft void
55e13db587SPoul-Henning Kamp.Fn geom_stats_close void
56e13db587SPoul-Henning Kamp.Ft int
57e13db587SPoul-Henning Kamp.Fn geom_stats_open void
58e13db587SPoul-Henning Kamp.Ft void
59e13db587SPoul-Henning Kamp.Fn geom_stats_resync void
60ace5be68SRuslan Ermilov.Ft "void *"
61e13db587SPoul-Henning Kamp.Fn geom_stats_snapshot_get void
62e13db587SPoul-Henning Kamp.Ft void
63e13db587SPoul-Henning Kamp.Fn geom_stats_snapshot_free "void *arg"
64e13db587SPoul-Henning Kamp.Ft void
65e13db587SPoul-Henning Kamp.Fn geom_stats_snapshot_timestamp "void *arg" "struct timespec *tp"
66e13db587SPoul-Henning Kamp.Ft void
67e13db587SPoul-Henning Kamp.Fn geom_stats_snapshot_reset "void *arg"
68ace5be68SRuslan Ermilov.Ft "struct g_stat *"
69e13db587SPoul-Henning Kamp.Fn geom_stats_snapshot_next "void *arg"
705e5bfe77SPoul-Henning Kamp.Ss "Control Functions"
715e5bfe77SPoul-Henning Kamp.Ft "struct gctl_req *"
725e5bfe77SPoul-Henning Kamp.Fn gctl_get_handle "void"
735e5bfe77SPoul-Henning Kamp.Ft void
745e5bfe77SPoul-Henning Kamp.Fn gctl_ro_param "struct gctl_req *req" "const char *name" "int len" "const void *value"
755e5bfe77SPoul-Henning Kamp.Ft void
765e5bfe77SPoul-Henning Kamp.Fn gctl_rw_param "struct gctl_req *req" "const char *name" "int len" "void *value"
775e5bfe77SPoul-Henning Kamp.Ft "const char *"
785e5bfe77SPoul-Henning Kamp.Fn gctl_issue "struct gctl_req *req"
795e5bfe77SPoul-Henning Kamp.Ft void
805e5bfe77SPoul-Henning Kamp.Fn gctl_free "struct gctl_req *req"
815e5bfe77SPoul-Henning Kamp.Ft void
825e5bfe77SPoul-Henning Kamp.Fn gctl_dump "struct gctl_req *req" "FILE *f"
83e13db587SPoul-Henning Kamp.Sh DESCRIPTION
84ace5be68SRuslan ErmilovThe
85ace5be68SRuslan Ermilov.Nm geom
86ace5be68SRuslan Ermilovlibrary contains the official and publicized API for
87e13db587SPoul-Henning Kampinteracting with the GEOM subsystem in the kernel.
88ace5be68SRuslan Ermilov.Ss "Statistics Functions"
89e13db587SPoul-Henning KampGEOM collects statistics data for all consumers and providers, but does
90e13db587SPoul-Henning Kampnot perform any normalization or presentation on the raw data, this is
91e13db587SPoul-Henning Kampleft as an excercize for user-land presentation utilities.
92e13db587SPoul-Henning Kamp.Pp
93e13db587SPoul-Henning KampThe
943fe5cc64SAlexey Zelkin.Fn geom_stats_open
95e13db587SPoul-Henning Kampand
963fe5cc64SAlexey Zelkin.Fn geom_stats_close
97ace5be68SRuslan Ermilovfunctions open and close the necessary pathways to access the raw
98ace5be68SRuslan Ermilovstatistics information in the kernel.
99ace5be68SRuslan ErmilovThese functions are likely to
100e13db587SPoul-Henning Kampopen one or more files and cache the file descriptors locally.
101b160a51eSPhilippe CharnierThe
1023fe5cc64SAlexey Zelkin.Fn geom_stats_open
103b160a51eSPhilippe Charnierfunction returns zero on success, and sets
104ace5be68SRuslan Ermilov.Va errno
105ace5be68SRuslan Ermilovif not.
106e13db587SPoul-Henning Kamp.Pp
107e13db587SPoul-Henning KampThe
1083fe5cc64SAlexey Zelkin.Fn geom_stats_resync
109e13db587SPoul-Henning Kampfunction will check if more statistics collection points have been
110e13db587SPoul-Henning Kampadded in the kernel since
1113fe5cc64SAlexey Zelkin.Fn geom_stats_open
112e13db587SPoul-Henning Kampor the previous call to
1133fe5cc64SAlexey Zelkin.Fn geom_stats_resync .
114e13db587SPoul-Henning Kamp.Pp
115ace5be68SRuslan ErmilovThe
1163fe5cc64SAlexey Zelkin.Fn geom_stats_snapshot_get
117ace5be68SRuslan Ermilovfunction
118ace5be68SRuslan Ermilovwill acquire a snapshot of the raw data from the kernel, and while a
119e13db587SPoul-Henning Kampreasonable effort is made to make this snapshot as atomic and consistent
120e13db587SPoul-Henning Kampas possible, no guarantee is given that it will actually be so.
121e13db587SPoul-Henning KampThe snapshot must be freed again using the
1223fe5cc64SAlexey Zelkin.Fn geom_stats_snapshot_free
123e13db587SPoul-Henning Kampfunction.
124b160a51eSPhilippe CharnierThe
1253fe5cc64SAlexey Zelkin.Fn geom_stats_snapshot_get
126b160a51eSPhilippe Charnierfunction returns
127ace5be68SRuslan Ermilov.Dv NULL
128ace5be68SRuslan Ermilovon failure.
129e13db587SPoul-Henning Kamp.Pp
130ace5be68SRuslan ErmilovThe
1313fe5cc64SAlexey Zelkin.Fn geom_stats_snapshot_timestamp
132ace5be68SRuslan Ermilovfunction
133ace5be68SRuslan Ermilovprovides access to the timestamp acquired in the snapshot.
134e13db587SPoul-Henning Kamp.Pp
135ace5be68SRuslan ErmilovThe
1363fe5cc64SAlexey Zelkin.Fn geom_stats_snapshot_reset
137e13db587SPoul-Henning Kampand
1383fe5cc64SAlexey Zelkin.Fn geom_stats_snapshot_next
139ace5be68SRuslan Ermilovfunctions
140ace5be68SRuslan Ermilovprovide an iterator over the statistics slots in the snapshot.
141ace5be68SRuslan ErmilovThe
1423fe5cc64SAlexey Zelkin.Fn geom_stats_snapshot_reset
143ace5be68SRuslan Ermilovfunction
144e13db587SPoul-Henning Kampforces the internal pointer in the snapshot back to before the first item.
145ace5be68SRuslan ErmilovThe
1463fe5cc64SAlexey Zelkin.Fn geom_stats_snapshot_next
147ace5be68SRuslan Ermilovfunction
148ace5be68SRuslan Ermilovreturns the next item, and
149ace5be68SRuslan Ermilov.Dv NULL
150ace5be68SRuslan Ermilovif there are no more items in the snapshot.
1515e5bfe77SPoul-Henning Kamp.Ss "Control Functions"
1525e5bfe77SPoul-Henning KampThe
1535e5bfe77SPoul-Henning Kamp.Fn gctl_*
1545e5bfe77SPoul-Henning Kampfunctions are used to send requests to GEOM classes.  In order for a GEOM
1555e5bfe77SPoul-Henning Kampclass to actually be able to receive these requests, it must have defined a
1565e5bfe77SPoul-Henning Kamp"ctlreq" method.
1575e5bfe77SPoul-Henning Kamp.Pp
1585e5bfe77SPoul-Henning KampA
1595e5bfe77SPoul-Henning Kamp.Ar struct gctl_req * ,
1605e5bfe77SPoul-Henning Kampobtained with
1615e5bfe77SPoul-Henning Kamp.Fn gctl_get_handle ,
1625e5bfe77SPoul-Henning Kampcan hold any number of parameters, which must be added to it with
1635e5bfe77SPoul-Henning Kamp.Fn gctl_ro_param
1645e5bfe77SPoul-Henning Kamp(for read-only parameters) or
1655e5bfe77SPoul-Henning Kamp.Fn gctl_rw_param
1665e5bfe77SPoul-Henning Kamp(for read/write parameters).
1675e5bfe77SPoul-Henning Kamp.Pp
1685e5bfe77SPoul-Henning KampBoth
1695e5bfe77SPoul-Henning Kamp.Fn gctl_ro_param
1705e5bfe77SPoul-Henning Kampand
1715e5bfe77SPoul-Henning Kamp.Fn gctl_rw_param
1725e5bfe77SPoul-Henning Kamptake a string
1735e5bfe77SPoul-Henning Kamp.Ar name ,
1745e5bfe77SPoul-Henning Kampwhich is used to identify the parameter, and a
1755e5bfe77SPoul-Henning Kamp.Ar value ,
1765e5bfe77SPoul-Henning Kampwhich contains - in the read-only case - the data to be passed to the
1775e5bfe77SPoul-Henning KampGEOM class, or - in the read/write case - a pointer to preallocated memory
1785e5bfe77SPoul-Henning Kampthat the GEOM class should fill with the desired data.  If
1795e5bfe77SPoul-Henning Kamp.Ar len
1805e5bfe77SPoul-Henning Kampis negative, it is assumed that
1815e5bfe77SPoul-Henning Kamp.Ar value
1825e5bfe77SPoul-Henning Kampis an ASCII string and the actual length is taken from the string length of
1835e5bfe77SPoul-Henning Kamp.Ar value ;
1845e5bfe77SPoul-Henning Kampotherwise it must hold the size of
1855e5bfe77SPoul-Henning Kamp.Ar value .
1865e5bfe77SPoul-Henning Kamp.Pp
1875e5bfe77SPoul-Henning KampA parameter with a
1885e5bfe77SPoul-Henning Kamp.Ar name
1895e5bfe77SPoul-Henning Kampcontaining the string "class" is mandatory for each request, and the
1905e5bfe77SPoul-Henning Kampcorresponding
1915e5bfe77SPoul-Henning Kamp.Ar value
1925e5bfe77SPoul-Henning Kampmust hold the name of the GEOM class where the request should be sent to.
1935e5bfe77SPoul-Henning Kamp.Pp
1945e5bfe77SPoul-Henning KampAlso mandatory for each request is a parameter with a
1955e5bfe77SPoul-Henning Kamp.Ar name
1965e5bfe77SPoul-Henning Kampcalled "verb", and the corresponding
1975e5bfe77SPoul-Henning Kamp.Ar value
1985e5bfe77SPoul-Henning Kampneeds to hold the command string that the GEOM class should react upon.
1995e5bfe77SPoul-Henning Kamp.Pp
2005e5bfe77SPoul-Henning KampOnce all desired parameters are filled in, the request must be sent to
2015e5bfe77SPoul-Henning Kampthe GEOM subsystem with
2025e5bfe77SPoul-Henning Kamp.Fn gctl_issue ,
2035e5bfe77SPoul-Henning Kampwhich returns NULL on success, or a string containing the error message
2045e5bfe77SPoul-Henning Kampon failure.
2055e5bfe77SPoul-Henning Kamp.Pp
2065e5bfe77SPoul-Henning KampAfter the request is finished, the allocated memory should be released with
2075e5bfe77SPoul-Henning Kamp.Fn gctl_free .
2085e5bfe77SPoul-Henning Kamp.Pp
2095e5bfe77SPoul-Henning Kamp.Fn gctl_dump
2105e5bfe77SPoul-Henning Kampcan be used to format the contents of
2115e5bfe77SPoul-Henning Kamp.Ar req
2125e5bfe77SPoul-Henning Kampto the open file handle pointed to by
2135e5bfe77SPoul-Henning Kamp.Ar f
2145e5bfe77SPoul-Henning Kampfor debugging purposes.
2155e5bfe77SPoul-Henning Kamp.Pp
2165e5bfe77SPoul-Henning KampError handling for the control functions is postponed until the call
2175e5bfe77SPoul-Henning Kampto
2185e5bfe77SPoul-Henning Kamp.Fn gctl_issue
2195e5bfe77SPoul-Henning Kampwhich returns NULL on success or an error message corresponding to the
2205e5bfe77SPoul-Henning Kampfirst error which happened.
2215e5bfe77SPoul-Henning Kamp.Sh EXAMPLES
2225e5bfe77SPoul-Henning KampCreate a request that is to be sent to the CCD class and tell
2235e5bfe77SPoul-Henning Kampit to destroy a specific geom:
2245e5bfe77SPoul-Henning Kamp.Bd -literal -offset indent
2255e5bfe77SPoul-Henning KampH = gctl_get_handle();
2265e5bfe77SPoul-Henning Kampgctl_ro_param(H, "verb", -1, "destroy geom");
2275e5bfe77SPoul-Henning Kampgctl_ro_param(H, "class", -1, "CCD");
2285e5bfe77SPoul-Henning Kampsprintf(buf, "ccd%d", ccd);
2295e5bfe77SPoul-Henning Kampgctl_ro_param(H, "geom", -1, buf);
2305e5bfe77SPoul-Henning Kamperrstr = gctl_issue(H);
2315e5bfe77SPoul-Henning Kampif (errstr != NULL)
2325e5bfe77SPoul-Henning Kamp    err(1, "Could not destroy ccd: %s", errstr);
2335e5bfe77SPoul-Henning Kampgctl_free(H);
2345e5bfe77SPoul-Henning Kamp.Ed
2355e5bfe77SPoul-Henning Kamp.Sh SEE ALSO
2365e5bfe77SPoul-Henning Kamp.Rs
2375e5bfe77SPoul-Henning Kamphttp://ezine.daemonnews.org/200308/blueprints.html
2385e5bfe77SPoul-Henning Kamp.Re
239e13db587SPoul-Henning Kamp.Sh HISTORY
240ace5be68SRuslan ErmilovThe
241e13db587SPoul-Henning Kamp.Nm geom
242ace5be68SRuslan Ermilovlibrary appeared in
243e13db587SPoul-Henning Kamp.Fx 5.1 .
2445e5bfe77SPoul-Henning Kamp.Sh AUTHORS
2455e5bfe77SPoul-Henning Kamp.An Poul-Henning Kamp Aq phk@FreeBSD.org
2465e5bfe77SPoul-Henning Kamp.An Lukas Ertl Aq le@FreeBSD.org
247