2014-10-18 12:33:23 +04:00
|
|
|
/* $NetBSD: union_vfsops.c,v 1.73 2014/10/18 08:33:29 snj 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>
|
2014-10-18 12:33:23 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: union_vfsops.c,v 1.73 2014/10/18 08:33:29 snj 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>
|
2006-05-15 01:31:52 +04:00
|
|
|
#include <sys/kauth.h>
|
2008-05-10 06:26:09 +04:00
|
|
|
#include <sys/module.h>
|
1997-05-05 11:19:05 +04:00
|
|
|
|
2003-03-16 11:26:46 +03:00
|
|
|
#include <fs/union/union.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2010-07-06 01:27:08 +04:00
|
|
|
MODULE(MODULE_CLASS_VFS, union, NULL);
|
2008-05-10 06:26:09 +04:00
|
|
|
|
2007-08-01 01:14:15 +04:00
|
|
|
VFS_PROTOS(union);
|
1996-02-10 01:39:56 +03:00
|
|
|
|
2008-06-28 05:34:05 +04:00
|
|
|
static struct sysctllog *union_sysctl_log;
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Mount union filesystem
|
|
|
|
*/
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
2007-11-26 22:01:26 +03:00
|
|
|
struct lwp *l = curlwp;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error = 0;
|
2007-07-12 23:35:32 +04:00
|
|
|
struct union_args *args = data;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnode *lowerrootvp = NULLVP;
|
|
|
|
struct vnode *upperrootvp = NULLVP;
|
1994-12-14 19:30:40 +03:00
|
|
|
struct union_mount *um = 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
|
|
|
|
2014-04-16 22:55:17 +04:00
|
|
|
if (args == NULL)
|
|
|
|
return EINVAL;
|
2007-07-12 23:35:32 +04:00
|
|
|
if (*data_len < sizeof *args)
|
|
|
|
return EINVAL;
|
|
|
|
|
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;
|
2007-07-12 23:35:32 +04:00
|
|
|
args->target = NULL;
|
|
|
|
args->mntflags = um->um_op;
|
|
|
|
*data_len = sizeof *args;
|
|
|
|
return 0;
|
2002-09-21 22:08:27 +04:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
lowerrootvp = mp->mnt_vnodecovered;
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(lowerrootvp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
/*
|
1994-12-14 19:30:40 +03:00
|
|
|
* Find upper node.
|
1994-06-08 15:33:09 +04:00
|
|
|
*/
|
Convert 67 namei call sites to use namei_simple, in these functions:
check_console, veriexecclose, veriexec_delete, veriexec_file_add,
emul_find_root, coff_load_shlib (sh3 version), coff_load_shlib,
compat_20_sys_statfs, compat_20_netbsd32_statfs,
ELFNAME2(netbsd32,probe_noteless), darwin_sys_statfs,
ibcs2_sys_statfs, ibcs2_sys_statvfs, linux_sys_uselib,
osf1_sys_statfs, sunos_sys_statfs, sunos32_sys_statfs,
ultrix_sys_statfs, do_sys_mount, fss_create_files (3 of 4),
adosfs_mount, cd9660_mount, coda_ioctl, coda_mount, ext2fs_mount,
ffs_mount, filecore_mount, hfs_mount, lfs_mount, msdosfs_mount,
ntfs_mount, sysvbfs_mount, udf_mount, union_mount, sys_chflags,
sys_lchflags, sys_chmod, sys_lchmod, sys_chown, sys_lchown,
sys___posix_chown, sys___posix_lchown, sys_link, do_sys_pstatvfs,
sys_quotactl, sys_revoke, sys_truncate, do_sys_utimes, sys_extattrctl,
sys_extattr_set_file, sys_extattr_set_link, sys_extattr_get_file,
sys_extattr_get_link, sys_extattr_delete_file,
sys_extattr_delete_link, sys_extattr_list_file, sys_extattr_list_link,
sys_setxattr, sys_lsetxattr, sys_getxattr, sys_lgetxattr,
sys_listxattr, sys_llistxattr, sys_removexattr, sys_lremovexattr
All have been scrutinized (several times, in fact) and compile-tested,
but not all have been explicitly tested in action.
XXX: While I haven't (intentionally) changed the use or nonuse of
XXX: TRYEMULROOT in any of these places, I'm not convinced all the
XXX: uses are correct; an audit might be desirable.
2009-06-29 09:08:15 +04:00
|
|
|
error = namei_simple_user(args->target,
|
|
|
|
NSM_FOLLOW_NOEMULROOT, &upperrootvp);
|
|
|
|
if (error != 0)
|
1994-06-08 15:33:09 +04:00
|
|
|
goto bad;
|
|
|
|
|
|
|
|
if (upperrootvp->v_type != VDIR) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2012-05-01 02:51:27 +04:00
|
|
|
um = kmem_zalloc(sizeof(struct union_mount), KM_SLEEP);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-07-12 23:35:32 +04:00
|
|
|
um->um_op = args->mntflags & UNMNT_OPMASK;
|
1994-06-08 15:33:09 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-21 22:29:22 +04:00
|
|
|
mp->mnt_iflag |= IMNT_MPSAFE;
|
|
|
|
|
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) {
|
2010-06-30 17:10:35 +04:00
|
|
|
vn_lock(um->um_uppervp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
error = VOP_WHITEOUT(um->um_uppervp,
|
|
|
|
(struct componentname *) 0, LOOKUP);
|
|
|
|
VOP_UNLOCK(um->um_uppervp);
|
1994-12-14 19:30:40 +03:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2006-07-24 02:06:03 +04:00
|
|
|
um->um_cred = l->l_cred;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_hold(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
|
2014-10-18 12:33:23 +04:00
|
|
|
* the filesystem for its own opinion. This means, that an update
|
1994-06-08 15:33:09 +04: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);
|
|
|
|
|
2002-07-30 11:40:07 +04:00
|
|
|
mp->mnt_data = um;
|
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,
|
2007-07-17 15:19:31 +04:00
|
|
|
mp->mnt_op->vfs_name, 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;
|
|
|
|
|
2007-07-12 23:35:32 +04:00
|
|
|
(void) copyinstr(args->target, xp, len - 1, &size);
|
2005-05-30 01:00:29 +04:00
|
|
|
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)
|
2012-05-01 02:51:27 +04:00
|
|
|
kmem_free(um, sizeof(struct union_mount));
|
1994-06-08 15:33:09 +04:00
|
|
|
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
|
2007-11-26 22:01:26 +03:00
|
|
|
union_start(struct mount *mp, int flags)
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free reference to union layer
|
|
|
|
*/
|
|
|
|
int
|
2007-11-26 22:01:26 +03:00
|
|
|
union_unmount(struct mount *mp, int mntflags)
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
|
|
|
struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
|
1994-06-17 19:21:33 +04:00
|
|
|
int freeing;
|
2006-03-20 22:54:15 +03:00
|
|
|
int error;
|
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-03-20 22:54:15 +03:00
|
|
|
for (freeing = 0; (error = vflush(mp, NULL, 0)) != 0;) {
|
1994-06-17 19:21:33 +04:00
|
|
|
struct vnode *vp;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
/* count #vnodes held on mount list */
|
2006-10-20 22:58:12 +04:00
|
|
|
n = 0;
|
|
|
|
TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes)
|
1994-06-17 19:21:33 +04:00
|
|
|
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-03-20 22:54:15 +03:00
|
|
|
error = vflush(mp, NULL, FORCECLOSE);
|
1999-08-01 03:56:15 +04:00
|
|
|
|
2006-03-20 22:54:15 +03:00
|
|
|
if (error)
|
|
|
|
return error;
|
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);
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_free(um->um_cred);
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Finally, throw away the union_mount structure
|
|
|
|
*/
|
2012-05-01 02:51:27 +04:00
|
|
|
kmem_free(um, sizeof(struct union_mount));
|
2008-05-13 12:31:12 +04:00
|
|
|
mp->mnt_data = NULL;
|
2012-05-01 02:51:27 +04:00
|
|
|
return 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_root(struct mount *mp, struct vnode **vpp)
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
|
|
|
struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return locked reference to root.
|
|
|
|
*/
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(um->um_uppervp);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (um->um_lowervp)
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(um->um_lowervp);
|
2007-02-04 18:03:20 +03:00
|
|
|
error = union_allocvp(vpp, mp, NULL, NULL, NULL,
|
|
|
|
um->um_uppervp, um->um_lowervp, 1);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
if (error) {
|
2014-02-16 13:50:25 +04:00
|
|
|
vrele(um->um_uppervp);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (um->um_lowervp)
|
|
|
|
vrele(um->um_lowervp);
|
2014-02-16 13:50:25 +04:00
|
|
|
return error;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
2014-02-16 13:50:25 +04:00
|
|
|
vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
|
|
|
|
return 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_statvfs(struct mount *mp, struct statvfs *sbp)
|
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) {
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VFS_STATVFS(um->um_lowervp->v_mount, sbuf);
|
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;
|
|
|
|
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VFS_STATVFS(um->um_uppervp->v_mount, sbuf);
|
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
|
2006-11-16 04:32:37 +03:00
|
|
|
union_sync(struct mount *mp, int waitfor,
|
2007-11-26 22:01:26 +03:00
|
|
|
kauth_cred_t cred)
|
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
|
2006-11-16 04:32:37 +03:00
|
|
|
union_vget(struct mount *mp, ino_t ino,
|
|
|
|
struct vnode **vpp)
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
2008-01-28 17:31:15 +03:00
|
|
|
static int
|
|
|
|
union_renamelock_enter(struct mount *mp)
|
|
|
|
{
|
|
|
|
struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
|
|
|
|
|
|
|
|
/* Lock just the upper fs, where the action happens. */
|
|
|
|
return VFS_RENAMELOCK_ENTER(um->um_uppervp->v_mount);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
union_renamelock_exit(struct mount *mp)
|
|
|
|
{
|
|
|
|
struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
|
|
|
|
|
|
|
|
VFS_RENAMELOCK_EXIT(um->um_uppervp->v_mount);
|
|
|
|
}
|
|
|
|
|
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 = {
|
2014-03-23 19:21:15 +04:00
|
|
|
.vfs_name = MOUNT_UNION,
|
|
|
|
.vfs_min_mount_data = sizeof (struct union_args),
|
|
|
|
.vfs_mount = union_mount,
|
|
|
|
.vfs_start = union_start,
|
|
|
|
.vfs_unmount = union_unmount,
|
|
|
|
.vfs_root = union_root,
|
|
|
|
.vfs_quotactl = (void *)eopnotsupp,
|
|
|
|
.vfs_statvfs = union_statvfs,
|
|
|
|
.vfs_sync = union_sync,
|
|
|
|
.vfs_vget = union_vget,
|
|
|
|
.vfs_fhtovp = (void *)eopnotsupp,
|
|
|
|
.vfs_vptofh = (void *)eopnotsupp,
|
|
|
|
.vfs_init = union_init,
|
|
|
|
.vfs_reinit = union_reinit,
|
|
|
|
.vfs_done = union_done,
|
|
|
|
.vfs_snapshot = (void *)eopnotsupp,
|
|
|
|
.vfs_extattrctl = vfs_stdextattrctl,
|
|
|
|
.vfs_suspendctl = (void *)eopnotsupp,
|
|
|
|
.vfs_renamelock_enter = union_renamelock_enter,
|
|
|
|
.vfs_renamelock_exit = union_renamelock_exit,
|
|
|
|
.vfs_fsync = (void *)eopnotsupp,
|
|
|
|
.vfs_opv_descs = union_vnodeopv_descs
|
1994-06-08 15:33:09 +04:00
|
|
|
};
|
2008-05-10 06:26:09 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
union_modcmd(modcmd_t cmd, void *arg)
|
|
|
|
{
|
2008-06-28 05:34:05 +04:00
|
|
|
int error;
|
2008-05-10 06:26:09 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MODULE_CMD_INIT:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = vfs_attach(&union_vfsops);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
sysctl_createv(&union_sysctl_log, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "union",
|
|
|
|
SYSCTL_DESCR("Union file system"),
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
break;
|
2008-05-10 06:26:09 +04:00
|
|
|
case MODULE_CMD_FINI:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = vfs_detach(&union_vfsops);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
sysctl_teardown(&union_sysctl_log);
|
|
|
|
break;
|
2008-05-10 06:26:09 +04:00
|
|
|
default:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
2008-05-10 06:26:09 +04:00
|
|
|
}
|
2008-06-28 05:34:05 +04:00
|
|
|
|
|
|
|
return (error);
|
2008-05-10 06:26:09 +04:00
|
|
|
}
|