xref: /freebsd/share/man/man9/g_attach.9 (revision 2357939bc239bd5334a169b62313806178dd8f30)
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_attach 9
29.Os
30.Sh NAME
31.Nm g_attach ,
32.Nm g_detach
33.Nd "attach/detach consumer to/from provider"
34.Sh SYNOPSIS
35.In geom/geom.h
36.Ft int
37.Fn g_attach "struct g_consumer *cp" "struct g_provider *pp"
38.Ft void
39.Fn g_detach "struct g_consumer *cp"
40.Sh DESCRIPTION
41The
42.Fn g_attach
43function attaches given consumer to given provider.
44For real provider access (ie. I/O operations), one still need to call the
45.Fn g_access
46function on consumer to gain access to attached provider.
47.Pp
48The
49.Fn g_detach
50function detaches the given consumer from the corresponding provider.
51This function is used when we do not want to communicate with the
52provider anymore.
53.Sh RESTRICTIONS/CONDITIONS
54.Fn g_attach :
55.Bl -item -offset indent
56.It
57The consumer can not be attached already.
58.It
59The operation should not create a topology loop.
60.It
61The topology lock has to be held.
62.El
63.Pp
64.Fn g_detach :
65.Bl -item -offset indent
66.It
67The consumer has to be attached.
68.It
69The access count has to be 0.
70.It
71There must be no active requests.
72.It
73The topology lock has to be held.
74.El
75.Sh RETURN VALUES
76.Fn g_attach
77returns the value 0 if successful; otherwise an error code is returned.
78.Sh ERRORS
79Possible errors:
80.Bl -tag -width Er
81.It Bq Er ELOOP
82The operation creates a topology loop.
83.El
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 DECLARE_GEOM_CLASS 9 ,
124.Xr geom 4 ,
125.Xr g_access 9 ,
126.Xr g_bio 9 ,
127.Xr g_consumer 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 pjd@FreeBSD.org .
138