[PATCH 01/25] Unionfs: Simplify unionfs_get_nlinks

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <akpm@...>
Cc: <linux-kernel@...>, <linux-fsdevel@...>, <viro@...>, <hch@...>, Josef 'Jeff' Sipek <jsipek@...>, Erez Zadok <ezk@...>
Date: Tuesday, September 25, 2007 - 11:09 pm

From: Josef 'Jeff' Sipek <jsipek@cs.sunysb.edu>

Since we set the right value for d_type in readdir, there's really no point
in having to calculate the number of directory links.  Some on-disk
filesystems don't even store the number of links for directories.

Signed-off-by: Josef 'Jeff' Sipek <jsipek@cs.sunysb.edu>
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
---
 fs/unionfs/subr.c |   41 +++++++----------------------------------
 1 files changed, 7 insertions(+), 34 deletions(-)

diff --git a/fs/unionfs/subr.c b/fs/unionfs/subr.c
index b7e7904..6b93b64 100644
--- a/fs/unionfs/subr.c
+++ b/fs/unionfs/subr.c
@@ -188,16 +188,10 @@ out:
 }
 
 /*
- * returns the sum of the n_link values of all the underlying inodes of the
- * passed inode
+ * returns the right n_link value based on the inode type
  */
 int unionfs_get_nlinks(const struct inode *inode)
 {
-	int sum_nlinks = 0;
-	int dirs = 0;
-	int bindex;
-	struct inode *lower_inode;
-
 	/* don't bother to do all the work since we're unlinked */
 	if (inode->i_nlink == 0)
 		return 0;
@@ -205,33 +199,12 @@ int unionfs_get_nlinks(const struct inode *inode)
 	if (!S_ISDIR(inode->i_mode))
 		return unionfs_lower_inode(inode)->i_nlink;
 
-	for (bindex = ibstart(inode); bindex <= ibend(inode); bindex++) {
-		lower_inode = unionfs_lower_inode_idx(inode, bindex);
-
-		/* ignore files */
-		if (!lower_inode || !S_ISDIR(lower_inode->i_mode))
-			continue;
-
-		BUG_ON(lower_inode->i_nlink < 0);
-
-		/* A deleted directory. */
-		if (lower_inode->i_nlink == 0)
-			continue;
-		dirs++;
-
-		/*
-		 * A broken directory...
-		 *
-		 * Some filesystems don't properly set the number of links
-		 * on empty directories
-		 */
-		if (lower_inode->i_nlink == 1)
-			sum_nlinks += 2;
-		else
-			sum_nlinks += (lower_inode->i_nlink - 2);
-	}
-
-	return (!dirs ? 0 : sum_nlinks + 2);
+	/*
+	 * For directories, we return 1. The only place that could cares
+	 * about links is readdir, and there's d_type there so even that
+	 * doesn't matter.
+	 */
+	return 1;
 }
 
 /* construct whiteout filename */
-- 
1.5.2.2

-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[GIT PULL -mm] 00/25 Unionfs updates/cleanups/fixes, Erez Zadok, (Tue Sep 25, 11:09 pm)
[PATCH 02/25] Unionfs: Remove unused #defines, Erez Zadok, (Tue Sep 25, 11:09 pm)
[PATCH 04/25] Unionfs: cache-coherency fixes, Erez Zadok, (Tue Sep 25, 11:09 pm)
[PATCH 01/25] Unionfs: Simplify unionfs_get_nlinks, Erez Zadok, (Tue Sep 25, 11:09 pm)
[PATCH 06/25] Unionfs: minor coding style updates, Erez Zadok, (Tue Sep 25, 11:09 pm)
Re: [PATCH 05/25] Unionfs: cast page-&gt;index loff_t before..., Christoph Hellwig, (Wed Sep 26, 4:31 am)