summaryrefslogtreecommitdiffstats
path: root/sys/fs/nullfs/null_vfsops.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2012-09-09 19:20:23 +0000
committerkib <kib@FreeBSD.org>2012-09-09 19:20:23 +0000
commit3ed1c80d257237f50d1eb45a535cd5a9b2ce243e (patch)
tree0f1623ea0434b273e48d26ddda4c72d4d29053ef /sys/fs/nullfs/null_vfsops.c
parent5a86a6849adc026d814651fd6afc864b2377b9c8 (diff)
downloadFreeBSD-src-3ed1c80d257237f50d1eb45a535cd5a9b2ce243e.zip
FreeBSD-src-3ed1c80d257237f50d1eb45a535cd5a9b2ce243e.tar.gz
Allow shared lookups for nullfs mounts, if lower filesystem supports
it. There are two problems which shall be addressed for shared lookups use to have measurable effect on nullfs scalability: 1. When vfs_lookup() calls VOP_LOOKUP() for nullfs, which passes lookup operation to lower fs, resulting vnode is often only shared-locked. Then null_nodeget() cannot instantiate covering vnode for lower vnode, since insmntque1() and null_hashins() require exclusive lock on the lower. Change the assert that lower vnode is exclusively locked to only require any lock. If null hash failed to find pre-existing nullfs vnode for lower vnode and the vnode is shared-locked, the lower vnode lock is upgraded. 2. Nullfs reclaims its vnodes on deactivation. This is due to nullfs inability to detect reclamation of the lower vnode. Reclamation of a nullfs vnode at deactivation time prevents a reference to the lower vnode to become stale. Change nullfs VOP_INACTIVE to not reclaim the vnode, instead use the VFS_RECLAIM_LOWERVP to get notification and reclaim upper vnode together with the reclamation of the lower vnode. Note that nullfs reclamation procedure calls vput() on the lowervp vnode, temporary unlocking the vnode being reclaimed. This seems to be fine for MPSAFE filesystems, but not-MPSAFE code often put partially initialized vnode on some globally visible list, and later can decide that half-constructed vnode is not needed. If nullfs mount is created above such filesystem, then other threads might catch such not properly initialized vnode. Instead of trying to overcome this case, e.g. by recursing the lower vnode lock in null_reclaim_lowervp(), I decided to rely on nearby removal of the support for non-MPSAFE filesystems. In collaboration with: pho MFC after: 3 weeks
Diffstat (limited to 'sys/fs/nullfs/null_vfsops.c')
-rw-r--r--sys/fs/nullfs/null_vfsops.c60
1 files changed, 44 insertions, 16 deletions
diff --git a/sys/fs/nullfs/null_vfsops.c b/sys/fs/nullfs/null_vfsops.c
index 08f722a..9c2851b 100644
--- a/sys/fs/nullfs/null_vfsops.c
+++ b/sys/fs/nullfs/null_vfsops.c
@@ -65,6 +65,7 @@ static vfs_statfs_t nullfs_statfs;
static vfs_unmount_t nullfs_unmount;
static vfs_vget_t nullfs_vget;
static vfs_extattrctl_t nullfs_extattrctl;
+static vfs_reclaim_lowervp_t nullfs_reclaim_lowervp;
/*
* Mount null layer
@@ -121,8 +122,10 @@ nullfs_mount(struct mount *mp)
*/
NDINIT(ndp, LOOKUP, FOLLOW|LOCKLEAF, UIO_SYSSPACE, target, curthread);
error = namei(ndp);
+
/*
* Re-lock vnode.
+ * XXXKIB This is deadlock-prone as well.
*/
if (isvnunlocked)
vn_lock(mp->mnt_vnodecovered, LK_EXCLUSIVE | LK_RETRY);
@@ -146,7 +149,7 @@ nullfs_mount(struct mount *mp)
}
xmp = (struct null_mount *) malloc(sizeof(struct null_mount),
- M_NULLFSMNT, M_WAITOK); /* XXX */
+ M_NULLFSMNT, M_WAITOK);
/*
* Save reference to underlying FS
@@ -186,10 +189,15 @@ nullfs_mount(struct mount *mp)
}
MNT_ILOCK(mp);
mp->mnt_kern_flag |= lowerrootvp->v_mount->mnt_kern_flag &
- (MNTK_MPSAFE | MNTK_SHARED_WRITES);
+ (MNTK_MPSAFE | MNTK_SHARED_WRITES | MNTK_LOOKUP_SHARED |
+ MNTK_EXTENDED_SHARED);
+ mp->mnt_kern_flag |= MNTK_LOOKUP_EXCL_DOTDOT;
MNT_IUNLOCK(mp);
mp->mnt_data = xmp;
vfs_getnewfsid(mp);
+ MNT_ILOCK(xmp->nullm_vfs);
+ TAILQ_INSERT_TAIL(&xmp->nullm_vfs->mnt_uppers, mp, mnt_upper_link);
+ MNT_IUNLOCK(xmp->nullm_vfs);
vfs_mountedfrom(mp, target);
@@ -206,14 +214,16 @@ nullfs_unmount(mp, mntflags)
struct mount *mp;
int mntflags;
{
- void *mntdata;
- int error;
- int flags = 0;
+ struct null_mount *mntdata;
+ struct mount *ump;
+ int error, flags;
NULLFSDEBUG("nullfs_unmount: mp = %p\n", (void *)mp);
if (mntflags & MNT_FORCE)
- flags |= FORCECLOSE;
+ flags = FORCECLOSE;
+ else
+ flags = 0;
/* There is 1 extra root vnode reference (nullm_rootvp). */
error = vflush(mp, 1, flags, curthread);
@@ -224,9 +234,17 @@ nullfs_unmount(mp, mntflags)
* Finally, throw away the null_mount structure
*/
mntdata = mp->mnt_data;
+ ump = mntdata->nullm_vfs;
+ MNT_ILOCK(ump);
+ while ((ump->mnt_kern_flag & MNTK_VGONE_UPPER) != 0) {
+ ump->mnt_kern_flag |= MNTK_VGONE_WAITER;
+ msleep(&ump->mnt_uppers, &ump->mnt_mtx, 0, "vgnupw", 0);
+ }
+ TAILQ_REMOVE(&ump->mnt_uppers, mp, mnt_upper_link);
+ MNT_IUNLOCK(ump);
mp->mnt_data = NULL;
free(mntdata, M_NULLFSMNT);
- return 0;
+ return (0);
}
static int
@@ -316,13 +334,10 @@ nullfs_vget(mp, ino, flags, vpp)
KASSERT((flags & LK_TYPE_MASK) != 0,
("nullfs_vget: no lock requested"));
- flags &= ~LK_TYPE_MASK;
- flags |= LK_EXCLUSIVE;
error = VFS_VGET(MOUNTTONULLMOUNT(mp)->nullm_vfs, ino, flags, vpp);
- if (error)
+ if (error != 0)
return (error);
-
return (null_nodeget(mp, *vpp, vpp));
}
@@ -334,11 +349,11 @@ nullfs_fhtovp(mp, fidp, flags, vpp)
struct vnode **vpp;
{
int error;
- error = VFS_FHTOVP(MOUNTTONULLMOUNT(mp)->nullm_vfs, fidp, LK_EXCLUSIVE,
+
+ error = VFS_FHTOVP(MOUNTTONULLMOUNT(mp)->nullm_vfs, fidp, flags,
vpp);
- if (error)
+ if (error != 0)
return (error);
-
return (null_nodeget(mp, *vpp, vpp));
}
@@ -350,10 +365,22 @@ nullfs_extattrctl(mp, cmd, filename_vp, namespace, attrname)
int namespace;
const char *attrname;
{
- return VFS_EXTATTRCTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd, filename_vp,
- namespace, attrname);
+
+ return (VFS_EXTATTRCTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd,
+ filename_vp, namespace, attrname));
}
+static void
+nullfs_reclaim_lowervp(struct mount *mp, struct vnode *lowervp)
+{
+ struct vnode *vp;
+
+ vp = null_hashget(mp, lowervp);
+ if (vp == NULL)
+ return;
+ vgone(vp);
+ vn_lock(lowervp, LK_EXCLUSIVE | LK_RETRY);
+}
static struct vfsops null_vfsops = {
.vfs_extattrctl = nullfs_extattrctl,
@@ -367,6 +394,7 @@ static struct vfsops null_vfsops = {
.vfs_uninit = nullfs_uninit,
.vfs_unmount = nullfs_unmount,
.vfs_vget = nullfs_vget,
+ .vfs_reclaim_lowervp = nullfs_reclaim_lowervp,
};
VFS_SET(null_vfsops, nullfs, VFCF_LOOPBACK | VFCF_JAIL);
OpenPOWER on IntegriCloud