xref: /freebsd/share/man/man4/geom.4 (revision 729362425c09cf6b362366aabc6fb547eee8035a)
1.\"
2.\" Copyright (c) 2002 Poul-Henning Kamp
3.\" Copyright (c) 2002 Networks Associates Technology, Inc.
4.\" All rights reserved.
5.\"
6.\" This software was developed for the FreeBSD Project by Poul-Henning Kamp
7.\" and NAI Labs, the Security Research Division of Network Associates, Inc.
8.\" under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
9.\" DARPA CHATS research program.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\" 1. Redistributions of source code must retain the above copyright
15.\"    notice, this list of conditions and the following disclaimer.
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\"    notice, this list of conditions and the following disclaimer in the
18.\"    documentation and/or other materials provided with the distribution.
19.\" 3. The names of the authors may not be used to endorse or promote
20.\"    products derived from this software without specific prior written
21.\"    permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\" $FreeBSD$
36.\"
37.Dd March 27, 2002
38.Os
39.Dt GEOM 4
40.Sh NAME
41.Nm GEOM
42.Nd modular disk I/O request transformation framework.
43.Sh DESCRIPTION
44The GEOM framework provides an infrastructure in which modules
45can perform transformations on disk I/O requests on their path from
46the upper kernel to the device drivers and back.
47.Pp
48Transformations in a GEOM context range from the simple geometric
49displacement performed in typical disklabel modules over RAID
50algorithms and device multipath resolution to full blown cryptographic
51protection of the stored data.
52.Pp
53Compared to traditional "volume management", GEOM differs from most
54and in some cases all previous implementations in the following ways:
55.Bl -bullet
56.It
57GEOM is extensible.  It is trivially simple to write a new class
58of transformation and it will not be given stepchild treatment.  If
59someone for some reason wanted to mount IBM MVS diskpacks, a class
60recognizing and configuring their VTOC information would be a trivial
61matter.
62.It
63GEOM is topologically agnostic.  Most volume management implementations
64have very strict notions of how classes can fit together, very often
65one fixed hierarchy is provided for instance  subdisk - plex -
66volume.
67.El
68.Pp
69Being extensible means that new transformations are treated no differently
70than existing transformations.
71.Pp
72Fixed hierarchies are bad because they make it impossible to express
73the intent efficiently.
74In the fixed hierarchy above it is not possible to mirror two
75physical disks and then partition the mirror into subdisks, instead
76one is forced to make subdisks on the physical volumes and to mirror
77these two and two resulting in a much more complex configuration.
78GEOM on the other hand does not care in which order things are done,
79the only restriction is that cycles in the graph will not be allowed.
80.Pp
81.Sh "TERMINOLOGY and TOPOLOGY"
82Geom is quite object oriented and consequently the terminology
83borrows a lot of context and semantics from the OO vocabulary:
84.Pp
85A "class", represented by the data structure g_class implements one
86particular kind of transformation.  Typical examples are MBR disk
87partition, BSD disklabel, and RAID5 classes.
88.Pp
89An instance of a class is called a "geom" and represented by the
90data structure "g_geom".  In a typical i386 FreeBSD system, there
91will be one geom of class MBR for each disk.
92.Pp
93A "provider", represented by the data structure "g_provider", is
94the front gate at which a geom offers service.
95A provider is "a disk-like thing which appears in /dev" - a logical
96disk in other words.
97All providers have three main properties: name, sectorsize and size.
98.Pp
99A "consumer" is the backdoor through which a geom connects to another
100geom provider and through which I/O requests are sent.
101.Pp
102The topological relationship between these entities are as follows:
103.Bl -bullet
104.It
105A class has zero or more geom instances.
106.It
107A geom has exactly one class it is derived from.
108.It
109A geom has zero or more consumers.
110.It
111A geom has zero or more providers.
112.It
113A consumer can be attached to zero or one providers.
114.It
115A provider can have zero or more consumers attached.
116.El
117.Pp
118All geoms have a rank-number assigned, which is used to detect and
119prevent loops in the acyclic directed graph.  This rank number is
120assigned as follows:
121.Bl -enum
122.It
123A geom with no attached consumers has rank=1
124.It
125A geom with attached consumers has a rank one higher than the
126highest rank of the geoms of the providers its consumers are
127attached to.
128.El
129.Sh "SPECIAL TOPOLOGICAL MANEUVERS"
130In addition to the straightforward attach, which attaches a consumer
131to a provider, and detach, which breaks the bond, a number of special
132topological maneuvers exists to facilitate configuration and to
133improve the overall flexibility.
134.Pp
135.Em TASTING
136is a process that happens whenever a new class or new provider
137is created and it is the class' chance to automatically configure an
138instance on providers, which it recognize as its own.
139A typical example is the MBR disk-partition class which will look for
140the MBR table in the first sector and if found and validated it will
141instantiate a geom to multiplex according to the contents of the MBR.
142.Pp
143A new class will be offered to all existing providers in turn and a new
144provider will be offered to all classes in turn.
145.Pp
146Exactly what a class does to recognize if it should accept the offered
147provider is not defined by GEOM, but the sensible set of options are:
148.Bl -bullet
149.It
150Examine specific data structures on the disk.
151.It
152Examine properties like sectorsize or mediasize for the provider.
153.It
154Examine the rank number of the provider's geom.
155.It
156Examine the method name of the provider's geom.
157.El
158.Pp
159.Em ORPHANIZATION
160is the process by which a provider is removed while
161it potentially is still being used.
162.Pp
163When a geom orphans a provider, all future I/O requests will
164"bounce" on the provider with an error code set by the geom.  Any
165consumers attached to the provider will receive notification about
166the orphanization when the eventloop gets around to it, and they
167need to take appropriate action at that time.
168.Pp
169A geom which came into being as a result of a normal taste operation
170should selfdestruct unless it has a way to keep functioning lacking
171the orphaned provider.
172Geoms like diskslicers should therefore selfdestruct whereas
173RAID5 or mirror geoms will be able to continue, as long as they do
174not loose quorum.
175.Pp
176When a provider is orphaned, this does not necessarily result in any
177immediate change in the topology: any attached consumers are still
178attached, any opened paths are still open, any outstanding I/O
179requests are still outstanding.
180.Pp
181The typical scenario is
182.Bl -bullet -offset indent -compact
183.It
184A device driver detects a disk has departed and orphans the provider for it.
185.It
186The geoms on top of the disk receive the orphanization event and
187orphans all their providers in turn.
188Providers, which are not attached to, will typically self-destruct
189right away.
190This process continues in a quasi-recursive fashion until all
191relevant pieces of the tree has heard the bad news.
192.It
193Eventually the buck stops when it reaches geom_dev at the top
194of the stack.
195.It
196Geom_dev will call destroy_dev(9) to stop any more request from
197coming in.
198It will sleep until all (if any) outstanding I/O requests have
199been returned.
200It will explicitly close (ie: zero the access counts), a change
201which will propagate all the way down through the mesh.
202It will then detach and destroy its geom.
203.It
204The geom whose provider is now attached will destroy the provider,
205detach and destroy its consumer and destroy its geom.
206.It
207This process percolates all the way down through the mesh, until
208the cleanup is complete.
209.El
210.Pp
211While this approach seems byzantine, it does provide the maximum
212flexibility and robustness in handling disappearing devices.
213.Pp
214The one absolutely crucial detail to be aware is that if the
215device driver does not return all I/O requests, the tree will
216not unravel and the geom event loop will stall.
217.Pp
218.Em SPOILING
219is a special case of orphanization used to protect
220against stale metadata.
221It is probably easiest to understand spoiling by going through
222an example.
223.Pp
224Imagine a disk, "da0" on top of which a MBR geom provides
225"da0s1" and "da0s2" and on top of "da0s1" a BSD geom provides
226"da0s1a" through "da0s1e", both the MBR and BSD geoms have
227autoconfigured based on data structures on the disk media.
228Now imagine the case where "da0" is opened for writing and those
229data structures are modified or overwritten:  Now the geoms would
230be operating on stale metadata unless some notification system
231can inform them otherwise.
232To avoid this situation, when the open of "da0" for write happens,
233all attached consumers are told about this, and geoms like
234MBR and BSD will selfdestruct as a result.
235When "da0" is closed again, it will be offered for tasting again
236and if the data structures for MBR and BSD are still there, new
237geoms will instantiate themselves anew.
238.Pp
239Now for the fine print:
240.Pp
241If any of the paths through the MBR or BSD module were open, they
242would have opened downwards with an exclusive bit rendering it
243impossible to open "da0" for writing in that case and conversely
244the requested exclusive bit would render it impossible to open a
245path through the MBR geom while "da0" is open for writing.
246.Pp
247From this it also follows that changing the size of open geoms can
248only be done through their cooperation.
249.Pp
250Finally: the spoiling only happens when the write count goes from
251zero to non-zero and the retasting only when the write count goes
252back to zero.
253.Pp
254.Em INSERT/DELETE
255are a very special operation which allows a new geom
256to be instantiated between a consumer and a provider attached to
257each other and to remove it again.
258.Pp
259To understand the utility of this, imagine a provider with
260being mounted as a file system.
261Between the DEVFS geoms consumer and its provider we insert
262a mirror module which configures itself with one mirror
263copy and consequently is transparent to the I/O requests
264on the path.
265We can now configure yet a mirror copy on the mirror geom,
266request a synchronization, and finally drop the first mirror
267copy.
268We have now in essence moved a mounted file system from one
269disk to another while it was being used.
270At this point the mirror geom can be deleted from the path
271again, it has served its purpose.
272.Pp
273.Em CONFIGURE
274is the process where the administrator issues instructions
275for a particular class to instantiate itself.  There are multiple
276ways to express intent in this case, a particular provider can be
277specified with a level of override forcing for instance a BSD
278disklabel module to attach to a provider which was not found palatable
279during the TASTE operation.
280.Pp
281Finally IO is the reason we even do this: it concerns itself with
282sending I/O requests through the graph.
283.Pp
284.Em "I/O REQUESTS
285represented by struct bio, originate at a consumer,
286are scheduled on its attached provider, and when processed, returned
287to the consumer.
288It is important to realize that the struct bio which
289enters through the provider of a particular geom does not "come
290out on the other side".
291Even simple transformations like MBR and BSD will clone the
292struct bio, modify the clone, and schedule the clone on their
293own consumer.
294Note that cloning the struct bio does not involve cloning the
295actual data area specified in the IO request.
296.Pp
297In total five different IO requests exist in GEOM: read, write,
298delete, format, get attribute, and set attribute.
299.Pp
300Read and write are self explanatory.
301.Pp
302Delete indicates that a certain range of data is no longer used
303and that it can be erased or freed as the underlying technology
304supports.
305Technologies like flash adaptation layers can arrange to erase
306the relevant blocks before they will become reassigned and
307cryptographic devices may want to fill random bits into the
308range to reduce the amount of data available for attack.
309.Pp
310It is important to recognize that a delete indication is not a
311request and consequently there is no guarantee that the data actually
312will be erased or made unavailable unless guaranteed by specific
313geoms in the graph.  If "secure delete" semantics are required, a
314geom should be pushed which converts delete indications into (a
315sequence of) write requests.
316.Pp
317Get attribute and set attribute supports inspection and manipulation
318of out-of-band attributes on a particular provider or path.
319Attributes are named by ascii strings and they will be discussed in
320a separate section below.
321.Pp
322(stay tuned while the author rests his brain and fingers: more to come.)
323.Sh HISTORY
324This software was developed for the FreeBSD Project by Poul-Henning Kamp
325and NAI Labs, the Security Research Division of Network Associates, Inc.
326under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
327DARPA CHATS research program.
328.Pp
329The first precursor for GEOM was a gruesome hack to Minix 1.2 and was
330never distributed.  An earlier attempt to implement a less general scheme
331in FreeBSD never succeeded.
332.Sh AUTHORS
333.An "Poul-Henning Kamp" Aq phk@FreeBSD.org
334