xref: /freebsd/share/man/man9/g_consumer.9 (revision 7ea28254ec5376b5deb86c136e1838d0134dbb22)
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 January 16, 2004
26.Dt G_CONSUMER 9
27.Os
28.Sh NAME
29.Nm g_new_consumer ,
30.Nm g_destroy_consumer
31.Nd "GEOM consumers management"
32.Sh SYNOPSIS
33.In geom/geom.h
34.Ft "struct g_consumer *"
35.Fn g_new_consumer "struct g_geom *gp"
36.Ft void
37.Fn g_destroy_consumer "struct g_consumer *cp"
38.Sh DESCRIPTION
39A GEOM consumer is the backdoor through which a geom connects to
40another GEOM provider and through which I/O requests are sent.
41.Pp
42The
43.Fn g_new_consumer
44function creates a new consumer on geom
45.Fa gp .
46Before using the new consumer, it has to be attached to a provider with
47.Xr g_attach 9
48and opened with
49.Xr g_access 9 .
50.Pp
51The
52.Fn g_destroy_consumer
53function destroys the given consumer and cancels all related pending events.
54This function is the last stage of killing an unwanted consumer.
55.Sh RESTRICTIONS/CONDITIONS
56.Fn g_new_consumer :
57.Bl -item -offset indent
58.It
59The geom
60.Fa gp
61has to have an
62.Va orphan
63method defined.
64.It
65The topology lock has to be held.
66.El
67.Pp
68.Fn g_destroy_consumer :
69.Bl -item -offset indent
70.It
71The consumer must not be attached to a provider.
72.It
73The access count has to be 0.
74.It
75The topology lock has to be held.
76.El
77.Sh RETURN VALUES
78The
79.Fn g_new_consumer
80function
81returns a pointer to the newly created consumer.
82.Sh EXAMPLES
83Create consumer, attach it to given provider, gain read access and clean up.
84.Bd -literal -offset indent
85void
86some_function(struct g_geom *mygeom, struct g_provider *pp)
87{
88	struct g_consumer *cp;
89
90	g_topology_assert();
91
92	/* Create new consumer on 'mygeom' geom. */
93	cp = g_new_consumer(mygeom);
94	/* Attach newly created consumer to given provider. */
95	if (g_attach(cp, pp) != 0) {
96		g_destroy_consumer(cp);
97		return;
98	}
99	/* Open provider for reading through our consumer. */
100	if (g_access(cp, 1, 0, 0) != 0) {
101		g_detach(cp);
102		g_destroy_consumer(cp);
103		return;
104	}
105
106	g_topology_unlock();
107	/*
108	 * Read data from provider.
109	 */
110	g_topology_lock();
111
112	/* Disconnect from provider (release access count). */
113	g_access(cp, -1, 0, 0);
114	/* Detach from provider. */
115	g_detach(cp);
116	/* Destroy consumer. */
117	g_destroy_consumer(cp);
118}
119.Ed
120.Sh SEE ALSO
121.Xr geom 4 ,
122.Xr DECLARE_GEOM_CLASS 9 ,
123.Xr g_access 9 ,
124.Xr g_attach 9 ,
125.Xr g_bio 9 ,
126.Xr g_data 9 ,
127.Xr g_event 9 ,
128.Xr g_geom 9 ,
129.Xr g_provider 9 ,
130.Xr g_provider_by_name 9 ,
131.Xr g_wither_geom 9
132.Sh AUTHORS
133.An -nosplit
134This manual page was written by
135.An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org .
136