2007-04-06 01:09:06 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2006-2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
#include <sys/malloc.h>
|
2007-04-06 01:09:06 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/cred.h>
|
|
|
|
#include <sys/vfs.h>
|
|
|
|
#include <sys/priv.h>
|
|
|
|
#include <sys/libkern.h>
|
|
|
|
|
|
|
|
MALLOC_DECLARE(M_MOUNT);
|
|
|
|
|
|
|
|
void
|
|
|
|
vfs_setmntopt(vfs_t *vfsp, const char *name, const char *arg,
|
|
|
|
int flags __unused)
|
|
|
|
{
|
|
|
|
struct vfsopt *opt;
|
|
|
|
size_t namesize;
|
2009-09-07 18:23:26 +00:00
|
|
|
int locked;
|
|
|
|
|
|
|
|
if (!(locked = mtx_owned(MNT_MTX(vfsp))))
|
|
|
|
MNT_ILOCK(vfsp);
|
2007-04-06 01:09:06 +00:00
|
|
|
|
|
|
|
if (vfsp->mnt_opt == NULL) {
|
2009-09-07 18:23:26 +00:00
|
|
|
void *opts;
|
|
|
|
|
|
|
|
MNT_IUNLOCK(vfsp);
|
|
|
|
opts = malloc(sizeof(*vfsp->mnt_opt), M_MOUNT, M_WAITOK);
|
|
|
|
MNT_ILOCK(vfsp);
|
|
|
|
if (vfsp->mnt_opt == NULL) {
|
|
|
|
vfsp->mnt_opt = opts;
|
|
|
|
TAILQ_INIT(vfsp->mnt_opt);
|
|
|
|
} else {
|
|
|
|
free(opts, M_MOUNT);
|
|
|
|
}
|
2007-04-06 01:09:06 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 18:23:26 +00:00
|
|
|
MNT_IUNLOCK(vfsp);
|
2007-04-06 01:09:06 +00:00
|
|
|
|
2009-09-07 18:23:26 +00:00
|
|
|
opt = malloc(sizeof(*opt), M_MOUNT, M_WAITOK);
|
2007-04-06 01:09:06 +00:00
|
|
|
namesize = strlen(name) + 1;
|
|
|
|
opt->name = malloc(namesize, M_MOUNT, M_WAITOK);
|
|
|
|
strlcpy(opt->name, name, namesize);
|
2009-03-02 23:26:30 +00:00
|
|
|
opt->pos = -1;
|
|
|
|
opt->seen = 1;
|
2007-04-06 01:09:06 +00:00
|
|
|
if (arg == NULL) {
|
|
|
|
opt->value = NULL;
|
|
|
|
opt->len = 0;
|
|
|
|
} else {
|
|
|
|
opt->len = strlen(arg) + 1;
|
|
|
|
opt->value = malloc(opt->len, M_MOUNT, M_WAITOK);
|
|
|
|
bcopy(arg, opt->value, opt->len);
|
|
|
|
}
|
2009-09-07 18:23:26 +00:00
|
|
|
|
|
|
|
MNT_ILOCK(vfsp);
|
2007-04-06 01:09:06 +00:00
|
|
|
TAILQ_INSERT_TAIL(vfsp->mnt_opt, opt, link);
|
2009-09-07 18:23:26 +00:00
|
|
|
if (!locked)
|
|
|
|
MNT_IUNLOCK(vfsp);
|
2007-04-06 01:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vfs_clearmntopt(vfs_t *vfsp, const char *name)
|
|
|
|
{
|
2009-09-07 18:23:26 +00:00
|
|
|
int locked;
|
2007-04-06 01:09:06 +00:00
|
|
|
|
2009-09-07 18:23:26 +00:00
|
|
|
if (!(locked = mtx_owned(MNT_MTX(vfsp))))
|
|
|
|
MNT_ILOCK(vfsp);
|
2009-03-02 23:26:30 +00:00
|
|
|
vfs_deleteopt(vfsp->mnt_opt, name);
|
2009-09-07 18:23:26 +00:00
|
|
|
if (!locked)
|
|
|
|
MNT_IUNLOCK(vfsp);
|
2007-04-06 01:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vfs_optionisset(const vfs_t *vfsp, const char *opt, char **argp)
|
|
|
|
{
|
2008-07-21 09:45:44 +00:00
|
|
|
struct vfsoptlist *opts = vfsp->mnt_optnew;
|
2007-04-06 01:09:06 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
if (opts == NULL)
|
|
|
|
return (0);
|
|
|
|
error = vfs_getopt(opts, opt, (void **)argp, NULL);
|
|
|
|
return (error != 0 ? 0 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-09-14 21:10:40 +00:00
|
|
|
mount_snapshot(kthread_t *td, vnode_t **vpp, const char *fstype, char *fspath,
|
2007-04-06 01:09:06 +00:00
|
|
|
char *fspec, int fsflags)
|
|
|
|
{
|
|
|
|
struct mount *mp;
|
|
|
|
struct vfsconf *vfsp;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
struct ucred *cr;
|
2009-09-14 21:10:40 +00:00
|
|
|
vnode_t *vp;
|
2007-04-06 01:09:06 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Be ultra-paranoid about making sure the type and fspath
|
|
|
|
* variables will fit in our mp buffers, including the
|
|
|
|
* terminating NUL.
|
|
|
|
*/
|
|
|
|
if (strlen(fstype) >= MFSNAMELEN || strlen(fspath) >= MNAMELEN)
|
|
|
|
return (ENAMETOOLONG);
|
|
|
|
|
|
|
|
vfsp = vfs_byname_kld(fstype, td, &error);
|
|
|
|
if (vfsp == NULL)
|
|
|
|
return (ENODEV);
|
|
|
|
|
2009-09-14 21:10:40 +00:00
|
|
|
vp = *vpp;
|
2007-04-06 01:09:06 +00:00
|
|
|
if (vp->v_type != VDIR)
|
|
|
|
return (ENOTDIR);
|
2009-09-14 21:10:40 +00:00
|
|
|
/*
|
|
|
|
* We need vnode lock to protect v_mountedhere and vnode interlock
|
|
|
|
* to protect v_iflag.
|
|
|
|
*/
|
|
|
|
vn_lock(vp, LK_SHARED | LK_RETRY);
|
2007-04-06 01:09:06 +00:00
|
|
|
VI_LOCK(vp);
|
2009-09-14 21:10:40 +00:00
|
|
|
if ((vp->v_iflag & VI_MOUNT) != 0 || vp->v_mountedhere != NULL) {
|
2007-04-06 01:09:06 +00:00
|
|
|
VI_UNLOCK(vp);
|
2009-09-14 21:10:40 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
2007-04-06 01:09:06 +00:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
vp->v_iflag |= VI_MOUNT;
|
|
|
|
VI_UNLOCK(vp);
|
2009-09-14 21:10:40 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
2007-04-06 01:09:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate and initialize the filesystem.
|
|
|
|
*/
|
2008-08-31 14:26:08 +00:00
|
|
|
mp = vfs_mount_alloc(vp, vfsp, fspath, td->td_ucred);
|
2007-04-06 01:09:06 +00:00
|
|
|
|
|
|
|
mp->mnt_optnew = NULL;
|
|
|
|
vfs_setmntopt(mp, "from", fspec, 0);
|
|
|
|
mp->mnt_optnew = mp->mnt_opt;
|
|
|
|
mp->mnt_opt = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the mount level flags.
|
|
|
|
*/
|
2009-09-14 21:10:40 +00:00
|
|
|
mp->mnt_flag &= ~MNT_UPDATEMASK;
|
2007-04-06 01:09:06 +00:00
|
|
|
mp->mnt_flag |= fsflags & (MNT_UPDATEMASK | MNT_FORCE | MNT_ROOTFS);
|
2009-09-14 21:10:40 +00:00
|
|
|
/*
|
|
|
|
* Snapshots are always read-only.
|
|
|
|
*/
|
|
|
|
mp->mnt_flag |= MNT_RDONLY;
|
|
|
|
/*
|
|
|
|
* We don't want snapshots to be visible in regular
|
|
|
|
* mount(8) and df(1) output.
|
|
|
|
*/
|
|
|
|
mp->mnt_flag |= MNT_IGNORE;
|
2007-04-18 15:24:48 +00:00
|
|
|
/*
|
|
|
|
* Unprivileged user can trigger mounting a snapshot, but we don't want
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
* him to unmount it, so we switch to privileged of original mount.
|
2007-04-18 15:24:48 +00:00
|
|
|
*/
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
crfree(mp->mnt_cred);
|
|
|
|
mp->mnt_cred = crdup(vp->v_mount->mnt_cred);
|
2007-04-18 15:24:48 +00:00
|
|
|
mp->mnt_stat.f_owner = mp->mnt_cred->cr_uid;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
/*
|
|
|
|
* XXX: This is evil, but we can't mount a snapshot as a regular user.
|
|
|
|
* XXX: Is is safe when snapshot is mounted from within a jail?
|
|
|
|
*/
|
|
|
|
cr = td->td_ucred;
|
|
|
|
td->td_ucred = kcred;
|
2009-05-11 15:33:26 +00:00
|
|
|
error = VFS_MOUNT(mp);
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
td->td_ucred = cr;
|
2007-04-06 01:09:06 +00:00
|
|
|
|
2009-09-14 21:10:40 +00:00
|
|
|
if (error == 0) {
|
2007-04-06 01:09:06 +00:00
|
|
|
if (mp->mnt_opt != NULL)
|
|
|
|
vfs_freeopts(mp->mnt_opt);
|
|
|
|
mp->mnt_opt = mp->mnt_optnew;
|
2009-05-11 15:33:26 +00:00
|
|
|
(void)VFS_STATFS(mp, &mp->mnt_stat);
|
2007-04-06 01:09:06 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Prevent external consumers of mount options from reading
|
|
|
|
* mnt_optnew.
|
|
|
|
*/
|
|
|
|
mp->mnt_optnew = NULL;
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
2007-04-17 21:16:34 +00:00
|
|
|
#ifdef FREEBSD_NAMECACHE
|
|
|
|
cache_purge(vp);
|
|
|
|
#endif
|
2009-09-14 21:10:40 +00:00
|
|
|
VI_LOCK(vp);
|
|
|
|
vp->v_iflag &= ~VI_MOUNT;
|
|
|
|
VI_UNLOCK(vp);
|
|
|
|
if (error == 0) {
|
2007-04-06 01:09:06 +00:00
|
|
|
vnode_t *mvp;
|
|
|
|
|
|
|
|
vp->v_mountedhere = mp;
|
2009-09-14 21:10:40 +00:00
|
|
|
/*
|
|
|
|
* Put the new filesystem on the mount list.
|
|
|
|
*/
|
2007-04-06 01:09:06 +00:00
|
|
|
mtx_lock(&mountlist_mtx);
|
|
|
|
TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
|
|
|
mtx_unlock(&mountlist_mtx);
|
|
|
|
vfs_event_signal(NULL, VQ_MOUNT, 0);
|
2009-05-11 15:33:26 +00:00
|
|
|
if (VFS_ROOT(mp, LK_EXCLUSIVE, &mvp))
|
2007-04-06 01:09:06 +00:00
|
|
|
panic("mount: lost mount");
|
2009-09-14 21:10:40 +00:00
|
|
|
vput(vp);
|
2008-08-31 14:26:08 +00:00
|
|
|
vfs_unbusy(mp);
|
2009-09-14 21:10:40 +00:00
|
|
|
*vpp = mvp;
|
2007-04-06 01:09:06 +00:00
|
|
|
} else {
|
2009-09-14 21:10:40 +00:00
|
|
|
vput(vp);
|
2008-08-31 14:26:08 +00:00
|
|
|
vfs_unbusy(mp);
|
2007-04-06 01:09:06 +00:00
|
|
|
vfs_mount_destroy(mp);
|
2009-09-14 21:10:40 +00:00
|
|
|
*vpp = NULL;
|
2007-04-06 01:09:06 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|