Date: Wed, Jul 12 2006 16:56:25 +1000
From: Nathan Scott <nathans@sgi.com>
References: 191713, SGI:PV953287
Subject: fix race on link

Remove a race condition where a linked inode could BUG_ON in
d_instantiate, due to fast transaction committal removing the last
remaining reference before we were all done.

===========================================================================
linux-2.6/xfs_iops.c
===========================================================================

--- a/fs/xfs/linux-2.6/xfs_iops.c	2006-07-12 16:59:30.000000000 +1000
+++ b/fs/xfs/linux-2.6/xfs_iops.c	2006-07-12 16:58:45.075668500 +1000
@@ -432,10 +432,12 @@ linvfs_link(
 	tdvp = LINVFS_GET_VP(dir);
 	vp = LINVFS_GET_VP(ip);
 
+	VN_HOLD(vp);
 	VOP_LINK(tdvp, vp, dentry, NULL, error);
-	if (!error) {
+	if (unlikely(error)) {
+		VN_RELE(vp);
+	} else {
 		VMODIFY(tdvp);
-		VN_HOLD(vp);
 		validate_fields(ip);
 		d_instantiate(dentry, ip);
 	}
