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
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 ,
66 .Nd userland API library for kernel GEOM subsystem
71 /* stdio.h is only required for `gctl_dump` */
75 .Ss "Statistics Functions"
77 .Fn geom_stats_close void
79 .Fn geom_stats_open void
81 .Fn geom_stats_resync void
83 .Fn geom_stats_snapshot_get void
85 .Fn geom_stats_snapshot_free "void *arg"
87 .Fn geom_stats_snapshot_timestamp "void *arg" "struct timespec *tp"
89 .Fn geom_stats_snapshot_reset "void *arg"
90 .Ft "struct devstat *"
91 .Fn geom_stats_snapshot_next "void *arg"
92 .Ss "Control Functions"
93 .Ft "struct gctl_req *"
94 .Fn gctl_get_handle "void"
96 .Fn gctl_ro_param "struct gctl_req *req" "const char *name" "int len" "const void *value"
98 .Fn gctl_rw_param "struct gctl_req *req" "const char *name" "int len" "void *value"
100 .Fn gctl_issue "struct gctl_req *req"
102 .Fn gctl_free "struct gctl_req *req"
104 .Fn gctl_dump "struct gctl_req *req" "FILE *f"
105 .Ss "Utility Functions"
109 .Fn geom_xml2tree "struct gmesh *gmp" "char *p"
111 .Fn geom_gettree "struct gmesh *gmp"
113 .Fn geom_deletetree "struct gmesh *gmp"
115 .Fn g_open "const char *name" "int dowrite"
119 .Fn g_mediasize "int fd"
121 .Fn g_sectorsize "int fd"
123 .Fn g_stripeoffset "int fd"
125 .Fn g_stripesize "int fd"
129 .Fn g_delete "int fd" "off_t offset" "off_t length"
131 .Fn g_device_path "const char *devpath"
133 .Fn g_get_ident "int fd" "char *ident" "size_t size"
135 .Fn g_get_name "const char *ident" "char *name" "size_t size"
137 .Fn g_open_by_ident "const char *ident" "int dowrite" "char *name" "size_t size"
139 .Fn g_providername "int fd"
143 library contains the official and publicized API for
144 interacting with the GEOM subsystem in the kernel.
145 .Ss "Statistics Functions"
146 GEOM collects statistics data for all consumers and providers, but does
147 not perform any normalization or presentation on the raw data, this is
148 left as an exercise for user-land presentation utilities.
154 functions open and close the necessary pathways to access the raw
155 statistics information in the kernel.
156 These functions are likely to
157 open one or more files and cache the file descriptors locally.
160 function returns zero on success, and sets
165 .Fn geom_stats_resync
166 function will check if more statistics collection points have been
167 added in the kernel since
169 or the previous call to
170 .Fn geom_stats_resync .
173 .Fn geom_stats_snapshot_get
175 will acquire a snapshot of the raw data from the kernel, and while a
176 reasonable effort is made to make this snapshot as atomic and consistent
177 as possible, no guarantee is given that it will actually be so.
178 The snapshot must be freed again using the
179 .Fn geom_stats_snapshot_free
182 .Fn geom_stats_snapshot_get
188 .Fn geom_stats_snapshot_timestamp
190 provides access to the timestamp acquired in the snapshot.
193 .Fn geom_stats_snapshot_reset
195 .Fn geom_stats_snapshot_next
197 provide an iterator over the statistics slots in the snapshot.
199 .Fn geom_stats_snapshot_reset
201 forces the internal pointer in the snapshot back to before the first item.
203 .Fn geom_stats_snapshot_next
205 returns the next item, and
207 if there are no more items in the snapshot.
208 .Ss "Control Functions"
211 functions are used to send requests to GEOM classes.
213 class to actually be able to receive these requests, it must have defined a
217 .Vt "struct gctl_req *" ,
219 .Fn gctl_get_handle ,
220 can hold any number of parameters, which must be added to it with
222 (for read-only parameters) or
224 (for read/write parameters).
232 which is used to identify the parameter, and a
234 which contains, in the read-only case, the data to be passed to the
235 GEOM class, or, in the read/write case, a pointer to preallocated memory
236 that the GEOM class should fill with the desired data.
239 is negative, it is assumed that
243 string and the actual length is taken from the string length of
245 otherwise it must hold the size of
250 containing the string
252 is mandatory for each request, and the
255 must hold the name of the GEOM class where the request should be sent to.
257 Also mandatory for each request is a parameter with a
261 and the corresponding
263 needs to hold the command string that the GEOM class should react upon.
265 Once all desired parameters are filled in, the request must be sent to
266 the GEOM subsystem with
270 on success, or a string containing the error message
273 After the request is finished, the allocated memory should be released with
279 can be used to format the contents of
281 to the open file handle pointed to by
283 for debugging purposes.
285 Error handling for the control functions is postponed until the call
290 on success, or an error message corresponding to the
291 first error which happened.
292 .Ss "Utility Functions"
295 function is a wrapper around
298 .Ar kern.geom.confxml
299 OID, and returns it's value.
300 The allocated memory should be released with
306 function parses the XML representation of a GEOM topology passed as
308 allocates the needed data structures to access this information and fills in
312 Memory allocated during this transformation should be released
319 function is a wrapper around the
324 Memory allocated during this operation should be released using
330 function releases memory allocated for storing the data-structures referenced by
335 functions are used to communicate with GEOM providers.
339 function opens the given provider and returns file descriptor number, which can
340 be used with other functions.
343 argument indicates if operations that modify the provider (like
347 are going to be called.
351 function closes the provider.
355 function returns size of the given provider.
359 function returns sector size of the given provider.
363 function returns stripe offset of the given provider.
367 function returns stripe size of the given provider.
373 request to flush write cache of the provider.
377 function tells the provider that the given data range is no longer used.
381 function returns the full path to a provider given a partial or full path to the
384 is returned if the device cannot be found or is not a valid geom provider.
388 function returns provider's fixed and unique identifier.
391 argument should be at least
397 function returns name of the provider, which identifier is equal to the
403 function opens provider using its identification, unlike
405 which uses the provider's name.
406 The function will store the provider's name in the
408 parameter if it is not
413 function returns the provider name of an open file descriptor.
415 is returned the file descriptor does not point to a valid geom provider.
421 return a value greater than or equal to
427 Create a request that is to be sent to the CCD class, and tell
428 it to destroy a specific geom:
429 .Bd -literal -offset indent
430 H = gctl_get_handle();
431 gctl_ro_param(H, "verb", -1, "destroy geom");
432 gctl_ro_param(H, "class", -1, "CCD");
433 sprintf(buf, "ccd%d", ccd);
434 gctl_ro_param(H, "geom", -1, buf);
435 errstr = gctl_issue(H);
437 err(1, "could not destroy ccd: %s", errstr);
446 .An Poul-Henning Kamp Aq Mt phk@FreeBSD.org
447 .An Lukas Ertl Aq Mt le@FreeBSD.org
448 .An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org