vdev_file.c revision be6fd75a69ae679453d9cda5bff3326111e6d1ca
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
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens * Copyright (c) 2013 by Delphix. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Virtual device vector for files.
4263d13f00c9691fa14620eff82abef795be0693George Wilsonvdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We must have a pathname, and it must be absolute.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
095bcd6622e3b3520eb3b71039a3be5cfab25b74George Wilson * Reopen the device if it's not currently open. Otherwise,
095bcd6622e3b3520eb3b71039a3be5cfab25b74George Wilson * just update the physical size of the device.
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] == '/');
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick spa_mode(vd->vdev_spa) | FOFFMAX, 0, &vp, 0, 0, rootdir, -1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Make sure it's a regular file.
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);
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick (void) VOP_CLOSE(vf->vf_vnode, spa_mode(vd->vdev_spa), 1, 0,
31d7e8fa33fae995f558673adb22641b5aa8b6e1George Wilson * Implements the interrupt side for file vdev types. This routine will be
31d7e8fa33fae995f558673adb22641b5aa8b6e1George Wilson * called when the I/O completes allowing us to transfer the I/O to the
31d7e8fa33fae995f558673adb22641b5aa8b6e1George Wilson * interrupt taskqs. For consistency, the code structure mimics disk vdev
31d7e8fa33fae995f558673adb22641b5aa8b6e1George Wilson zio->io_error = (geterror(bp) != 0 ? EIO : 0);
31d7e8fa33fae995f558673adb22641b5aa8b6e1George Wilson error = vn_rdwr((bp->b_flags & B_READ) ? UIO_READ : UIO_WRITE,
31d7e8fa33fae995f558673adb22641b5aa8b6e1George Wilson vp, bp->b_un.b_addr, bp->b_bcount, ldbtob(bp->b_lblkno),
31d7e8fa33fae995f558673adb22641b5aa8b6e1George Wilson UIO_SYSSPACE, 0, RLIM64_INFINITY, kcred, &resid);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* XXPOLICY */
fa9e4066f08beec538e775443c5be79dd423fcabahrens zio->io_error = VOP_FSYNC(vf->vf_vnode, FSYNC | FDSYNC,
31d7e8fa33fae995f558673adb22641b5aa8b6e1George Wilson vb = kmem_alloc(sizeof (vdev_buf_t), KM_SLEEP);
31d7e8fa33fae995f558673adb22641b5aa8b6e1George Wilson bp->b_flags = (zio->io_type == ZIO_TYPE_READ ? B_READ : B_WRITE);
ec94d32216ed5705f5176582355cc311cf848e73Adam Leventhal spa_taskq_dispatch_ent(spa, ZIO_TYPE_FREE, ZIO_TASKQ_ISSUE,
31d7e8fa33fae995f558673adb22641b5aa8b6e1George Wilson vdev_file_io_strategy, bp, 0, &zio->io_tqent);
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick/* ARGSUSED */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * From userland we access disks just like files.