vdev_disk.c revision 2264ca7f5db194583c672cb5779a67f52bcd92a9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/zfs_context.h>
#include <sys/refcount.h>
#include <sys/vdev_disk.h>
#include <sys/vdev_impl.h>
/*
* Virtual device vector for disks.
*/
extern ldi_ident_t zfs_li;
typedef struct vdev_disk_buf {
static int
{
int error;
int otyp;
/*
* We must have a pathname, and it must be absolute.
*/
return (EINVAL);
}
/*
* When opening a disk device, we want to preserve the user's original
* intent. We always want to open the device by the path the user gave
* us, even if it is one of multiple paths to the save device. But we
* Therefore the sequence of opening devices is:
*
* 1. Try opening the device by path. For legacy pools without the
* 'whole_disk' property, attempt to fix the path by appending 's0'.
*
* 2. If the devid of the device matches the stored value, return
* success.
*
* 3. Otherwise, the device may have moved. Try opening the device
* by the devid instead.
*
* If the vdev is part of the root pool, we avoid opening it by path.
* We do this because there is no /dev path available early in boot,
* and if we try to open the device by path at a later point, we can
* deadlock when devfsadm attempts to open the underlying backing store
* file.
*/
return (EINVAL);
}
}
} else {
}
}
/*
* Compare the devid to the stored value.
*/
kcred);
}
}
/*
* If we succeeded in opening the device, but 'vdev_wholedisk'
* is not yet set, then this must be a slice.
*/
vd->vdev_wholedisk = 0;
}
/*
* If we were unable to open by path, or the devid check fails, open by
* devid instead.
*/
/*
* If all else fails, then try opening by physical path (if available)
* or the logical path (if we failed due to the devid check). While not
* as reliable as the devid, this will give us something, and the higher
* level vdev validation will prevent us from opening the wrong device.
*/
if (error) {
/*
* Note that we don't support the legacy auto-wholedisk support
* as above. This hasn't been used in a very long time and we
* don't need to propagate its oddities to this edge condition.
*/
}
if (error) {
return (error);
}
/*
* Once a device is opened, verify that the physical device path (if
* available) is up to date.
*/
if (vd->vdev_physpath)
}
if (minorname)
}
/*
* Determine the actual size of the device.
*/
return (EINVAL);
}
/*
* If we own the whole disk, try to enable disk write caching.
* We ignore errors because it's OK if we can't do it.
*/
int wce = 1;
}
/*
* Determine the device's minimum transfer size.
* If the ioctl isn't supported, assume DEV_BSIZE.
*/
/*
* Clear the nowritecache bit, so that on a vdev_reopen() we will
* try again.
*/
return (0);
}
static void
{
return;
}
int
{
int error = 0;
return (EINVAL);
return (error);
}
static void
{
/*
* The rest of the zio stack only deals with EIO, ECKSUM, and ENXIO.
* Rather than teach the rest of the stack about other error
* possibilities (EFAULT, etc), we normalize the error value here.
*/
}
static void
{
}
static void
{
}
static int
{
struct dk_callback *dkc;
int error;
/* XXPOLICY */
if (!vdev_readable(vd)) {
return (ZIO_PIPELINE_CONTINUE);
}
case DKIOCFLUSHWRITECACHE:
if (zfs_nocacheflush)
break;
if (vd->vdev_nowritecache) {
break;
}
if (error == 0) {
/*
* The ioctl will be done asychronously,
* and will call vdev_disk_ioctl_done()
* upon completion.
*/
return (ZIO_PIPELINE_STOP);
}
/*
* If we get ENOTSUP or ENOTTY, we know that
* no future attempts will ever succeed.
* In this case we set a persistent bit so
* that we don't bother with the ioctl in the
* future.
*/
}
break;
default:
}
return (ZIO_PIPELINE_CONTINUE);
}
/* ldi_strategy() will return non-zero only on programming errors */
return (ZIO_PIPELINE_STOP);
}
static void
{
/*
* If the device returned EIO, then attempt a DKIOCSTATE ioctl to see if
* the device has been removed. If this is the case, then we trigger an
* asynchronous removal of the device. Otherwise, probe the device and
* make sure it's still accessible.
*/
}
}
}
NULL,
VDEV_TYPE_DISK, /* name of this vdev type */
B_TRUE /* leaf vdev */
};
/*
* Given the root disk device devid or pathname, read the label from
* the device, and construct a configuration nvlist.
*/
int
{
int l;
int error = -1;
char *minor_name;
/*
* Read the device label and build the nvlist.
*/
&minor_name) == 0) {
}
zfs_li)))
return (error);
if (ldi_get_size(vd_lh, &s)) {
return (EIO);
}
for (l = 0; l < VDEV_LABELS; l++) {
/* read vdev label */
continue;
continue;
}
continue;
}
continue;
}
break;
}
return (error);
}