1 .\" Copyright (c) 2003 Poul-Henning Kamp
2 .\" Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
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
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
34 .Nm geom_stats_close ,
35 .Nm geom_stats_resync ,
36 .Nm geom_stats_snapshot_get ,
37 .Nm geom_stats_snapshot_free ,
38 .Nm geom_stats_snapshot_timestamp ,
39 .Nm geom_stats_snapshot_reset ,
40 .Nm geom_stats_snapshot_next ,
64 .Nd userland API library for kernel GEOM subsystem
69 /* stdio.h is only required for `gctl_dump` */
73 .Ss "Statistics Functions"
75 .Fn geom_stats_close void
77 .Fn geom_stats_open void
79 .Fn geom_stats_resync void
81 .Fn geom_stats_snapshot_get void
83 .Fn geom_stats_snapshot_free "void *arg"
85 .Fn geom_stats_snapshot_timestamp "void *arg" "struct timespec *tp"
87 .Fn geom_stats_snapshot_reset "void *arg"
88 .Ft "struct devstat *"
89 .Fn geom_stats_snapshot_next "void *arg"
90 .Ss "Control Functions"
91 .Ft "struct gctl_req *"
92 .Fn gctl_get_handle "void"
94 .Fn gctl_ro_param "struct gctl_req *req" "const char *name" "int len" "const void *value"
96 .Fn gctl_rw_param "struct gctl_req *req" "const char *name" "int len" "void *value"
98 .Fn gctl_issue "struct gctl_req *req"
100 .Fn gctl_free "struct gctl_req *req"
102 .Fn gctl_dump "struct gctl_req *req" "FILE *f"
103 .Ss "Utility Functions"
107 .Fn geom_xml2tree "struct gmesh *gmp" "char *p"
109 .Fn geom_gettree "struct gmesh *gmp"
111 .Fn geom_deletetree "struct gmesh *gmp"
113 .Fn g_open "const char *name" "int dowrite"
117 .Fn g_mediasize "int fd"
119 .Fn g_sectorsize "int fd"
121 .Fn g_stripeoffset "int fd"
123 .Fn g_stripesize "int fd"
127 .Fn g_delete "int fd" "off_t offset" "off_t length"
129 .Fn g_device_path "const char *devpath"
131 .Fn g_get_ident "int fd" "char *ident" "size_t size"
133 .Fn g_get_name "const char *ident" "char *name" "size_t size"
135 .Fn g_open_by_ident "const char *ident" "int dowrite" "char *name" "size_t size"
137 .Fn g_providername "int fd"
141 library contains the official and publicized API for
142 interacting with the GEOM subsystem in the kernel.
143 .Ss "Statistics Functions"
144 GEOM collects statistics data for all consumers and providers, but does
145 not perform any normalization or presentation on the raw data, this is
146 left as an exercise for user-land presentation utilities.
152 functions open and close the necessary pathways to access the raw
153 statistics information in the kernel.
154 These functions are likely to
155 open one or more files and cache the file descriptors locally.
158 function returns zero on success, and sets
163 .Fn geom_stats_resync
164 function will check if more statistics collection points have been
165 added in the kernel since
167 or the previous call to
168 .Fn geom_stats_resync .
171 .Fn geom_stats_snapshot_get
173 will acquire a snapshot of the raw data from the kernel, and while a
174 reasonable effort is made to make this snapshot as atomic and consistent
175 as possible, no guarantee is given that it will actually be so.
176 The snapshot must be freed again using the
177 .Fn geom_stats_snapshot_free
180 .Fn geom_stats_snapshot_get
186 .Fn geom_stats_snapshot_timestamp
188 provides access to the timestamp acquired in the snapshot.
191 .Fn geom_stats_snapshot_reset
193 .Fn geom_stats_snapshot_next
195 provide an iterator over the statistics slots in the snapshot.
197 .Fn geom_stats_snapshot_reset
199 forces the internal pointer in the snapshot back to before the first item.
201 .Fn geom_stats_snapshot_next
203 returns the next item, and
205 if there are no more items in the snapshot.
206 .Ss "Control Functions"
209 functions are used to send requests to GEOM classes.
211 class to actually be able to receive these requests, it must have defined a
215 .Vt "struct gctl_req *" ,
217 .Fn gctl_get_handle ,
218 can hold any number of parameters, which must be added to it with
220 (for read-only parameters) or
222 (for read/write parameters).
230 which is used to identify the parameter, and a
232 which contains, in the read-only case, the data to be passed to the
233 GEOM class, or, in the read/write case, a pointer to preallocated memory
234 that the GEOM class should fill with the desired data.
237 is negative, it is assumed that
241 string and the actual length is taken from the string length of
243 otherwise it must hold the size of
248 containing the string
250 is mandatory for each request, and the
253 must hold the name of the GEOM class where the request should be sent to.
255 Also mandatory for each request is a parameter with a
259 and the corresponding
261 needs to hold the command string that the GEOM class should react upon.
263 Once all desired parameters are filled in, the request must be sent to
264 the GEOM subsystem with
268 on success, or a string containing the error message
271 After the request is finished, the allocated memory should be released with
277 can be used to format the contents of
279 to the open file handle pointed to by
281 for debugging purposes.
283 Error handling for the control functions is postponed until the call
288 on success, or an error message corresponding to the
289 first error which happened.
290 .Ss "Utility Functions"
293 function is a wrapper around
296 .Ar kern.geom.confxml
297 OID, and returns it's value.
298 The allocated memory should be released with
304 function parses the XML representation of a GEOM topology passed as
306 allocates the needed data structures to access this information and fills in
310 Memory allocated during this transformation should be released
317 function is a wrapper around the
322 Memory allocated during this operation should be released using
328 function releases memory allocated for storing the data-structures referenced by
333 functions are used to communicate with GEOM providers.
337 function opens the given provider and returns file descriptor number, which can
338 be used with other functions.
341 argument indicates if operations that modify the provider (like
345 are going to be called.
349 function closes the provider.
353 function returns size of the given provider.
357 function returns sector size of the given provider.
361 function returns stripe offset of the given provider.
365 function returns stripe size of the given provider.
371 request to flush write cache of the provider.
375 function tells the provider that the given data range is no longer used.
379 function returns the full path to a provider given a partial or full path to the
382 is returned if the device cannot be found or is not a valid geom provider.
386 function returns provider's fixed and unique identifier.
389 argument should be at least
395 function returns name of the provider, which identifier is equal to the
401 function opens provider using its identification, unlike
403 which uses the provider's name.
404 The function will store the provider's name in the
406 parameter if it is not
411 function returns the provider name of an open file descriptor.
413 is returned the file descriptor does not point to a valid geom provider.
419 return a value greater than or equal to
425 Create a request that is to be sent to the CCD class, and tell
426 it to destroy a specific geom:
427 .Bd -literal -offset indent
428 H = gctl_get_handle();
429 gctl_ro_param(H, "verb", -1, "destroy geom");
430 gctl_ro_param(H, "class", -1, "CCD");
431 sprintf(buf, "ccd%d", ccd);
432 gctl_ro_param(H, "geom", -1, buf);
433 errstr = gctl_issue(H);
435 err(1, "could not destroy ccd: %s", errstr);
444 .An Poul-Henning Kamp Aq Mt phk@FreeBSD.org
445 .An Lukas Ertl Aq Mt le@FreeBSD.org
446 .An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org