Re: latest -git: BUG at fs/jfs/namei.c:512 assert(ip->i_nlink)

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Dave Kleikamp
Date: Thursday, July 17, 2008 - 4:09 pm

On Thu, 2008-07-17 at 20:35 +0200, Vegard Nossum wrote:

This assert shouldn't be here.  It would be better to handle this with
jfs_error(), which will mark the superblock dirty, and take appropriate
action.


How about this one?  So far, compile tested only.

JFS: The kernel shouldn't trap when deleting a file with nlink == 0.

Signed-off-by: Dave Kleikamp <shaggy@linux.vnet.ibm.com>

diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index 2aba823..10340be 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -508,33 +508,35 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
 		IWRITE_UNLOCK(ip);
 		goto out1;
 	}
-
-	ASSERT(ip->i_nlink);
-
 	ip->i_ctime = dip->i_ctime = dip->i_mtime = CURRENT_TIME;
 	mark_inode_dirty(dip);
 
-	/* update target's inode */
-	inode_dec_link_count(ip);
+	if (ip->i_nlink == 0)
+		jfs_error(dip->i_sb, "jfs_unlink: i_nlink already zero");
+	else {
+		/* update target's inode */
+		inode_dec_link_count(ip);
 
-	/*
-	 *	commit zero link count object
-	 */
-	if (ip->i_nlink == 0) {
-		assert(!test_cflag(COMMIT_Nolink, ip));
-		/* free block resources */
-		if ((new_size = commitZeroLink(tid, ip)) < 0) {
-			txAbort(tid, 1);	/* Marks FS Dirty */
-			txEnd(tid);
-			mutex_unlock(&JFS_IP(ip)->commit_mutex);
-			mutex_unlock(&JFS_IP(dip)->commit_mutex);
-			IWRITE_UNLOCK(ip);
-			rc = new_size;
-			goto out1;
+		/*
+		 *	commit zero link count object
+		 */
+		if (ip->i_nlink == 0) {
+			assert(!test_cflag(COMMIT_Nolink, ip));
+			/* free block resources */
+			new_size = commitZeroLink(tid, ip);
+			if (new_size < 0) {
+				txAbort(tid, 1);	/* Marks FS Dirty */
+				txEnd(tid);
+				mutex_unlock(&JFS_IP(ip)->commit_mutex);
+				mutex_unlock(&JFS_IP(dip)->commit_mutex);
+				IWRITE_UNLOCK(ip);
+				rc = new_size;
+				goto out1;
+			}
+			tblk = tid_to_tblock(tid);
+			tblk->xflag |= COMMIT_DELETE;
+			tblk->u.ip = ip;
 		}
-		tblk = tid_to_tblock(tid);
-		tblk->xflag |= COMMIT_DELETE;
-		tblk->u.ip = ip;
 	}
 
 	/*

-- 
David Kleikamp
IBM Linux Technology Center

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: latest -git: BUG at fs/jfs/namei.c:512 assert(ip->i_nlink), Dave Kleikamp, (Thu Jul 17, 4:09 pm)