linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ovl: nfs_export: Parse index inode's nlink when 'd_inode(lowerdentry)->i_nlink == 1'
@ 2021-08-06  9:53 Zhihao Cheng
  0 siblings, 0 replies; only message in thread
From: Zhihao Cheng @ 2021-08-06  9:53 UTC (permalink / raw)
  To: miklos, amir73il; +Cc: linux-unionfs, linux-kernel, chengzhihao1, yukuai3

For overlayfs mounted by "nfs_export=on", all files/directories will be
indexed regardless of whether 'nlink > 1' satisfies. Following process
may cause breaking hard links on copy up:

  mkdir low upper work merge
  touch low/file
  mount -t overlay over
    -oupperdir=upper,lowerdir=low,workdir=work,nfs_export=on merge
  chmod +x merge/file
  #  Now nlink of upper/file's correspoding index file equals to 2,
     and we have xattr "trusted.overlay.nlink=U-1" on upper/file
  echo 3 > /proc/sys/vm/drop_caches
  # merge/file's nlink changes to 2

For nfs_export enabled overlayfs, don't ignore parsing index inode's nlink
when 'd_inode(lowerdentry)->i_nlink == 1'.

Fixes: f168f1098dd9038 ("ovl: add support for "nfs_export" configuration")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
---
 fs/overlayfs/inode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index 5e828a1c98a8..75a61243371c 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -832,7 +832,8 @@ unsigned int ovl_get_nlink(struct ovl_fs *ofs, struct dentry *lowerdentry,
 	char buf[13];
 	int err;
 
-	if (!lowerdentry || !upperdentry || d_inode(lowerdentry)->i_nlink == 1)
+	if (!lowerdentry || !upperdentry ||
+		(!ofs->config.nfs_export && d_inode(lowerdentry)->i_nlink == 1))
 		return fallback;
 
 	err = ovl_do_getxattr(ofs, upperdentry, OVL_XATTR_NLINK,
-- 
2.31.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-06  9:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06  9:53 [PATCH] ovl: nfs_export: Parse index inode's nlink when 'd_inode(lowerdentry)->i_nlink == 1' Zhihao Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).