freebsd-skq/share/man/man9/disk.9

256 lines
9.5 KiB
Groff
Raw Normal View History

.\"
.\" Copyright (c) 2003 Robert N. M. Watson
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice(s), this list of conditions and the following disclaimer as
.\" the first lines of this file unmodified other than the possible
.\" addition of one or more copyright notices.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice(s), this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
.\" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
.\" DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd August 3, 2017
.Dt DISK 9
.Os
.Sh NAME
.Nm disk
2004-02-19 12:02:54 +00:00
.Nd kernel disk storage API
.Sh SYNOPSIS
.In geom/geom_disk.h
.Ft struct disk *
2004-02-19 12:02:54 +00:00
.Fn disk_alloc void
.Ft void
2004-02-19 12:02:54 +00:00
.Fn disk_create "struct disk *disk" "int version"
.Ft void
.Fn disk_gone "struct disk *disk"
.Ft void
.Fn disk_destroy "struct disk *disk"
2012-10-30 13:05:50 +00:00
.Ft int
.Fn disk_resize "struct disk *disk" "int flags"
.Ft void
.Fn disk_add_alias "struct disk *disk" "const char *alias"
.Sh DESCRIPTION
The disk storage API permits kernel device drivers providing access to
disk-like storage devices to advertise the device to other kernel
components, including
2004-02-19 12:02:54 +00:00
.Xr GEOM 4
and
.Xr devfs 5 .
.Pp
Each disk device is described by a
.Vt "struct disk"
structure, which contains a variety of parameters for the disk device,
function pointers for various methods that may be performed on the device,
as well as private data storage for the device driver.
In addition, some fields are reserved for use by GEOM in managing access
to the device and its statistics.
2004-02-18 22:10:08 +00:00
.Pp
GEOM has the ownership of
.Vt "struct disk" ,
2004-02-18 22:10:08 +00:00
and drivers must allocate storage for it with the
.Fn disk_alloc
function,
fill in the fields and call
.Fn disk_create
when the device is ready to service requests.
.Fn disk_add_alias
adds an alias for the disk and must be called before
.Fn disk_create ,
but may be called multiple times.
For each alias added, a device node will be created with
.Xr make_dev_alias 9
in the same way primary device nodes are created with
.Xr make_dev 9
for
.Va d_name
and
.Va d_unit .
Care should be taken to ensure that only one driver creates aliases
for any given name.
2012-10-30 13:05:50 +00:00
.Fn disk_resize
can be called by the driver after modifying
.Va d_mediasize
to notify GEOM about the disk capacity change.
The
.Fa flags
field should be set to either M_WAITOK, or M_NOWAIT.
.Fn disk_gone
orphans all of the providers associated with the drive, setting an error
condition of ENXIO in each one.
In addition, it prevents a re-taste on last close for writing if an error
condition has been set in the provider.
2004-02-18 22:10:08 +00:00
After calling
2004-02-19 12:02:54 +00:00
.Fn disk_destroy ,
the device driver is not allowed to access the contents of
.Vt "struct disk"
anymore.
.Pp
2004-02-19 12:02:54 +00:00
The
2004-02-18 22:10:08 +00:00
.Fn disk_create
2004-02-19 12:02:54 +00:00
function
takes a second parameter,
.Fa version ,
2004-02-18 22:10:08 +00:00
which must always be passed
.Dv DISK_VERSION .
2004-02-19 12:02:54 +00:00
If GEOM detects that the driver is compiled against an unsupported version,
2004-02-18 22:10:08 +00:00
it will ignore the device and print a warning on the console.
.Ss Descriptive Fields
The following fields identify the disk device described by the structure
instance, and must be filled in prior to submitting the structure to
2004-02-19 12:02:54 +00:00
.Fn disk_create
2004-02-18 22:10:08 +00:00
and may not be subsequently changed:
2004-02-19 12:02:54 +00:00
.Bl -tag -width indent
.It Vt u_int Va d_flags
Optional flags indicating to the storage framework what optional features
or descriptions the storage device driver supports.
Currently supported flags are
.Dv DISKFLAG_OPEN
(maintained by storage framework),
.Dv DISKFLAG_CANDELETE
(maintained by device driver),
and
.Dv DISKFLAG_CANFLUSHCACHE
(maintained by device driver).
.It Vt "const char *" Va d_name
Holds the name of the storage device class, e.g.,
2004-02-19 12:02:54 +00:00
.Dq Li ahd .
This value typically uniquely identifies a particular driver device,
and must not conflict with devices serviced by other device drivers.
.It Vt u_int Va d_unit
Holds the instance of the storage device class, e.g.,
2004-02-19 12:02:54 +00:00
.Dq Li 4 .
This namespace is managed by the device driver, and assignment of unit
numbers might be a property of probe order, or in some cases topology.
Together, the
.Va d_name
and
.Va d_unit
values will uniquely identify a disk storage device.
.El
.Ss Disk Device Methods
The following fields identify various disk device methods, if implemented:
2004-02-19 12:02:54 +00:00
.Bl -tag -width indent
.It Vt "disk_open_t *" Va d_open
2004-02-19 12:02:54 +00:00
Optional: invoked when the disk device is opened.
If no method is provided, open will always succeed.
.It Vt "disk_close_t *" Va d_close
2004-02-19 12:02:54 +00:00
Optional: invoked when the disk device is closed.
2004-02-18 22:10:08 +00:00
Although an error code may be returned, the call should always terminate
2004-06-21 14:11:45 +00:00
any state setup by the corresponding open method call.
.It Vt "disk_strategy_t *" Va d_strategy
2004-02-19 12:02:54 +00:00
Mandatory: invoked when a new
.Vt "struct bio"
is to be initiated on the disk device.
.It Vt "disk_ioctl_t *" Va d_ioctl
2004-02-19 12:02:54 +00:00
Optional: invoked when an I/O control operation is initiated on the disk device.
2004-02-18 22:10:08 +00:00
Please note that for security reasons these operations should not
be able to affect other devices than the one on which they are performed.
.It Vt "dumper_t *" Va d_dump
2004-02-19 12:02:54 +00:00
Optional: if configured with
.Xr dumpon 8 ,
2004-02-18 22:10:08 +00:00
this function is invoked from a very restricted system state after a
2004-02-19 12:02:54 +00:00
kernel panic to record a copy of the system RAM to the disk.
Fix a bug which causes a panic in daopen(). The panic is caused by a da(4) instance going away while GEOM is still probing it. In this case, the GEOM disk class instance has been created by disk_create(), and the taste of the disk is queued in the GEOM event queue. While that event is queued, the da(4) instance goes away. When the open call comes into the da(4) driver, it dereferences the freed (but non-NULL) peripheral pointer provided by GEOM, which results in a panic. The solution is to add a callback to the GEOM disk code that is called when all of its resources are cleaned up. This is implemented inside GEOM by adding an optional callback that is called when all consumers have detached from a provider, and the provider is about to be deleted. scsi_cd.c, scsi_da.c: In the register routine for the cd(4) and da(4) routines, acquire a reference to the CAM peripheral instance just before we call disk_create(). Use the new GEOM disk d_gone() callback to register a callback (dadiskgonecb()/cddiskgonecb()) that decrements the peripheral reference count once GEOM has finished cleaning up its resources. In the cd(4) driver, clean up open and close behavior slightly. GEOM makes sure we only get one open() and one close call, so there is no need to set an open flag and decrement the reference count if we are not the first open. In the cd(4) driver, use cam_periph_release_locked() in a couple of error scenarios to avoid extra mutex calls. geom.h: Add a new, optional, providergone callback that is called when a provider is about to be deleted. geom_disk.h: Add a new d_gone() callback to the GEOM disk interface. Bump the DISK_VERSION to version 2. This probably should have been done after a couple of previous changes, especially the addition of the d_getattr() callback. geom_disk.c: Add a providergone callback for the disk class, g_disk_providergone(), that calls the user's d_gone() callback if it exists. Bump the DISK_VERSION to 2. geom_subr.c: In g_destroy_provider(), call the providergone callback if it has been provided. In g_new_geomf(), propagate the class's providergone callback to the new geom instance. blkfront.c: Callers of disk_create() are supposed to pass in DISK_VERSION, not an explicit disk API version number. Update the blkfront driver to do that. disk.9: Update the disk(9) man page to include information on the new d_gone() callback, as well as the previously added d_getattr() callback, d_descr field, and HBA PCI ID fields. MFC after: 5 days
2012-06-24 04:29:03 +00:00
.It Vt "disk_getattr_t *" Va d_getattr
Optional: if this method is provided, it gives the disk driver the
opportunity to override the default GEOM response to BIO_GETATTR requests.
This function should return -1 if the attribute is not handled, 0 if the
attribute is handled, or an errno to be passed to g_io_deliver().
.It Vt "disk_gone_t *" Va d_gone
Optional: if this method is provided, it will be called after disk_gone()
is called, once GEOM has finished its cleanup process.
Once this callback is called, it is safe for the disk driver to free all of
its resources, as it will not be receiving further calls from GEOM.
.El
2004-02-18 22:10:08 +00:00
.Ss Mandatory Media Properties
The following fields identify the size and granularity of the disk device.
These fields must stay stable from return of the drivers open method until
the close method is called, but it is perfectly legal to modify them in
the open method before returning.
2004-02-19 12:02:54 +00:00
.Bl -tag -width indent
.It Vt u_int Va d_sectorsize
2004-02-19 12:02:54 +00:00
The sector size of the disk device in bytes.
.It Vt off_t Va d_mediasize
The size of the disk device in bytes.
2004-02-18 22:10:08 +00:00
.It Vt u_int Va d_maxsize
2004-02-19 12:02:54 +00:00
The maximum supported size in bytes of an I/O request.
2004-02-18 22:10:08 +00:00
Requests larger than this size will be chopped up by GEOM.
.El
.Ss Optional Media Properties
These optional fields can provide extra information about the disk
device.
Do not initialize these fields if the field/concept does not apply.
These fields must stay stable from return of the drivers open method until
the close method is called, but it is perfectly legal to modify them in
the open method before returning.
2004-02-19 12:02:54 +00:00
.Bl -tag -width indent
.It Vt u_int Va d_fwsectors , Vt u_int Va d_fwheads
2004-02-18 22:10:08 +00:00
The number of sectors and heads advertised on the disk device by the
firmware or BIOS.
These values are almost universally bogus, but on some architectures
2004-02-19 12:02:54 +00:00
necessary for the correct calculation of disk partitioning.
.It Vt u_int Va d_stripeoffset , Vt u_int Va d_stripesize
2004-02-18 22:10:08 +00:00
These two fields can be used to describe the width and location of
natural performance boundaries for most disk technologies.
Please see
2004-02-19 12:02:54 +00:00
.Pa src/sys/geom/notes
2004-02-18 22:10:08 +00:00
for details.
.It Vt char Va d_ident[DISK_IDENT_SIZE]
Fix a bug which causes a panic in daopen(). The panic is caused by a da(4) instance going away while GEOM is still probing it. In this case, the GEOM disk class instance has been created by disk_create(), and the taste of the disk is queued in the GEOM event queue. While that event is queued, the da(4) instance goes away. When the open call comes into the da(4) driver, it dereferences the freed (but non-NULL) peripheral pointer provided by GEOM, which results in a panic. The solution is to add a callback to the GEOM disk code that is called when all of its resources are cleaned up. This is implemented inside GEOM by adding an optional callback that is called when all consumers have detached from a provider, and the provider is about to be deleted. scsi_cd.c, scsi_da.c: In the register routine for the cd(4) and da(4) routines, acquire a reference to the CAM peripheral instance just before we call disk_create(). Use the new GEOM disk d_gone() callback to register a callback (dadiskgonecb()/cddiskgonecb()) that decrements the peripheral reference count once GEOM has finished cleaning up its resources. In the cd(4) driver, clean up open and close behavior slightly. GEOM makes sure we only get one open() and one close call, so there is no need to set an open flag and decrement the reference count if we are not the first open. In the cd(4) driver, use cam_periph_release_locked() in a couple of error scenarios to avoid extra mutex calls. geom.h: Add a new, optional, providergone callback that is called when a provider is about to be deleted. geom_disk.h: Add a new d_gone() callback to the GEOM disk interface. Bump the DISK_VERSION to version 2. This probably should have been done after a couple of previous changes, especially the addition of the d_getattr() callback. geom_disk.c: Add a providergone callback for the disk class, g_disk_providergone(), that calls the user's d_gone() callback if it exists. Bump the DISK_VERSION to 2. geom_subr.c: In g_destroy_provider(), call the providergone callback if it has been provided. In g_new_geomf(), propagate the class's providergone callback to the new geom instance. blkfront.c: Callers of disk_create() are supposed to pass in DISK_VERSION, not an explicit disk API version number. Update the blkfront driver to do that. disk.9: Update the disk(9) man page to include information on the new d_gone() callback, as well as the previously added d_getattr() callback, d_descr field, and HBA PCI ID fields. MFC after: 5 days
2012-06-24 04:29:03 +00:00
This field can and should be used to store disk's serial number if the
d_getattr method described above isn't implemented, or if it does not
support the GEOM::ident attribute.
.It Vt char Va d_descr[DISK_IDENT_SIZE]
This field can be used to store the disk vendor and product description.
.It Vt uint16_t Va d_hba_vendor
This field can be used to store the PCI vendor ID for the HBA connected to
the disk.
.It Vt uint16_t Va d_hba_device
This field can be used to store the PCI device ID for the HBA connected to
the disk.
.It Vt uint16_t Va d_hba_subvendor
This field can be used to store the PCI subvendor ID for the HBA connected to
the disk.
.It Vt uint16_t Va d_hba_subdevice
This field can be used to store the PCI subdevice ID for the HBA connected to
the disk.
.El
.Ss Driver Private Data
This field may be used by the device driver to store a pointer to
private data to implement the disk service.
2004-02-19 12:02:54 +00:00
.Bl -tag -width indent
.It Vt "void *" Va d_drv1
Private data pointer.
2004-02-19 12:02:54 +00:00
Typically used to store a pointer to the drivers
.Vt softc
structure for this disk device.
.El
.Sh SEE ALSO
.Xr GEOM 4 ,
.Xr devfs 5 ,
.Xr MAKE_DEV 9
.Sh AUTHORS
This manual page was written by
.An Robert Watson .
.Sh BUGS
Disk aliases are not a general purpose aliasing mechanism, but are
intended only to ease the transition from one name to another.
They can be used to ensure that nvd0 and nda0 are the same thing.
They cannot be used to implement the diskX concept from macOS.