1.\" 2.\" Copyright (c) 2004 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.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 15.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 18.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24.\" 25.Dd April 24, 2016 26.Dt G_GEOM 9 27.Os 28.Sh NAME 29.Nm g_new_geomf , 30.Nm g_new_geom , 31.Nm g_destroy_geom 32.Nd "geom management" 33.Sh SYNOPSIS 34.In geom/geom.h 35.Ft "struct g_geom *" 36.Fn g_new_geomf "struct g_class *mp" "const char *fmt" ... 37.Ft "struct g_geom *" 38.Fn g_new_geom "struct g_class *mp" "const char *name" 39.Ft void 40.Fn g_destroy_geom "struct g_geom *gp" 41.Sh DESCRIPTION 42The geom (do not confuse 43.Dq geom 44with 45.Dq GEOM ) 46is an instance of a GEOM class. 47For example: in a typical i386 48.Fx 49system, there will be one geom 50of class MBR for each disk. 51The geom's name is not really important, it is only used in the XML 52dump and for debugging purposes. 53There can be many geoms with the same name. 54.Pp 55The 56.Fn g_new_geomf 57function creates a new geom, which will be an instance of the class 58.Fa mp . 59The geom's name is created in a 60.Xr printf 3 Ns 61-like way from the rest of the arguments. 62.Pp 63The 64.Fn g_new_geom 65function is very similar to 66.Fn g_new_geomf 67except that it accepts a regular string instead of a 68.Xr printf 3 Ns 69-like format strng as the geom's name. 70.Pp 71The 72.Fn g_destroy_geom 73function destroys the given geom immediately and cancels all related pending 74events. 75.Pp 76The 77.Vt g_geom 78structure 79contains fields that should be set by the caller after geom creation, but before 80creating any providers or consumers related to this geom (not all are required): 81.Bl -tag -offset indent -width indent 82.It Vt "g_start_t *" Va start 83Pointer to a function used for I/O processing. 84.It Vt "g_spoiled_t *" Va spoiled 85Pointer to a function used for consumers spoiling. 86.It Vt "g_dumpconf_t *" Va dumpconf 87Pointer to a function used for configuration in XML format dumping. 88.It Vt "g_access_t *" Va access 89Pointer to a function used for access control. 90.It Vt "g_orphan_t *" Va orphan 91Pointer to a function used to inform about orphaned consumer. 92.It Vt "g_ioctl_t *" Va ioctl 93Pointer to a function used for handling ioctl requests. 94.It Vt "void *" Va softc 95Field for private use. 96.El 97.Sh RESTRICTIONS/CONDITIONS 98If you intend to use providers in this geom you must set field 99.Va start 100of your geom. 101.Pp 102If you are planning to use consumers in your geom you must set fields 103.Va orphan 104and 105.Va access 106for it. 107.Pp 108.Fn g_new_geomf 109and 110.Fn g_new_geom : 111.Bl -item -offset indent 112.It 113Class 114.Fa mp 115must be valid (registered in GEOM). 116.It 117The topology lock has to be held. 118.El 119.Pp 120.Fn g_destroy_geom : 121.Bl -item -offset indent 122.It 123The geom cannot possess any providers. 124.It 125The geom cannot possess any consumers. 126.It 127The topology lock has to be held. 128.El 129.Sh RETURN VALUES 130The 131.Fn g_new_geomf 132function 133returns a pointer to the newly created geom. 134.Sh EXAMPLES 135Create an example geom. 136.Bd -literal -offset indent 137static void 138g_example_start(struct bio *bp) 139{ 140 141 [...] 142} 143 144static void 145g_example_orphan(struct g_consumer *cp) 146{ 147 148 g_topology_assert(); 149 150 [...] 151} 152 153static void 154g_example_spoiled(struct g_consumer *cp) 155{ 156 157 g_topology_assert(); 158 159 [...] 160} 161 162static int 163g_example_access(struct g_provider *pp, int dr, int dw, int de) 164{ 165 166 [...] 167} 168 169static struct g_geom * 170create_example_geom(struct g_class *myclass) 171{ 172 struct g_geom *gp; 173 174 g_topology_lock(); 175 gp = g_new_geomf(myclass, "example_geom"); 176 g_topology_unlock(); 177 gp->start = g_example_start; 178 gp->orphan = g_example_orphan; 179 gp->spoiled = g_example_spoiled; 180 gp->access = g_example_access; 181 gp->softc = NULL; 182 183 return (gp); 184} 185 186static int 187destroy_example_geom(struct g_geom *gp) 188{ 189 190 g_topology_lock(); 191 if (!LIST_EMPTY(&gp->provider) || 192 !LIST_EMPTY(&gp->consumer)) { 193 g_topology_unlock(); 194 return (EBUSY); 195 } 196 g_destroy_geom(gp); 197 g_topology_unlock(); 198 199 return (0); 200} 201.Ed 202.Sh SEE ALSO 203.Xr geom 4 , 204.Xr DECLARE_GEOM_CLASS 9 , 205.Xr g_access 9 , 206.Xr g_attach 9 , 207.Xr g_bio 9 , 208.Xr g_consumer 9 , 209.Xr g_data 9 , 210.Xr g_event 9 , 211.Xr g_provider 9 , 212.Xr g_provider_by_name 9 , 213.Xr g_wither_geom 9 214.Sh AUTHORS 215.An -nosplit 216This manual page was written by 217.An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org . 218