2006-01-05 23:31:33 +03:00
|
|
|
/* $NetBSD: union_vfsops.c,v 1.32 2006/01/05 20:31:33 wrstuden Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994 The Regents of the University of California.
|
2003-08-07 20:26:28 +04: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.
|
|
|
|
* 3. 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.
|
|
|
|
*
|
|
|
|
* @(#)union_vfsops.c 8.20 (Berkeley) 5/20/95
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* Copyright (c) 1994 Jan-Simon Pendry.
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 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.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)union_vfsops.c 8.20 (Berkeley) 5/20/95
|
1994-06-08 15:33:09 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Union Layer
|
|
|
|
*/
|
|
|
|
|
2001-11-10 16:33:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
2006-01-05 23:31:33 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: union_vfsops.c,v 1.32 2006/01/05 20:31:33 wrstuden Exp $");
|
2001-11-10 16:33:40 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
#include <sys/sysctl.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/filedesc.h>
|
|
|
|
#include <sys/queue.h>
|
1997-05-05 11:19:05 +04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2003-03-16 11:26:46 +03:00
|
|
|
#include <fs/union/union.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2005-08-30 23:11:43 +04:00
|
|
|
int union_mount(struct mount *, const char *, void *, struct nameidata *,
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *);
|
|
|
|
int union_start(struct mount *, int, struct lwp *);
|
|
|
|
int union_unmount(struct mount *, int, struct lwp *);
|
2005-08-30 23:11:43 +04:00
|
|
|
int union_root(struct mount *, struct vnode **);
|
2005-12-11 15:16:03 +03:00
|
|
|
int union_quotactl(struct mount *, int, uid_t, void *, struct lwp *);
|
|
|
|
int union_statvfs(struct mount *, struct statvfs *, struct lwp *);
|
|
|
|
int union_sync(struct mount *, int, struct ucred *, struct lwp *);
|
2005-08-30 23:11:43 +04:00
|
|
|
int union_vget(struct mount *, ino_t, struct vnode **);
|
1996-02-10 01:39:56 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Mount union filesystem
|
|
|
|
*/
|
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
union_mount(mp, path, data, ndp, l)
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mount *mp;
|
1996-12-22 13:10:12 +03:00
|
|
|
const char *path;
|
|
|
|
void *data;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct nameidata *ndp;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l;
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
struct union_args args;
|
|
|
|
struct vnode *lowerrootvp = NULLVP;
|
|
|
|
struct vnode *upperrootvp = NULLVP;
|
1994-12-14 19:30:40 +03:00
|
|
|
struct union_mount *um = 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct ucred *cred = 0;
|
2005-05-30 01:00:29 +04:00
|
|
|
const char *cp;
|
|
|
|
char *xp;
|
1994-06-08 15:33:09 +04:00
|
|
|
int len;
|
1995-03-09 15:05:21 +03:00
|
|
|
size_t size;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
#ifdef UNION_DIAGNOSTIC
|
1997-09-10 17:44:20 +04:00
|
|
|
printf("union_mount(mp = %p)\n", mp);
|
1994-06-08 15:33:09 +04:00
|
|
|
#endif
|
|
|
|
|
2002-09-21 22:08:27 +04:00
|
|
|
if (mp->mnt_flag & MNT_GETARGS) {
|
|
|
|
um = MOUNTTOUNIONMOUNT(mp);
|
|
|
|
if (um == NULL)
|
|
|
|
return EIO;
|
|
|
|
args.target = NULL;
|
|
|
|
args.mntflags = um->um_op;
|
|
|
|
return copyout(&args, data, sizeof(args));
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Update is a no-op
|
|
|
|
*/
|
|
|
|
if (mp->mnt_flag & MNT_UPDATE) {
|
|
|
|
/*
|
|
|
|
* Need to provide.
|
|
|
|
* 1. a way to convert between rdonly and rdwr mounts.
|
|
|
|
* 2. support for nfs exports.
|
|
|
|
*/
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get argument
|
|
|
|
*/
|
2004-05-12 06:07:37 +04:00
|
|
|
error = copyin(data, &args, sizeof(struct union_args));
|
1996-02-10 01:39:56 +03:00
|
|
|
if (error)
|
1994-06-08 15:33:09 +04:00
|
|
|
goto bad;
|
|
|
|
|
|
|
|
lowerrootvp = mp->mnt_vnodecovered;
|
|
|
|
VREF(lowerrootvp);
|
|
|
|
|
|
|
|
/*
|
1994-12-14 19:30:40 +03:00
|
|
|
* Find upper node.
|
1994-06-08 15:33:09 +04:00
|
|
|
*/
|
2001-08-03 02:40:58 +04:00
|
|
|
NDINIT(ndp, LOOKUP, FOLLOW,
|
2005-12-11 15:16:03 +03:00
|
|
|
UIO_USERSPACE, args.target, l);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1996-02-10 01:39:56 +03:00
|
|
|
if ((error = namei(ndp)) != 0)
|
1994-06-08 15:33:09 +04:00
|
|
|
goto bad;
|
|
|
|
|
|
|
|
upperrootvp = ndp->ni_vp;
|
|
|
|
|
|
|
|
if (upperrootvp->v_type != VDIR) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
um = (struct union_mount *) malloc(sizeof(struct union_mount),
|
|
|
|
M_UFSMNT, M_WAITOK); /* XXX */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keep a held reference to the target vnodes.
|
|
|
|
* They are vrele'd in union_unmount.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
um->um_op = args.mntflags & UNMNT_OPMASK;
|
|
|
|
switch (um->um_op) {
|
|
|
|
case UNMNT_ABOVE:
|
|
|
|
um->um_lowervp = lowerrootvp;
|
|
|
|
um->um_uppervp = upperrootvp;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNMNT_BELOW:
|
|
|
|
um->um_lowervp = upperrootvp;
|
|
|
|
um->um_uppervp = lowerrootvp;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNMNT_REPLACE:
|
|
|
|
vrele(lowerrootvp);
|
|
|
|
lowerrootvp = NULLVP;
|
|
|
|
um->um_uppervp = upperrootvp;
|
|
|
|
um->um_lowervp = lowerrootvp;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1994-12-14 19:30:40 +03:00
|
|
|
/*
|
|
|
|
* Unless the mount is readonly, ensure that the top layer
|
|
|
|
* supports whiteout operations
|
|
|
|
*/
|
|
|
|
if ((mp->mnt_flag & MNT_RDONLY) == 0) {
|
|
|
|
error = VOP_WHITEOUT(um->um_uppervp, (struct componentname *) 0, LOOKUP);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
um->um_cred = l->l_proc->p_ucred;
|
1994-12-14 19:30:40 +03:00
|
|
|
crhold(um->um_cred);
|
2005-12-11 15:16:03 +03:00
|
|
|
um->um_cmode = UN_DIRMODE &~ l->l_proc->p_cwdi->cwdi_cmask;
|
1994-06-08 15:33:09 +04: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
|
|
|
|
* the filesystem for it's own opinion. This means, that an update
|
|
|
|
* 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);
|
|
|
|
|
2002-07-30 11:40:07 +04:00
|
|
|
mp->mnt_data = um;
|
2004-07-01 14:03:29 +04:00
|
|
|
mp->mnt_leaf = um->um_uppervp->v_mount->mnt_leaf;
|
2000-06-10 22:27:01 +04:00
|
|
|
vfs_getnewfsid(mp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2004-04-21 05:05:31 +04:00
|
|
|
error = set_statvfs_info( path, UIO_USERSPACE, NULL, UIO_USERSPACE,
|
2005-12-11 15:16:03 +03:00
|
|
|
mp, l);
|
2003-04-17 01:44:18 +04:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
switch (um->um_op) {
|
|
|
|
case UNMNT_ABOVE:
|
1994-06-16 03:07:54 +04:00
|
|
|
cp = "<above>:";
|
1994-06-08 15:33:09 +04:00
|
|
|
break;
|
|
|
|
case UNMNT_BELOW:
|
1994-06-16 03:07:54 +04:00
|
|
|
cp = "<below>:";
|
1994-06-08 15:33:09 +04:00
|
|
|
break;
|
|
|
|
case UNMNT_REPLACE:
|
|
|
|
cp = "";
|
|
|
|
break;
|
1996-02-10 01:39:56 +03:00
|
|
|
default:
|
|
|
|
cp = "<invalid>:";
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("union_mount: bad um_op");
|
|
|
|
#endif
|
|
|
|
break;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
len = strlen(cp);
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(mp->mnt_stat.f_mntfromname, cp, len);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2005-05-30 01:00:29 +04:00
|
|
|
xp = mp->mnt_stat.f_mntfromname + len;
|
1994-06-08 15:33:09 +04:00
|
|
|
len = MNAMELEN - len;
|
|
|
|
|
2005-05-30 01:00:29 +04:00
|
|
|
(void) copyinstr(args.target, xp, len - 1, &size);
|
|
|
|
memset(xp + size, 0, len - size);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
#ifdef UNION_DIAGNOSTIC
|
1996-10-13 06:21:25 +04:00
|
|
|
printf("union_mount: from %s, on %s\n",
|
1996-10-11 02:46:11 +04:00
|
|
|
mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
|
1994-06-08 15:33:09 +04:00
|
|
|
#endif
|
2003-03-17 12:11:29 +03:00
|
|
|
|
|
|
|
/* Setup the readdir hook if it's not set already */
|
|
|
|
if (!vn_union_readdir_hook)
|
|
|
|
vn_union_readdir_hook = union_readdirhook;
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:
|
1994-12-14 19:30:40 +03:00
|
|
|
if (um)
|
|
|
|
free(um, M_UFSMNT);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (cred)
|
|
|
|
crfree(cred);
|
|
|
|
if (upperrootvp)
|
|
|
|
vrele(upperrootvp);
|
|
|
|
if (lowerrootvp)
|
|
|
|
vrele(lowerrootvp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VFS start. Nothing needed here - the start routine
|
|
|
|
* on the underlying filesystem(s) will have been called
|
|
|
|
* when that filesystem was mounted.
|
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
/*ARGSUSED*/
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
union_start(mp, flags, l)
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mount *mp;
|
|
|
|
int flags;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l;
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free reference to union layer
|
|
|
|
*/
|
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
union_unmount(mp, mntflags, l)
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mount *mp;
|
|
|
|
int mntflags;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l;
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
|
|
|
struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
|
1994-06-17 19:21:33 +04:00
|
|
|
int freeing;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
#ifdef UNION_DIAGNOSTIC
|
1997-09-10 17:44:20 +04:00
|
|
|
printf("union_unmount(mp = %p)\n", mp);
|
1994-06-08 15:33:09 +04:00
|
|
|
#endif
|
|
|
|
|
1994-06-17 19:21:33 +04:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2006-01-05 23:31:33 +03:00
|
|
|
for (freeing = 0; vflush(mp, NULL, 0) != 0;) {
|
1994-06-17 19:21:33 +04:00
|
|
|
struct vnode *vp;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
/* count #vnodes held on mount list */
|
|
|
|
for (n = 0, vp = mp->mnt_vnodelist.lh_first;
|
|
|
|
vp != NULLVP;
|
|
|
|
vp = vp->v_mntvnodes.le_next)
|
|
|
|
n++;
|
|
|
|
|
|
|
|
/* if this is unchanged then stop */
|
|
|
|
if (n == freeing)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* otherwise try once more time */
|
|
|
|
freeing = n;
|
|
|
|
}
|
|
|
|
|
1999-08-01 03:56:15 +04:00
|
|
|
/*
|
|
|
|
* Ok, now that we've tried doing it gently, get out the hammer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (mntflags & MNT_FORCE)
|
2006-01-05 23:31:33 +03:00
|
|
|
vflush(mp, NULL, FORCECLOSE);
|
1999-08-01 03:56:15 +04:00
|
|
|
|
1994-06-08 15:33:09 +04: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);
|
|
|
|
/*
|
|
|
|
* Finally, throw away the union_mount structure
|
|
|
|
*/
|
|
|
|
free(mp->mnt_data, M_UFSMNT); /* XXX */
|
|
|
|
mp->mnt_data = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-06-29 22:43:21 +04:00
|
|
|
union_root(mp, vpp)
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mount *mp;
|
|
|
|
struct vnode **vpp;
|
|
|
|
{
|
|
|
|
struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
|
|
|
|
int error;
|
|
|
|
int loselock;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return locked reference to root.
|
|
|
|
*/
|
|
|
|
VREF(um->um_uppervp);
|
|
|
|
if ((um->um_op == UNMNT_BELOW) &&
|
|
|
|
VOP_ISLOCKED(um->um_uppervp)) {
|
|
|
|
loselock = 1;
|
|
|
|
} else {
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(um->um_uppervp, LK_EXCLUSIVE | LK_RETRY);
|
1994-06-08 15:33:09 +04:00
|
|
|
loselock = 0;
|
|
|
|
}
|
|
|
|
if (um->um_lowervp)
|
|
|
|
VREF(um->um_lowervp);
|
|
|
|
error = union_allocvp(vpp, mp,
|
|
|
|
(struct vnode *) 0,
|
|
|
|
(struct vnode *) 0,
|
|
|
|
(struct componentname *) 0,
|
|
|
|
um->um_uppervp,
|
1994-12-14 19:30:40 +03:00
|
|
|
um->um_lowervp,
|
2003-06-29 22:43:21 +04:00
|
|
|
1);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
if (error) {
|
|
|
|
if (!loselock)
|
1998-03-01 05:20:01 +03:00
|
|
|
VOP_UNLOCK(um->um_uppervp, 0);
|
1994-06-08 15:33:09 +04:00
|
|
|
vrele(um->um_uppervp);
|
|
|
|
if (um->um_lowervp)
|
|
|
|
vrele(um->um_lowervp);
|
|
|
|
} else {
|
|
|
|
if (loselock)
|
|
|
|
VTOUNION(*vpp)->un_flags &= ~UN_ULOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1996-02-10 01:39:56 +03:00
|
|
|
/*ARGSUSED*/
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
union_quotactl(mp, cmd, uid, arg, l)
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mount *mp;
|
|
|
|
int cmd;
|
|
|
|
uid_t uid;
|
2004-04-27 21:37:30 +04:00
|
|
|
void *arg;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l;
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
union_statvfs(mp, sbp, l)
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mount *mp;
|
2004-04-21 05:05:31 +04:00
|
|
|
struct statvfs *sbp;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l;
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
|
2005-08-24 19:21:28 +04:00
|
|
|
struct statvfs *sbuf = malloc(sizeof(*sbuf), M_TEMP, M_WAITOK | M_ZERO);
|
2004-05-24 07:09:48 +04:00
|
|
|
unsigned long lbsize;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
#ifdef UNION_DIAGNOSTIC
|
2004-04-21 05:05:31 +04:00
|
|
|
printf("union_statvfs(mp = %p, lvp = %p, uvp = %p)\n", mp,
|
1996-10-11 02:46:11 +04:00
|
|
|
um->um_lowervp, um->um_uppervp);
|
1994-06-08 15:33:09 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (um->um_lowervp) {
|
2005-12-11 15:16:03 +03:00
|
|
|
error = VFS_STATVFS(um->um_lowervp->v_mount, sbuf, l);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error)
|
2004-05-24 07:09:48 +04:00
|
|
|
goto done;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
2004-05-24 07:09:48 +04:00
|
|
|
/* now copy across the "interesting" information and fake the rest */
|
|
|
|
lbsize = sbuf->f_bsize;
|
|
|
|
sbp->f_blocks = sbuf->f_blocks - sbuf->f_bfree;
|
|
|
|
sbp->f_files = sbuf->f_files - sbuf->f_ffree;
|
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
error = VFS_STATVFS(um->um_uppervp->v_mount, sbuf, l);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error)
|
2004-05-24 07:09:48 +04:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
sbp->f_flag = sbuf->f_flag;
|
|
|
|
sbp->f_bsize = sbuf->f_bsize;
|
|
|
|
sbp->f_frsize = sbuf->f_frsize;
|
|
|
|
sbp->f_iosize = sbuf->f_iosize;
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
1998-03-01 05:20:01 +03: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
|
2003-01-06 23:30:28 +03:00
|
|
|
* is writable).
|
1994-06-08 15:33:09 +04:00
|
|
|
*/
|
2004-05-24 07:09:48 +04:00
|
|
|
|
|
|
|
if (sbuf->f_bsize != lbsize)
|
|
|
|
sbp->f_blocks = sbp->f_blocks * lbsize / sbuf->f_bsize;
|
|
|
|
sbp->f_blocks += sbuf->f_blocks;
|
|
|
|
sbp->f_bfree = sbuf->f_bfree;
|
|
|
|
sbp->f_bavail = sbuf->f_bavail;
|
|
|
|
sbp->f_bresvd = sbuf->f_bresvd;
|
|
|
|
sbp->f_files += sbuf->f_files;
|
|
|
|
sbp->f_ffree = sbuf->f_ffree;
|
|
|
|
sbp->f_favail = sbuf->f_favail;
|
|
|
|
sbp->f_fresvd = sbuf->f_fresvd;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2004-04-21 05:05:31 +04:00
|
|
|
copy_statvfs_info(sbp, mp);
|
2004-05-24 07:09:48 +04:00
|
|
|
done:
|
|
|
|
free(sbuf, M_TEMP);
|
|
|
|
return error;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
1996-02-10 01:39:56 +03:00
|
|
|
/*ARGSUSED*/
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
union_sync(mp, waitfor, cred, l)
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mount *mp;
|
|
|
|
int waitfor;
|
|
|
|
struct ucred *cred;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l;
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - Assumes no data cached at union layer.
|
|
|
|
*/
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-02-10 01:39:56 +03:00
|
|
|
/*ARGSUSED*/
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
2003-06-29 22:43:21 +04:00
|
|
|
union_vget(mp, ino, vpp)
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mount *mp;
|
|
|
|
ino_t ino;
|
|
|
|
struct vnode **vpp;
|
|
|
|
{
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
SYSCTL_SETUP(sysctl_vfs_union_setup, "sysctl vfs.union subtree setup")
|
1998-03-01 05:20:01 +03:00
|
|
|
{
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
|
2004-03-24 18:34:46 +03:00
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
CTLTYPE_NODE, "vfs", NULL,
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_VFS, CTL_EOL);
|
2004-03-24 18:34:46 +03:00
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
2004-05-25 08:44:43 +04:00
|
|
|
CTLTYPE_NODE, "union",
|
|
|
|
SYSCTL_DESCR("Union file system"),
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_VFS, 15, CTL_EOL);
|
|
|
|
/*
|
|
|
|
* XXX the "15" above could be dynamic, thereby eliminating
|
|
|
|
* one more instance of the "number to vfs" mapping problem,
|
|
|
|
* but "15" is the order as taken from sys/mount.h
|
|
|
|
*/
|
1998-03-01 05:20:01 +03:00
|
|
|
}
|
|
|
|
|
2001-01-22 15:17:35 +03:00
|
|
|
extern const struct vnodeopv_desc union_vnodeop_opv_desc;
|
1998-02-18 10:05:47 +03:00
|
|
|
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_desc * const union_vnodeopv_descs[] = {
|
1998-02-18 10:05:47 +03:00
|
|
|
&union_vnodeop_opv_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vfsops union_vfsops = {
|
|
|
|
MOUNT_UNION,
|
|
|
|
union_mount,
|
|
|
|
union_start,
|
|
|
|
union_unmount,
|
|
|
|
union_root,
|
|
|
|
union_quotactl,
|
2004-04-21 05:05:31 +04:00
|
|
|
union_statvfs,
|
1994-06-08 15:33:09 +04:00
|
|
|
union_sync,
|
|
|
|
union_vget,
|
Apply the NFS exports list rototill patch:
- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.
Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
2005-09-23 16:10:31 +04:00
|
|
|
NULL, /* vfs_fhtovp */
|
|
|
|
NULL, /* vfs_vptofh */
|
1994-06-08 15:33:09 +04:00
|
|
|
union_init,
|
2003-03-17 13:28:41 +03:00
|
|
|
NULL, /* vfs_reinit */
|
2000-03-16 21:08:17 +03:00
|
|
|
union_done,
|
1998-02-18 10:05:47 +03:00
|
|
|
NULL, /* vfs_mountroot */
|
2004-05-31 06:04:35 +04:00
|
|
|
(int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
|
2005-01-02 19:08:28 +03:00
|
|
|
vfs_stdextattrctl,
|
1998-02-18 10:05:47 +03:00
|
|
|
union_vnodeopv_descs,
|
1994-06-08 15:33:09 +04:00
|
|
|
};
|
2005-03-29 06:41:05 +04:00
|
|
|
VFS_ATTACH(union_vfsops);
|