1f827ccb9SPawel Jakub Dawidek.\" 2f827ccb9SPawel Jakub Dawidek.\" Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3f827ccb9SPawel Jakub Dawidek.\" All rights reserved. 4f827ccb9SPawel Jakub Dawidek.\" 5f827ccb9SPawel Jakub Dawidek.\" Redistribution and use in source and binary forms, with or without 6f827ccb9SPawel Jakub Dawidek.\" modification, are permitted provided that the following conditions 7f827ccb9SPawel Jakub Dawidek.\" are met: 8f827ccb9SPawel Jakub Dawidek.\" 1. Redistributions of source code must retain the above copyright 9f827ccb9SPawel Jakub Dawidek.\" notice, this list of conditions and the following disclaimer. 10f827ccb9SPawel Jakub Dawidek.\" 2. Redistributions in binary form must reproduce the above copyright 11f827ccb9SPawel Jakub Dawidek.\" notice, this list of conditions and the following disclaimer in the 12f827ccb9SPawel Jakub Dawidek.\" documentation and/or other materials provided with the distribution. 13f827ccb9SPawel Jakub Dawidek.\" 14f827ccb9SPawel Jakub Dawidek.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 15f827ccb9SPawel Jakub Dawidek.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16f827ccb9SPawel Jakub Dawidek.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17f827ccb9SPawel Jakub Dawidek.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 18f827ccb9SPawel Jakub Dawidek.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19f827ccb9SPawel Jakub Dawidek.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20f827ccb9SPawel Jakub Dawidek.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21f827ccb9SPawel Jakub Dawidek.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22f827ccb9SPawel Jakub Dawidek.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23f827ccb9SPawel Jakub Dawidek.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24f827ccb9SPawel Jakub Dawidek.\" 25f827ccb9SPawel Jakub Dawidek.Dd January 16, 2004 266f39ea88SRuslan Ermilov.Dt G_CONSUMER 9 27f827ccb9SPawel Jakub Dawidek.Os 28f827ccb9SPawel Jakub Dawidek.Sh NAME 29f827ccb9SPawel Jakub Dawidek.Nm g_new_consumer , 30f827ccb9SPawel Jakub Dawidek.Nm g_destroy_consumer 31f827ccb9SPawel Jakub Dawidek.Nd "GEOM consumers management" 32f827ccb9SPawel Jakub Dawidek.Sh SYNOPSIS 33f827ccb9SPawel Jakub Dawidek.In geom/geom.h 34f827ccb9SPawel Jakub Dawidek.Ft "struct g_consumer *" 35f827ccb9SPawel Jakub Dawidek.Fn g_new_consumer "struct g_geom *gp" 36f827ccb9SPawel Jakub Dawidek.Ft void 37f827ccb9SPawel Jakub Dawidek.Fn g_destroy_consumer "struct g_consumer *cp" 38f827ccb9SPawel Jakub Dawidek.Sh DESCRIPTION 39eaad868dSLukas ErtlA GEOM consumer is the backdoor through which a geom connects to 40f827ccb9SPawel Jakub Dawidekanother GEOM provider and through which I/O requests are sent. 41f827ccb9SPawel Jakub Dawidek.Pp 42f827ccb9SPawel Jakub DawidekThe 43f827ccb9SPawel Jakub Dawidek.Fn g_new_consumer 44eaad868dSLukas Ertlfunction creates a new consumer on geom 45f827ccb9SPawel Jakub Dawidek.Fa gp . 46eaad868dSLukas ErtlBefore using the new consumer, it has to be attached to a provider with 47f827ccb9SPawel Jakub Dawidek.Xr g_attach 9 48eaad868dSLukas Ertland opened with 49eaad868dSLukas Ertl.Xr g_access 9 . 50f827ccb9SPawel Jakub Dawidek.Pp 51f827ccb9SPawel Jakub DawidekThe 52f827ccb9SPawel Jakub Dawidek.Fn g_destroy_consumer 53eaad868dSLukas Ertlfunction destroys the given consumer and cancels all related pending events. 54f827ccb9SPawel Jakub DawidekThis function is the last stage of killing an unwanted consumer. 55f827ccb9SPawel Jakub Dawidek.Sh RESTRICTIONS/CONDITIONS 56f827ccb9SPawel Jakub Dawidek.Fn g_new_consumer : 57f827ccb9SPawel Jakub Dawidek.Bl -item -offset indent 58f827ccb9SPawel Jakub Dawidek.It 59eaad868dSLukas ErtlThe geom 60eaad868dSLukas Ertl.Fa gp 61a41d535dSDag-Erling Smørgravhas to have an 62a41d535dSDag-Erling Smørgrav.Va orphan 63a41d535dSDag-Erling Smørgravmethod defined. 64f827ccb9SPawel Jakub Dawidek.It 65f827ccb9SPawel Jakub DawidekThe topology lock has to be held. 66f827ccb9SPawel Jakub Dawidek.El 67f827ccb9SPawel Jakub Dawidek.Pp 68f827ccb9SPawel Jakub Dawidek.Fn g_destroy_consumer : 69f827ccb9SPawel Jakub Dawidek.Bl -item -offset indent 70f827ccb9SPawel Jakub Dawidek.It 71eaad868dSLukas ErtlThe consumer must not be attached to a provider. 72f827ccb9SPawel Jakub Dawidek.It 73f827ccb9SPawel Jakub DawidekThe access count has to be 0. 74f827ccb9SPawel Jakub Dawidek.It 75f827ccb9SPawel Jakub DawidekThe topology lock has to be held. 76f827ccb9SPawel Jakub Dawidek.El 77f827ccb9SPawel Jakub Dawidek.Sh RETURN VALUES 786f39ea88SRuslan ErmilovThe 79f827ccb9SPawel Jakub Dawidek.Fn g_new_consumer 806f39ea88SRuslan Ermilovfunction 8106bb88dcSPawel Jakub Dawidekreturns a pointer to the newly created consumer. 82f827ccb9SPawel Jakub Dawidek.Sh EXAMPLES 83f827ccb9SPawel Jakub DawidekCreate consumer, attach it to given provider, gain read access and clean up. 84f827ccb9SPawel Jakub Dawidek.Bd -literal -offset indent 85f827ccb9SPawel Jakub Dawidekvoid 86f827ccb9SPawel Jakub Dawideksome_function(struct g_geom *mygeom, struct g_provider *pp) 87f827ccb9SPawel Jakub Dawidek{ 88f827ccb9SPawel Jakub Dawidek struct g_consumer *cp; 89f827ccb9SPawel Jakub Dawidek 90f827ccb9SPawel Jakub Dawidek g_topology_assert(); 91f827ccb9SPawel Jakub Dawidek 92f827ccb9SPawel Jakub Dawidek /* Create new consumer on 'mygeom' geom. */ 93f827ccb9SPawel Jakub Dawidek cp = g_new_consumer(mygeom); 94f827ccb9SPawel Jakub Dawidek /* Attach newly created consumer to given provider. */ 95f827ccb9SPawel Jakub Dawidek if (g_attach(cp, pp) != 0) { 96f827ccb9SPawel Jakub Dawidek g_destroy_consumer(cp); 97f827ccb9SPawel Jakub Dawidek return; 98f827ccb9SPawel Jakub Dawidek } 99f827ccb9SPawel Jakub Dawidek /* Open provider for reading through our consumer. */ 1009a7e5576SPawel Jakub Dawidek if (g_access(cp, 1, 0, 0) != 0) { 101f827ccb9SPawel Jakub Dawidek g_detach(cp); 102f827ccb9SPawel Jakub Dawidek g_destroy_consumer(cp); 103f827ccb9SPawel Jakub Dawidek return; 104f827ccb9SPawel Jakub Dawidek } 105f827ccb9SPawel Jakub Dawidek 106f827ccb9SPawel Jakub Dawidek g_topology_unlock(); 107f827ccb9SPawel Jakub Dawidek /* 108f827ccb9SPawel Jakub Dawidek * Read data from provider. 109f827ccb9SPawel Jakub Dawidek */ 110f827ccb9SPawel Jakub Dawidek g_topology_lock(); 111f827ccb9SPawel Jakub Dawidek 112f827ccb9SPawel Jakub Dawidek /* Disconnect from provider (release access count). */ 1139a7e5576SPawel Jakub Dawidek g_access(cp, -1, 0, 0); 114f827ccb9SPawel Jakub Dawidek /* Detach from provider. */ 115f827ccb9SPawel Jakub Dawidek g_detach(cp); 116f827ccb9SPawel Jakub Dawidek /* Destroy consumer. */ 117f827ccb9SPawel Jakub Dawidek g_destroy_consumer(cp); 118f827ccb9SPawel Jakub Dawidek} 119f827ccb9SPawel Jakub Dawidek.Ed 120f827ccb9SPawel Jakub Dawidek.Sh SEE ALSO 121f827ccb9SPawel Jakub Dawidek.Xr geom 4 , 1221c85060aSRuslan Ermilov.Xr DECLARE_GEOM_CLASS 9 , 1238217df6dSPawel Jakub Dawidek.Xr g_access 9 , 124f827ccb9SPawel Jakub Dawidek.Xr g_attach 9 , 125f827ccb9SPawel Jakub Dawidek.Xr g_bio 9 , 126f827ccb9SPawel Jakub Dawidek.Xr g_data 9 , 127f827ccb9SPawel Jakub Dawidek.Xr g_event 9 , 128f827ccb9SPawel Jakub Dawidek.Xr g_geom 9 , 129f827ccb9SPawel Jakub Dawidek.Xr g_provider 9 , 130f827ccb9SPawel Jakub Dawidek.Xr g_provider_by_name 9 , 131f827ccb9SPawel Jakub Dawidek.Xr g_wither_geom 9 132f827ccb9SPawel Jakub Dawidek.Sh AUTHORS 133f827ccb9SPawel Jakub Dawidek.An -nosplit 134f827ccb9SPawel Jakub DawidekThis manual page was written by 135*8a7314fcSBaptiste Daroussin.An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org . 136