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.
32 .Nd "control access to GEOM consumers and their providers"
36 .Fn g_access "struct g_consumer *cp" "int dcr" "int dcw" "int dce"
40 function allows to open, close, and generally change access to the provider
41 which is attached to the given consumer
48 represent relative read, write, and exclusive access count changes.
49 Read and write access counts are self explanatory, and
50 exclusive access counts deny write access to other interested parties.
51 A provider's access count is the sum of the access counts of all
54 After attaching a consumer to a provider with
58 function has to be called on the consumer before starting I/O requests.
59 .Sh RESTRICTIONS/CONDITIONS
60 The consumer has to be attached to a provider.
62 The intended change must not result in a negative access count.
64 No-operation is not permitted
73 The provider's geom must have an access method defined (e.g.,
76 The topology lock has to be held.
80 function returns 0 if successful; otherwise an error code is returned.
83 cannot fail when the arguments
88 are less than or equal to 0.
90 Create a consumer, attach it to a given provider, gain read access and
92 .Bd -literal -offset indent
94 some_function(struct g_geom *mygeom, struct g_provider *pp)
96 struct g_consumer *cp;
102 /* Create new consumer on 'mygeom' geom. */
103 cp = g_new_consumer(mygeom);
104 /* Attach newly created consumer to given provider. */
105 if (g_attach(cp, pp) != 0) {
106 g_destroy_consumer(cp);
109 /* Open provider for reading through our consumer. */
110 error = g_access(cp, 1, 0, 0);
112 printf("Cannot access provider: %s\\n", error);
114 g_destroy_consumer(cp);
119 * Don't hold topology lock while reading.
122 ptr = g_read_data(cp, 0, pp->sectorsize, &error);
124 printf("Error while reading: %d\\n", error);
126 * Do something useful with data.
130 /* Disconnect from provider (release access count). */
131 g_access(cp, -1, 0, 0);
132 /* Detach from provider. */
134 /* Destroy consumer. */
135 g_destroy_consumer(cp);
142 The function is trying to open a provider with an exclusive access count, but
143 it is already open for writing.
145 The function is trying to open a provider for writing, but it is already
149 Any other error that can be returned by the provider's access method.
152 .Xr DECLARE_GEOM_CLASS 9 ,
160 .Xr g_provider_by_name 9 ,
164 This manual page was written by
165 .An Pawel Jakub Dawidek Aq pjd@FreeBSD.org .