2 .\" Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
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.
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.
31 .Nd "attach/detach GEOM consumers to/from providers"
35 .Fn g_attach "struct g_consumer *cp" "struct g_provider *pp"
37 .Fn g_detach "struct g_consumer *cp"
41 function attaches given consumer
45 thus establishing a communication channel between the consumer and the
46 provider that allows to change access counts and perform I/O operations.
50 function detaches given consumer
52 from its corresponding provider, tearing down the communication channel
54 .Sh RESTRICTIONS/CONDITIONS
56 .Bl -item -offset indent
58 The consumer must not be attached to a provider.
60 The operation must not create a topology loop.
62 The topology lock has to be held.
66 .Bl -item -offset indent
68 The consumer has to be attached.
70 The access count has to be 0.
72 There must be no active requests.
74 The topology lock has to be held.
79 function returns 0 if successful; otherwise an error code is returned.
81 Create a consumer, attach it to a given provider, gain read access and clean up.
82 .Bd -literal -offset indent
84 some_function(struct g_geom *mygeom, struct g_provider *pp)
86 struct g_consumer *cp;
90 /* Create new consumer on 'mygeom' geom. */
91 cp = g_new_consumer(mygeom);
92 /* Attach newly created consumer to given provider. */
93 if (g_attach(cp, pp) != 0) {
94 g_destroy_consumer(cp);
97 /* Open provider for reading through our consumer. */
98 if (g_access(cp, 1, 0, 0) != 0) {
100 g_destroy_consumer(cp);
106 * Read data from provider.
110 /* Disconnect from provider (release access count). */
111 g_access(cp, -1, 0, 0);
112 /* Detach from provider. */
114 /* Destroy consumer. */
115 g_destroy_consumer(cp);
122 The operation creates a topology loop.
124 Provider got orphaned.
128 .Xr DECLARE_GEOM_CLASS 9 ,
136 .Xr g_provider_by_name 9 ,
140 This manual page was written by
141 .An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org .