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 ,
62 .Nd userland API library for kernel GEOM subsystem
67 /* stdio.h is only required for `gctl_dump` */
71 .Ss "Statistics Functions"
73 .Fn geom_stats_close void
75 .Fn geom_stats_open void
77 .Fn geom_stats_resync void
79 .Fn geom_stats_snapshot_get void
81 .Fn geom_stats_snapshot_free "void *arg"
83 .Fn geom_stats_snapshot_timestamp "void *arg" "struct timespec *tp"
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"
92 .Fn gctl_ro_param "struct gctl_req *req" "const char *name" "int len" "const void *value"
94 .Fn gctl_rw_param "struct gctl_req *req" "const char *name" "int len" "void *value"
96 .Fn gctl_issue "struct gctl_req *req"
98 .Fn gctl_free "struct gctl_req *req"
100 .Fn gctl_dump "struct gctl_req *req" "FILE *f"
101 .Ss "Utility Functions"
103 .Fn g_open "const char *name" "int dowrite"
107 .Fn g_mediasize "int fd"
109 .Fn g_sectorsize "int fd"
111 .Fn g_stripeoffset "int fd"
113 .Fn g_stripesize "int fd"
117 .Fn g_delete "int fd" "off_t offset" "off_t length"
119 .Fn g_device_path "const char *devpath"
121 .Fn g_get_ident "int fd" "char *ident" "size_t size"
123 .Fn g_get_name "const char *ident" "char *name" "size_t size"
125 .Fn g_open_by_ident "const char *ident" "int dowrite" "char *name" "size_t size"
127 .Fn g_providername "int fd"
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.
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.
148 function returns zero on success, and sets
153 .Fn geom_stats_resync
154 function will check if more statistics collection points have been
155 added in the kernel since
157 or the previous call to
158 .Fn geom_stats_resync .
161 .Fn geom_stats_snapshot_get
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
170 .Fn geom_stats_snapshot_get
176 .Fn geom_stats_snapshot_timestamp
178 provides access to the timestamp acquired in the snapshot.
181 .Fn geom_stats_snapshot_reset
183 .Fn geom_stats_snapshot_next
185 provide an iterator over the statistics slots in the snapshot.
187 .Fn geom_stats_snapshot_reset
189 forces the internal pointer in the snapshot back to before the first item.
191 .Fn geom_stats_snapshot_next
193 returns the next item, and
195 if there are no more items in the snapshot.
196 .Ss "Control Functions"
199 functions are used to send requests to GEOM classes.
201 class to actually be able to receive these requests, it must have defined a
205 .Vt "struct gctl_req *" ,
207 .Fn gctl_get_handle ,
208 can hold any number of parameters, which must be added to it with
210 (for read-only parameters) or
212 (for read/write parameters).
220 which is used to identify the parameter, and a
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.
227 is negative, it is assumed that
231 string and the actual length is taken from the string length of
233 otherwise it must hold the size of
238 containing the string
240 is mandatory for each request, and the
243 must hold the name of the GEOM class where the request should be sent to.
245 Also mandatory for each request is a parameter with a
249 and the corresponding
251 needs to hold the command string that the GEOM class should react upon.
253 Once all desired parameters are filled in, the request must be sent to
254 the GEOM subsystem with
258 on success, or a string containing the error message
261 After the request is finished, the allocated memory should be released with
267 can be used to format the contents of
269 to the open file handle pointed to by
271 for debugging purposes.
273 Error handling for the control functions is postponed until the call
278 on success, or an error message corresponding to the
279 first error which happened.
280 .Ss "Utility Functions"
283 functions are used to communicate with GEOM providers.
287 function opens the given provider and returns file descriptor number, which can
288 be used with other functions.
291 argument indicates if operations that modify the provider (like
295 are going to be called.
299 function closes the provider.
303 function returns size of the given provider.
307 function returns sector size of the given provider.
311 function returns stripe offset of the given provider.
315 function returns stripe size of the given provider.
321 request to flush write cache of the provider.
325 function tells the provider that the given data range is no longer used.
329 function returns the full path to a provider given a partial or full path to the
332 is returned if the device cannot be found or is not a valid geom provider.
336 function returns provider's fixed and unique identifier.
339 argument should be at least
345 function returns name of the provider, which identifier is equal to the
351 function opens provider using its identification, unlike
353 which uses the provider's name.
354 The function will store the provider's name in the
356 parameter if it is not
361 function returns the provider name of an open file descriptor.
363 is returned the file descriptor does not point to a valid geom provider.
369 return a value greater than or equal to
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);
385 err(1, "could not destroy ccd: %s", errstr);
394 .An Poul-Henning Kamp Aq Mt phk@FreeBSD.org
395 .An Lukas Ertl Aq Mt le@FreeBSD.org
396 .An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org