]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - lib/libgeom/libgeom.3
MFH r328332:
[FreeBSD/stable/10.git] / lib / libgeom / libgeom.3
1 .\" Copyright (c) 2003 Poul-Henning Kamp
2 .\" Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\" 3. The names of the authors may not be used to endorse or promote
14 .\"    products derived from this software without specific prior written
15 .\"    permission.
16 .\"
17 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" SUCH DAMAGE.
28 .\"
29 .\" $FreeBSD$
30 .\"
31 .Dd April 22, 2017
32 .Dt LIBGEOM 3
33 .Os
34 .Sh NAME
35 .Nm geom_stats_open ,
36 .Nm geom_stats_close ,
37 .Nm geom_stats_resync ,
38 .Nm geom_stats_snapshot_get ,
39 .Nm geom_stats_snapshot_free ,
40 .Nm geom_stats_snapshot_timestamp ,
41 .Nm geom_stats_snapshot_reset ,
42 .Nm geom_stats_snapshot_next ,
43 .Nm gctl_get_handle ,
44 .Nm gctl_ro_param ,
45 .Nm gctl_rw_param ,
46 .Nm gctl_issue ,
47 .Nm gctl_free ,
48 .Nm gctl_dump ,
49 .Nm g_open ,
50 .Nm g_close ,
51 .Nm g_mediasize ,
52 .Nm g_sectorsize ,
53 .Nm g_stripeoffset ,
54 .Nm g_stripesize ,
55 .Nm g_flush ,
56 .Nm g_delete ,
57 .Nm g_device_path ,
58 .Nm g_get_ident ,
59 .Nm g_get_name ,
60 .Nm g_open_by_ident ,
61 .Nm g_providername
62 .Nd userland API library for kernel GEOM subsystem
63 .Sh LIBRARY
64 .Lb libgeom
65 .Sh SYNOPSIS
66 .Bd -literal
67 /* stdio.h is only required for `gctl_dump` */
68 .Ed
69 .In stdio.h
70 .In libgeom.h
71 .Ss "Statistics Functions"
72 .Ft void
73 .Fn geom_stats_close void
74 .Ft int
75 .Fn geom_stats_open void
76 .Ft void
77 .Fn geom_stats_resync void
78 .Ft "void *"
79 .Fn geom_stats_snapshot_get void
80 .Ft void
81 .Fn geom_stats_snapshot_free "void *arg"
82 .Ft void
83 .Fn geom_stats_snapshot_timestamp "void *arg" "struct timespec *tp"
84 .Ft void
85 .Fn geom_stats_snapshot_reset "void *arg"
86 .Ft "struct devstat *"
87 .Fn geom_stats_snapshot_next "void *arg"
88 .Ss "Control Functions"
89 .Ft "struct gctl_req *"
90 .Fn gctl_get_handle "void"
91 .Ft void
92 .Fn gctl_ro_param "struct gctl_req *req" "const char *name" "int len" "const void *value"
93 .Ft void
94 .Fn gctl_rw_param "struct gctl_req *req" "const char *name" "int len" "void *value"
95 .Ft "const char *"
96 .Fn gctl_issue "struct gctl_req *req"
97 .Ft void
98 .Fn gctl_free "struct gctl_req *req"
99 .Ft void
100 .Fn gctl_dump "struct gctl_req *req" "FILE *f"
101 .Ss "Utility Functions"
102 .Ft int
103 .Fn g_open "const char *name" "int dowrite"
104 .Ft int
105 .Fn g_close "int fd"
106 .Ft off_t
107 .Fn g_mediasize "int fd"
108 .Ft ssize_t
109 .Fn g_sectorsize "int fd"
110 .Ft ssize_t
111 .Fn g_stripeoffset "int fd"
112 .Ft ssize_t
113 .Fn g_stripesize "int fd"
114 .Ft int
115 .Fn g_flush "int fd"
116 .Ft int
117 .Fn g_delete "int fd" "off_t offset" "off_t length"
118 .Ft "char *"
119 .Fn g_device_path "const char *devpath"
120 .Ft int
121 .Fn g_get_ident "int fd" "char *ident" "size_t size"
122 .Ft int
123 .Fn g_get_name "const char *ident" "char *name" "size_t size"
124 .Ft int
125 .Fn g_open_by_ident "const char *ident" "int dowrite" "char *name" "size_t size"
126 .Ft "char *"
127 .Fn g_providername "int fd"
128 .Sh DESCRIPTION
129 The
130 .Nm geom
131 library contains the official and publicized API for
132 interacting with the GEOM subsystem in the kernel.
133 .Ss "Statistics Functions"
134 GEOM collects statistics data for all consumers and providers, but does
135 not perform any normalization or presentation on the raw data, this is
136 left as an exercise for user-land presentation utilities.
137 .Pp
138 The
139 .Fn geom_stats_open
140 and
141 .Fn geom_stats_close
142 functions open and close the necessary pathways to access the raw
143 statistics information in the kernel.
144 These functions are likely to
145 open one or more files and cache the file descriptors locally.
146 The
147 .Fn geom_stats_open
148 function returns zero on success, and sets
149 .Va errno
150 if not.
151 .Pp
152 The
153 .Fn geom_stats_resync
154 function will check if more statistics collection points have been
155 added in the kernel since
156 .Fn geom_stats_open
157 or the previous call to
158 .Fn geom_stats_resync .
159 .Pp
160 The
161 .Fn geom_stats_snapshot_get
162 function
163 will acquire a snapshot of the raw data from the kernel, and while a
164 reasonable effort is made to make this snapshot as atomic and consistent
165 as possible, no guarantee is given that it will actually be so.
166 The snapshot must be freed again using the
167 .Fn geom_stats_snapshot_free
168 function.
169 The
170 .Fn geom_stats_snapshot_get
171 function returns
172 .Dv NULL
173 on failure.
174 .Pp
175 The
176 .Fn geom_stats_snapshot_timestamp
177 function
178 provides access to the timestamp acquired in the snapshot.
179 .Pp
180 The
181 .Fn geom_stats_snapshot_reset
182 and
183 .Fn geom_stats_snapshot_next
184 functions
185 provide an iterator over the statistics slots in the snapshot.
186 The
187 .Fn geom_stats_snapshot_reset
188 function
189 forces the internal pointer in the snapshot back to before the first item.
190 The
191 .Fn geom_stats_snapshot_next
192 function
193 returns the next item, and
194 .Dv NULL
195 if there are no more items in the snapshot.
196 .Ss "Control Functions"
197 The
198 .Fn gctl_*
199 functions are used to send requests to GEOM classes.
200 In order for a GEOM
201 class to actually be able to receive these requests, it must have defined a
202 "ctlreq" method.
203 .Pp
204 A
205 .Vt "struct gctl_req *" ,
206 obtained with
207 .Fn gctl_get_handle ,
208 can hold any number of parameters, which must be added to it with
209 .Fn gctl_ro_param
210 (for read-only parameters) or
211 .Fn gctl_rw_param
212 (for read/write parameters).
213 .Pp
214 Both
215 .Fn gctl_ro_param
216 and
217 .Fn gctl_rw_param
218 take a string
219 .Fa name ,
220 which is used to identify the parameter, and a
221 .Fa value ,
222 which contains, in the read-only case, the data to be passed to the
223 GEOM class, or, in the read/write case, a pointer to preallocated memory
224 that the GEOM class should fill with the desired data.
225 If
226 .Fa len
227 is negative, it is assumed that
228 .Fa value
229 is an
230 .Tn ASCII
231 string and the actual length is taken from the string length of
232 .Fa value ;
233 otherwise it must hold the size of
234 .Fa value .
235 .Pp
236 A parameter with a
237 .Fa name
238 containing the string
239 .Qq Li class
240 is mandatory for each request, and the
241 corresponding
242 .Fa value
243 must hold the name of the GEOM class where the request should be sent to.
244 .Pp
245 Also mandatory for each request is a parameter with a
246 .Fa name
247 called
248 .Qq Li verb ,
249 and the corresponding
250 .Fa value
251 needs to hold the command string that the GEOM class should react upon.
252 .Pp
253 Once all desired parameters are filled in, the request must be sent to
254 the GEOM subsystem with
255 .Fn gctl_issue ,
256 which returns
257 .Dv NULL
258 on success, or a string containing the error message
259 on failure.
260 .Pp
261 After the request is finished, the allocated memory should be released with
262 .Fn gctl_free .
263 .Pp
264 The
265 .Fn gctl_dump
266 function
267 can be used to format the contents of
268 .Fa req
269 to the open file handle pointed to by
270 .Fa f ,
271 for debugging purposes.
272 .Pp
273 Error handling for the control functions is postponed until the call
274 to
275 .Fn gctl_issue ,
276 which returns
277 .Dv NULL
278 on success, or an error message corresponding to the
279 first error which happened.
280 .Ss "Utility Functions"
281 The
282 .Fn g_*
283 functions are used to communicate with GEOM providers.
284 .Pp
285 The
286 .Fn g_open
287 function opens the given provider and returns file descriptor number, which can
288 be used with other functions.
289 The
290 .Fa dowrite
291 argument indicates if operations that modify the provider (like
292 .Fn g_flush
293 or
294 .Fn g_delete )
295 are going to be called.
296 .Pp
297 The
298 .Fn g_close
299 function closes the provider.
300 .Pp
301 The
302 .Fn g_mediasize
303 function returns size of the given provider.
304 .Pp
305 The
306 .Fn g_sectorsize
307 function returns sector size of the given provider.
308 .Pp
309 The
310 .Fn g_stripeoffset
311 function returns stripe offset of the given provider.
312 .Pp
313 The
314 .Fn g_stripesize
315 function returns stripe size of the given provider.
316 .Pp
317 The
318 .Fn g_flush
319 function sends
320 .Dv BIO_FLUSH
321 request to flush write cache of the provider.
322 .Pp
323 The
324 .Fn g_delete
325 function tells the provider that the given data range is no longer used.
326 .Pp
327 The
328 .Fn g_device_path
329 function returns the full path to a provider given a partial or full path to the
330 device node.
331 .Dv NULL
332 is returned if the device cannot be found or is not a valid geom provider.
333 .Pp
334 The
335 .Fn g_get_ident
336 function returns provider's fixed and unique identifier.
337 The
338 .Fa ident
339 argument should be at least
340 .Dv DISK_IDENT_SIZE
341 big.
342 .Pp
343 The
344 .Fn g_get_name
345 function returns name of the provider, which identifier is equal to the
346 .Fa ident
347 string.
348 .Pp
349 The
350 .Fn g_open_by_ident
351 function opens provider using its identification, unlike
352 .Fn g_open
353 which uses the provider's name.
354 The function will store the provider's name in the
355 .Fa name
356 parameter if it is not
357 .Dv NULL .
358 .Pp
359 The
360 .Fn g_providername
361 function returns the provider name of an open file descriptor.
362 .Dv NULL
363 is returned the file descriptor does not point to a valid geom provider.
364 .Pp
365 All functions except
366 .Fn g_providername
367 and
368 .Fn g_device_path
369 return a value greater than or equal to
370 .Va 0
371 on success or
372 .Va -1
373 on failure.
374 .Sh EXAMPLES
375 Create a request that is to be sent to the CCD class, and tell
376 it to destroy a specific geom:
377 .Bd -literal -offset indent
378 H = gctl_get_handle();
379 gctl_ro_param(H, "verb", -1, "destroy geom");
380 gctl_ro_param(H, "class", -1, "CCD");
381 sprintf(buf, "ccd%d", ccd);
382 gctl_ro_param(H, "geom", -1, buf);
383 errstr = gctl_issue(H);
384 if (errstr != NULL)
385     err(1, "could not destroy ccd: %s", errstr);
386 gctl_free(H);
387 .Ed
388 .Sh HISTORY
389 The
390 .Nm geom
391 library appeared in
392 .Fx 5.1 .
393 .Sh AUTHORS
394 .An Poul-Henning Kamp Aq phk@FreeBSD.org
395 .An Lukas Ertl Aq le@FreeBSD.org
396 .An Pawel Jakub Dawidek Aq pjd@FreeBSD.org