Linux NFS development
 help / color / mirror / Atom feed
* [PATCH] NFSv4: Always set NLINK even if the server doesn't support it
@ 2025-05-02 15:15 Han Young
  2025-05-02 15:39 ` Trond Myklebust
  2025-05-04 12:57 ` [PATCH v2] " Han Young
  0 siblings, 2 replies; 3+ messages in thread
From: Han Young @ 2025-05-02 15:15 UTC (permalink / raw)
  To: trondmy, anna; +Cc: linux-nfs, Han Young

fattr4_numlinks is a recommended attribute, so the client should emulate
it even if the server doesn't support it. In decode_attr_nlink function
in nfs4xdr.c, nlink is initialized to 1. However, this default value
isn't set to the inode due to the check in nfs_fhget.

So if the server doesn't support numlinks, inode's nlink will be zero,
the mount will fail with error "Stale file handle". Change the check in
nfs_fhget so that the nlink value is always set.

Signed-off-by: Han Young <hanyang.tony@bytedance.com>
---
 fs/nfs/inode.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 119e447758b9..c19f135b5041 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -553,10 +553,11 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
 			inode->i_size = nfs_size_to_loff_t(fattr->size);
 		else
 			nfs_set_cache_invalid(inode, NFS_INO_INVALID_SIZE);
-		if (fattr->valid & NFS_ATTR_FATTR_NLINK)
-			set_nlink(inode, fattr->nlink);
-		else if (fattr_supported & NFS_ATTR_FATTR_NLINK)
+		if (!(fattr->valid & NFS_ATTR_FATTR_NLINK) &&
+			   fattr_supported & NFS_ATTR_FATTR_NLINK)
 			nfs_set_cache_invalid(inode, NFS_INO_INVALID_NLINK);
+		else
+			set_nlink(inode, fattr->nlink);
 		if (fattr->valid & NFS_ATTR_FATTR_OWNER)
 			inode->i_uid = fattr->uid;
 		else if (fattr_supported & NFS_ATTR_FATTR_OWNER)
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-04 12:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-02 15:15 [PATCH] NFSv4: Always set NLINK even if the server doesn't support it Han Young
2025-05-02 15:39 ` Trond Myklebust
2025-05-04 12:57 ` [PATCH v2] " Han Young

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox