vdev_file.c revision 51ece83525fa18f5e72627610f480dffc7e492fd
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
32b87932f3ef0887d873b7f6d2d1943799b2afc0ek * Copyright 2008 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.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw error = VOP_GETATTR(vf->vf_vnode, &vattr, 0, kcred, NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) VOP_PUTPAGE(vf->vf_vnode, 0, 0, B_INVAL, kcred, NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) VOP_CLOSE(vf->vf_vnode, spa_mode, 1, 0, kcred, NULL);
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,
1f7ad2e1275fff503991bf4b43bc5cf1d815669fgw * Determine if the underlying device is accessible by reading and writing
1f7ad2e1275fff503991bf4b43bc5cf1d815669fgw * to a known location. We must be able to do this during syncing context
1f7ad2e1275fff503991bf4b43bc5cf1d815669fgw * and thus we cannot set the vdev state directly.
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 ?
e05725b117836db173257fae43fb0746eb857fb5bonwick zio->io_error = zio_handle_device_injection(vd, EIO);
1f7ad2e1275fff503991bf4b43bc5cf1d815669fgw * If an error has been encountered then attempt to probe the device
1f7ad2e1275fff503991bf4b43bc5cf1d815669fgw * to determine if it's still accessible.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * From userland we access disks just like files.