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