xref: /freebsd/share/man/man9/g_geom.9 (revision c2025a76606b44c4d5367b7509fbc0285ae1e7f8)
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
286f39ea88SRuslan Ermilov.Dt G_GEOM 9
29f827ccb9SPawel Jakub Dawidek.Os
30f827ccb9SPawel Jakub Dawidek.Sh NAME
31f827ccb9SPawel Jakub Dawidek.Nm g_new_geomf ,
32f827ccb9SPawel Jakub Dawidek.Nm g_destroy_geom
33f827ccb9SPawel Jakub Dawidek.Nd "geom management"
34f827ccb9SPawel Jakub Dawidek.Sh SYNOPSIS
35f827ccb9SPawel Jakub Dawidek.In geom/geom.h
36f827ccb9SPawel Jakub Dawidek.Ft "struct g_geom *"
37f827ccb9SPawel Jakub Dawidek.Fn g_new_geomf "struct g_class *mp" "const char *fmt" ...
38f827ccb9SPawel Jakub Dawidek.Ft void
39f827ccb9SPawel Jakub Dawidek.Fn g_destroy_geom "struct g_geom *gp"
40f827ccb9SPawel Jakub Dawidek.Sh DESCRIPTION
41f827ccb9SPawel Jakub DawidekThe geom (do not confuse
42f827ccb9SPawel Jakub Dawidek.Dq geom
43f827ccb9SPawel Jakub Dawidekwith
44f827ccb9SPawel Jakub Dawidek.Dq GEOM )
45f827ccb9SPawel Jakub Dawidekis an instance of a GEOM class.
466f39ea88SRuslan ErmilovFor example: in a typical i386
476f39ea88SRuslan Ermilov.Fx
486f39ea88SRuslan Ermilovsystem, there will be one geom
49f827ccb9SPawel Jakub Dawidekof class MBR for each disk.
50f827ccb9SPawel Jakub DawidekThe geom's name is not really important, it is only used in the XML
51f827ccb9SPawel Jakub Dawidekdump and for debugging purposes.
52f827ccb9SPawel Jakub DawidekThere can be many geoms with the same name.
53f827ccb9SPawel Jakub Dawidek.Pp
54f827ccb9SPawel Jakub DawidekThe
55f827ccb9SPawel Jakub Dawidek.Fn g_new_geomf
56f827ccb9SPawel Jakub Dawidekfunction creates a new geom, which will be an instance of the class
57f827ccb9SPawel Jakub Dawidek.Fa mp .
586f39ea88SRuslan ErmilovThe geom's name is created in a
596f39ea88SRuslan Ermilov.Xr printf 3 Ns
606f39ea88SRuslan Ermilov-like way from the rest of the arguments.
61f827ccb9SPawel Jakub Dawidek.Pp
62f827ccb9SPawel Jakub DawidekThe
63f827ccb9SPawel Jakub Dawidek.Fn g_destroy_geom
64797bac4bSLukas Ertlfunction destroys the given geom immediately and cancels all related pending
65f827ccb9SPawel Jakub Dawidekevents.
66f827ccb9SPawel Jakub Dawidek.Pp
67797bac4bSLukas ErtlThe
68f827ccb9SPawel Jakub Dawidek.Vt g_geom
69797bac4bSLukas Ertlstructure
70797bac4bSLukas Ertlcontains fields that should be set by the caller after geom creation, but before
71f827ccb9SPawel Jakub Dawidekcreating any providers or consumers related to this geom (not all are required):
726f39ea88SRuslan Ermilov.Bl -tag -offset indent -width indent
73f827ccb9SPawel Jakub Dawidek.It Vt "g_start_t *" Va start
74f827ccb9SPawel Jakub DawidekPointer to a function used for I/O processing.
75f827ccb9SPawel Jakub Dawidek.It Vt "g_spoiled_t *" Va spoiled
76f827ccb9SPawel Jakub DawidekPointer to a function used for consumers spoiling.
77f827ccb9SPawel Jakub Dawidek.It Vt "g_dumpconf_t *" Va dumpconf
78f827ccb9SPawel Jakub DawidekPointer to a function used for configuration in XML format dumping.
79f827ccb9SPawel Jakub Dawidek.It Vt "g_access_t *" Va access
80f827ccb9SPawel Jakub DawidekPointer to a function used for access control.
81f827ccb9SPawel Jakub Dawidek.It Vt "g_orphan_t *" Va orphan
82f827ccb9SPawel Jakub DawidekPointer to a function used to inform about orphaned consumer.
83f827ccb9SPawel Jakub Dawidek.It Vt "g_ioctl_t *" Va ioctl
84f827ccb9SPawel Jakub DawidekPointer to a function used for handling ioctl requests.
85f827ccb9SPawel Jakub Dawidek.It Vt "void *" Va softc
86f827ccb9SPawel Jakub DawidekField for private use.
87f827ccb9SPawel Jakub Dawidek.El
88f827ccb9SPawel Jakub Dawidek.Sh RESTRICTIONS/CONDITIONS
89f827ccb9SPawel Jakub DawidekIf you intend to use providers in this geom you must set field
90f827ccb9SPawel Jakub Dawidek.Va start
91f827ccb9SPawel Jakub Dawidekof your geom.
92f827ccb9SPawel Jakub Dawidek.Pp
93f827ccb9SPawel Jakub DawidekIf you are planning to use consumers in your geom you must set fields
94f827ccb9SPawel Jakub Dawidek.Va orphan
95f827ccb9SPawel Jakub Dawidekand
96f827ccb9SPawel Jakub Dawidek.Va access
97f827ccb9SPawel Jakub Dawidekfor it.
98f827ccb9SPawel Jakub Dawidek.Pp
99f827ccb9SPawel Jakub Dawidek.Fn g_new_geomf :
100f827ccb9SPawel Jakub Dawidek.Bl -item -offset indent
101f827ccb9SPawel Jakub Dawidek.It
102f827ccb9SPawel Jakub DawidekClass
103f827ccb9SPawel Jakub Dawidek.Fa mp
104f827ccb9SPawel Jakub Dawidekmust be valid (registered in GEOM).
105f827ccb9SPawel Jakub Dawidek.It
106f827ccb9SPawel Jakub DawidekThe topology lock has to be held.
107f827ccb9SPawel Jakub Dawidek.El
108f827ccb9SPawel Jakub Dawidek.Pp
109f827ccb9SPawel Jakub Dawidek.Fn g_destroy_geom :
110f827ccb9SPawel Jakub Dawidek.Bl -item -offset indent
111f827ccb9SPawel Jakub Dawidek.It
112*c2025a76SJoel DahlThe geom cannot possess any providers.
113f827ccb9SPawel Jakub Dawidek.It
114*c2025a76SJoel DahlThe geom cannot possess any consumers.
115f827ccb9SPawel Jakub Dawidek.It
116f827ccb9SPawel Jakub DawidekThe topology lock has to be held.
117f827ccb9SPawel Jakub Dawidek.El
118f827ccb9SPawel Jakub Dawidek.Sh RETURN VALUES
1196f39ea88SRuslan ErmilovThe
120f827ccb9SPawel Jakub Dawidek.Fn g_new_geomf
1216f39ea88SRuslan Ermilovfunction
12206bb88dcSPawel Jakub Dawidekreturns a pointer to the newly created geom.
123f827ccb9SPawel Jakub Dawidek.Sh EXAMPLES
124f827ccb9SPawel Jakub DawidekCreate an example geom.
125f827ccb9SPawel Jakub Dawidek.Bd -literal -offset indent
126f827ccb9SPawel Jakub Dawidekstatic struct geom *
127f827ccb9SPawel Jakub Dawidekg_example_start(struct bio *bp)
128f827ccb9SPawel Jakub Dawidek{
129f827ccb9SPawel Jakub Dawidek
130f827ccb9SPawel Jakub Dawidek	[...]
131f827ccb9SPawel Jakub Dawidek}
132f827ccb9SPawel Jakub Dawidek
133f827ccb9SPawel Jakub Dawidekstatic void
134f827ccb9SPawel Jakub Dawidekg_example_orphan(struct g_consumer *cp)
135f827ccb9SPawel Jakub Dawidek{
136f827ccb9SPawel Jakub Dawidek
137f827ccb9SPawel Jakub Dawidek	g_topology_assert();
138f827ccb9SPawel Jakub Dawidek
139f827ccb9SPawel Jakub Dawidek	[...]
140f827ccb9SPawel Jakub Dawidek}
141f827ccb9SPawel Jakub Dawidek
142f827ccb9SPawel Jakub Dawidekstatic void
143f827ccb9SPawel Jakub Dawidekg_example_spoiled(struct g_consumer *cp)
144f827ccb9SPawel Jakub Dawidek{
145f827ccb9SPawel Jakub Dawidek
146f827ccb9SPawel Jakub Dawidek	g_topology_assert();
147f827ccb9SPawel Jakub Dawidek
148f827ccb9SPawel Jakub Dawidek	[...]
149f827ccb9SPawel Jakub Dawidek}
150f827ccb9SPawel Jakub Dawidek
151f827ccb9SPawel Jakub Dawidekstatic void
152f827ccb9SPawel Jakub Dawidekg_example_access(struct g_provider *pp, int dr, int dw, int de)
153f827ccb9SPawel Jakub Dawidek{
154f827ccb9SPawel Jakub Dawidek
155f827ccb9SPawel Jakub Dawidek	[...]
156f827ccb9SPawel Jakub Dawidek}
157f827ccb9SPawel Jakub Dawidek
158f827ccb9SPawel Jakub Dawidekstatic struct g_geom *
159f827ccb9SPawel Jakub Dawidekcreate_example_geom(struct g_class *myclass)
160f827ccb9SPawel Jakub Dawidek{
161f827ccb9SPawel Jakub Dawidek	struct g_geom *gp;
162f827ccb9SPawel Jakub Dawidek
163f827ccb9SPawel Jakub Dawidek	g_topology_lock();
164f827ccb9SPawel Jakub Dawidek	gp = g_new_geomf(myclass, "example_geom");
165f827ccb9SPawel Jakub Dawidek	g_topology_unlock();
166f827ccb9SPawel Jakub Dawidek	gp->start = g_example_start;
167f827ccb9SPawel Jakub Dawidek	gp->orphan = g_example_orphan;
168f827ccb9SPawel Jakub Dawidek	gp->spoiled = g_example_spoiled;
169f827ccb9SPawel Jakub Dawidek	gp->access = g_example_access;
170f827ccb9SPawel Jakub Dawidek	gp->softc = NULL;
171f827ccb9SPawel Jakub Dawidek
172f827ccb9SPawel Jakub Dawidek	return (gp);
173f827ccb9SPawel Jakub Dawidek}
174f827ccb9SPawel Jakub Dawidek
175f827ccb9SPawel Jakub Dawidekstatic int
176f827ccb9SPawel Jakub Dawidekdestroy_example_geom(struct g_geom *gp)
177f827ccb9SPawel Jakub Dawidek{
178f827ccb9SPawel Jakub Dawidek
179f827ccb9SPawel Jakub Dawidek	g_topology_lock();
180f827ccb9SPawel Jakub Dawidek	if (!LIST_EMPTY(&gp->provider) ||
181f827ccb9SPawel Jakub Dawidek	    !LIST_EMPTY(&gp->consumer)) {
182f827ccb9SPawel Jakub Dawidek		g_topology_unlock();
183f827ccb9SPawel Jakub Dawidek		return (EBUSY);
184f827ccb9SPawel Jakub Dawidek	}
185f827ccb9SPawel Jakub Dawidek	g_destroy_geom(gp);
186f827ccb9SPawel Jakub Dawidek	g_topology_unlock();
187f827ccb9SPawel Jakub Dawidek
188f827ccb9SPawel Jakub Dawidek	return (0);
189f827ccb9SPawel Jakub Dawidek}
190f827ccb9SPawel Jakub Dawidek.Ed
191f827ccb9SPawel Jakub Dawidek.Sh SEE ALSO
192f827ccb9SPawel Jakub Dawidek.Xr geom 4 ,
1931c85060aSRuslan Ermilov.Xr DECLARE_GEOM_CLASS 9 ,
1948217df6dSPawel Jakub Dawidek.Xr g_access 9 ,
195f827ccb9SPawel Jakub Dawidek.Xr g_attach 9 ,
196f827ccb9SPawel Jakub Dawidek.Xr g_bio 9 ,
197f827ccb9SPawel Jakub Dawidek.Xr g_consumer 9 ,
198f827ccb9SPawel Jakub Dawidek.Xr g_data 9 ,
199f827ccb9SPawel Jakub Dawidek.Xr g_event 9 ,
200f827ccb9SPawel Jakub Dawidek.Xr g_provider 9 ,
201f827ccb9SPawel Jakub Dawidek.Xr g_provider_by_name 9 ,
202f827ccb9SPawel Jakub Dawidek.Xr g_wither_geom 9
203f827ccb9SPawel Jakub Dawidek.Sh AUTHORS
204f827ccb9SPawel Jakub Dawidek.An -nosplit
205f827ccb9SPawel Jakub DawidekThis manual page was written by
206f827ccb9SPawel Jakub Dawidek.An Pawel Jakub Dawidek Aq pjd@FreeBSD.org .
207