mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-18 02:20:59 +03:00
3558fd73b5
I appologize in advance why to many things ended up in this commit. When it could be seperated in to a whole series of commits teasing that all apart now would take considerable time and I'm not sure there's much merrit in it. As such I'll just summerize the intent of the changes which are all (or partly) in this commit. Broadly the intent is to remove as much Solaris specific code as possible and replace it with native Linux equivilants. More specifically: 1) Replace all instances of zfsvfs_t with zfs_sb_t. While the type is largely the same calling it private super block data rather than a zfsvfs is more consistent with how Linux names this. While non critical it makes the code easier to read when your thinking in Linux friendly VFS terms. 2) Replace vnode_t with struct inode. The Linux VFS doesn't have the notion of a vnode and there's absolutely no good reason to create one. There are in fact several good reasons to remove it. It just adds overhead on Linux if we were to manage one, it conplicates the code, and it likely will lead to bugs so there's a good change it will be out of date. The code has been updated to remove all need for this type. 3) Replace all vtype_t's with umode types. Along with this shift all uses of types to mode bits. The Solaris code would pass a vtype which is redundant with the Linux mode. Just update all the code to use the Linux mode macros and remove this redundancy. 4) Remove using of vn_* helpers and replace where needed with inode helpers. The big example here is creating iput_aync to replace vn_rele_async. Other vn helpers will be addressed as needed but they should be be emulated. They are a Solaris VFS'ism and should simply be replaced with Linux equivilants. 5) Update znode alloc/free code. Under Linux it's common to embed the inode specific data with the inode itself. This removes the need for an extra memory allocation. In zfs this information is called a znode and it now embeds the inode with it. Allocators have been updated accordingly. 6) Minimal integration with the vfs flags for setting up the super block and handling mount options has been added this code will need to be refined but functionally it's all there. This will be the first and last of these to large to review commits.
217 lines
4.7 KiB
C
217 lines
4.7 KiB
C
/*
|
|
* CDDL HEADER START
|
|
*
|
|
* The contents of this file are subject to the terms of the
|
|
* Common Development and Distribution License (the "License").
|
|
* You may not use this file except in compliance with the License.
|
|
*
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
* See the License for the specific language governing permissions
|
|
* and limitations under the License.
|
|
*
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
*
|
|
* CDDL HEADER END
|
|
*/
|
|
/*
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
|
*/
|
|
|
|
#include <sys/zfs_context.h>
|
|
#include <sys/spa.h>
|
|
#include <sys/vdev_file.h>
|
|
#include <sys/vdev_impl.h>
|
|
#include <sys/zio.h>
|
|
#include <sys/fs/zfs.h>
|
|
#include <sys/fm/fs/zfs.h>
|
|
|
|
/*
|
|
* Virtual device vector for files.
|
|
*/
|
|
|
|
static void
|
|
vdev_file_hold(vdev_t *vd)
|
|
{
|
|
ASSERT(vd->vdev_path != NULL);
|
|
}
|
|
|
|
static void
|
|
vdev_file_rele(vdev_t *vd)
|
|
{
|
|
ASSERT(vd->vdev_path != NULL);
|
|
}
|
|
|
|
static int
|
|
vdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift)
|
|
{
|
|
vdev_file_t *vf;
|
|
vnode_t *vp;
|
|
vattr_t vattr;
|
|
int error;
|
|
|
|
/*
|
|
* We must have a pathname, and it must be absolute.
|
|
*/
|
|
if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
|
|
vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
|
|
return (EINVAL);
|
|
}
|
|
|
|
/*
|
|
* Reopen the device if it's not currently open. Otherwise,
|
|
* just update the physical size of the device.
|
|
*/
|
|
if (vd->vdev_tsd != NULL) {
|
|
ASSERT(vd->vdev_reopening);
|
|
vf = vd->vdev_tsd;
|
|
goto skip_open;
|
|
}
|
|
|
|
vf = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_file_t), KM_SLEEP);
|
|
|
|
/*
|
|
* We always open the files from the root of the global zone, even if
|
|
* we're in a local zone. If the user has gotten to this point, the
|
|
* administrator has already decided that the pool should be available
|
|
* to local zone users, so the underlying devices should be as well.
|
|
*/
|
|
ASSERT(vd->vdev_path != NULL && vd->vdev_path[0] == '/');
|
|
error = vn_openat(vd->vdev_path + 1, UIO_SYSSPACE,
|
|
spa_mode(vd->vdev_spa) | FOFFMAX, 0, &vp, 0, 0, rootdir, -1);
|
|
|
|
if (error) {
|
|
vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
|
|
return (error);
|
|
}
|
|
|
|
vf->vf_vnode = vp;
|
|
|
|
#ifdef _KERNEL
|
|
/*
|
|
* Make sure it's a regular file.
|
|
*/
|
|
if (vp->v_type != VREG) {
|
|
vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
|
|
return (ENODEV);
|
|
}
|
|
#endif
|
|
|
|
skip_open:
|
|
/*
|
|
* Determine the physical size of the file.
|
|
*/
|
|
vattr.va_mask = AT_SIZE;
|
|
error = VOP_GETATTR(vf->vf_vnode, &vattr, 0, kcred, NULL);
|
|
if (error) {
|
|
vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
|
|
return (error);
|
|
}
|
|
|
|
*psize = vattr.va_size;
|
|
*ashift = SPA_MINBLOCKSHIFT;
|
|
|
|
return (0);
|
|
}
|
|
|
|
static void
|
|
vdev_file_close(vdev_t *vd)
|
|
{
|
|
vdev_file_t *vf = vd->vdev_tsd;
|
|
|
|
if (vd->vdev_reopening || vf == NULL)
|
|
return;
|
|
|
|
if (vf->vf_vnode != NULL) {
|
|
(void) VOP_PUTPAGE(vf->vf_vnode, 0, 0, B_INVAL, kcred, NULL);
|
|
(void) VOP_CLOSE(vf->vf_vnode, spa_mode(vd->vdev_spa), 1, 0,
|
|
kcred, NULL);
|
|
}
|
|
|
|
vd->vdev_delayed_close = B_FALSE;
|
|
kmem_free(vf, sizeof (vdev_file_t));
|
|
vd->vdev_tsd = NULL;
|
|
}
|
|
|
|
static int
|
|
vdev_file_io_start(zio_t *zio)
|
|
{
|
|
vdev_t *vd = zio->io_vd;
|
|
vdev_file_t *vf = vd->vdev_tsd;
|
|
ssize_t resid = 0;
|
|
|
|
if (zio->io_type == ZIO_TYPE_IOCTL) {
|
|
/* XXPOLICY */
|
|
if (!vdev_readable(vd)) {
|
|
zio->io_error = ENXIO;
|
|
return (ZIO_PIPELINE_CONTINUE);
|
|
}
|
|
|
|
switch (zio->io_cmd) {
|
|
case DKIOCFLUSHWRITECACHE:
|
|
zio->io_error = VOP_FSYNC(vf->vf_vnode, FSYNC | FDSYNC,
|
|
kcred, NULL);
|
|
break;
|
|
default:
|
|
zio->io_error = ENOTSUP;
|
|
}
|
|
|
|
return (ZIO_PIPELINE_CONTINUE);
|
|
}
|
|
|
|
zio->io_error = vn_rdwr(zio->io_type == ZIO_TYPE_READ ?
|
|
UIO_READ : UIO_WRITE, vf->vf_vnode, zio->io_data,
|
|
zio->io_size, zio->io_offset, UIO_SYSSPACE,
|
|
0, RLIM64_INFINITY, kcred, &resid);
|
|
|
|
if (resid != 0 && zio->io_error == 0)
|
|
zio->io_error = ENOSPC;
|
|
|
|
zio_interrupt(zio);
|
|
|
|
return (ZIO_PIPELINE_STOP);
|
|
}
|
|
|
|
/* ARGSUSED */
|
|
static void
|
|
vdev_file_io_done(zio_t *zio)
|
|
{
|
|
}
|
|
|
|
vdev_ops_t vdev_file_ops = {
|
|
vdev_file_open,
|
|
vdev_file_close,
|
|
vdev_default_asize,
|
|
vdev_file_io_start,
|
|
vdev_file_io_done,
|
|
NULL,
|
|
vdev_file_hold,
|
|
vdev_file_rele,
|
|
VDEV_TYPE_FILE, /* name of this vdev type */
|
|
B_TRUE /* leaf vdev */
|
|
};
|
|
|
|
/*
|
|
* From userland we access disks just like files.
|
|
*/
|
|
#ifndef _KERNEL
|
|
|
|
vdev_ops_t vdev_disk_ops = {
|
|
vdev_file_open,
|
|
vdev_file_close,
|
|
vdev_default_asize,
|
|
vdev_file_io_start,
|
|
vdev_file_io_done,
|
|
NULL,
|
|
vdev_file_hold,
|
|
vdev_file_rele,
|
|
VDEV_TYPE_DISK, /* name of this vdev type */
|
|
B_TRUE /* leaf vdev */
|
|
};
|
|
|
|
#endif
|