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