vdev_file.c revision 0a4e9518a44f226be6d39383330b5b1792d2f184
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * or http://www.opensolaris.org/os/licensing.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
0a4e9518a44f226be6d39383330b5b1792d2f184gw * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#pragma ident "%Z%%M% %I% %E% SMI"
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/zfs_context.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/spa.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/vdev_file.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/vdev_impl.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/zio.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/fs/zfs.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Virtual device vector for files.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int
0a4e9518a44f226be6d39383330b5b1792d2f184gwvdev_file_open_common(vdev_t *vd)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_file_t *vf;
fa9e4066f08beec538e775443c5be79dd423fcabahrens vnode_t *vp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens int error;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We must have a pathname, and it must be absolute.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
fa9e4066f08beec538e775443c5be79dd423fcabahrens vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (EINVAL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens vf = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_file_t), KM_SLEEP);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We always open the files from the root of the global zone, even if
fa9e4066f08beec538e775443c5be79dd423fcabahrens * we're in a local zone. If the user has gotten to this point, the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * administrator has already decided that the pool should be available
fa9e4066f08beec538e775443c5be79dd423fcabahrens * to local zone users, so the underlying devices should be as well.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT(vd->vdev_path != NULL && vd->vdev_path[0] == '/');
0a4e9518a44f226be6d39383330b5b1792d2f184gw error = vn_openat(vd->vdev_path + 1, UIO_SYSSPACE,
0a4e9518a44f226be6d39383330b5b1792d2f184gw spa_mode | FOFFMAX, 0, &vp, 0, 0, rootdir);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (error) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (error);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens vf->vf_vnode = vp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#ifdef _KERNEL
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Make sure it's a regular file.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (vp->v_type != VREG) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (ENODEV);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif
fa9e4066f08beec538e775443c5be79dd423fcabahrens
0a4e9518a44f226be6d39383330b5b1792d2f184gw return (0);
0a4e9518a44f226be6d39383330b5b1792d2f184gw}
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gwstatic int
0a4e9518a44f226be6d39383330b5b1792d2f184gwvdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift)
0a4e9518a44f226be6d39383330b5b1792d2f184gw{
0a4e9518a44f226be6d39383330b5b1792d2f184gw vdev_file_t *vf;
0a4e9518a44f226be6d39383330b5b1792d2f184gw vattr_t vattr;
0a4e9518a44f226be6d39383330b5b1792d2f184gw int error;
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw if ((error = vdev_file_open_common(vd)) != 0)
0a4e9518a44f226be6d39383330b5b1792d2f184gw return (error);
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw vf = vd->vdev_tsd;
0a4e9518a44f226be6d39383330b5b1792d2f184gw
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Determine the physical size of the file.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens vattr.va_mask = AT_SIZE;
0a4e9518a44f226be6d39383330b5b1792d2f184gw error = VOP_GETATTR(vf->vf_vnode, &vattr, 0, kcred);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (error) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (error);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens *psize = vattr.va_size;
fa9e4066f08beec538e775443c5be79dd423fcabahrens *ashift = SPA_MINBLOCKSHIFT;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void
fa9e4066f08beec538e775443c5be79dd423fcabahrensvdev_file_close(vdev_t *vd)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_file_t *vf = vd->vdev_tsd;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (vf == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (vf->vf_vnode != NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) VOP_PUTPAGE(vf->vf_vnode, 0, 0, B_INVAL, kcred);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) VOP_CLOSE(vf->vf_vnode, spa_mode, 1, 0, kcred);
fa9e4066f08beec538e775443c5be79dd423fcabahrens VN_RELE(vf->vf_vnode);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens kmem_free(vf, sizeof (vdev_file_t));
fa9e4066f08beec538e775443c5be79dd423fcabahrens vd->vdev_tsd = NULL;
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
0a4e9518a44f226be6d39383330b5b1792d2f184gwstatic int
0a4e9518a44f226be6d39383330b5b1792d2f184gwvdev_file_probe_io(vdev_t *vd, caddr_t data, size_t size, uint64_t offset,
0a4e9518a44f226be6d39383330b5b1792d2f184gw enum uio_rw rw)
0a4e9518a44f226be6d39383330b5b1792d2f184gw{
0a4e9518a44f226be6d39383330b5b1792d2f184gw vdev_file_t *vf = vd->vdev_tsd;
0a4e9518a44f226be6d39383330b5b1792d2f184gw ssize_t resid;
0a4e9518a44f226be6d39383330b5b1792d2f184gw int error = 0;
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw if (vd == NULL || vf == NULL || vf->vf_vnode == NULL)
0a4e9518a44f226be6d39383330b5b1792d2f184gw return (EINVAL);
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw ASSERT(rw == UIO_READ || rw == UIO_WRITE);
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw error = vn_rdwr(rw, vf->vf_vnode, data, size, offset, UIO_SYSSPACE,
0a4e9518a44f226be6d39383330b5b1792d2f184gw 0, RLIM64_INFINITY, kcred, &resid);
0a4e9518a44f226be6d39383330b5b1792d2f184gw if (error || resid != 0)
0a4e9518a44f226be6d39383330b5b1792d2f184gw return (EIO);
0a4e9518a44f226be6d39383330b5b1792d2f184gw return (0);
0a4e9518a44f226be6d39383330b5b1792d2f184gw}
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gwstatic int
0a4e9518a44f226be6d39383330b5b1792d2f184gwvdev_file_probe(vdev_t *vd)
0a4e9518a44f226be6d39383330b5b1792d2f184gw{
0a4e9518a44f226be6d39383330b5b1792d2f184gw vdev_t *nvd;
0a4e9518a44f226be6d39383330b5b1792d2f184gw char *vl_boot;
0a4e9518a44f226be6d39383330b5b1792d2f184gw uint64_t offset;
0a4e9518a44f226be6d39383330b5b1792d2f184gw int l, error = 0, retries = 0;
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw if (vd == NULL)
0a4e9518a44f226be6d39383330b5b1792d2f184gw return (EINVAL);
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw /* Hijack the current vdev */
0a4e9518a44f226be6d39383330b5b1792d2f184gw nvd = vd;
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw /*
0a4e9518a44f226be6d39383330b5b1792d2f184gw * Pick a random label to rewrite.
0a4e9518a44f226be6d39383330b5b1792d2f184gw */
0a4e9518a44f226be6d39383330b5b1792d2f184gw l = spa_get_random(VDEV_LABELS);
0a4e9518a44f226be6d39383330b5b1792d2f184gw ASSERT(l < VDEV_LABELS);
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw offset = vdev_label_offset(vd->vdev_psize, l,
0a4e9518a44f226be6d39383330b5b1792d2f184gw offsetof(vdev_label_t, vl_boot_header));
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw vl_boot = kmem_alloc(VDEV_BOOT_HEADER_SIZE, KM_SLEEP);
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw while ((error = vdev_file_probe_io(nvd, vl_boot, VDEV_BOOT_HEADER_SIZE,
0a4e9518a44f226be6d39383330b5b1792d2f184gw offset, UIO_READ)) != 0 && retries == 0) {
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw /*
0a4e9518a44f226be6d39383330b5b1792d2f184gw * If we failed with the vdev that was passed in then
0a4e9518a44f226be6d39383330b5b1792d2f184gw * try allocating a new one and try again.
0a4e9518a44f226be6d39383330b5b1792d2f184gw */
0a4e9518a44f226be6d39383330b5b1792d2f184gw nvd = kmem_zalloc(sizeof (vdev_t), KM_SLEEP);
0a4e9518a44f226be6d39383330b5b1792d2f184gw if (vd->vdev_path)
0a4e9518a44f226be6d39383330b5b1792d2f184gw nvd->vdev_path = spa_strdup(vd->vdev_path);
0a4e9518a44f226be6d39383330b5b1792d2f184gw error = vdev_file_open_common(nvd);
0a4e9518a44f226be6d39383330b5b1792d2f184gw if (error) {
0a4e9518a44f226be6d39383330b5b1792d2f184gw vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
0a4e9518a44f226be6d39383330b5b1792d2f184gw nvd->vdev_stat.vs_aux);
0a4e9518a44f226be6d39383330b5b1792d2f184gw break;
0a4e9518a44f226be6d39383330b5b1792d2f184gw }
0a4e9518a44f226be6d39383330b5b1792d2f184gw retries++;
0a4e9518a44f226be6d39383330b5b1792d2f184gw }
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw if ((spa_mode & FWRITE) && !error) {
0a4e9518a44f226be6d39383330b5b1792d2f184gw error = vdev_file_probe_io(nvd, vl_boot, VDEV_BOOT_HEADER_SIZE,
0a4e9518a44f226be6d39383330b5b1792d2f184gw offset, UIO_WRITE);
0a4e9518a44f226be6d39383330b5b1792d2f184gw }
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw if (retries) {
0a4e9518a44f226be6d39383330b5b1792d2f184gw vdev_file_close(nvd);
0a4e9518a44f226be6d39383330b5b1792d2f184gw if (nvd->vdev_path)
0a4e9518a44f226be6d39383330b5b1792d2f184gw spa_strfree(nvd->vdev_path);
0a4e9518a44f226be6d39383330b5b1792d2f184gw kmem_free(nvd, sizeof (vdev_t));
0a4e9518a44f226be6d39383330b5b1792d2f184gw }
0a4e9518a44f226be6d39383330b5b1792d2f184gw kmem_free(vl_boot, VDEV_BOOT_HEADER_SIZE);
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw if (!error)
0a4e9518a44f226be6d39383330b5b1792d2f184gw vd->vdev_is_failing = B_FALSE;
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw return (error);
0a4e9518a44f226be6d39383330b5b1792d2f184gw}
0a4e9518a44f226be6d39383330b5b1792d2f184gw
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void
fa9e4066f08beec538e775443c5be79dd423fcabahrensvdev_file_io_start(zio_t *zio)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_t *vd = zio->io_vd;
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_file_t *vf = vd->vdev_tsd;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ssize_t resid;
fa9e4066f08beec538e775443c5be79dd423fcabahrens int error;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (zio->io_type == ZIO_TYPE_IOCTL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio_vdev_io_bypass(zio);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* XXPOLICY */
0a4e9518a44f226be6d39383330b5b1792d2f184gw if (!vdev_readable(vd)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio->io_error = ENXIO;
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio_next_stage_async(zio);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (zio->io_cmd) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens case DKIOCFLUSHWRITECACHE:
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio->io_error = VOP_FSYNC(vf->vf_vnode, FSYNC | FDSYNC,
fa9e4066f08beec538e775443c5be79dd423fcabahrens kcred);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dprintf("fsync(%s) = %d\n", vdev_description(vd),
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio->io_error);
fa9e4066f08beec538e775443c5be79dd423fcabahrens break;
fa9e4066f08beec538e775443c5be79dd423fcabahrens default:
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio->io_error = ENOTSUP;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio_next_stage_async(zio);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrens /*
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrens * In the kernel, don't bother double-caching, but in userland,
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrens * we want to test the vdev_cache code.
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrens */
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrens#ifndef _KERNEL
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (zio->io_type == ZIO_TYPE_READ && vdev_cache_read(zio) == 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return;
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrens#endif
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((zio = vdev_queue_io(zio)) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* XXPOLICY */
0a4e9518a44f226be6d39383330b5b1792d2f184gw if (zio->io_type == ZIO_TYPE_WRITE)
0a4e9518a44f226be6d39383330b5b1792d2f184gw error = vdev_writeable(vd) ? vdev_error_inject(vd, zio) : ENXIO;
0a4e9518a44f226be6d39383330b5b1792d2f184gw else
0a4e9518a44f226be6d39383330b5b1792d2f184gw error = vdev_readable(vd) ? vdev_error_inject(vd, zio) : ENXIO;
0a4e9518a44f226be6d39383330b5b1792d2f184gw error = (vd->vdev_remove_wanted || vd->vdev_is_failing) ? ENXIO : error;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (error) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio->io_error = error;
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio_next_stage_async(zio);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio->io_error = vn_rdwr(zio->io_type == ZIO_TYPE_READ ?
fa9e4066f08beec538e775443c5be79dd423fcabahrens UIO_READ : UIO_WRITE, vf->vf_vnode, zio->io_data,
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio->io_size, zio->io_offset, UIO_SYSSPACE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens 0, RLIM64_INFINITY, kcred, &resid);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (resid != 0 && zio->io_error == 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio->io_error = ENOSPC;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio_next_stage_async(zio);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void
fa9e4066f08beec538e775443c5be79dd423fcabahrensvdev_file_io_done(zio_t *zio)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw if (zio_injection_enabled && zio->io_error == 0)
0a4e9518a44f226be6d39383330b5b1792d2f184gw zio->io_error = zio_handle_device_injection(zio->io_vd, EIO);
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw /*
0a4e9518a44f226be6d39383330b5b1792d2f184gw * If this device is truely gone, then attempt to remove it
0a4e9518a44f226be6d39383330b5b1792d2f184gw * from the configuration.
0a4e9518a44f226be6d39383330b5b1792d2f184gw */
0a4e9518a44f226be6d39383330b5b1792d2f184gw if (zio->io_error == EIO) {
0a4e9518a44f226be6d39383330b5b1792d2f184gw vdev_t *vd = zio->io_vd;
0a4e9518a44f226be6d39383330b5b1792d2f184gw
0a4e9518a44f226be6d39383330b5b1792d2f184gw if (vdev_probe(vd) != 0)
0a4e9518a44f226be6d39383330b5b1792d2f184gw vd->vdev_is_failing = B_TRUE;
0a4e9518a44f226be6d39383330b5b1792d2f184gw }
0a4e9518a44f226be6d39383330b5b1792d2f184gw
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_queue_io_done(zio);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrens#ifndef _KERNEL
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (zio->io_type == ZIO_TYPE_WRITE)
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_cache_write(zio);
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrens#endif
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio_next_stage(zio);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensvdev_ops_t vdev_file_ops = {
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_file_open,
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_file_close,
0a4e9518a44f226be6d39383330b5b1792d2f184gw vdev_file_probe,
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_default_asize,
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_file_io_start,
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_file_io_done,
fa9e4066f08beec538e775443c5be79dd423fcabahrens NULL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens VDEV_TYPE_FILE, /* name of this vdev type */
fa9e4066f08beec538e775443c5be79dd423fcabahrens B_TRUE /* leaf vdev */
fa9e4066f08beec538e775443c5be79dd423fcabahrens};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * From userland we access disks just like files.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens#ifndef _KERNEL
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensvdev_ops_t vdev_disk_ops = {
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_file_open,
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_file_close,
0a4e9518a44f226be6d39383330b5b1792d2f184gw vdev_file_probe,
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_default_asize,
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_file_io_start,
fa9e4066f08beec538e775443c5be79dd423fcabahrens vdev_file_io_done,
fa9e4066f08beec538e775443c5be79dd423fcabahrens NULL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens VDEV_TYPE_DISK, /* name of this vdev type */
fa9e4066f08beec538e775443c5be79dd423fcabahrens B_TRUE /* leaf vdev */
fa9e4066f08beec538e775443c5be79dd423fcabahrens};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif