xref: /freebsd/share/man/man9/g_consumer.9 (revision 0a36787e4c1fa0cf77dcf83be0867178476e372b)
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.Sh RESTRICTIONS/CONDITIONS
58.Fn g_new_consumer :
59.Bl -item -offset indent
60.It
61The geom
62.Fa gp
63has to have an
64.Va orphan
65method defined.
66.It
67The topology lock has to be held.
68.El
69.Pp
70.Fn g_destroy_consumer :
71.Bl -item -offset indent
72.It
73The consumer must not be attached to a provider.
74.It
75The access count has to be 0.
76.It
77The topology lock has to be held.
78.El
79.Sh RETURN VALUES
80The
81.Fn g_new_consumer
82function
83returns a pointer to the newly created consumer.
84.Sh EXAMPLES
85Create consumer, attach it to given provider, gain read access and clean up.
86.Bd -literal -offset indent
87void
88some_function(struct g_geom *mygeom, struct g_provider *pp)
89{
90	struct g_consumer *cp;
91
92	g_topology_assert();
93
94	/* Create new consumer on 'mygeom' geom. */
95	cp = g_new_consumer(mygeom);
96	/* Attach newly created consumer to given provider. */
97	if (g_attach(cp, pp) != 0) {
98		g_destroy_consumer(cp);
99		return;
100	}
101	/* Open provider for reading through our consumer. */
102	if (g_access(cp, 1, 0, 0) != 0) {
103		g_detach(cp);
104		g_destroy_consumer(cp);
105		return;
106	}
107
108	g_topology_unlock();
109	/*
110	 * Read data from provider.
111	 */
112	g_topology_lock();
113
114	/* Disconnect from provider (release access count). */
115	g_access(cp, -1, 0, 0);
116	/* Detach from provider. */
117	g_detach(cp);
118	/* Destroy consumer. */
119	g_destroy_consumer(cp);
120}
121.Ed
122.Sh SEE ALSO
123.Xr geom 4 ,
124.Xr DECLARE_GEOM_CLASS 9 ,
125.Xr g_access 9 ,
126.Xr g_attach 9 ,
127.Xr g_bio 9 ,
128.Xr g_data 9 ,
129.Xr g_event 9 ,
130.Xr g_geom 9 ,
131.Xr g_provider 9 ,
132.Xr g_provider_by_name 9 ,
133.Xr g_wither_geom 9
134.Sh AUTHORS
135.An -nosplit
136This manual page was written by
137.An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org .
138