[PATCH] gfs2: Move i_nlink checks from gfs2_{link,rename,mkdir} to VFS layer

Youling Tang posted 1 patch 5 days, 20 hours ago
fs/gfs2/gfs2.h       |  1 +
fs/gfs2/inode.c      | 10 ----------
fs/gfs2/ops_fstype.c |  1 +
3 files changed, 2 insertions(+), 10 deletions(-)
[PATCH] gfs2: Move i_nlink checks from gfs2_{link,rename,mkdir} to VFS layer
Posted by Youling Tang 5 days, 20 hours ago
From: Youling Tang <tangyouling@kylinos.cn>

vfs_{link, rename, mkdir} will check i_nlink. When sb->s_max_links is set,
set sb->s_max_links in gfs2 to simplify the code.

Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
---
 fs/gfs2/gfs2.h       |  1 +
 fs/gfs2/inode.c      | 10 ----------
 fs/gfs2/ops_fstype.c |  1 +
 3 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/fs/gfs2/gfs2.h b/fs/gfs2/gfs2.h
index ed78e5f20f41..06a7f731d34c 100644
--- a/fs/gfs2/gfs2.h
+++ b/fs/gfs2/gfs2.h
@@ -18,6 +18,7 @@ enum {
 };
 
 #define GFS2_FAST_NAME_SIZE 8
+#define GFS2_LINK_MAX	0xffffffff
 
 #endif /* __GFS2_DOT_H__ */
 
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 8760e7e20c9d..f2a6420e1fa8 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -373,8 +373,6 @@ static int create_ok(struct gfs2_inode *dip, const struct qstr *name,
 
 	if (dip->i_entries == (u32)-1)
 		return -EFBIG;
-	if (S_ISDIR(mode) && dip->i_inode.i_nlink == (u32)-1)
-		return -EMLINK;
 
 	return 0;
 }
@@ -1079,9 +1077,6 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
 	error = -EPERM;
 	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
 		goto out_gunlock;
-	error = -EMLINK;
-	if (ip->i_inode.i_nlink == (u32)-1)
-		goto out_gunlock;
 
 	error = gfs2_diradd_alloc_required(dir, &dentry->d_name, &da);
 	if (error < 0)
@@ -1623,11 +1618,6 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
 				error = -EFBIG;
 				goto out_gunlock;
 			}
-			if (S_ISDIR(ip->i_inode.i_mode) &&
-			    ndip->i_inode.i_nlink == (u32)-1) {
-				error = -EMLINK;
-				goto out_gunlock;
-			}
 		}
 	}
 
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index efe99b732551..823f3d987d6c 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -1152,6 +1152,7 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
 	sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE;
 	sb->s_time_gran = 1;
 	sb->s_maxbytes = MAX_LFS_FILESIZE;
+	sb->s_max_links = GFS2_LINK_MAX;
 
 	/* Set up the buffer cache and fill in some fake block size values
 	   to allow us to read-in the on-disk superblock. */
-- 
2.43.0
Re: [PATCH] gfs2: Move i_nlink checks from gfs2_{link,rename,mkdir} to VFS layer
Posted by Al Viro 5 days, 18 hours ago
On Fri, Sep 26, 2025 at 10:56:04AM +0800, Youling Tang wrote:
> From: Youling Tang <tangyouling@kylinos.cn>
> 
> vfs_{link, rename, mkdir} will check i_nlink. When sb->s_max_links is set,
> set sb->s_max_links in gfs2 to simplify the code.

For gfs2 you are going to run into a problem - link count is not stable until
you take gfs2 locks; checks in vfs_link() et.al. will be inevitably racy for
cluster filesystems.
Re: [PATCH] gfs2: Move i_nlink checks from gfs2_{link,rename,mkdir} to VFS layer
Posted by Youling Tang 5 days, 17 hours ago
On 9/26/25 12:48, Al Viro wrote:

> On Fri, Sep 26, 2025 at 10:56:04AM +0800, Youling Tang wrote:
>> From: Youling Tang <tangyouling@kylinos.cn>
>>
>> vfs_{link, rename, mkdir} will check i_nlink. When sb->s_max_links is set,
>> set sb->s_max_links in gfs2 to simplify the code.
> For gfs2 you are going to run into a problem - link count is not stable until
> you take gfs2 locks; checks in vfs_link() et.al. will be inevitably racy for
> cluster filesystems.

Thank you for pointing out this important issue. Let's discard this patch.

Thanks,
Youling.