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