xref: /freebsd/share/man/man9/DECLARE_GEOM_CLASS.9 (revision 193d9e768ba63fcfb187cfd17f461f7d41345048)
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 August 13, 2007
28.Dt DECLARE_GEOM_CLASS 9
29.Os
30.Sh NAME
31.Nm DECLARE_GEOM_CLASS
32.Nd "GEOM class declaration macro"
33.Sh SYNOPSIS
34.In geom/geom.h
35.Fn DECLARE_GEOM_CLASS "class" "mod_name"
36.Sh DESCRIPTION
37The
38.Fn DECLARE_GEOM_CLASS
39macro registers a GEOM class in GEOM.
40A GEOM class itself implements one particular kind of transformation.
41Typical examples are: MBR disk partition,
42.Bx
43disklabel and RAID5 classes.
44.Fn DECLARE_GEOM_CLASS
45can be used both for compiled in and loaded as
46.Xr kld 4
47modules GEOM classes and it is the only official way for class registration.
48.Pp
49The arguments to
50.Fn DECLARE_GEOM_CLASS
51are:
52.Bl -tag -offset indent -width Fa
53.It Fa class
54The
55.Vt g_class
56structure which describes a GEOM class.
57.It Fa mod_name
58A kernel module name (not a class name!).
59.El
60.Pp
61Structure
62.Vt g_class
63contains data describing the class.
64They are:
65.Bl -tag -offset indent -width indent
66.It Vt "const char *" Va name
67Class name.
68.It Vt "g_taste_t *" Va taste
69Pointer to function used for taste event handling.
70If it is
71.Pf non- Dv NULL
72it is called in three situations:
73.Pp
74.Bl -dash -compact
75.It
76On class activation, all existing providers are offered for tasting.
77.It
78When new provider is created it is offered for tasting.
79.It
80After last write access to a provider is closed it is offered for retasting
81(on first write open event
82.Dq spoil
83was sent).
84.El
85.It Vt "g_config_t *" Va config
86This field is not used anymore, its functionality was replaced by the
87.Va ctlreq
88field.
89.It Vt "g_ctl_req_t *" Va ctlreq
90Pointer to function used for handling events from userland applications.
91.It Vt "g_init_t *" Va init
92Pointer to function which is called right after class registration.
93.It Vt "g_fini_t *" Va fini
94Pointer to function which is called right before class deregistration.
95.It Vt "g_ctl_destroy_geom_t *" Va destroy_geom
96Pointer to a function which is called for every geom on class unload.
97If this field is not set, the class can not be unloaded.
98.El
99.Pp
100Only a
101.Fa name
102field is required; the rest are optional.
103.Sh RESTRICTIONS/CONDITIONS
104The fields of
105.Vt g_class
106should always be initialized using C99-style field naming
107(see the initialization of
108.Va example_class
109below).
110.Sh EXAMPLES
111Example class declaration.
112.Bd -literal -offset indent
113static struct g_geom *
114g_example_taste(struct g_class *mp, struct g_provider *pp,
115    int flags __unused)
116{
117	g_topology_assert();
118
119	[...]
120}
121
122static void
123g_example_ctlreq(struct gctl_req *req, struct g_class *cp,
124    char const *verb)
125{
126
127	[...]
128}
129
130static int
131g_example_destroy_geom(struct gctl_req *req, struct g_class *cp,
132    struct g_geom *gp)
133{
134
135	g_topology_assert();
136
137	[...]
138}
139
140static void
141g_example_init(struct g_class *mp)
142{
143
144	[...]
145}
146
147static void
148g_example_fini(struct g_class *mp)
149{
150
151	[...]
152}
153
154struct g_class example_class = {
155	.name = "EXAMPLE",
156	.taste = g_example_taste,
157	.ctlreq = g_example_ctlreq,
158	.init = g_example_init,
159	.fini = g_example_fini,
160	.destroy_geom = g_example_destroy_geom
161};
162
163DECLARE_GEOM_CLASS(example_class, g_example);
164.Ed
165.Sh SEE ALSO
166.Xr geom 4 ,
167.Xr g_attach 9 ,
168.Xr g_bio 9 ,
169.Xr g_consumer 9 ,
170.Xr g_data 9 ,
171.Xr g_event 9 ,
172.Xr g_geom 9 ,
173.Xr g_provider 9 ,
174.Xr g_provider_by_name 9 ,
175.Xr g_wither_geom 9
176.Sh AUTHORS
177.An -nosplit
178This manual page was written by
179.An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org .
180