]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/disk.9
disk(9): Fix a few mandoc related errors
[FreeBSD/FreeBSD.git] / share / man / man9 / disk.9
1 .\"
2 .\" Copyright (c) 2003 Robert N. M. Watson
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(s), this list of conditions and the following disclaimer as
10 .\"    the first lines of this file unmodified other than the possible
11 .\"    addition of one or more copyright notices.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice(s), this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17 .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 .\" DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
20 .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 .\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 .\" DAMAGE.
27 .\"
28 .\" $FreeBSD$
29 .\"
30 .Dd April 30, 2020
31 .Dt DISK 9
32 .Os
33 .Sh NAME
34 .Nm disk
35 .Nd kernel disk storage API
36 .Sh SYNOPSIS
37 .In geom/geom_disk.h
38 .Ft struct disk *
39 .Fn disk_alloc void
40 .Ft void
41 .Fn disk_create "struct disk *disk" "int version"
42 .Ft void
43 .Fn disk_gone "struct disk *disk"
44 .Ft void
45 .Fn disk_destroy "struct disk *disk"
46 .Ft int
47 .Fn disk_resize "struct disk *disk" "int flags"
48 .Ft void
49 .Fn disk_add_alias "struct disk *disk" "const char *alias"
50 .Sh DESCRIPTION
51 The disk storage API permits kernel device drivers providing access to
52 disk-like storage devices to advertise the device to other kernel
53 components, including
54 .Xr GEOM 4
55 and
56 .Xr devfs 5 .
57 .Pp
58 Each disk device is described by a
59 .Vt "struct disk"
60 structure, which contains a variety of parameters for the disk device,
61 function pointers for various methods that may be performed on the device,
62 as well as private data storage for the device driver.
63 In addition, some fields are reserved for use by GEOM in managing access
64 to the device and its statistics.
65 .Pp
66 GEOM has the ownership of
67 .Vt "struct disk" ,
68 and drivers must allocate storage for it with the
69 .Fn disk_alloc
70 function,
71 fill in the fields and call
72 .Fn disk_create
73 when the device is ready to service requests.
74 .Fn disk_add_alias
75 adds an alias for the disk and must be called before
76 .Fn disk_create ,
77 but may be called multiple times.
78 For each alias added, a device node will be created with
79 .Xr make_dev_alias 9
80 in the same way primary device nodes are created with
81 .Xr make_dev 9
82 for
83 .Va d_name
84 and
85 .Va d_unit .
86 Care should be taken to ensure that only one driver creates aliases
87 for any given name.
88 .Fn disk_resize
89 can be called by the driver after modifying
90 .Va d_mediasize
91 to notify GEOM about the disk capacity change.
92 The
93 .Fa flags
94 field should be set to either M_WAITOK, or M_NOWAIT.
95 .Fn disk_gone
96 orphans all of the providers associated with the drive, setting an error
97 condition of ENXIO in each one.
98 In addition, it prevents a re-taste on last close for writing if an error
99 condition has been set in the provider.
100 After calling
101 .Fn disk_destroy ,
102 the device driver is not allowed to access the contents of
103 .Vt "struct disk"
104 anymore.
105 .Pp
106 The
107 .Fn disk_create
108 function
109 takes a second parameter,
110 .Fa version ,
111 which must always be passed
112 .Dv DISK_VERSION .
113 If GEOM detects that the driver is compiled against an unsupported version,
114 it will ignore the device and print a warning on the console.
115 .Ss Descriptive Fields
116 The following fields identify the disk device described by the structure
117 instance, and must be filled in prior to submitting the structure to
118 .Fn disk_create
119 and may not be subsequently changed:
120 .Bl -tag -width indent
121 .It Vt u_int Va d_flags
122 Optional flags indicating to the storage framework what optional features
123 or descriptions the storage device driver supports.
124 Currently supported flags are
125 .Dv DISKFLAG_OPEN
126 (maintained by storage framework),
127 .Dv DISKFLAG_CANDELETE
128 (maintained by device driver),
129 and
130 .Dv DISKFLAG_CANFLUSHCACHE
131 (maintained by device driver).
132 .It Vt "const char *" Va d_name
133 Holds the name of the storage device class, e.g.,
134 .Dq Li ahd .
135 This value typically uniquely identifies a particular driver device,
136 and must not conflict with devices serviced by other device drivers.
137 .It Vt u_int Va d_unit
138 Holds the instance of the storage device class, e.g.,
139 .Dq Li 4 .
140 This namespace is managed by the device driver, and assignment of unit
141 numbers might be a property of probe order, or in some cases topology.
142 Together, the
143 .Va d_name
144 and
145 .Va d_unit
146 values will uniquely identify a disk storage device.
147 .El
148 .Ss Disk Device Methods
149 The following fields identify various disk device methods, if implemented:
150 .Bl -tag -width indent
151 .It Vt "disk_open_t *" Va d_open
152 Optional: invoked when the disk device is opened.
153 If no method is provided, open will always succeed.
154 .It Vt "disk_close_t *" Va d_close
155 Optional: invoked when the disk device is closed.
156 Although an error code may be returned, the call should always terminate
157 any state setup by the corresponding open method call.
158 .It Vt "disk_strategy_t *" Va d_strategy
159 Mandatory: invoked when a new
160 .Vt "struct bio"
161 is to be initiated on the disk device.
162 .It Vt "disk_ioctl_t *" Va d_ioctl
163 Optional: invoked when an I/O control operation is initiated on the disk device.
164 Please note that for security reasons these operations should not
165 be able to affect other devices than the one on which they are performed.
166 .It Vt "dumper_t *" Va d_dump
167 Optional: if configured with
168 .Xr dumpon 8 ,
169 this function is invoked from a very restricted system state after a
170 kernel panic to record a copy of the system RAM to the disk.
171 .It Vt "disk_getattr_t *" Va d_getattr
172 Optional: if this method is provided, it gives the disk driver the
173 opportunity to override the default GEOM response to BIO_GETATTR requests.
174 This function should return -1 if the attribute is not handled, 0 if the
175 attribute is handled, or an errno to be passed to
176 .Fn g_io_deliver .
177 .It Vt "disk_gone_t *" Va d_gone
178 Optional: if this method is provided, it will be called after
179 .Fn disk_gone
180 is called, once GEOM has finished its cleanup process.
181 Once this callback is called, it is safe for the disk driver to free all of
182 its resources, as it will not be receiving further calls from GEOM.
183 .El
184 .Ss Mandatory Media Properties
185 The following fields identify the size and granularity of the disk device.
186 These fields must stay stable from return of the drivers open method until
187 the close method is called, but it is perfectly legal to modify them in
188 the open method before returning.
189 .Bl -tag -width indent
190 .It Vt u_int Va d_sectorsize
191 The sector size of the disk device in bytes.
192 .It Vt off_t Va d_mediasize
193 The size of the disk device in bytes.
194 .It Vt u_int Va d_maxsize
195 The maximum supported size in bytes of an I/O request.
196 Requests larger than this size will be chopped up by GEOM.
197 .El
198 .Ss Optional Media Properties
199 These optional fields can provide extra information about the disk
200 device.
201 Do not initialize these fields if the field/concept does not apply.
202 These fields must stay stable from return of the drivers open method until
203 the close method is called, but it is perfectly legal to modify them in
204 the open method before returning.
205 .Bl -tag -width indent
206 .It Vt u_int Va d_fwsectors , Vt u_int Va d_fwheads
207 The number of sectors and heads advertised on the disk device by the
208 firmware or BIOS.
209 These values are almost universally bogus, but on some architectures
210 necessary for the correct calculation of disk partitioning.
211 .It Vt u_int Va d_stripeoffset , Vt u_int Va d_stripesize
212 These two fields can be used to describe the width and location of
213 natural performance boundaries for most disk technologies.
214 Please see
215 .Pa src/sys/geom/notes
216 for details.
217 .It Vt char Va d_ident[DISK_IDENT_SIZE]
218 This field can and should be used to store disk's serial number if the
219 d_getattr method described above isn't implemented, or if it does not
220 support the GEOM::ident attribute.
221 .It Vt char Va d_descr[DISK_IDENT_SIZE]
222 This field can be used to store the disk vendor and product description.
223 .It Vt uint16_t Va d_hba_vendor
224 This field can be used to store the PCI vendor ID for the HBA connected to
225 the disk.
226 .It Vt uint16_t Va d_hba_device
227 This field can be used to store the PCI device ID for the HBA connected to
228 the disk.
229 .It Vt uint16_t Va d_hba_subvendor
230 This field can be used to store the PCI subvendor ID for the HBA connected to
231 the disk.
232 .It Vt uint16_t Va d_hba_subdevice
233 This field can be used to store the PCI subdevice ID for the HBA connected to
234 the disk.
235 .El
236 .Ss Driver Private Data
237 This field may be used by the device driver to store a pointer to
238 private data to implement the disk service.
239 .Bl -tag -width indent
240 .It Vt "void *" Va d_drv1
241 Private data pointer.
242 Typically used to store a pointer to the drivers
243 .Vt softc
244 structure for this disk device.
245 .El
246 .Sh SEE ALSO
247 .Xr GEOM 4 ,
248 .Xr devfs 5
249 .Sh HISTORY
250 The
251 .Nm kernel disk storage API
252 first appeared in
253 .Fx 4.9 .
254 .Sh AUTHORS
255 This manual page was written by
256 .An Robert Watson .
257 .Sh BUGS
258 Disk aliases are not a general purpose aliasing mechanism, but are
259 intended only to ease the transition from one name to another.
260 They can be used to ensure that nvd0 and nda0 are the same thing.
261 They cannot be used to implement the diskX concept from macOS.