[PATCH] Fix race between link() and unlink() (1 of 1)

Dave Kleikamp <[email protected]> Thu, 30 Oct 2003 10:16:59 -0600
Newsgroups gmane.comp.file-systems.jfs.patches
Message-ID <[email protected]>
# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
#	           ChangeSet	1.1172  -> 1.1173 
#	      fs/jfs/namei.c	1.18    -> 1.19   
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/10/30	[email protected]	1.1173
# JFS: Fix race between link() and unlink()
#    
# JFS isn't happy it thinks a file has been removed, and link() increases
# its nlink count back from zero.
# --------------------------------------------
#
diff -Nru a/fs/jfs/namei.c b/fs/jfs/namei.c
--- a/fs/jfs/namei.c	Thu Oct 30 10:15:02 2003
+++ b/fs/jfs/namei.c	Thu Oct 30 10:15:02 2003
@@ -758,6 +758,12 @@
 	jfs_info("jfs_link: %s %s", old_dentry->d_name.name,
 		 dentry->d_name.name);
 
+	if (ip->i_nlink == JFS_LINK_MAX)
+		return -EMLINK;
+
+	if (ip->i_nlink == 0)
+		return -ENOENT;
+
 	/* JFS does NOT support link() on directories */
 	if (S_ISDIR(ip->i_mode))
 		return -EPERM;
@@ -766,11 +772,6 @@
 
 	down(&JFS_IP(dir)->commit_sem);
 	down(&JFS_IP(ip)->commit_sem);
-
-	if (ip->i_nlink == JFS_LINK_MAX) {
-		rc = -EMLINK;
-		goto out;
-	}
 
 	/*
 	 * scan parent directory for entry/freespace