2015-04-21 01:59:19 +03:00
|
|
|
/* $NetBSD: union_vnops.c,v 1.63 2015/04/20 23:03:08 riastradh Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
1998-03-01 05:20:01 +03:00
|
|
|
* Copyright (c) 1992, 1993, 1994, 1995
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1994-06-08 15:33:09 +04:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed 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.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 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_vnops.c 8.33 (Berkeley) 7/31/95
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993, 1994, 1995 Jan-Simon Pendry.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed 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.
|
1994-06-08 15:33:09 +04:00
|
|
|
* 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_vnops.c 8.33 (Berkeley) 7/31/95
|
1994-06-08 15:33:09 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-10 16:33:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
2015-04-21 01:59:19 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.63 2015/04/20 23:03:08 riastradh 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>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/time.h>
|
1994-12-14 19:30:40 +03:00
|
|
|
#include <sys/stat.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/queue.h>
|
1998-03-01 05:20:01 +03:00
|
|
|
#include <sys/lock.h>
|
2006-05-15 01:31:52 +04:00
|
|
|
#include <sys/kauth.h>
|
|
|
|
|
2003-03-16 11:26:46 +03:00
|
|
|
#include <fs/union/union.h>
|
1998-03-01 05:20:01 +03:00
|
|
|
#include <miscfs/genfs/genfs.h>
|
2011-08-12 18:36:29 +04:00
|
|
|
#include <miscfs/specfs/specdev.h>
|
1996-02-10 01:39:56 +03:00
|
|
|
|
2005-08-30 23:11:43 +04:00
|
|
|
int union_lookup(void *);
|
|
|
|
int union_create(void *);
|
|
|
|
int union_whiteout(void *);
|
|
|
|
int union_mknod(void *);
|
|
|
|
int union_open(void *);
|
|
|
|
int union_close(void *);
|
|
|
|
int union_access(void *);
|
|
|
|
int union_getattr(void *);
|
|
|
|
int union_setattr(void *);
|
|
|
|
int union_read(void *);
|
|
|
|
int union_write(void *);
|
|
|
|
int union_ioctl(void *);
|
|
|
|
int union_poll(void *);
|
|
|
|
int union_revoke(void *);
|
|
|
|
int union_mmap(void *);
|
|
|
|
int union_fsync(void *);
|
|
|
|
int union_seek(void *);
|
|
|
|
int union_remove(void *);
|
|
|
|
int union_link(void *);
|
|
|
|
int union_rename(void *);
|
|
|
|
int union_mkdir(void *);
|
|
|
|
int union_rmdir(void *);
|
|
|
|
int union_symlink(void *);
|
|
|
|
int union_readdir(void *);
|
|
|
|
int union_readlink(void *);
|
|
|
|
int union_abortop(void *);
|
|
|
|
int union_inactive(void *);
|
|
|
|
int union_reclaim(void *);
|
|
|
|
int union_lock(void *);
|
|
|
|
int union_unlock(void *);
|
|
|
|
int union_bmap(void *);
|
|
|
|
int union_print(void *);
|
|
|
|
int union_islocked(void *);
|
|
|
|
int union_pathconf(void *);
|
|
|
|
int union_advlock(void *);
|
|
|
|
int union_strategy(void *);
|
2011-08-12 18:36:29 +04:00
|
|
|
int union_bwrite(void *);
|
2005-08-30 23:11:43 +04:00
|
|
|
int union_getpages(void *);
|
|
|
|
int union_putpages(void *);
|
|
|
|
int union_kqfilter(void *);
|
1996-02-10 01:39:56 +03:00
|
|
|
|
2005-08-30 23:11:43 +04:00
|
|
|
static int union_lookup1(struct vnode *, struct vnode **,
|
|
|
|
struct vnode **, struct componentname *);
|
1998-03-01 05:20:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global vfs data structures
|
|
|
|
*/
|
2005-08-30 23:11:43 +04:00
|
|
|
int (**union_vnodeop_p)(void *);
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_entry_desc union_vnodeop_entries[] = {
|
1996-02-10 01:39:56 +03:00
|
|
|
{ &vop_default_desc, vn_default_error },
|
|
|
|
{ &vop_lookup_desc, union_lookup }, /* lookup */
|
|
|
|
{ &vop_create_desc, union_create }, /* create */
|
|
|
|
{ &vop_whiteout_desc, union_whiteout }, /* whiteout */
|
|
|
|
{ &vop_mknod_desc, union_mknod }, /* mknod */
|
|
|
|
{ &vop_open_desc, union_open }, /* open */
|
|
|
|
{ &vop_close_desc, union_close }, /* close */
|
|
|
|
{ &vop_access_desc, union_access }, /* access */
|
|
|
|
{ &vop_getattr_desc, union_getattr }, /* getattr */
|
|
|
|
{ &vop_setattr_desc, union_setattr }, /* setattr */
|
|
|
|
{ &vop_read_desc, union_read }, /* read */
|
|
|
|
{ &vop_write_desc, union_write }, /* write */
|
2014-07-25 12:20:51 +04:00
|
|
|
{ &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */
|
|
|
|
{ &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */
|
1996-02-10 01:39:56 +03:00
|
|
|
{ &vop_ioctl_desc, union_ioctl }, /* ioctl */
|
1998-03-01 05:20:01 +03:00
|
|
|
{ &vop_poll_desc, union_poll }, /* select */
|
|
|
|
{ &vop_revoke_desc, union_revoke }, /* revoke */
|
1996-02-10 01:39:56 +03:00
|
|
|
{ &vop_mmap_desc, union_mmap }, /* mmap */
|
|
|
|
{ &vop_fsync_desc, union_fsync }, /* fsync */
|
|
|
|
{ &vop_seek_desc, union_seek }, /* seek */
|
|
|
|
{ &vop_remove_desc, union_remove }, /* remove */
|
|
|
|
{ &vop_link_desc, union_link }, /* link */
|
|
|
|
{ &vop_rename_desc, union_rename }, /* rename */
|
|
|
|
{ &vop_mkdir_desc, union_mkdir }, /* mkdir */
|
|
|
|
{ &vop_rmdir_desc, union_rmdir }, /* rmdir */
|
|
|
|
{ &vop_symlink_desc, union_symlink }, /* symlink */
|
|
|
|
{ &vop_readdir_desc, union_readdir }, /* readdir */
|
|
|
|
{ &vop_readlink_desc, union_readlink }, /* readlink */
|
|
|
|
{ &vop_abortop_desc, union_abortop }, /* abortop */
|
|
|
|
{ &vop_inactive_desc, union_inactive }, /* inactive */
|
|
|
|
{ &vop_reclaim_desc, union_reclaim }, /* reclaim */
|
|
|
|
{ &vop_lock_desc, union_lock }, /* lock */
|
|
|
|
{ &vop_unlock_desc, union_unlock }, /* unlock */
|
|
|
|
{ &vop_bmap_desc, union_bmap }, /* bmap */
|
|
|
|
{ &vop_strategy_desc, union_strategy }, /* strategy */
|
2011-08-12 18:36:29 +04:00
|
|
|
{ &vop_bwrite_desc, union_bwrite }, /* bwrite */
|
1996-02-10 01:39:56 +03:00
|
|
|
{ &vop_print_desc, union_print }, /* print */
|
|
|
|
{ &vop_islocked_desc, union_islocked }, /* islocked */
|
|
|
|
{ &vop_pathconf_desc, union_pathconf }, /* pathconf */
|
|
|
|
{ &vop_advlock_desc, union_advlock }, /* advlock */
|
2000-12-11 05:50:17 +03:00
|
|
|
{ &vop_getpages_desc, union_getpages }, /* getpages */
|
2001-12-06 07:29:23 +03:00
|
|
|
{ &vop_putpages_desc, union_putpages }, /* putpages */
|
2003-03-17 14:39:16 +03:00
|
|
|
{ &vop_kqfilter_desc, union_kqfilter }, /* kqfilter */
|
2000-12-11 05:50:17 +03:00
|
|
|
{ NULL, NULL }
|
1996-02-10 01:39:56 +03:00
|
|
|
};
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_desc union_vnodeop_opv_desc =
|
1996-02-10 01:39:56 +03:00
|
|
|
{ &union_vnodeop_p, union_vnodeop_entries };
|
|
|
|
|
2011-08-12 18:36:29 +04:00
|
|
|
#define NODE_IS_SPECIAL(vp) \
|
|
|
|
((vp)->v_type == VBLK || (vp)->v_type == VCHR || \
|
|
|
|
(vp)->v_type == VSOCK || (vp)->v_type == VFIFO)
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
static int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_lookup1(struct vnode *udvp, struct vnode **dvpp, struct vnode **vpp,
|
|
|
|
struct componentname *cnp)
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct vnode *tdvp;
|
1994-06-16 03:07:54 +04:00
|
|
|
struct vnode *dvp;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mount *mp;
|
|
|
|
|
1994-06-16 03:07:54 +04:00
|
|
|
dvp = *dvpp;
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* If stepping up the directory tree, check for going
|
|
|
|
* back across the mount point, in which case do what
|
|
|
|
* lookup would do by stepping back down the mount
|
|
|
|
* hierarchy.
|
|
|
|
*/
|
|
|
|
if (cnp->cn_flags & ISDOTDOT) {
|
2007-10-11 00:42:20 +04:00
|
|
|
while ((dvp != udvp) && (dvp->v_vflag & VV_ROOT)) {
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Don't do the NOCROSSMOUNT check
|
|
|
|
* at this level. By definition,
|
|
|
|
* union fs deals with namespaces, not
|
|
|
|
* filesystems.
|
|
|
|
*/
|
|
|
|
tdvp = dvp;
|
1994-06-16 03:07:54 +04:00
|
|
|
*dvpp = dvp = dvp->v_mount->mnt_vnodecovered;
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(tdvp);
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error = VOP_LOOKUP(dvp, &tdvp, cnp);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2014-02-13 13:50:31 +04:00
|
|
|
if (dvp != tdvp) {
|
|
|
|
if (cnp->cn_flags & ISDOTDOT)
|
|
|
|
VOP_UNLOCK(dvp);
|
|
|
|
error = vn_lock(tdvp, LK_EXCLUSIVE);
|
|
|
|
if (cnp->cn_flags & ISDOTDOT)
|
|
|
|
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
if (error) {
|
|
|
|
vrele(tdvp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
dvp = tdvp;
|
2014-02-07 19:29:20 +04:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lastly check if the current node is a mount point in
|
|
|
|
* which case walk up the mount hierarchy making sure not to
|
|
|
|
* bump into the root of the mount tree (ie. dvp != udvp).
|
|
|
|
*/
|
|
|
|
while (dvp != udvp && (dvp->v_type == VDIR) &&
|
|
|
|
(mp = dvp->v_mountedhere)) {
|
PR kern/38141 lookup/vfs_busy acquire rwlock recursively
Simplify the mount locking. Remove all the crud to deal with recursion on
the mount lock, and crud to deal with unmount as another weirdo lock.
Hopefully this will once and for all fix the deadlocks with this. With this
commit there are two locks on each mount:
- krwlock_t mnt_unmounting. This is used to prevent unmount across critical
sections like getnewvnode(). It's only ever read locked with rw_tryenter(),
and is only ever write locked in dounmount(). A write hold can't be taken
on this lock if the current LWP could hold a vnode lock.
- kmutex_t mnt_updating. This is taken by threads updating the mount, for
example when going r/o -> r/w, and is only present to serialize updates.
In order to take this lock, a read hold must first be taken on
mnt_unmounting, and the two need to be held across the operation.
One effect of this change: previously if an unmount failed, we would make a
half hearted attempt to back out of it gracefully, but that was unlikely to
work in a lot of cases. Now while an unmount that will be aborted is in
progress, new file operations within the mount will fail instead of being
delayed. That is unlikely to be a problem though, because if the admin
requests unmount of a file system then s(he) has made a decision to deny
access to the resource.
2008-05-06 22:43:44 +04:00
|
|
|
if (vfs_busy(mp, NULL))
|
1994-06-08 15:33:09 +04:00
|
|
|
continue;
|
2007-02-04 18:03:20 +03:00
|
|
|
vput(dvp);
|
2003-06-29 22:43:21 +04:00
|
|
|
error = VFS_ROOT(mp, &tdvp);
|
2008-04-30 16:49:16 +04:00
|
|
|
vfs_unbusy(mp, false, NULL);
|
1998-03-01 05:20:01 +03:00
|
|
|
if (error) {
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
dvp = tdvp;
|
|
|
|
}
|
|
|
|
|
|
|
|
*vpp = dvp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_lookup(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
2014-02-07 19:29:20 +04:00
|
|
|
struct vop_lookup_v2_args /* {
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnodeop_desc *a_desc;
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
int uerror, lerror;
|
|
|
|
struct vnode *uppervp, *lowervp;
|
|
|
|
struct vnode *upperdvp, *lowerdvp;
|
|
|
|
struct vnode *dvp = ap->a_dvp;
|
|
|
|
struct union_node *dun = VTOUNION(dvp);
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct union_mount *um = MOUNTTOUNIONMOUNT(dvp->v_mount);
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t saved_cred = NULL;
|
1994-12-14 19:30:40 +03:00
|
|
|
int iswhiteout;
|
|
|
|
struct vattr va;
|
|
|
|
|
|
|
|
#ifdef notyet
|
|
|
|
if (cnp->cn_namelen == 3 &&
|
|
|
|
cnp->cn_nameptr[2] == '.' &&
|
|
|
|
cnp->cn_nameptr[1] == '.' &&
|
|
|
|
cnp->cn_nameptr[0] == '.') {
|
|
|
|
dvp = *ap->a_vpp = LOWERVP(ap->a_dvp);
|
|
|
|
if (dvp == NULLVP)
|
|
|
|
return (ENOENT);
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(dvp);
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
|
1994-12-14 19:30:40 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1999-08-02 03:16:34 +04:00
|
|
|
if ((cnp->cn_flags & ISLASTCN) &&
|
|
|
|
(dvp->v_mount->mnt_flag & MNT_RDONLY) &&
|
|
|
|
(cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
|
|
|
|
return (EROFS);
|
|
|
|
|
2011-08-05 12:17:47 +04:00
|
|
|
start:
|
1994-06-08 15:33:09 +04:00
|
|
|
upperdvp = dun->un_uppervp;
|
|
|
|
lowerdvp = dun->un_lowervp;
|
|
|
|
uppervp = NULLVP;
|
|
|
|
lowervp = NULLVP;
|
1994-12-14 19:30:40 +03:00
|
|
|
iswhiteout = 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* do the lookup in the upper level.
|
|
|
|
* if that level comsumes additional pathnames,
|
|
|
|
* then assume that something special is going
|
|
|
|
* on and just return that vnode.
|
|
|
|
*/
|
1994-06-16 03:07:54 +04:00
|
|
|
if (upperdvp != NULLVP) {
|
|
|
|
uerror = union_lookup1(um->um_uppervp, &upperdvp,
|
1998-03-01 05:20:01 +03:00
|
|
|
&uppervp, cnp);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (cnp->cn_consume != 0) {
|
2014-02-07 19:29:20 +04:00
|
|
|
if (uppervp != upperdvp)
|
|
|
|
VOP_UNLOCK(uppervp);
|
1994-06-08 15:33:09 +04:00
|
|
|
*ap->a_vpp = uppervp;
|
|
|
|
return (uerror);
|
|
|
|
}
|
1994-12-14 19:30:40 +03:00
|
|
|
if (uerror == ENOENT || uerror == EJUSTRETURN) {
|
|
|
|
if (cnp->cn_flags & ISWHITEOUT) {
|
|
|
|
iswhiteout = 1;
|
|
|
|
} else if (lowerdvp != NULLVP) {
|
|
|
|
lerror = VOP_GETATTR(upperdvp, &va,
|
2007-11-26 22:01:26 +03:00
|
|
|
cnp->cn_cred);
|
1994-12-14 19:30:40 +03:00
|
|
|
if (lerror == 0 && (va.va_flags & OPAQUE))
|
|
|
|
iswhiteout = 1;
|
|
|
|
}
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
} else {
|
|
|
|
uerror = ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* in a similar way to the upper layer, do the lookup
|
|
|
|
* in the lower layer. this time, if there is some
|
|
|
|
* component magic going on, then vput whatever we got
|
|
|
|
* back from the upper layer and return the lower vnode
|
|
|
|
* instead.
|
|
|
|
*/
|
1994-12-14 19:30:40 +03:00
|
|
|
if (lowerdvp != NULLVP && !iswhiteout) {
|
1994-06-08 15:33:09 +04:00
|
|
|
int nameiop;
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(lowerdvp, LK_EXCLUSIVE | LK_RETRY);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Only do a LOOKUP on the bottom node, since
|
|
|
|
* we won't be making changes to it anyway.
|
|
|
|
*/
|
|
|
|
nameiop = cnp->cn_nameiop;
|
|
|
|
cnp->cn_nameiop = LOOKUP;
|
|
|
|
if (um->um_op == UNMNT_BELOW) {
|
|
|
|
saved_cred = cnp->cn_cred;
|
|
|
|
cnp->cn_cred = um->um_cred;
|
|
|
|
}
|
2006-12-09 19:11:50 +03:00
|
|
|
|
1996-05-11 02:57:49 +04:00
|
|
|
/*
|
|
|
|
* we shouldn't have to worry about locking interactions
|
|
|
|
* between the lower layer and our union layer (w.r.t.
|
|
|
|
* `..' processing) because we don't futz with lowervp
|
|
|
|
* locks in the union-node instantiation code path.
|
|
|
|
*/
|
1994-06-16 03:07:54 +04:00
|
|
|
lerror = union_lookup1(um->um_lowervp, &lowerdvp,
|
1994-06-08 15:33:09 +04:00
|
|
|
&lowervp, cnp);
|
|
|
|
if (um->um_op == UNMNT_BELOW)
|
|
|
|
cnp->cn_cred = saved_cred;
|
|
|
|
cnp->cn_nameiop = nameiop;
|
|
|
|
|
|
|
|
if (lowervp != lowerdvp)
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(lowerdvp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
if (cnp->cn_consume != 0) {
|
1994-06-16 03:07:54 +04:00
|
|
|
if (uppervp != NULLVP) {
|
1994-06-08 15:33:09 +04:00
|
|
|
if (uppervp == upperdvp)
|
|
|
|
vrele(uppervp);
|
|
|
|
else
|
|
|
|
vput(uppervp);
|
|
|
|
uppervp = NULLVP;
|
|
|
|
}
|
|
|
|
*ap->a_vpp = lowervp;
|
|
|
|
return (lerror);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
lerror = ENOENT;
|
1994-06-17 19:21:33 +04:00
|
|
|
if ((cnp->cn_flags & ISDOTDOT) && dun->un_pvp != NULLVP) {
|
|
|
|
lowervp = LOWERVP(dun->un_pvp);
|
|
|
|
if (lowervp != NULLVP) {
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(lowervp);
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(lowervp, LK_EXCLUSIVE | LK_RETRY);
|
1994-06-17 19:21:33 +04:00
|
|
|
lerror = 0;
|
|
|
|
}
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
1999-08-02 03:16:34 +04:00
|
|
|
/*
|
|
|
|
* EJUSTRETURN is used by underlying filesystems to indicate that
|
|
|
|
* a directory modification op was started successfully.
|
|
|
|
* This will only happen in the upper layer, since
|
|
|
|
* the lower layer only does LOOKUPs.
|
|
|
|
* If this union is mounted read-only, bounce it now.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((uerror == EJUSTRETURN) && (cnp->cn_flags & ISLASTCN) &&
|
|
|
|
(dvp->v_mount->mnt_flag & MNT_RDONLY) &&
|
|
|
|
((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME)))
|
|
|
|
uerror = EROFS;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* at this point, we have uerror and lerror indicating
|
|
|
|
* possible errors with the lookups in the upper and lower
|
|
|
|
* layers. additionally, uppervp and lowervp are (locked)
|
|
|
|
* references to existing vnodes in the upper and lower layers.
|
|
|
|
*
|
|
|
|
* there are now three cases to consider.
|
|
|
|
* 1. if both layers returned an error, then return whatever
|
|
|
|
* error the upper layer generated.
|
|
|
|
*
|
|
|
|
* 2. if the top layer failed and the bottom layer succeeded
|
|
|
|
* then two subcases occur.
|
|
|
|
* a. the bottom vnode is not a directory, in which
|
|
|
|
* case just return a new union vnode referencing
|
|
|
|
* an empty top layer and the existing bottom layer.
|
|
|
|
* b. the bottom vnode is a directory, in which case
|
|
|
|
* create a new directory in the top-level and
|
|
|
|
* continue as in case 3.
|
|
|
|
*
|
|
|
|
* 3. if the top layer succeeded then return a new union
|
|
|
|
* vnode referencing whatever the new top layer and
|
|
|
|
* whatever the bottom layer returned.
|
|
|
|
*/
|
|
|
|
|
|
|
|
*ap->a_vpp = NULLVP;
|
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/* case 1. */
|
|
|
|
if ((uerror != 0) && (lerror != 0)) {
|
|
|
|
return (uerror);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* case 2. */
|
|
|
|
if (uerror != 0 /* && (lerror == 0) */ ) {
|
|
|
|
if (lowervp->v_type == VDIR) { /* case 2b. */
|
1996-05-11 02:57:49 +04:00
|
|
|
/*
|
|
|
|
* We may be racing another process to make the
|
|
|
|
* upper-level shadow directory. Be careful with
|
|
|
|
* locks/etc!
|
2011-08-05 12:17:47 +04:00
|
|
|
* If we have to create a shadow directory and want
|
|
|
|
* to commit the node we have to restart the lookup
|
|
|
|
* to get the componentname right.
|
1996-05-11 02:57:49 +04:00
|
|
|
*/
|
2006-04-15 07:56:25 +04:00
|
|
|
if (upperdvp) {
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(upperdvp);
|
2006-04-15 07:56:25 +04:00
|
|
|
uerror = union_mkshadow(um, upperdvp, cnp,
|
|
|
|
&uppervp);
|
|
|
|
vn_lock(upperdvp, LK_EXCLUSIVE | LK_RETRY);
|
2011-08-05 12:17:47 +04:00
|
|
|
if (uerror == 0 && cnp->cn_nameiop != LOOKUP) {
|
2014-01-23 14:13:55 +04:00
|
|
|
vrele(uppervp);
|
2011-08-05 12:17:47 +04:00
|
|
|
if (lowervp != NULLVP)
|
|
|
|
vput(lowervp);
|
|
|
|
goto start;
|
|
|
|
}
|
2006-04-15 07:56:25 +04:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
if (uerror) {
|
1994-06-16 03:07:54 +04:00
|
|
|
if (lowervp != NULLVP) {
|
1994-06-08 15:33:09 +04:00
|
|
|
vput(lowervp);
|
|
|
|
lowervp = NULLVP;
|
|
|
|
}
|
|
|
|
return (uerror);
|
|
|
|
}
|
|
|
|
}
|
2014-02-16 13:50:25 +04:00
|
|
|
} else { /* uerror == 0 */
|
|
|
|
if (uppervp != upperdvp)
|
|
|
|
VOP_UNLOCK(uppervp);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
1994-06-16 03:07:54 +04:00
|
|
|
if (lowervp != NULLVP)
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(lowervp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
error = union_allocvp(ap->a_vpp, dvp->v_mount, dvp, upperdvp, cnp,
|
2003-06-29 22:43:21 +04:00
|
|
|
uppervp, lowervp, 1);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
if (error) {
|
1994-06-16 03:07:54 +04:00
|
|
|
if (uppervp != NULLVP)
|
2014-02-16 13:50:25 +04:00
|
|
|
vrele(uppervp);
|
1994-06-16 03:07:54 +04:00
|
|
|
if (lowervp != NULLVP)
|
1994-06-08 15:33:09 +04:00
|
|
|
vrele(lowervp);
|
2014-02-07 19:29:20 +04:00
|
|
|
return error;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
2014-02-07 19:29:20 +04:00
|
|
|
return 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_create(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
2014-01-23 14:13:55 +04:00
|
|
|
struct vop_create_v3_args /* {
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct union_node *un = VTOUNION(ap->a_dvp);
|
1998-03-01 05:20:01 +03:00
|
|
|
struct vnode *dvp = un->un_uppervp;
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
if (dvp != NULLVP) {
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
struct vnode *vp;
|
1994-12-14 19:30:40 +03:00
|
|
|
struct mount *mp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1994-12-14 19:30:40 +03:00
|
|
|
mp = ap->a_dvp->v_mount;
|
2014-05-17 08:03:49 +04:00
|
|
|
|
|
|
|
vp = NULL;
|
1998-03-01 05:20:01 +03:00
|
|
|
error = VOP_CREATE(dvp, &vp, cnp, ap->a_vap);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
error = union_allocvp(ap->a_vpp, mp, NULLVP, NULLVP, cnp, vp,
|
2003-06-29 22:43:21 +04:00
|
|
|
NULLVP, 1);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error)
|
2014-01-23 14:13:55 +04:00
|
|
|
vrele(vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (EROFS);
|
|
|
|
}
|
|
|
|
|
1994-12-14 19:30:40 +03:00
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_whiteout(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-12-14 19:30:40 +03:00
|
|
|
struct vop_whiteout_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
int a_flags;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-12-14 19:30:40 +03:00
|
|
|
struct union_node *un = VTOUNION(ap->a_dvp);
|
1998-03-01 05:20:01 +03:00
|
|
|
struct componentname *cnp = ap->a_cnp;
|
1994-12-14 19:30:40 +03:00
|
|
|
|
1994-12-30 01:42:10 +03:00
|
|
|
if (un->un_uppervp == NULLVP)
|
1994-12-14 19:30:40 +03:00
|
|
|
return (EOPNOTSUPP);
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
return (VOP_WHITEOUT(un->un_uppervp, cnp, ap->a_flags));
|
1994-12-14 19:30:40 +03:00
|
|
|
}
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_mknod(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
2014-01-23 14:13:55 +04:00
|
|
|
struct vop_mknod_v3_args /* {
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct union_node *un = VTOUNION(ap->a_dvp);
|
1998-03-01 05:20:01 +03:00
|
|
|
struct vnode *dvp = un->un_uppervp;
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
if (dvp != NULLVP) {
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
struct vnode *vp;
|
1994-12-14 19:30:40 +03:00
|
|
|
struct mount *mp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1994-12-14 19:30:40 +03:00
|
|
|
mp = ap->a_dvp->v_mount;
|
1998-03-01 05:20:01 +03:00
|
|
|
error = VOP_MKNOD(dvp, &vp, cnp, ap->a_vap);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2001-07-24 19:39:30 +04:00
|
|
|
error = union_allocvp(ap->a_vpp, mp, NULLVP, NULLVP,
|
2003-06-29 22:43:21 +04:00
|
|
|
cnp, vp, NULLVP, 1);
|
2001-07-24 19:39:30 +04:00
|
|
|
if (error)
|
2014-01-23 14:13:55 +04:00
|
|
|
vrele(vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (EROFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_open(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_open_args /* {
|
|
|
|
struct vnodeop_desc *a_desc;
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_mode;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct union_node *un = VTOUNION(ap->a_vp);
|
1994-12-30 01:42:10 +03:00
|
|
|
struct vnode *tvp;
|
|
|
|
int mode = ap->a_mode;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t cred = ap->a_cred;
|
2007-11-26 22:01:26 +03:00
|
|
|
struct lwp *l = curlwp;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is an existing upper vp then simply open that.
|
|
|
|
*/
|
1994-12-30 01:42:10 +03:00
|
|
|
tvp = un->un_uppervp;
|
|
|
|
if (tvp == NULLVP) {
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* If the lower vnode is being opened for writing, then
|
|
|
|
* copy the file contents to the upper vnode and open that,
|
|
|
|
* otherwise can simply open the lower vnode.
|
|
|
|
*/
|
1994-12-30 01:42:10 +03:00
|
|
|
tvp = un->un_lowervp;
|
|
|
|
if ((ap->a_mode & FWRITE) && (tvp->v_type == VREG)) {
|
2005-12-11 15:16:03 +03:00
|
|
|
error = union_copyup(un, (mode&O_TRUNC) == 0, cred, l);
|
1994-12-30 01:42:10 +03:00
|
|
|
if (error == 0)
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_OPEN(un->un_uppervp, mode, cred);
|
1994-12-30 01:42:10 +03:00
|
|
|
return (error);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-03-25 16:05:41 +03:00
|
|
|
* Just open the lower vnode, but check for nodev mount flag
|
1994-06-08 15:33:09 +04:00
|
|
|
*/
|
1999-03-25 16:05:41 +03:00
|
|
|
if ((tvp->v_type == VBLK || tvp->v_type == VCHR) &&
|
|
|
|
(ap->a_vp->v_mount->mnt_flag & MNT_NODEV))
|
|
|
|
return ENXIO;
|
1994-06-08 15:33:09 +04:00
|
|
|
un->un_openl++;
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(tvp, LK_EXCLUSIVE | LK_RETRY);
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_OPEN(tvp, mode, cred);
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(tvp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
1999-03-25 16:05:41 +03:00
|
|
|
/*
|
|
|
|
* Just open the upper vnode, checking for nodev mount flag first
|
|
|
|
*/
|
|
|
|
if ((tvp->v_type == VBLK || tvp->v_type == VCHR) &&
|
|
|
|
(ap->a_vp->v_mount->mnt_flag & MNT_NODEV))
|
|
|
|
return ENXIO;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_OPEN(tvp, mode, cred);
|
1994-12-30 01:42:10 +03:00
|
|
|
|
|
|
|
return (error);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_close(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_close_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_fflag;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct union_node *un = VTOUNION(ap->a_vp);
|
|
|
|
struct vnode *vp;
|
2011-08-12 18:36:29 +04:00
|
|
|
int error;
|
|
|
|
bool do_lock;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
vp = un->un_uppervp;
|
2011-08-12 18:36:29 +04:00
|
|
|
if (vp != NULLVP) {
|
|
|
|
do_lock = false;
|
|
|
|
} else {
|
|
|
|
KASSERT(un->un_openl > 0);
|
1994-06-08 15:33:09 +04:00
|
|
|
--un->un_openl;
|
|
|
|
vp = un->un_lowervp;
|
2011-08-12 18:36:29 +04:00
|
|
|
do_lock = true;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
2011-08-12 18:36:29 +04:00
|
|
|
KASSERT(vp != NULLVP);
|
1994-12-13 19:59:50 +03:00
|
|
|
ap->a_vp = vp;
|
2011-08-12 18:36:29 +04:00
|
|
|
if (do_lock)
|
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
error = VCALL(vp, VOFFSET(vop_close), ap);
|
|
|
|
if (do_lock)
|
|
|
|
VOP_UNLOCK(vp);
|
|
|
|
|
|
|
|
return error;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check access permission on the union vnode.
|
|
|
|
* The access check being enforced is to check
|
|
|
|
* against both the underlying vnode, and any
|
|
|
|
* copied vnode. This ensures that no additional
|
|
|
|
* file permissions are given away simply because
|
|
|
|
* the user caused an implicit file copy.
|
|
|
|
*/
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_access(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_access_args /* {
|
|
|
|
struct vnodeop_desc *a_desc;
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_mode;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1999-08-02 03:16:34 +04:00
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct union_node *un = VTOUNION(vp);
|
1994-12-13 19:59:50 +03:00
|
|
|
int error = EACCES;
|
1999-08-02 03:16:34 +04:00
|
|
|
struct union_mount *um = MOUNTTOUNIONMOUNT(vp->v_mount);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disallow write attempts on read-only file systems;
|
|
|
|
* unless the file is a socket, fifo, or a block or
|
|
|
|
* character device resident on the file system.
|
|
|
|
*/
|
|
|
|
if (ap->a_mode & VWRITE) {
|
|
|
|
switch (vp->v_type) {
|
|
|
|
case VDIR:
|
|
|
|
case VLNK:
|
|
|
|
case VREG:
|
|
|
|
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
|
|
|
return (EROFS);
|
|
|
|
break;
|
|
|
|
case VBAD:
|
|
|
|
case VBLK:
|
|
|
|
case VCHR:
|
|
|
|
case VSOCK:
|
|
|
|
case VFIFO:
|
|
|
|
case VNON:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1994-06-16 03:07:54 +04:00
|
|
|
if ((vp = un->un_uppervp) != NULLVP) {
|
1998-03-01 05:20:01 +03:00
|
|
|
ap->a_vp = vp;
|
|
|
|
return (VCALL(vp, VOFFSET(vop_access), ap));
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
1994-06-16 03:07:54 +04:00
|
|
|
if ((vp = un->un_lowervp) != NULLVP) {
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
ap->a_vp = vp;
|
|
|
|
error = VCALL(vp, VOFFSET(vop_access), ap);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error == 0) {
|
1998-03-01 05:20:01 +03:00
|
|
|
if (um->um_op == UNMNT_BELOW) {
|
|
|
|
ap->a_cred = um->um_cred;
|
|
|
|
error = VCALL(vp, VOFFSET(vop_access), ap);
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(vp);
|
1994-12-30 01:42:10 +03:00
|
|
|
if (error)
|
|
|
|
return (error);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-06-16 03:07:54 +04:00
|
|
|
* We handle getattr only to change the fsid and
|
|
|
|
* track object sizes
|
1994-06-08 15:33:09 +04:00
|
|
|
*/
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_getattr(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_getattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
struct union_node *un = VTOUNION(ap->a_vp);
|
|
|
|
struct vnode *vp = un->un_uppervp;
|
|
|
|
struct vattr *vap;
|
|
|
|
struct vattr va;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some programs walk the filesystem hierarchy by counting
|
|
|
|
* links to directories to avoid stat'ing all the time.
|
|
|
|
* This means the link count on directories needs to be "correct".
|
|
|
|
* The only way to do that is to call getattr on both layers
|
|
|
|
* and fix up the link count. The link count will not necessarily
|
|
|
|
* be accurate but will be large enough to defeat the tree walkers.
|
1999-08-02 03:16:34 +04:00
|
|
|
*
|
|
|
|
* To make life more interesting, some filesystems don't keep
|
|
|
|
* track of link counts in the expected way, and return a
|
|
|
|
* link count of `1' for those directories; if either of the
|
|
|
|
* component directories returns a link count of `1', we return a 1.
|
1994-06-08 15:33:09 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
vap = ap->a_vap;
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
vp = un->un_uppervp;
|
|
|
|
if (vp != NULLVP) {
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_GETATTR(vp, vap, ap->a_cred);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2011-11-21 22:29:22 +04:00
|
|
|
mutex_enter(&un->un_lock);
|
1994-06-16 03:07:54 +04:00
|
|
|
union_newsize(ap->a_vp, vap->va_size, VNOVAL);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vp == NULLVP) {
|
|
|
|
vp = un->un_lowervp;
|
|
|
|
} else if (vp->v_type == VDIR) {
|
|
|
|
vp = un->un_lowervp;
|
1999-08-02 03:16:34 +04:00
|
|
|
if (vp != NULLVP)
|
|
|
|
vap = &va;
|
1994-06-08 15:33:09 +04:00
|
|
|
} else {
|
|
|
|
vp = NULLVP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vp != NULLVP) {
|
2011-10-18 13:22:53 +04:00
|
|
|
if (vp == un->un_lowervp)
|
|
|
|
vn_lock(vp, LK_SHARED | LK_RETRY);
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_GETATTR(vp, vap, ap->a_cred);
|
2011-10-18 13:22:53 +04:00
|
|
|
if (vp == un->un_lowervp)
|
|
|
|
VOP_UNLOCK(vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2011-11-21 22:29:22 +04:00
|
|
|
mutex_enter(&un->un_lock);
|
1994-06-16 03:07:54 +04:00
|
|
|
union_newsize(ap->a_vp, VNOVAL, vap->va_size);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
1999-08-02 03:16:34 +04:00
|
|
|
if ((vap != ap->a_vap) && (vap->va_type == VDIR)) {
|
|
|
|
/*
|
|
|
|
* Link count manipulation:
|
|
|
|
* - If both return "2", return 2 (no subdirs)
|
|
|
|
* - If one or the other return "1", return "1" (ENOCLUE)
|
|
|
|
*/
|
|
|
|
if ((ap->a_vap->va_nlink == 2) &&
|
|
|
|
(vap->va_nlink == 2))
|
|
|
|
;
|
|
|
|
else if (ap->a_vap->va_nlink != 1) {
|
|
|
|
if (vap->va_nlink == 1)
|
|
|
|
ap->a_vap->va_nlink = 1;
|
|
|
|
else
|
|
|
|
ap->a_vap->va_nlink += vap->va_nlink;
|
|
|
|
}
|
|
|
|
}
|
2004-04-21 05:05:31 +04:00
|
|
|
ap->a_vap->va_fsid = ap->a_vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
|
1994-06-08 15:33:09 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_setattr(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_setattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1999-08-02 03:16:34 +04:00
|
|
|
struct vattr *vap = ap->a_vap;
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct union_node *un = VTOUNION(vp);
|
2011-08-10 10:27:02 +04:00
|
|
|
bool size_only; /* All but va_size are VNOVAL. */
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
|
2011-08-10 10:27:02 +04:00
|
|
|
size_only = (vap->va_flags == VNOVAL && vap->va_uid == (uid_t)VNOVAL &&
|
|
|
|
vap->va_gid == (gid_t)VNOVAL && vap->va_atime.tv_sec == VNOVAL &&
|
|
|
|
vap->va_mtime.tv_sec == VNOVAL && vap->va_mode == (mode_t)VNOVAL);
|
|
|
|
|
|
|
|
if (!size_only && (vp->v_mount->mnt_flag & MNT_RDONLY))
|
1999-08-02 03:16:34 +04:00
|
|
|
return (EROFS);
|
|
|
|
if (vap->va_size != VNOVAL) {
|
|
|
|
switch (vp->v_type) {
|
|
|
|
case VDIR:
|
|
|
|
return (EISDIR);
|
|
|
|
case VCHR:
|
|
|
|
case VBLK:
|
|
|
|
case VSOCK:
|
|
|
|
case VFIFO:
|
|
|
|
break;
|
|
|
|
case VREG:
|
|
|
|
case VLNK:
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Disallow write attempts if the filesystem is
|
|
|
|
* mounted read-only.
|
|
|
|
*/
|
|
|
|
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
|
|
|
return (EROFS);
|
|
|
|
}
|
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Handle case of truncating lower object to zero size,
|
|
|
|
* by creating a zero length upper object. This is to
|
|
|
|
* handle the case of open with O_TRUNC and O_CREAT.
|
|
|
|
*/
|
1994-12-30 01:42:10 +03:00
|
|
|
if ((un->un_uppervp == NULLVP) &&
|
1994-06-08 15:33:09 +04:00
|
|
|
/* assert(un->un_lowervp != NULLVP) */
|
1994-12-30 01:42:10 +03:00
|
|
|
(un->un_lowervp->v_type == VREG)) {
|
1999-08-02 03:16:34 +04:00
|
|
|
error = union_copyup(un, (vap->va_size != 0),
|
2007-11-26 22:01:26 +03:00
|
|
|
ap->a_cred, curlwp);
|
1994-12-15 22:15:06 +03:00
|
|
|
if (error)
|
|
|
|
return (error);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-08-10 10:27:02 +04:00
|
|
|
* Try to set attributes in upper layer, ignore size change to zero
|
|
|
|
* for devices to handle O_TRUNC and return read-only filesystem error
|
|
|
|
* otherwise.
|
1994-06-08 15:33:09 +04:00
|
|
|
*/
|
1994-12-30 01:42:10 +03:00
|
|
|
if (un->un_uppervp != NULLVP) {
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_SETATTR(un->un_uppervp, vap, ap->a_cred);
|
2011-11-21 22:29:22 +04:00
|
|
|
if ((error == 0) && (vap->va_size != VNOVAL)) {
|
|
|
|
mutex_enter(&un->un_lock);
|
1999-08-02 03:16:34 +04:00
|
|
|
union_newsize(ap->a_vp, vap->va_size, VNOVAL);
|
2011-11-21 22:29:22 +04:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
} else {
|
2011-08-10 10:27:02 +04:00
|
|
|
KASSERT(un->un_lowervp != NULLVP);
|
2011-08-12 18:36:29 +04:00
|
|
|
if (NODE_IS_SPECIAL(un->un_lowervp)) {
|
2011-08-10 10:27:02 +04:00
|
|
|
if (size_only &&
|
|
|
|
(vap->va_size == 0 || vap->va_size == VNOVAL))
|
|
|
|
error = 0;
|
|
|
|
else
|
|
|
|
error = EROFS;
|
2011-08-12 18:36:29 +04:00
|
|
|
} else {
|
2011-08-10 10:27:02 +04:00
|
|
|
error = EROFS;
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_read(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_read_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
int a_ioflag;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
struct vnode *vp = OTHERVP(ap->a_vp);
|
|
|
|
int dolock = (vp == LOWERVP(ap->a_vp));
|
|
|
|
|
|
|
|
if (dolock)
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
1994-06-08 15:33:09 +04:00
|
|
|
error = VOP_READ(vp, ap->a_uio, ap->a_ioflag, ap->a_cred);
|
|
|
|
if (dolock)
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1994-06-16 03:07:54 +04:00
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* perhaps the size of the underlying object has changed under
|
|
|
|
* our feet. take advantage of the offset information present
|
|
|
|
* in the uio structure.
|
|
|
|
*/
|
|
|
|
if (error == 0) {
|
|
|
|
struct union_node *un = VTOUNION(ap->a_vp);
|
|
|
|
off_t cur = ap->a_uio->uio_offset;
|
2011-11-21 22:29:22 +04:00
|
|
|
off_t usz = VNOVAL, lsz = VNOVAL;
|
1994-06-16 03:07:54 +04:00
|
|
|
|
2011-11-21 22:29:22 +04:00
|
|
|
mutex_enter(&un->un_lock);
|
1994-06-16 03:07:54 +04:00
|
|
|
if (vp == un->un_uppervp) {
|
|
|
|
if (cur > un->un_uppersz)
|
2011-11-21 22:29:22 +04:00
|
|
|
usz = cur;
|
1994-06-16 03:07:54 +04:00
|
|
|
} else {
|
|
|
|
if (cur > un->un_lowersz)
|
2011-11-21 22:29:22 +04:00
|
|
|
lsz = cur;
|
1994-06-16 03:07:54 +04:00
|
|
|
}
|
2011-11-21 22:29:22 +04:00
|
|
|
|
|
|
|
if (usz != VNOVAL || lsz != VNOVAL)
|
|
|
|
union_newsize(ap->a_vp, usz, lsz);
|
|
|
|
else
|
|
|
|
mutex_exit(&un->un_lock);
|
1994-06-16 03:07:54 +04:00
|
|
|
}
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_write(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_read_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
int a_ioflag;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
1994-12-14 19:30:40 +03:00
|
|
|
struct vnode *vp;
|
|
|
|
struct union_node *un = VTOUNION(ap->a_vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1994-12-14 19:30:40 +03:00
|
|
|
vp = UPPERVP(ap->a_vp);
|
2011-08-10 10:27:02 +04:00
|
|
|
if (vp == NULLVP) {
|
|
|
|
vp = LOWERVP(ap->a_vp);
|
2011-08-12 18:36:29 +04:00
|
|
|
if (NODE_IS_SPECIAL(vp)) {
|
2011-08-10 10:27:02 +04:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
error = VOP_WRITE(vp, ap->a_uio, ap->a_ioflag,
|
|
|
|
ap->a_cred);
|
|
|
|
VOP_UNLOCK(vp);
|
|
|
|
return error;
|
|
|
|
}
|
2011-08-12 18:36:29 +04:00
|
|
|
panic("union: missing upper layer in write");
|
2011-08-10 10:27:02 +04:00
|
|
|
}
|
1994-12-14 19:30:40 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
error = VOP_WRITE(vp, ap->a_uio, ap->a_ioflag, ap->a_cred);
|
|
|
|
|
1994-06-16 03:07:54 +04:00
|
|
|
/*
|
|
|
|
* the size of the underlying object may be changed by the
|
|
|
|
* write.
|
|
|
|
*/
|
|
|
|
if (error == 0) {
|
|
|
|
off_t cur = ap->a_uio->uio_offset;
|
|
|
|
|
2011-11-21 22:29:22 +04:00
|
|
|
mutex_enter(&un->un_lock);
|
1994-12-14 19:30:40 +03:00
|
|
|
if (cur > un->un_uppersz)
|
|
|
|
union_newsize(ap->a_vp, cur, VNOVAL);
|
2011-11-21 22:29:22 +04:00
|
|
|
else
|
|
|
|
mutex_exit(&un->un_lock);
|
1994-06-16 03:07:54 +04:00
|
|
|
}
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_ioctl(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_ioctl_args /* {
|
|
|
|
struct vnode *a_vp;
|
1998-03-01 05:20:01 +03:00
|
|
|
int a_command;
|
2004-04-27 21:37:30 +04:00
|
|
|
void *a_data;
|
1994-06-08 15:33:09 +04:00
|
|
|
int a_fflag;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
2000-03-30 16:22:12 +04:00
|
|
|
struct vnode *ovp = OTHERVP(ap->a_vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
ap->a_vp = ovp;
|
|
|
|
return (VCALL(ovp, VOFFSET(vop_ioctl), ap));
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_poll(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1996-09-07 16:40:22 +04:00
|
|
|
struct vop_poll_args /* {
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnode *a_vp;
|
1996-09-07 16:40:22 +04:00
|
|
|
int a_events;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
2000-03-30 16:22:12 +04:00
|
|
|
struct vnode *ovp = OTHERVP(ap->a_vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
ap->a_vp = ovp;
|
|
|
|
return (VCALL(ovp, VOFFSET(vop_poll), ap));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_revoke(void *v)
|
1998-03-01 05:20:01 +03:00
|
|
|
{
|
|
|
|
struct vop_revoke_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_flags;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *a_p;
|
1998-03-01 05:20:01 +03:00
|
|
|
} */ *ap = v;
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
|
|
|
|
if (UPPERVP(vp))
|
|
|
|
VOP_REVOKE(UPPERVP(vp), ap->a_flags);
|
|
|
|
if (LOWERVP(vp))
|
|
|
|
VOP_REVOKE(LOWERVP(vp), ap->a_flags);
|
2008-01-02 14:48:20 +03:00
|
|
|
vgone(vp); /* XXXAD?? */
|
1998-03-01 05:20:01 +03:00
|
|
|
return (0);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_mmap(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_mmap_args /* {
|
|
|
|
struct vnode *a_vp;
|
2007-07-29 17:12:42 +04:00
|
|
|
vm_prot_t a_prot;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
2000-03-30 16:22:12 +04:00
|
|
|
struct vnode *ovp = OTHERVP(ap->a_vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
ap->a_vp = ovp;
|
|
|
|
return (VCALL(ovp, VOFFSET(vop_mmap), ap));
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_fsync(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_fsync_args /* {
|
|
|
|
struct vnode *a_vp;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
1999-03-22 20:24:19 +03:00
|
|
|
int a_flags;
|
2000-09-20 02:01:59 +04:00
|
|
|
off_t offhi;
|
|
|
|
off_t offlo;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error = 0;
|
1999-03-22 20:24:19 +03:00
|
|
|
struct vnode *targetvp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1999-03-22 20:24:19 +03:00
|
|
|
/*
|
|
|
|
* If vinvalbuf is calling us, it's a "shallow fsync" -- don't
|
|
|
|
* bother syncing the underlying vnodes, since (a) they'll be
|
|
|
|
* fsync'ed when reclaimed and (b) we could deadlock if
|
|
|
|
* they're locked; otherwise, pass it through to the
|
|
|
|
* underlying layer.
|
|
|
|
*/
|
2011-08-12 18:36:29 +04:00
|
|
|
if (ap->a_vp->v_type == VBLK || ap->a_vp->v_type == VCHR) {
|
|
|
|
error = spec_fsync(v);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1999-03-22 20:24:19 +03:00
|
|
|
if (ap->a_flags & FSYNC_RECLAIM)
|
|
|
|
return 0;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1999-03-22 20:24:19 +03:00
|
|
|
targetvp = OTHERVP(ap->a_vp);
|
1994-06-16 03:07:54 +04:00
|
|
|
if (targetvp != NULLVP) {
|
1994-06-08 15:33:09 +04:00
|
|
|
int dolock = (targetvp == LOWERVP(ap->a_vp));
|
|
|
|
|
|
|
|
if (dolock)
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(targetvp, LK_EXCLUSIVE | LK_RETRY);
|
2000-09-20 02:01:59 +04:00
|
|
|
error = VOP_FSYNC(targetvp, ap->a_cred, ap->a_flags,
|
2007-11-26 22:01:26 +03:00
|
|
|
ap->a_offlo, ap->a_offhi);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (dolock)
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(targetvp);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_seek(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_seek_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
off_t a_oldoff;
|
|
|
|
off_t a_newoff;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
2000-03-30 16:22:12 +04:00
|
|
|
struct vnode *ovp = OTHERVP(ap->a_vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
ap->a_vp = ovp;
|
|
|
|
return (VCALL(ovp, VOFFSET(vop_seek), ap));
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_remove(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_remove_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct componentname *a_cnp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
struct union_node *dun = VTOUNION(ap->a_dvp);
|
|
|
|
struct union_node *un = VTOUNION(ap->a_vp);
|
1998-03-01 05:20:01 +03:00
|
|
|
struct componentname *cnp = ap->a_cnp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1994-12-14 19:30:40 +03:00
|
|
|
if (dun->un_uppervp == NULLVP)
|
|
|
|
panic("union remove: null upper vnode");
|
|
|
|
|
|
|
|
if (un->un_uppervp != NULLVP) {
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnode *dvp = dun->un_uppervp;
|
|
|
|
struct vnode *vp = un->un_uppervp;
|
|
|
|
|
2014-02-13 13:55:04 +04:00
|
|
|
/*
|
|
|
|
* Account for VOP_REMOVE to vrele dvp and vp.
|
|
|
|
* Note: VOP_REMOVE will unlock dvp and vp.
|
|
|
|
*/
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(dvp);
|
|
|
|
vref(vp);
|
2007-12-08 22:29:36 +03:00
|
|
|
if (union_dowhiteout(un, cnp->cn_cred))
|
1994-12-14 19:30:40 +03:00
|
|
|
cnp->cn_flags |= DOWHITEOUT;
|
|
|
|
error = VOP_REMOVE(dvp, vp, cnp);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (!error)
|
|
|
|
union_removed_upper(un);
|
2014-02-13 13:55:04 +04:00
|
|
|
vrele(ap->a_dvp);
|
|
|
|
vrele(ap->a_vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
} else {
|
1994-12-14 19:30:40 +03:00
|
|
|
error = union_mkwhiteout(
|
|
|
|
MOUNTTOUNIONMOUNT(UNIONTOV(dun)->v_mount),
|
2011-08-23 11:39:37 +04:00
|
|
|
dun->un_uppervp, ap->a_cnp, un);
|
1994-06-08 15:33:09 +04:00
|
|
|
vput(ap->a_dvp);
|
|
|
|
vput(ap->a_vp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_link(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
2015-04-21 01:59:19 +03:00
|
|
|
struct vop_link_v2_args /* {
|
1996-02-09 17:45:36 +03:00
|
|
|
struct vnode *a_dvp;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnode *a_vp;
|
|
|
|
struct componentname *a_cnp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-16 03:07:54 +04:00
|
|
|
int error = 0;
|
1998-03-01 05:20:01 +03:00
|
|
|
struct componentname *cnp = ap->a_cnp;
|
1996-02-09 17:45:36 +03:00
|
|
|
struct union_node *dun;
|
1994-06-16 03:07:54 +04:00
|
|
|
struct vnode *vp;
|
1998-03-01 05:20:01 +03:00
|
|
|
struct vnode *dvp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1996-02-09 17:45:36 +03:00
|
|
|
dun = VTOUNION(ap->a_dvp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2011-08-12 21:41:17 +04:00
|
|
|
KASSERT((ap->a_cnp->cn_flags & LOCKPARENT) != 0);
|
1998-03-01 05:20:01 +03:00
|
|
|
|
1996-02-09 17:45:36 +03:00
|
|
|
if (ap->a_dvp->v_op != ap->a_vp->v_op) {
|
|
|
|
vp = ap->a_vp;
|
1994-06-08 15:33:09 +04:00
|
|
|
} else {
|
1996-02-09 17:45:36 +03:00
|
|
|
struct union_node *un = VTOUNION(ap->a_vp);
|
|
|
|
if (un->un_uppervp == NULLVP) {
|
2011-11-21 22:29:22 +04:00
|
|
|
const bool droplock = (dun->un_uppervp == un->un_dirvp);
|
|
|
|
|
1996-05-11 02:57:49 +04:00
|
|
|
/*
|
1998-03-01 05:20:01 +03:00
|
|
|
* Needs to be copied before we can link it.
|
1996-05-11 02:57:49 +04:00
|
|
|
*/
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
|
2011-11-21 22:29:22 +04:00
|
|
|
if (droplock)
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(dun->un_uppervp);
|
2007-12-08 22:29:36 +03:00
|
|
|
error = union_copyup(un, 1, cnp->cn_cred, curlwp);
|
2011-11-21 22:29:22 +04:00
|
|
|
if (droplock) {
|
2011-11-14 22:42:57 +04:00
|
|
|
vn_lock(dun->un_uppervp,
|
|
|
|
LK_EXCLUSIVE | LK_RETRY);
|
1998-03-01 05:20:01 +03:00
|
|
|
/*
|
|
|
|
* During copyup, we dropped the lock on the
|
1996-05-11 02:57:49 +04:00
|
|
|
* dir and invalidated any saved namei lookup
|
|
|
|
* state for the directory we'll be entering
|
|
|
|
* the link in. We need to re-run the lookup
|
|
|
|
* in that directory to reset any state needed
|
|
|
|
* for VOP_LINK.
|
1998-03-01 05:20:01 +03:00
|
|
|
* Call relookup on the union-layer to reset
|
|
|
|
* the state.
|
1996-05-11 02:57:49 +04:00
|
|
|
*/
|
|
|
|
vp = NULLVP;
|
|
|
|
if (dun->un_uppervp == NULLVP)
|
1998-03-01 05:20:01 +03:00
|
|
|
panic("union: null upperdvp?");
|
2011-01-02 08:09:30 +03:00
|
|
|
error = relookup(ap->a_dvp, &vp, ap->a_cnp, 0);
|
1998-03-01 05:20:01 +03:00
|
|
|
if (error) {
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(ap->a_vp);
|
1998-03-01 05:20:01 +03:00
|
|
|
return EROFS; /* ? */
|
1996-05-11 02:57:49 +04:00
|
|
|
}
|
|
|
|
if (vp != NULLVP) {
|
1998-03-01 05:20:01 +03:00
|
|
|
/*
|
|
|
|
* The name we want to create has
|
|
|
|
* mysteriously appeared (a race?)
|
|
|
|
*/
|
1996-05-11 02:57:49 +04:00
|
|
|
error = EEXIST;
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(ap->a_vp);
|
2006-12-09 19:11:50 +03:00
|
|
|
vput(vp);
|
|
|
|
return (error);
|
1996-05-11 02:57:49 +04:00
|
|
|
}
|
1994-06-16 03:07:54 +04:00
|
|
|
}
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(ap->a_vp);
|
1994-06-16 03:07:54 +04:00
|
|
|
}
|
1996-02-09 17:45:36 +03:00
|
|
|
vp = un->un_uppervp;
|
1994-06-16 03:07:54 +04:00
|
|
|
}
|
|
|
|
|
1996-02-09 17:45:36 +03:00
|
|
|
dvp = dun->un_uppervp;
|
|
|
|
if (dvp == NULLVP)
|
1994-06-08 15:33:09 +04:00
|
|
|
error = EROFS;
|
1994-06-16 03:07:54 +04:00
|
|
|
|
2015-04-21 01:59:19 +03:00
|
|
|
if (error)
|
1994-06-16 03:07:54 +04:00
|
|
|
return (error);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2015-04-21 01:59:19 +03:00
|
|
|
return VOP_LINK(dvp, vp, cnp);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_rename(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_rename_args /* {
|
|
|
|
struct vnode *a_fdvp;
|
|
|
|
struct vnode *a_fvp;
|
|
|
|
struct componentname *a_fcnp;
|
|
|
|
struct vnode *a_tdvp;
|
|
|
|
struct vnode *a_tvp;
|
|
|
|
struct componentname *a_tcnp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
struct vnode *fdvp = ap->a_fdvp;
|
|
|
|
struct vnode *fvp = ap->a_fvp;
|
|
|
|
struct vnode *tdvp = ap->a_tdvp;
|
|
|
|
struct vnode *tvp = ap->a_tvp;
|
|
|
|
|
2014-02-13 13:55:04 +04:00
|
|
|
/*
|
|
|
|
* Account for VOP_RENAME to vrele all nodes.
|
|
|
|
* Note: VOP_RENAME will unlock tdvp.
|
|
|
|
*/
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
if (fdvp->v_op == union_vnodeop_p) { /* always true */
|
|
|
|
struct union_node *un = VTOUNION(fdvp);
|
|
|
|
if (un->un_uppervp == NULLVP) {
|
1994-12-14 19:30:40 +03:00
|
|
|
/*
|
|
|
|
* this should never happen in normal
|
|
|
|
* operation but might if there was
|
|
|
|
* a problem creating the top-level shadow
|
|
|
|
* directory.
|
|
|
|
*/
|
|
|
|
error = EXDEV;
|
1994-06-08 15:33:09 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
fdvp = un->un_uppervp;
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(fdvp);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fvp->v_op == union_vnodeop_p) { /* always true */
|
|
|
|
struct union_node *un = VTOUNION(fvp);
|
|
|
|
if (un->un_uppervp == NULLVP) {
|
1994-12-14 19:30:40 +03:00
|
|
|
/* XXX: should do a copyup */
|
|
|
|
error = EXDEV;
|
1994-06-08 15:33:09 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1994-12-14 19:30:40 +03:00
|
|
|
if (un->un_lowervp != NULLVP)
|
|
|
|
ap->a_fcnp->cn_flags |= DOWHITEOUT;
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
fvp = un->un_uppervp;
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(fvp);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tdvp->v_op == union_vnodeop_p) {
|
|
|
|
struct union_node *un = VTOUNION(tdvp);
|
|
|
|
if (un->un_uppervp == NULLVP) {
|
1994-06-16 03:07:54 +04:00
|
|
|
/*
|
|
|
|
* this should never happen in normal
|
|
|
|
* operation but might if there was
|
|
|
|
* a problem creating the top-level shadow
|
|
|
|
* directory.
|
|
|
|
*/
|
1994-12-14 19:30:40 +03:00
|
|
|
error = EXDEV;
|
1994-06-08 15:33:09 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
tdvp = un->un_uppervp;
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(tdvp);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
1994-06-16 03:07:54 +04:00
|
|
|
if (tvp != NULLVP && tvp->v_op == union_vnodeop_p) {
|
1994-06-08 15:33:09 +04:00
|
|
|
struct union_node *un = VTOUNION(tvp);
|
|
|
|
|
|
|
|
tvp = un->un_uppervp;
|
1994-06-16 03:07:54 +04:00
|
|
|
if (tvp != NULLVP) {
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(tvp);
|
1994-06-16 03:07:54 +04:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
2006-12-09 19:11:50 +03:00
|
|
|
error = VOP_RENAME(fdvp, fvp, ap->a_fcnp, tdvp, tvp, ap->a_tcnp);
|
|
|
|
goto out;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
bad:
|
|
|
|
vput(tdvp);
|
1994-06-16 03:07:54 +04:00
|
|
|
if (tvp != NULLVP)
|
1994-06-08 15:33:09 +04:00
|
|
|
vput(tvp);
|
2006-12-09 19:11:50 +03:00
|
|
|
vrele(fdvp);
|
|
|
|
vrele(fvp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2006-12-09 19:11:50 +03:00
|
|
|
out:
|
|
|
|
if (fdvp != ap->a_fdvp) {
|
|
|
|
vrele(ap->a_fdvp);
|
|
|
|
}
|
|
|
|
if (fvp != ap->a_fvp) {
|
|
|
|
vrele(ap->a_fvp);
|
|
|
|
}
|
2014-02-13 13:55:04 +04:00
|
|
|
if (tdvp != ap->a_tdvp) {
|
|
|
|
vrele(ap->a_tdvp);
|
|
|
|
}
|
|
|
|
if (tvp != ap->a_tvp) {
|
|
|
|
vrele(ap->a_tvp);
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_mkdir(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
2014-01-23 14:13:55 +04:00
|
|
|
struct vop_mkdir_v3_args /* {
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct union_node *un = VTOUNION(ap->a_dvp);
|
|
|
|
struct vnode *dvp = un->un_uppervp;
|
1998-03-01 05:20:01 +03:00
|
|
|
struct componentname *cnp = ap->a_cnp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1994-06-16 03:07:54 +04:00
|
|
|
if (dvp != NULLVP) {
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
struct vnode *vp;
|
|
|
|
|
2014-05-17 08:07:15 +04:00
|
|
|
vp = NULL;
|
1998-03-01 05:20:01 +03:00
|
|
|
error = VOP_MKDIR(dvp, &vp, cnp, ap->a_vap);
|
1994-12-14 19:30:40 +03:00
|
|
|
if (error) {
|
|
|
|
vrele(ap->a_dvp);
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
1994-12-14 19:30:40 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
error = union_allocvp(ap->a_vpp, ap->a_dvp->v_mount, ap->a_dvp,
|
2003-06-29 22:43:21 +04:00
|
|
|
NULLVP, cnp, vp, NULLVP, 1);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error)
|
2014-01-23 14:13:55 +04:00
|
|
|
vrele(vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (EROFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_rmdir(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_rmdir_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct componentname *a_cnp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
struct union_node *dun = VTOUNION(ap->a_dvp);
|
|
|
|
struct union_node *un = VTOUNION(ap->a_vp);
|
1998-03-01 05:20:01 +03:00
|
|
|
struct componentname *cnp = ap->a_cnp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1994-12-14 19:30:40 +03:00
|
|
|
if (dun->un_uppervp == NULLVP)
|
|
|
|
panic("union rmdir: null upper vnode");
|
|
|
|
|
2011-08-07 10:01:51 +04:00
|
|
|
error = union_check_rmdir(un, cnp->cn_cred);
|
|
|
|
if (error) {
|
|
|
|
vput(ap->a_dvp);
|
|
|
|
vput(ap->a_vp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1994-12-14 19:30:40 +03:00
|
|
|
if (un->un_uppervp != NULLVP) {
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnode *dvp = dun->un_uppervp;
|
|
|
|
struct vnode *vp = un->un_uppervp;
|
|
|
|
|
2014-02-13 13:55:04 +04:00
|
|
|
/*
|
|
|
|
* Account for VOP_RMDIR to vrele dvp and vp.
|
|
|
|
* Note: VOP_RMDIR will unlock dvp and vp.
|
|
|
|
*/
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(dvp);
|
|
|
|
vref(vp);
|
2007-12-08 22:29:36 +03:00
|
|
|
if (union_dowhiteout(un, cnp->cn_cred))
|
1994-12-14 19:30:40 +03:00
|
|
|
cnp->cn_flags |= DOWHITEOUT;
|
1998-03-01 05:20:01 +03:00
|
|
|
error = VOP_RMDIR(dvp, vp, ap->a_cnp);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (!error)
|
|
|
|
union_removed_upper(un);
|
2014-02-13 13:55:04 +04:00
|
|
|
vrele(ap->a_dvp);
|
|
|
|
vrele(ap->a_vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
} else {
|
1994-12-14 19:30:40 +03:00
|
|
|
error = union_mkwhiteout(
|
|
|
|
MOUNTTOUNIONMOUNT(UNIONTOV(dun)->v_mount),
|
2011-08-23 11:39:37 +04:00
|
|
|
dun->un_uppervp, ap->a_cnp, un);
|
1994-06-08 15:33:09 +04:00
|
|
|
vput(ap->a_dvp);
|
|
|
|
vput(ap->a_vp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_symlink(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
2014-01-23 14:13:55 +04:00
|
|
|
struct vop_symlink_v3_args /* {
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
char *a_target;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct union_node *un = VTOUNION(ap->a_dvp);
|
|
|
|
struct vnode *dvp = un->un_uppervp;
|
1998-03-01 05:20:01 +03:00
|
|
|
struct componentname *cnp = ap->a_cnp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1994-06-16 03:07:54 +04:00
|
|
|
if (dvp != NULLVP) {
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
|
2001-07-24 19:39:30 +04:00
|
|
|
error = VOP_SYMLINK(dvp, ap->a_vpp, cnp, ap->a_vap,
|
|
|
|
ap->a_target);
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (EROFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* union_readdir works in concert with getdirentries and
|
|
|
|
* readdir(3) to provide a list of entries in the unioned
|
|
|
|
* directories. getdirentries is responsible for walking
|
|
|
|
* down the union stack. readdir(3) is responsible for
|
|
|
|
* eliminating duplicate names from the returned data stream.
|
|
|
|
*/
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_readdir(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_readdir_args /* {
|
|
|
|
struct vnodeop_desc *a_desc;
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
1994-06-08 15:33:09 +04:00
|
|
|
int *a_eofflag;
|
1998-03-01 05:20:01 +03:00
|
|
|
u_long *a_cookies;
|
1994-06-08 15:33:09 +04:00
|
|
|
int a_ncookies;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1998-03-01 05:20:01 +03:00
|
|
|
struct union_node *un = VTOUNION(ap->a_vp);
|
|
|
|
struct vnode *uvp = un->un_uppervp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
if (uvp == NULLVP)
|
1994-06-08 15:33:09 +04:00
|
|
|
return (0);
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
ap->a_vp = uvp;
|
|
|
|
return (VCALL(uvp, VOFFSET(vop_readdir), ap));
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_readlink(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_readlink_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
struct vnode *vp = OTHERVP(ap->a_vp);
|
|
|
|
int dolock = (vp == LOWERVP(ap->a_vp));
|
|
|
|
|
|
|
|
if (dolock)
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
1994-12-13 19:59:50 +03:00
|
|
|
ap->a_vp = vp;
|
|
|
|
error = VCALL(vp, VOFFSET(vop_readlink), ap);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (dolock)
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_abortop(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_abortop_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct componentname *a_cnp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2011-11-14 22:42:57 +04:00
|
|
|
KASSERT(UPPERVP(ap->a_dvp) != NULL);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2011-11-14 22:42:57 +04:00
|
|
|
ap->a_dvp = UPPERVP(ap->a_dvp);
|
|
|
|
return VCALL(ap->a_dvp, VOFFSET(vop_abortop), ap);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_inactive(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_inactive_args /* {
|
2005-12-11 15:16:03 +03:00
|
|
|
const struct vnodeop_desc *a_desc;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnode *a_vp;
|
2008-01-02 14:48:20 +03:00
|
|
|
bool *a_recycle;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1998-03-01 05:20:01 +03:00
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct union_node *un = VTOUNION(vp);
|
|
|
|
struct vnode **vpp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do nothing (and _don't_ bypass).
|
|
|
|
* Wait to vrele lowervp until reclaim,
|
|
|
|
* so that until then our union_node is in the
|
|
|
|
* cache and reusable.
|
|
|
|
*
|
|
|
|
* NEEDSWORK: Someday, consider inactive'ing
|
|
|
|
* the lowervp and then trying to reactivate it
|
|
|
|
* with capabilities (v_id)
|
|
|
|
* like they do in the name lookup cache code.
|
|
|
|
* That's too much work for now.
|
|
|
|
*/
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
if (un->un_dircache != 0) {
|
|
|
|
for (vpp = un->un_dircache; *vpp != NULLVP; vpp++)
|
|
|
|
vrele(*vpp);
|
|
|
|
free(un->un_dircache, M_TEMP);
|
|
|
|
un->un_dircache = 0;
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2011-11-21 22:29:22 +04:00
|
|
|
*ap->a_recycle = ((un->un_cflags & UN_CACHED) == 0);
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(vp);
|
1994-12-14 19:30:40 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_reclaim(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_reclaim_args /* {
|
|
|
|
struct vnode *a_vp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
union_freevp(ap->a_vp);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-03-12 13:40:05 +04:00
|
|
|
static int
|
|
|
|
union_lock1(struct vnode *vp, struct vnode *lockvp, int flags)
|
|
|
|
{
|
|
|
|
struct vop_lock_args ap;
|
|
|
|
|
|
|
|
if (lockvp == vp) {
|
|
|
|
ap.a_vp = vp;
|
|
|
|
ap.a_flags = flags;
|
|
|
|
return genfs_lock(&ap);
|
|
|
|
} else
|
|
|
|
return VOP_LOCK(lockvp, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
union_unlock1(struct vnode *vp, struct vnode *lockvp)
|
|
|
|
{
|
|
|
|
struct vop_unlock_args ap;
|
|
|
|
|
|
|
|
if (lockvp == vp) {
|
|
|
|
ap.a_vp = vp;
|
|
|
|
return genfs_unlock(&ap);
|
|
|
|
} else
|
|
|
|
return VOP_UNLOCK(lockvp);
|
|
|
|
}
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_lock(void *v)
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
1998-03-01 05:20:01 +03:00
|
|
|
struct vop_lock_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_flags;
|
|
|
|
} */ *ap = v;
|
2014-03-12 13:40:05 +04:00
|
|
|
struct vnode *vp = ap->a_vp, *lockvp;
|
|
|
|
struct union_node *un = VTOUNION(vp);
|
2014-02-27 20:51:37 +04:00
|
|
|
int flags = ap->a_flags;
|
1998-03-01 05:20:01 +03:00
|
|
|
int error;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2014-02-27 20:51:37 +04:00
|
|
|
if ((flags & LK_NOWAIT) != 0) {
|
|
|
|
if (!mutex_tryenter(&un->un_lock))
|
|
|
|
return EBUSY;
|
2014-03-12 13:40:05 +04:00
|
|
|
lockvp = LOCKVP(vp);
|
|
|
|
error = union_lock1(vp, lockvp, flags);
|
2014-02-27 20:51:37 +04:00
|
|
|
mutex_exit(&un->un_lock);
|
2014-03-12 13:40:05 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
if (mutex_tryenter(vp->v_interlock)) {
|
2014-03-24 17:42:40 +04:00
|
|
|
error = vdead_check(vp, VDEAD_NOWAIT);
|
2014-03-12 13:40:05 +04:00
|
|
|
mutex_exit(vp->v_interlock);
|
|
|
|
} else
|
|
|
|
error = EBUSY;
|
|
|
|
if (error)
|
|
|
|
union_unlock1(vp, lockvp);
|
2014-02-27 20:51:37 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-11-21 22:29:22 +04:00
|
|
|
mutex_enter(&un->un_lock);
|
|
|
|
for (;;) {
|
2014-03-12 13:40:05 +04:00
|
|
|
lockvp = LOCKVP(vp);
|
2011-11-21 22:29:22 +04:00
|
|
|
mutex_exit(&un->un_lock);
|
2014-03-12 13:40:05 +04:00
|
|
|
error = union_lock1(vp, lockvp, flags);
|
2011-11-21 22:29:22 +04:00
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
mutex_enter(&un->un_lock);
|
2014-03-12 13:40:05 +04:00
|
|
|
if (lockvp == LOCKVP(vp))
|
2011-11-21 22:29:22 +04:00
|
|
|
break;
|
2014-03-12 13:40:05 +04:00
|
|
|
union_unlock1(vp, lockvp);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
2014-03-12 13:40:05 +04:00
|
|
|
mutex_exit(&un->un_lock);
|
|
|
|
|
2014-02-27 20:51:37 +04:00
|
|
|
mutex_enter(vp->v_interlock);
|
2014-03-24 17:42:40 +04:00
|
|
|
error = vdead_check(vp, VDEAD_NOWAIT);
|
|
|
|
if (error) {
|
2014-03-12 13:40:05 +04:00
|
|
|
union_unlock1(vp, lockvp);
|
2014-03-24 17:42:40 +04:00
|
|
|
error = vdead_check(vp, 0);
|
|
|
|
KASSERT(error == ENOENT);
|
2014-02-27 20:51:37 +04:00
|
|
|
}
|
|
|
|
mutex_exit(vp->v_interlock);
|
2014-03-24 17:42:40 +04:00
|
|
|
return error;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_unlock(void *v)
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
1998-03-01 05:20:01 +03:00
|
|
|
struct vop_unlock_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_flags;
|
|
|
|
} */ *ap = v;
|
2014-03-12 13:40:05 +04:00
|
|
|
struct vnode *vp = ap->a_vp, *lockvp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2014-03-12 13:40:05 +04:00
|
|
|
lockvp = LOCKVP(vp);
|
|
|
|
union_unlock1(vp, lockvp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2011-11-21 22:29:22 +04:00
|
|
|
return 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_bmap(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_bmap_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
daddr_t a_bn;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
daddr_t *a_bnp;
|
|
|
|
int *a_runp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
struct vnode *vp = OTHERVP(ap->a_vp);
|
|
|
|
int dolock = (vp == LOWERVP(ap->a_vp));
|
|
|
|
|
|
|
|
if (dolock)
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
1994-12-13 19:59:50 +03:00
|
|
|
ap->a_vp = vp;
|
|
|
|
error = VCALL(vp, VOFFSET(vop_bmap), ap);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (dolock)
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_print(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_print_args /* {
|
|
|
|
struct vnode *a_vp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
|
1996-10-13 06:21:25 +04:00
|
|
|
printf("\ttag VT_UNION, vp=%p, uppervp=%p, lowervp=%p\n",
|
1998-03-01 05:20:01 +03:00
|
|
|
vp, UPPERVP(vp), LOWERVP(vp));
|
|
|
|
if (UPPERVP(vp) != NULLVP)
|
|
|
|
vprint("union: upper", UPPERVP(vp));
|
|
|
|
if (LOWERVP(vp) != NULLVP)
|
|
|
|
vprint("union: lower", LOWERVP(vp));
|
1996-05-11 02:57:49 +04:00
|
|
|
if (VTOUNION(vp)->un_dircache) {
|
|
|
|
struct vnode **vpp;
|
|
|
|
for (vpp = VTOUNION(vp)->un_dircache; *vpp != NULLVP; vpp++)
|
|
|
|
vprint("dircache:", *vpp);
|
|
|
|
}
|
1998-03-01 05:20:01 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_islocked(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_islocked_args /* {
|
|
|
|
struct vnode *a_vp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
2011-11-21 22:29:22 +04:00
|
|
|
struct vnode *vp;
|
|
|
|
struct union_node *un;
|
|
|
|
|
|
|
|
un = VTOUNION(ap->a_vp);
|
|
|
|
mutex_enter(&un->un_lock);
|
|
|
|
vp = LOCKVP(ap->a_vp);
|
|
|
|
mutex_exit(&un->un_lock);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2011-11-21 22:29:22 +04:00
|
|
|
if (vp == ap->a_vp)
|
|
|
|
return genfs_islocked(ap);
|
|
|
|
else
|
|
|
|
return VOP_ISLOCKED(vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_pathconf(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_pathconf_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_name;
|
1998-03-01 05:20:01 +03:00
|
|
|
int *a_retval;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
|
|
|
struct vnode *vp = OTHERVP(ap->a_vp);
|
|
|
|
int dolock = (vp == LOWERVP(ap->a_vp));
|
|
|
|
|
|
|
|
if (dolock)
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
1994-12-13 19:59:50 +03:00
|
|
|
ap->a_vp = vp;
|
|
|
|
error = VCALL(vp, VOFFSET(vop_pathconf), ap);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (dolock)
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_advlock(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_advlock_args /* {
|
|
|
|
struct vnode *a_vp;
|
2004-04-27 21:37:30 +04:00
|
|
|
void *a_id;
|
1994-06-08 15:33:09 +04:00
|
|
|
int a_op;
|
|
|
|
struct flock *a_fl;
|
|
|
|
int a_flags;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
2000-03-30 16:22:12 +04:00
|
|
|
struct vnode *ovp = OTHERVP(ap->a_vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
ap->a_vp = ovp;
|
|
|
|
return (VCALL(ovp, VOFFSET(vop_advlock), ap));
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_strategy(void *v)
|
1996-02-10 01:39:56 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vop_strategy_args /* {
|
2004-01-25 21:06:48 +03:00
|
|
|
struct vnode *a_vp;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct buf *a_bp;
|
1996-02-10 01:39:56 +03:00
|
|
|
} */ *ap = v;
|
2004-01-25 21:06:48 +03:00
|
|
|
struct vnode *ovp = OTHERVP(ap->a_vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
struct buf *bp = ap->a_bp;
|
|
|
|
|
2011-08-12 21:41:17 +04:00
|
|
|
KASSERT(ovp != NULLVP);
|
|
|
|
if (!NODE_IS_SPECIAL(ovp))
|
|
|
|
KASSERT((bp->b_flags & B_READ) || ovp != LOWERVP(bp->b_vp));
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2004-01-25 21:06:48 +03:00
|
|
|
return (VOP_STRATEGY(ovp, bp));
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
2000-12-11 05:50:17 +03:00
|
|
|
|
2011-08-12 18:36:29 +04:00
|
|
|
int
|
|
|
|
union_bwrite(void *v)
|
|
|
|
{
|
|
|
|
struct vop_bwrite_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct buf *a_bp;
|
|
|
|
} */ *ap = v;
|
|
|
|
struct vnode *ovp = OTHERVP(ap->a_vp);
|
|
|
|
struct buf *bp = ap->a_bp;
|
|
|
|
|
2011-08-12 21:41:17 +04:00
|
|
|
KASSERT(ovp != NULLVP);
|
|
|
|
if (!NODE_IS_SPECIAL(ovp))
|
|
|
|
KASSERT((bp->b_flags & B_READ) || ovp != LOWERVP(bp->b_vp));
|
2011-08-12 18:36:29 +04:00
|
|
|
|
|
|
|
return (VOP_BWRITE(ovp, bp));
|
|
|
|
}
|
|
|
|
|
2000-12-11 05:50:17 +03:00
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_getpages(void *v)
|
2000-12-11 05:50:17 +03:00
|
|
|
{
|
|
|
|
struct vop_getpages_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
voff_t a_offset;
|
2001-05-27 01:27:10 +04:00
|
|
|
struct vm_page **a_m;
|
2000-12-11 05:50:17 +03:00
|
|
|
int *a_count;
|
|
|
|
int a_centeridx;
|
|
|
|
vm_prot_t a_access_type;
|
|
|
|
int a_advice;
|
|
|
|
int a_flags;
|
|
|
|
} */ *ap = v;
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
|
2011-06-12 07:35:36 +04:00
|
|
|
KASSERT(mutex_owned(vp->v_interlock));
|
2000-12-11 05:50:17 +03:00
|
|
|
|
2001-12-06 07:29:23 +03:00
|
|
|
if (ap->a_flags & PGO_LOCKED) {
|
|
|
|
return EBUSY;
|
|
|
|
}
|
2000-12-11 05:50:17 +03:00
|
|
|
ap->a_vp = OTHERVP(vp);
|
2011-06-12 07:35:36 +04:00
|
|
|
KASSERT(vp->v_interlock == ap->a_vp->v_interlock);
|
|
|
|
|
|
|
|
/* Just pass the request on to the underlying layer. */
|
|
|
|
return VCALL(ap->a_vp, VOFFSET(vop_getpages), ap);
|
2000-12-11 05:50:17 +03:00
|
|
|
}
|
2001-12-06 07:29:23 +03:00
|
|
|
|
|
|
|
int
|
2008-02-27 22:59:48 +03:00
|
|
|
union_putpages(void *v)
|
2001-12-06 07:29:23 +03:00
|
|
|
{
|
|
|
|
struct vop_putpages_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
voff_t a_offlo;
|
|
|
|
voff_t a_offhi;
|
|
|
|
int a_flags;
|
|
|
|
} */ *ap = v;
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
|
2011-06-12 07:35:36 +04:00
|
|
|
KASSERT(mutex_owned(vp->v_interlock));
|
2001-12-06 07:29:23 +03:00
|
|
|
|
|
|
|
ap->a_vp = OTHERVP(vp);
|
2011-06-12 07:35:36 +04:00
|
|
|
KASSERT(vp->v_interlock == ap->a_vp->v_interlock);
|
|
|
|
|
2007-04-16 09:14:54 +04:00
|
|
|
if (ap->a_flags & PGO_RECLAIM) {
|
2011-06-12 07:35:36 +04:00
|
|
|
mutex_exit(vp->v_interlock);
|
2007-04-16 09:14:54 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2011-06-12 07:35:36 +04:00
|
|
|
|
|
|
|
/* Just pass the request on to the underlying layer. */
|
|
|
|
return VCALL(ap->a_vp, VOFFSET(vop_putpages), ap);
|
2001-12-06 07:29:23 +03:00
|
|
|
}
|
2003-03-17 14:39:16 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
union_kqfilter(void *v)
|
|
|
|
{
|
|
|
|
struct vop_kqfilter_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct knote *a_kn;
|
|
|
|
} */ *ap = v;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We watch either the upper layer file (if it already exists),
|
|
|
|
* or the lower layer one. If there is lower layer file only
|
|
|
|
* at this moment, we will keep watching that lower layer file
|
|
|
|
* even if upper layer file would be created later on.
|
|
|
|
*/
|
|
|
|
if (UPPERVP(ap->a_vp))
|
|
|
|
error = VOP_KQFILTER(UPPERVP(ap->a_vp), ap->a_kn);
|
|
|
|
else if (LOWERVP(ap->a_vp))
|
|
|
|
error = VOP_KQFILTER(LOWERVP(ap->a_vp), ap->a_kn);
|
|
|
|
else {
|
|
|
|
/* panic? */
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|