From da6efd2c77e4ffe406a8f9e6ad3c2c500e275240 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 10 Jul 2004 16:29:45 +0000 Subject: [PATCH] There was a mountlist race in getnewvnode() whereby the system could block obtaining the mountlist token while adding a vnode to the mountlist prior to initializing the vnode's v_usecount and v_data fields. This bug is possibly responsible for or related to occassional reports of duplicate inodes in the system. Fix the potential problem by more completely initializing the vnode prior to adding it to the mountlist. Note that FreeBSD-5 also rearranged thei r code along the same lines (though this change is independant of their work). --- sys/kern/vfs_subr.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index fffe158a26..cf4e3f68c8 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -37,7 +37,7 @@ * * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 * $FreeBSD: src/sys/kern/vfs_subr.c,v 1.249.2.30 2003/04/04 20:35:57 tegge Exp $ - * $DragonFly: src/sys/kern/vfs_subr.c,v 1.34 2004/07/04 05:16:30 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_subr.c,v 1.35 2004/07/10 16:29:45 dillon Exp $ */ /* @@ -636,7 +636,7 @@ getnewvnode(enum vtagtype tag, struct mount *mp, lwkt_tokref ilock; lwkt_tokref vlock; - s = splbio(); + s = splbio(); /* YYY remove me */ /* * Try to reuse vnodes if we hit the max. This situation only @@ -803,12 +803,17 @@ getnewvnode(enum vtagtype tag, struct mount *mp, vp->v_type = VNON; vp->v_tag = tag; vp->v_op = vops; - insmntque(vp, mp); *vpp = vp; vp->v_usecount = 1; - vp->v_data = 0; + vp->v_data = NULL; splx(s); + /* + * Placing the vnode on the mount point's queue makes it visible. + * We had better already have a ref on it. + */ + insmntque(vp, mp); + vfs_object_create(vp, td); return (0); } -- 2.35.2