]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/lib/libgeom/libgeom.3
merge fix for boot-time hang on centos' xen
[FreeBSD/FreeBSD.git] / 6 / lib / libgeom / libgeom.3
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
84 The
85 .Nm geom
86 library contains the official and publicized API for
87 interacting with the GEOM subsystem in the kernel.
88 .Ss "Statistics Functions"
89 GEOM collects statistics data for all consumers and providers, but does
90 not perform any normalization or presentation on the raw data, this is
91 left as an exercise for user-land presentation utilities.
92 .Pp
93 The
94 .Fn geom_stats_open
95 and
96 .Fn geom_stats_close
97 functions open and close the necessary pathways to access the raw
98 statistics information in the kernel.
99 These functions are likely to
100 open one or more files and cache the file descriptors locally.
101 The
102 .Fn geom_stats_open
103 function returns zero on success, and sets
104 .Va errno
105 if not.
106 .Pp
107 The
108 .Fn geom_stats_resync
109 function will check if more statistics collection points have been
110 added in the kernel since
111 .Fn geom_stats_open
112 or the previous call to
113 .Fn geom_stats_resync .
114 .Pp
115 The
116 .Fn geom_stats_snapshot_get
117 function
118 will acquire a snapshot of the raw data from the kernel, and while a
119 reasonable effort is made to make this snapshot as atomic and consistent
120 as possible, no guarantee is given that it will actually be so.
121 The snapshot must be freed again using the
122 .Fn geom_stats_snapshot_free
123 function.
124 The
125 .Fn geom_stats_snapshot_get
126 function returns
127 .Dv NULL
128 on failure.
129 .Pp
130 The
131 .Fn geom_stats_snapshot_timestamp
132 function
133 provides access to the timestamp acquired in the snapshot.
134 .Pp
135 The
136 .Fn geom_stats_snapshot_reset
137 and
138 .Fn geom_stats_snapshot_next
139 functions
140 provide an iterator over the statistics slots in the snapshot.
141 The
142 .Fn geom_stats_snapshot_reset
143 function
144 forces the internal pointer in the snapshot back to before the first item.
145 The
146 .Fn geom_stats_snapshot_next
147 function
148 returns the next item, and
149 .Dv NULL
150 if there are no more items in the snapshot.
151 .Ss "Control Functions"
152 The
153 .Fn gctl_*
154 functions are used to send requests to GEOM classes.
155 In order for a GEOM
156 class to actually be able to receive these requests, it must have defined a
157 "ctlreq" method.
158 .Pp
159 A
160 .Vt "struct gctl_req *" ,
161 obtained with
162 .Fn gctl_get_handle ,
163 can 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
169 Both
170 .Fn gctl_ro_param
171 and
172 .Fn gctl_rw_param
173 take a string
174 .Fa name ,
175 which is used to identify the parameter, and a
176 .Fa value ,
177 which contains, in the read-only case, the data to be passed to the
178 GEOM class, or, in the read/write case, a pointer to preallocated memory
179 that the GEOM class should fill with the desired data.
180 If
181 .Fa len
182 is negative, it is assumed that
183 .Fa value
184 is an
185 .Tn ASCII
186 string and the actual length is taken from the string length of
187 .Fa value ;
188 otherwise it must hold the size of
189 .Fa value .
190 .Pp
191 A parameter with a
192 .Fa name
193 containing the string
194 .Qq Li class
195 is mandatory for each request, and the
196 corresponding
197 .Fa value
198 must hold the name of the GEOM class where the request should be sent to.
199 .Pp
200 Also mandatory for each request is a parameter with a
201 .Fa name
202 called
203 .Qq Li verb ,
204 and the corresponding
205 .Fa value
206 needs to hold the command string that the GEOM class should react upon.
207 .Pp
208 Once all desired parameters are filled in, the request must be sent to
209 the GEOM subsystem with
210 .Fn gctl_issue ,
211 which returns
212 .Dv NULL
213 on success, or a string containing the error message
214 on failure.
215 .Pp
216 After the request is finished, the allocated memory should be released with
217 .Fn gctl_free .
218 .Pp
219 The
220 .Fn gctl_dump
221 function
222 can be used to format the contents of
223 .Fa req
224 to the open file handle pointed to by
225 .Fa f ,
226 for debugging purposes.
227 .Pp
228 Error handling for the control functions is postponed until the call
229 to
230 .Fn gctl_issue ,
231 which returns
232 .Dv NULL
233 on success, or an error message corresponding to the
234 first error which happened.
235 .Sh EXAMPLES
236 Create a request that is to be sent to the CCD class, and tell
237 it to destroy a specific geom:
238 .Bd -literal -offset indent
239 H = gctl_get_handle();
240 gctl_ro_param(H, "verb", -1, "destroy geom");
241 gctl_ro_param(H, "class", -1, "CCD");
242 sprintf(buf, "ccd%d", ccd);
243 gctl_ro_param(H, "geom", -1, buf);
244 errstr = gctl_issue(H);
245 if (errstr != NULL)
246     err(1, "could not destroy ccd: %s", errstr);
247 gctl_free(H);
248 .Ed
249 .Sh SEE ALSO
250 .Pa http://ezine.daemonnews.org/200308/blueprints.html
251 .Sh HISTORY
252 The
253 .Nm geom
254 library 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