xref: /freebsd/lib/libgeom/libgeom.3 (revision 862b46f607ea4641313eff08f6df8fd1d930394c)
1.\" Copyright (c) 2003 Poul-Henning Kamp
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. The names of the authors may not be used to endorse or promote
13.\"    products derived from this software without specific prior written
14.\"    permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\" $FreeBSD$
29.\"
30.Dd March 7, 2004
31.Dt LIBGEOM 3
32.Os
33.Sh NAME
34.Nm geom_stats_open ,
35.Nm geom_stats_close ,
36.Nm geom_stats_resync ,
37.Nm geom_stats_snapshot_get ,
38.Nm geom_stats_snapshot_free ,
39.Nm geom_stats_snapshot_timestamp ,
40.Nm geom_stats_snapshot_reset ,
41.Nm geom_stats_snapshot_next ,
42.Nm gctl_get_handle ,
43.Nm gctl_ro_param ,
44.Nm gctl_rw_param ,
45.Nm gctl_issue ,
46.Nm gctl_free ,
47.Nm gctl_dump
48.Nd userland API library for kernel GEOM subsystem
49.Sh LIBRARY
50.Lb libgeom
51.Sh SYNOPSIS
52.In libgeom.h
53.Ss "Statistics Functions"
54.Ft void
55.Fn geom_stats_close void
56.Ft int
57.Fn geom_stats_open void
58.Ft void
59.Fn geom_stats_resync void
60.Ft "void *"
61.Fn geom_stats_snapshot_get void
62.Ft void
63.Fn geom_stats_snapshot_free "void *arg"
64.Ft void
65.Fn geom_stats_snapshot_timestamp "void *arg" "struct timespec *tp"
66.Ft void
67.Fn geom_stats_snapshot_reset "void *arg"
68.Ft "struct g_stat *"
69.Fn geom_stats_snapshot_next "void *arg"
70.Ss "Control Functions"
71.Ft "struct gctl_req *"
72.Fn gctl_get_handle "void"
73.Ft void
74.Fn gctl_ro_param "struct gctl_req *req" "const char *name" "int len" "const void *value"
75.Ft void
76.Fn gctl_rw_param "struct gctl_req *req" "const char *name" "int len" "void *value"
77.Ft "const char *"
78.Fn gctl_issue "struct gctl_req *req"
79.Ft void
80.Fn gctl_free "struct gctl_req *req"
81.Ft void
82.Fn gctl_dump "struct gctl_req *req" "FILE *f"
83.Sh DESCRIPTION
84The
85.Nm geom
86library contains the official and publicized API for
87interacting with the GEOM subsystem in the kernel.
88.Ss "Statistics Functions"
89GEOM collects statistics data for all consumers and providers, but does
90not perform any normalization or presentation on the raw data, this is
91left as an excercize for user-land presentation utilities.
92.Pp
93The
94.Fn geom_stats_open
95and
96.Fn geom_stats_close
97functions open and close the necessary pathways to access the raw
98statistics information in the kernel.
99These functions are likely to
100open one or more files and cache the file descriptors locally.
101The
102.Fn geom_stats_open
103function returns zero on success, and sets
104.Va errno
105if not.
106.Pp
107The
108.Fn geom_stats_resync
109function will check if more statistics collection points have been
110added in the kernel since
111.Fn geom_stats_open
112or the previous call to
113.Fn geom_stats_resync .
114.Pp
115The
116.Fn geom_stats_snapshot_get
117function
118will acquire a snapshot of the raw data from the kernel, and while a
119reasonable effort is made to make this snapshot as atomic and consistent
120as possible, no guarantee is given that it will actually be so.
121The snapshot must be freed again using the
122.Fn geom_stats_snapshot_free
123function.
124The
125.Fn geom_stats_snapshot_get
126function returns
127.Dv NULL
128on failure.
129.Pp
130The
131.Fn geom_stats_snapshot_timestamp
132function
133provides access to the timestamp acquired in the snapshot.
134.Pp
135The
136.Fn geom_stats_snapshot_reset
137and
138.Fn geom_stats_snapshot_next
139functions
140provide an iterator over the statistics slots in the snapshot.
141The
142.Fn geom_stats_snapshot_reset
143function
144forces the internal pointer in the snapshot back to before the first item.
145The
146.Fn geom_stats_snapshot_next
147function
148returns the next item, and
149.Dv NULL
150if there are no more items in the snapshot.
151.Ss "Control Functions"
152The
153.Fn gctl_*
154functions are used to send requests to GEOM classes.
155In order for a GEOM
156class to actually be able to receive these requests, it must have defined a
157"ctlreq" method.
158.Pp
159A
160.Vt "struct gctl_req *" ,
161obtained with
162.Fn gctl_get_handle ,
163can hold any number of parameters, which must be added to it with
164.Fn gctl_ro_param
165(for read-only parameters) or
166.Fn gctl_rw_param
167(for read/write parameters).
168.Pp
169Both
170.Fn gctl_ro_param
171and
172.Fn gctl_rw_param
173take a string
174.Fa name ,
175which is used to identify the parameter, and a
176.Fa value ,
177which contains, in the read-only case, the data to be passed to the
178GEOM class, or, in the read/write case, a pointer to preallocated memory
179that the GEOM class should fill with the desired data.
180If
181.Fa len
182is negative, it is assumed that
183.Fa value
184is an
185.Tn ASCII
186string and the actual length is taken from the string length of
187.Fa value ;
188otherwise it must hold the size of
189.Fa value .
190.Pp
191A parameter with a
192.Fa name
193containing the string
194.Qq Li class
195is mandatory for each request, and the
196corresponding
197.Fa value
198must hold the name of the GEOM class where the request should be sent to.
199.Pp
200Also mandatory for each request is a parameter with a
201.Fa name
202called
203.Qq Li verb ,
204and the corresponding
205.Fa value
206needs to hold the command string that the GEOM class should react upon.
207.Pp
208Once all desired parameters are filled in, the request must be sent to
209the GEOM subsystem with
210.Fn gctl_issue ,
211which returns
212.Dv NULL
213on success, or a string containing the error message
214on failure.
215.Pp
216After the request is finished, the allocated memory should be released with
217.Fn gctl_free .
218.Pp
219The
220.Fn gctl_dump
221function
222can be used to format the contents of
223.Fa req
224to the open file handle pointed to by
225.Fa f ,
226for debugging purposes.
227.Pp
228Error handling for the control functions is postponed until the call
229to
230.Fn gctl_issue ,
231which returns
232.Dv NULL
233on success, or an error message corresponding to the
234first error which happened.
235.Sh EXAMPLES
236Create a request that is to be sent to the CCD class, and tell
237it to destroy a specific geom:
238.Bd -literal -offset indent
239H = gctl_get_handle();
240gctl_ro_param(H, "verb", -1, "destroy geom");
241gctl_ro_param(H, "class", -1, "CCD");
242sprintf(buf, "ccd%d", ccd);
243gctl_ro_param(H, "geom", -1, buf);
244errstr = gctl_issue(H);
245if (errstr != NULL)
246    err(1, "could not destroy ccd: %s", errstr);
247gctl_free(H);
248.Ed
249.Sh SEE ALSO
250.Pa http://ezine.daemonnews.org/200308/blueprints.html
251.Sh HISTORY
252The
253.Nm geom
254library appeared in
255.Fx 5.1 .
256.Sh AUTHORS
257.An Poul-Henning Kamp Aq phk@FreeBSD.org
258.An Lukas Ertl Aq le@FreeBSD.org
259