vdev_file.c revision 0a4e9518a44f226be6d39383330b5b1792d2f184
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
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 * CDDL HEADER END
0a4e9518a44f226be6d39383330b5b1792d2f184gw * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens#pragma ident "%Z%%M% %I% %E% SMI"
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Virtual device vector for files.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We must have a pathname, and it must be absolute.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
fa9e4066f08beec538e775443c5be79dd423fcabahrens vf = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_file_t), KM_SLEEP);
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 ASSERT(vd->vdev_path != NULL && vd->vdev_path[0] == '/');
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Make sure it's a regular file.
0a4e9518a44f226be6d39383330b5b1792d2f184gw return (0);
0a4e9518a44f226be6d39383330b5b1792d2f184gwvdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Determine the physical size of the file.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) VOP_PUTPAGE(vf->vf_vnode, 0, 0, B_INVAL, kcred);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) VOP_CLOSE(vf->vf_vnode, spa_mode, 1, 0, kcred);
0a4e9518a44f226be6d39383330b5b1792d2f184gwvdev_file_probe_io(vdev_t *vd, caddr_t data, size_t size, uint64_t offset,
0a4e9518a44f226be6d39383330b5b1792d2f184gw error = vn_rdwr(rw, vf->vf_vnode, data, size, offset, UIO_SYSSPACE,
0a4e9518a44f226be6d39383330b5b1792d2f184gw return (0);
0a4e9518a44f226be6d39383330b5b1792d2f184gw /* Hijack the current vdev */
0a4e9518a44f226be6d39383330b5b1792d2f184gw * Pick a random label to rewrite.
0a4e9518a44f226be6d39383330b5b1792d2f184gw while ((error = vdev_file_probe_io(nvd, vl_boot, VDEV_BOOT_HEADER_SIZE,
0a4e9518a44f226be6d39383330b5b1792d2f184gw * If we failed with the vdev that was passed in then
0a4e9518a44f226be6d39383330b5b1792d2f184gw * try allocating a new one and try again.
0a4e9518a44f226be6d39383330b5b1792d2f184gw error = vdev_file_probe_io(nvd, vl_boot, VDEV_BOOT_HEADER_SIZE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* XXPOLICY */
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio->io_error = VOP_FSYNC(vf->vf_vnode, FSYNC | FDSYNC,
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrens * In the kernel, don't bother double-caching, but in userland,
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrens * we want to test the vdev_cache code.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (zio->io_type == ZIO_TYPE_READ && vdev_cache_read(zio) == 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* XXPOLICY */
0a4e9518a44f226be6d39383330b5b1792d2f184gw error = vdev_writeable(vd) ? vdev_error_inject(vd, zio) : ENXIO;
0a4e9518a44f226be6d39383330b5b1792d2f184gw error = vdev_readable(vd) ? vdev_error_inject(vd, zio) : ENXIO;
0a4e9518a44f226be6d39383330b5b1792d2f184gw error = (vd->vdev_remove_wanted || vd->vdev_is_failing) ? ENXIO : error;
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio->io_error = vn_rdwr(zio->io_type == ZIO_TYPE_READ ?
0a4e9518a44f226be6d39383330b5b1792d2f184gw zio->io_error = zio_handle_device_injection(zio->io_vd, EIO);
0a4e9518a44f226be6d39383330b5b1792d2f184gw * If this device is truely gone, then attempt to remove it
0a4e9518a44f226be6d39383330b5b1792d2f184gw * from the configuration.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * From userland we access disks just like files.