2005-01-06 18:10:42 +00:00
|
|
|
/*-
|
1997-02-10 02:22:35 +00:00
|
|
|
* Copyright (c) 1994, 1995 The Regents of the University of California.
|
|
|
|
* Copyright (c) 1994, 1995 Jan-Simon Pendry.
|
1994-05-24 10:09:53 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software donated to Berkeley by
|
|
|
|
* Jan-Simon Pendry.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
|
|
|
*
|
1997-02-10 02:22:35 +00:00
|
|
|
* @(#)union_vfsops.c 8.20 (Berkeley) 5/20/95
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Union Layer
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1994-09-22 19:38:41 +00:00
|
|
|
#include <sys/kernel.h>
|
2001-06-28 03:50:17 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/filedesc.h>
|
2001-05-23 09:42:29 +00:00
|
|
|
#include <fs/unionfs/union.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2005-10-31 15:41:29 +00:00
|
|
|
static MALLOC_DEFINE(M_UNIONFSMNT, "union_mount", "UNION mount structure");
|
1997-10-12 20:26:33 +00:00
|
|
|
|
2003-06-12 20:48:38 +00:00
|
|
|
extern vfs_init_t union_init;
|
|
|
|
static vfs_root_t union_root;
|
2004-07-30 22:08:52 +00:00
|
|
|
static vfs_mount_t union_mount;
|
2003-06-12 20:48:38 +00:00
|
|
|
static vfs_statfs_t union_statfs;
|
|
|
|
static vfs_unmount_t union_unmount;
|
1995-03-16 18:17:34 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
2002-09-22 08:54:17 +00:00
|
|
|
* Mount union filesystem.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1997-11-18 15:07:35 +00:00
|
|
|
static int
|
2004-07-30 22:08:52 +00:00
|
|
|
union_mount(mp, td)
|
1994-05-24 10:09:53 +00:00
|
|
|
struct mount *mp;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
2002-05-24 00:44:44 +00:00
|
|
|
struct vfsoptlist *opts;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct vnode *lowerrootvp = NULLVP;
|
|
|
|
struct vnode *upperrootvp = NULLVP;
|
1997-02-10 02:22:35 +00:00
|
|
|
struct union_mount *um = 0;
|
2004-10-05 05:59:29 +00:00
|
|
|
struct vattr va;
|
2002-05-24 00:44:44 +00:00
|
|
|
char *cp = 0, *target;
|
2002-06-15 22:48:14 +00:00
|
|
|
int op;
|
1994-05-24 10:09:53 +00:00
|
|
|
int len;
|
2002-10-06 11:42:14 +00:00
|
|
|
size_t size;
|
2003-01-18 01:01:20 +00:00
|
|
|
struct componentname fakecn;
|
2004-07-30 22:08:52 +00:00
|
|
|
struct nameidata nd, *ndp = &nd;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
UDEBUG(("union_mount(mp = %p)\n", (void *)mp));
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2002-05-24 00:44:44 +00:00
|
|
|
opts = mp->mnt_optnew;
|
1997-09-27 13:40:20 +00:00
|
|
|
/*
|
|
|
|
* Disable clustered write, otherwise system becomes unstable.
|
|
|
|
*/
|
|
|
|
mp->mnt_flag |= MNT_NOCLUSTERW;
|
|
|
|
|
2004-11-09 22:21:10 +00:00
|
|
|
if (mp->mnt_flag & MNT_ROOTFS)
|
|
|
|
return (EOPNOTSUPP);
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Update is a no-op
|
|
|
|
*/
|
2002-05-24 00:44:44 +00:00
|
|
|
if (mp->mnt_flag & MNT_UPDATE)
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
2002-09-22 08:54:17 +00:00
|
|
|
* Need to provide:
|
1994-05-24 10:09:53 +00:00
|
|
|
* 1. a way to convert between rdonly and rdwr mounts.
|
|
|
|
* 2. support for nfs exports.
|
|
|
|
*/
|
2002-05-24 00:44:44 +00:00
|
|
|
return (EOPNOTSUPP);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
2002-05-24 00:44:44 +00:00
|
|
|
* Get arguments.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
2002-05-24 00:44:44 +00:00
|
|
|
error = vfs_getopt(opts, "target", (void **)&target, &len);
|
|
|
|
if (error || target[len - 1] != '\0')
|
|
|
|
return (EINVAL);
|
|
|
|
|
2002-06-15 22:48:14 +00:00
|
|
|
op = 0;
|
|
|
|
if (vfs_getopt(opts, "below", NULL, NULL) == 0)
|
|
|
|
op = UNMNT_BELOW;
|
|
|
|
if (vfs_getopt(opts, "replace", NULL, NULL) == 0) {
|
|
|
|
/* These options are mutually exclusive. */
|
|
|
|
if (op)
|
|
|
|
return (EINVAL);
|
|
|
|
op = UNMNT_REPLACE;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* UNMNT_ABOVE is the default.
|
|
|
|
*/
|
|
|
|
if (op == 0)
|
|
|
|
op = UNMNT_ABOVE;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
/*
|
|
|
|
* Obtain lower vnode. Vnode is stored in mp->mnt_vnodecovered.
|
|
|
|
* We need to reference it but not lock it.
|
|
|
|
*/
|
1994-05-24 10:09:53 +00:00
|
|
|
lowerrootvp = mp->mnt_vnodecovered;
|
|
|
|
VREF(lowerrootvp);
|
|
|
|
/*
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
* Obtain upper vnode by calling namei() on the path. The
|
2005-04-27 09:07:13 +00:00
|
|
|
* upperrootvp will be turned referenced and locked.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
2005-04-27 09:07:13 +00:00
|
|
|
NDINIT(ndp, LOOKUP, FOLLOW|LOCKLEAF, UIO_SYSSPACE, target, td);
|
1994-10-10 07:55:48 +00:00
|
|
|
error = namei(ndp);
|
|
|
|
if (error)
|
1994-05-24 10:09:53 +00:00
|
|
|
goto bad;
|
1999-12-15 23:02:35 +00:00
|
|
|
NDFREE(ndp, NDF_ONLY_PNBUF);
|
1994-05-24 10:09:53 +00:00
|
|
|
upperrootvp = ndp->ni_vp;
|
|
|
|
|
1999-12-11 16:13:02 +00:00
|
|
|
UDEBUG(("mount_root UPPERVP %p locked = %d\n", upperrootvp,
|
|
|
|
VOP_ISLOCKED(upperrootvp, NULL)));
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
|
1997-04-14 10:52:25 +00:00
|
|
|
/*
|
|
|
|
* Check multi union mount to avoid `lock myself again' panic.
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
* Also require that it be a directory.
|
1997-04-14 10:52:25 +00:00
|
|
|
*/
|
|
|
|
if (upperrootvp == VTOUNION(lowerrootvp)->un_uppervp) {
|
1997-04-19 06:04:13 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("union_mount: multi union mount?\n");
|
|
|
|
#endif
|
1997-04-14 10:52:25 +00:00
|
|
|
error = EDEADLK;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
if (upperrootvp->v_type != VDIR) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
* Allocate our union_mount structure and populate the fields.
|
|
|
|
* The vnode references are stored in the union_mount as held,
|
|
|
|
* unlocked references. Depending on the _BELOW flag, the
|
|
|
|
* filesystems are viewed in a different order. In effect this
|
|
|
|
* is the same as providing a mount-under option to the mount
|
|
|
|
* syscall.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
um = (struct union_mount *) malloc(sizeof(struct union_mount),
|
2003-02-19 05:47:46 +00:00
|
|
|
M_UNIONFSMNT, M_WAITOK | M_ZERO);
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
|
2002-06-15 22:48:14 +00:00
|
|
|
um->um_op = op;
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
|
2004-10-05 05:59:29 +00:00
|
|
|
error = VOP_GETATTR(upperrootvp, &va, td->td_ucred, td);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
um->um_upperdev = va.va_fsid;
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
switch (um->um_op) {
|
|
|
|
case UNMNT_ABOVE:
|
|
|
|
um->um_lowervp = lowerrootvp;
|
|
|
|
um->um_uppervp = upperrootvp;
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
upperrootvp = NULL;
|
|
|
|
lowerrootvp = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNMNT_BELOW:
|
2005-04-27 09:07:13 +00:00
|
|
|
VOP_UNLOCK(upperrootvp, 0, td);
|
|
|
|
vn_lock(lowerrootvp, LK_RETRY|LK_EXCLUSIVE, td);
|
1994-05-24 10:09:53 +00:00
|
|
|
um->um_lowervp = upperrootvp;
|
|
|
|
um->um_uppervp = lowerrootvp;
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
upperrootvp = NULL;
|
|
|
|
lowerrootvp = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UNMNT_REPLACE:
|
|
|
|
vrele(lowerrootvp);
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
lowerrootvp = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
um->um_uppervp = upperrootvp;
|
|
|
|
um->um_lowervp = lowerrootvp;
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
upperrootvp = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
/*
|
|
|
|
* Unless the mount is readonly, ensure that the top layer
|
2002-09-22 08:54:17 +00:00
|
|
|
* supports whiteout operations.
|
1997-02-10 02:22:35 +00:00
|
|
|
*/
|
|
|
|
if ((mp->mnt_flag & MNT_RDONLY) == 0) {
|
2003-01-18 01:01:20 +00:00
|
|
|
/*
|
|
|
|
* XXX Fake up a struct componentname with only cn_nameiop
|
|
|
|
* and cn_thread valid; union_whiteout() needs to use the
|
|
|
|
* thread pointer to lock the vnode.
|
|
|
|
*/
|
|
|
|
bzero(&fakecn, sizeof(fakecn));
|
|
|
|
fakecn.cn_nameiop = LOOKUP;
|
|
|
|
fakecn.cn_thread = td;
|
|
|
|
error = VOP_WHITEOUT(um->um_uppervp, &fakecn, LOOKUP);
|
1997-02-10 02:22:35 +00:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
}
|
2005-04-27 09:07:13 +00:00
|
|
|
VOP_UNLOCK(um->um_uppervp, 0, td);
|
1997-02-10 02:22:35 +00:00
|
|
|
|
2002-02-27 18:32:23 +00:00
|
|
|
um->um_cred = crhold(td->td_ucred);
|
2004-11-13 11:53:02 +00:00
|
|
|
FILEDESC_LOCK_FAST(td->td_proc->p_fd);
|
2001-09-12 08:38:13 +00:00
|
|
|
um->um_cmode = UN_DIRMODE &~ td->td_proc->p_fd->fd_cmask;
|
2004-11-13 11:53:02 +00:00
|
|
|
FILEDESC_UNLOCK_FAST(td->td_proc->p_fd);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Depending on what you think the MNT_LOCAL flag might mean,
|
|
|
|
* you may want the && to be || on the conditional below.
|
|
|
|
* At the moment it has been defined that the filesystem is
|
|
|
|
* only local if it is all local, ie the MNT_LOCAL flag implies
|
|
|
|
* that the entire namespace is local. If you think the MNT_LOCAL
|
|
|
|
* flag implies that some of the files might be stored locally
|
|
|
|
* then you will want to change the conditional.
|
|
|
|
*/
|
|
|
|
if (um->um_op == UNMNT_ABOVE) {
|
|
|
|
if (((um->um_lowervp == NULLVP) ||
|
|
|
|
(um->um_lowervp->v_mount->mnt_flag & MNT_LOCAL)) &&
|
|
|
|
(um->um_uppervp->v_mount->mnt_flag & MNT_LOCAL))
|
|
|
|
mp->mnt_flag |= MNT_LOCAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy in the upper layer's RDONLY flag. This is for the benefit
|
|
|
|
* of lookup() which explicitly checks the flag, rather than asking
|
1998-04-17 22:37:19 +00:00
|
|
|
* the filesystem for its own opinion. This means, that an update
|
1994-05-24 10:09:53 +00:00
|
|
|
* mount of the underlying filesystem to go from rdonly to rdwr
|
|
|
|
* will leave the unioned view as read-only.
|
|
|
|
*/
|
|
|
|
mp->mnt_flag |= (um->um_uppervp->v_mount->mnt_flag & MNT_RDONLY);
|
|
|
|
|
|
|
|
mp->mnt_data = (qaddr_t) um;
|
1997-02-10 02:22:35 +00:00
|
|
|
vfs_getnewfsid(mp);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
switch (um->um_op) {
|
|
|
|
case UNMNT_ABOVE:
|
1997-02-10 02:22:35 +00:00
|
|
|
cp = "<above>:";
|
1994-05-24 10:09:53 +00:00
|
|
|
break;
|
|
|
|
case UNMNT_BELOW:
|
1997-02-10 02:22:35 +00:00
|
|
|
cp = "<below>:";
|
1994-05-24 10:09:53 +00:00
|
|
|
break;
|
|
|
|
case UNMNT_REPLACE:
|
|
|
|
cp = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
len = strlen(cp);
|
|
|
|
bcopy(cp, mp->mnt_stat.f_mntfromname, len);
|
|
|
|
|
|
|
|
cp = mp->mnt_stat.f_mntfromname + len;
|
|
|
|
len = MNAMELEN - len;
|
|
|
|
|
2002-05-24 00:44:44 +00:00
|
|
|
(void) copystr(target, cp, len - 1, &size);
|
1994-05-24 10:09:53 +00:00
|
|
|
bzero(cp + size, len - size);
|
|
|
|
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
UDEBUG(("union_mount: from %s, on %s\n",
|
|
|
|
mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname));
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
if (um) {
|
|
|
|
if (um->um_uppervp)
|
2005-04-27 09:07:13 +00:00
|
|
|
vput(um->um_uppervp);
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
if (um->um_lowervp)
|
|
|
|
vrele(um->um_lowervp);
|
|
|
|
/* XXX other fields */
|
1997-10-12 20:26:33 +00:00
|
|
|
free(um, M_UNIONFSMNT);
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
if (upperrootvp)
|
2005-04-27 09:07:13 +00:00
|
|
|
vput(upperrootvp);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (lowerrootvp)
|
|
|
|
vrele(lowerrootvp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-22 08:54:17 +00:00
|
|
|
* Free reference to union layer.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1997-11-18 15:07:35 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
union_unmount(mp, mntflags, td)
|
1994-05-24 10:09:53 +00:00
|
|
|
struct mount *mp;
|
|
|
|
int mntflags;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
|
|
|
|
int error;
|
1997-02-10 02:22:35 +00:00
|
|
|
int freeing;
|
1994-05-24 10:09:53 +00:00
|
|
|
int flags = 0;
|
|
|
|
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
UDEBUG(("union_unmount(mp = %p)\n", (void *)mp));
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
if (mntflags & MNT_FORCE)
|
|
|
|
flags |= FORCECLOSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keep flushing vnodes from the mount list.
|
|
|
|
* This is needed because of the un_pvp held
|
|
|
|
* reference to the parent vnode.
|
|
|
|
* If more vnodes have been freed on a given pass,
|
|
|
|
* the try again. The loop will iterate at most
|
|
|
|
* (d) times, where (d) is the maximum tree depth
|
|
|
|
* in the filesystem.
|
|
|
|
*/
|
2004-07-12 08:14:09 +00:00
|
|
|
for (freeing = 0; (error = vflush(mp, 0, flags, td)) != 0;) {
|
1997-02-10 02:22:35 +00:00
|
|
|
int n;
|
|
|
|
|
|
|
|
/* count #vnodes held on mount list */
|
2003-11-01 04:36:50 +00:00
|
|
|
n = mp->mnt_nvnodelistsize;
|
1997-02-10 02:22:35 +00:00
|
|
|
|
|
|
|
/* if this is unchanged then stop */
|
|
|
|
if (n == freeing)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* otherwise try once more time */
|
|
|
|
freeing = n;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
2002-09-22 08:54:17 +00:00
|
|
|
/*
|
|
|
|
* If the most recent vflush failed, the filesystem is still busy.
|
|
|
|
*/
|
2001-05-16 18:04:37 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Discard references to upper and lower target vnodes.
|
|
|
|
*/
|
|
|
|
if (um->um_lowervp)
|
|
|
|
vrele(um->um_lowervp);
|
|
|
|
vrele(um->um_uppervp);
|
|
|
|
crfree(um->um_cred);
|
|
|
|
/*
|
2002-09-22 08:54:17 +00:00
|
|
|
* Finally, throw away the union_mount structure.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1997-10-12 20:26:33 +00:00
|
|
|
free(mp->mnt_data, M_UNIONFSMNT); /* XXX */
|
1994-05-24 10:09:53 +00:00
|
|
|
mp->mnt_data = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1997-11-18 15:07:35 +00:00
|
|
|
static int
|
2005-03-24 07:36:16 +00:00
|
|
|
union_root(mp, flags, vpp, td)
|
1994-05-24 10:09:53 +00:00
|
|
|
struct mount *mp;
|
2005-03-24 07:36:16 +00:00
|
|
|
int flags;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct vnode **vpp;
|
2004-07-12 08:14:09 +00:00
|
|
|
struct thread *td;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
* Supply an unlocked reference to um_uppervp and to um_lowervp. It
|
|
|
|
* is possible for um_uppervp to be locked without the associated
|
|
|
|
* root union_node being locked. We let union_allocvp() deal with
|
|
|
|
* it.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1999-12-11 16:13:02 +00:00
|
|
|
UDEBUG(("union_root UPPERVP %p locked = %d\n", um->um_uppervp,
|
|
|
|
VOP_ISLOCKED(um->um_uppervp, NULL)));
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
VREF(um->um_uppervp);
|
|
|
|
if (um->um_lowervp)
|
|
|
|
VREF(um->um_lowervp);
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
|
|
|
|
error = union_allocvp(vpp, mp, NULLVP, NULLVP, NULL,
|
|
|
|
um->um_uppervp, um->um_lowervp, 1);
|
|
|
|
UDEBUG(("error %d\n", error));
|
1999-12-11 16:13:02 +00:00
|
|
|
UDEBUG(("union_root2 UPPERVP %p locked = %d\n", um->um_uppervp,
|
|
|
|
VOP_ISLOCKED(um->um_uppervp, NULL)));
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1997-11-18 15:07:35 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
union_statfs(mp, sbp, td)
|
1994-05-24 10:09:53 +00:00
|
|
|
struct mount *mp;
|
|
|
|
struct statfs *sbp;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
|
|
|
|
struct statfs mstat;
|
|
|
|
int lbsize;
|
|
|
|
|
This is a major fixup of unionfs. At least 30 serious bugs have been
fixed (many due to changing semantics in other parts of the kernel and not
the original author's fault), including one critical one: unionfs could
cause UFS corruption in the fronting store due to calling VOP_OPEN for
writing without turning on vmio for the UFS vnode.
Most of the bugs were related to semantics changes in VOP calls, lock
ordering problems (causing deadlocks), improper handling of a read-only
backing store (such as an NFS mount), improper referencing and locking
of vnodes, not using real struct locks for vnode locking, not using
recursive locks when accessing the fronting store, and things like that.
New functionality has been added: unionfs now has mmap() support, but
only partially tested, and rename has been enhanced considerably.
There are still some things that unionfs cannot do. You cannot
rename a directory without confusing unionfs, and there are issues
with softlinks, hardlinks, and special files. unionfs mostly doesn't
understand them (and never did).
There are probably still panic situations, but hopefully no where near
as many as before this commit.
The unionfs in this commit has been tested overlayed on /usr/src
(backing /usr/src being a read-only NFS mount, fronting /usr/src being
a local filesystem). kernel builds have been tested, buildworld is
undergoing testing. More testing is necessary.
1999-09-26 20:52:41 +00:00
|
|
|
UDEBUG(("union_statfs(mp = %p, lvp = %p, uvp = %p)\n",
|
|
|
|
(void *)mp, (void *)um->um_lowervp, (void *)um->um_uppervp));
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
bzero(&mstat, sizeof(mstat));
|
|
|
|
|
|
|
|
if (um->um_lowervp) {
|
2001-09-12 08:38:13 +00:00
|
|
|
error = VFS_STATFS(um->um_lowervp->v_mount, &mstat, td);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-09-22 08:54:17 +00:00
|
|
|
/*
|
|
|
|
* Now copy across the "interesting" information and fake the rest.
|
|
|
|
*/
|
1994-05-24 10:09:53 +00:00
|
|
|
#if 0
|
|
|
|
sbp->f_type = mstat.f_type;
|
|
|
|
sbp->f_flags = mstat.f_flags;
|
|
|
|
sbp->f_bsize = mstat.f_bsize;
|
|
|
|
sbp->f_iosize = mstat.f_iosize;
|
|
|
|
#endif
|
|
|
|
lbsize = mstat.f_bsize;
|
|
|
|
sbp->f_blocks = mstat.f_blocks;
|
|
|
|
sbp->f_bfree = mstat.f_bfree;
|
|
|
|
sbp->f_bavail = mstat.f_bavail;
|
|
|
|
sbp->f_files = mstat.f_files;
|
|
|
|
sbp->f_ffree = mstat.f_ffree;
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = VFS_STATFS(um->um_uppervp->v_mount, &mstat, td);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
sbp->f_flags = mstat.f_flags;
|
|
|
|
sbp->f_bsize = mstat.f_bsize;
|
|
|
|
sbp->f_iosize = mstat.f_iosize;
|
|
|
|
|
|
|
|
/*
|
2002-09-22 08:54:17 +00:00
|
|
|
* If the lower and upper blocksizes differ, then frig the
|
1994-05-24 10:09:53 +00:00
|
|
|
* block counts so that the sizes reported by df make some
|
2002-09-22 08:54:17 +00:00
|
|
|
* kind of sense. None of this makes sense though.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
if (mstat.f_bsize != lbsize)
|
1997-05-07 14:37:32 +00:00
|
|
|
sbp->f_blocks = ((off_t) sbp->f_blocks * lbsize) / mstat.f_bsize;
|
1997-02-10 02:22:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The "total" fields count total resources in all layers,
|
|
|
|
* the "free" fields count only those resources which are
|
|
|
|
* free in the upper layer (since only the upper layer
|
|
|
|
* is writeable).
|
|
|
|
*/
|
1994-05-24 10:09:53 +00:00
|
|
|
sbp->f_blocks += mstat.f_blocks;
|
1997-02-10 02:22:35 +00:00
|
|
|
sbp->f_bfree = mstat.f_bfree;
|
|
|
|
sbp->f_bavail = mstat.f_bavail;
|
1994-05-24 10:09:53 +00:00
|
|
|
sbp->f_files += mstat.f_files;
|
1997-02-10 02:22:35 +00:00
|
|
|
sbp->f_ffree = mstat.f_ffree;
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1997-11-18 15:07:35 +00:00
|
|
|
static struct vfsops union_vfsops = {
|
2003-06-12 20:48:38 +00:00
|
|
|
.vfs_init = union_init,
|
2004-07-30 22:08:52 +00:00
|
|
|
.vfs_mount = union_mount,
|
2003-06-12 20:48:38 +00:00
|
|
|
.vfs_root = union_root,
|
|
|
|
.vfs_statfs = union_statfs,
|
|
|
|
.vfs_unmount = union_unmount,
|
1994-05-24 10:09:53 +00:00
|
|
|
};
|
1994-09-21 03:47:43 +00:00
|
|
|
|
2001-05-24 15:20:11 +00:00
|
|
|
VFS_SET(union_vfsops, unionfs, VFCF_LOOPBACK);
|