[PATCH v2] tux3: remove unneeded verification of nlink in mknod,link,rename op

Chao Yu chao2.yu at samsung.com
Thu Aug 7 02:40:15 PDT 2014


VFS has already did the verification of nlink for ->mknod/->link/->rename, so
we'd better remove these redundant codes.
Additionally we should set ->s_max_links with TUX_LINK_MAX in fill_super(),
then VFS could verify the nlink with upper bound value correctly.

v2:
 o set s_max_links with the right value suggested by Daniel Phillips.

Signed-off-by: Chao Yu <chao2.yu at samsung.com>
---
 fs/tux3/namei.c | 19 ++++---------------
 fs/tux3/super.c |  1 +
 2 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/fs/tux3/namei.c b/fs/tux3/namei.c
index 4a7e9bf..d598a7b 100644
--- a/fs/tux3/namei.c
+++ b/fs/tux3/namei.c
@@ -46,14 +46,11 @@ static int __tux3_mknod(struct inode *dir, struct dentry *dentry,
 			struct tux_iattr *iattr, dev_t rdev)
 {
 	struct inode *inode;
-	int err, is_dir = S_ISDIR(iattr->mode);
+	int err;
 
 	if (!huge_valid_dev(rdev))
 		return -EINVAL;
 
-	if (is_dir && dir->i_nlink >= TUX_LINK_MAX)
-		return -EMLINK;
-
 	change_begin(tux_sb(dir->i_sb));
 	inode = tux_new_inode(dir, iattr, rdev);
 	err = PTR_ERR(inode);
@@ -61,7 +58,7 @@ static int __tux3_mknod(struct inode *dir, struct dentry *dentry,
 		err = tux_add_dirent(dir, dentry, inode);
 		if (!err) {
 			unlock_new_inode(inode);
-			if (is_dir)
+			if (S_ISDIR(iattr->mode))
 				inode_inc_link_count(dir);
 		}
 	}
@@ -101,9 +98,6 @@ static int tux3_link(struct dentry *old_dentry, struct inode *dir,
 	struct sb *sb = tux_sb(inode->i_sb);
 	int err;
 
-	if (inode->i_nlink >= TUX_LINK_MAX)
-		return -EMLINK;
-
 	change_begin(sb);
 	tux3_iattrdirty(inode);
 	inode->i_ctime = gettime();
@@ -289,17 +283,12 @@ static int tux3_rename(struct inode *old_dir, struct dentry *old_dentry,
 			drop_nlink(new_inode);
 		inode_dec_link_count(new_inode);
 	} else {
-		new_subdir = S_ISDIR(old_inode->i_mode) && new_dir != old_dir;
-		if (new_subdir) {
-			if (new_dir->i_nlink >= TUX_LINK_MAX) {
-				err = -EMLINK;
-				goto error;
-			}
-		}
 		err = tux_create_dirent(new_dir, &new_dentry->d_name,
 					old_inode);
 		if (err)
 			goto error;
+
+		new_subdir = S_ISDIR(old_inode->i_mode) && new_dir != old_dir;
 		if (new_subdir)
 			inode_inc_link_count(new_dir);
 	}
diff --git a/fs/tux3/super.c b/fs/tux3/super.c
index c2cb4dc..0ee8b11 100644
--- a/fs/tux3/super.c
+++ b/fs/tux3/super.c
@@ -445,6 +445,7 @@ static int tux3_fill_super(struct super_block *sb, void *data, int silent)
 	sb->s_magic = TUX3_SUPER_MAGIC;
 	sb->s_op = &tux3_super_ops;
 	sb->s_time_gran = 1;
+	sb->s_max_links = TUX_LINK_MAX;
 
 	err = -EIO;
 	blocksize = sb_min_blocksize(sb, BLOCK_SIZE);
-- 
2.0.1.474.g72c7794





More information about the Tux3 mailing list