vdev_file.c revision ea8dc4b6d2251b437950c0056bc626b311c73c27
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
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Copyright 2006 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.
fa9e4066f08beec538e775443c5be79dd423fcabahrensvdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift)
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 * When using a file vdev in kernel context, the underlying filesystem
fa9e4066f08beec538e775443c5be79dd423fcabahrens * will already be caching the data. Don't cache it again here.
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 error = vn_openat(vd->vdev_path + 1, UIO_SYSSPACE, spa_mode | FOFFMAX,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Make sure it's a regular file.
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);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* XXPOLICY */
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio->io_error = VOP_FSYNC(vf->vf_vnode, FSYNC | FDSYNC,
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (zio->io_type == ZIO_TYPE_READ && vdev_cache_read(zio) == 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* XXPOLICY */
fa9e4066f08beec538e775443c5be79dd423fcabahrens error = vdev_is_dead(vd) ? ENXIO : vdev_error_inject(vd, zio);
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio->io_error = vn_rdwr(zio->io_type == ZIO_TYPE_READ ?
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock zio->io_error = zio_handle_device_injection(zio->io_vd, EIO);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * From userland we access disks just like files.