From 97aa3ba44f0b3911866e5dfc31b0d7a9fb124855 Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Thu, 9 May 2019 08:40:51 +0900 Subject: [PATCH] Fix link count of root inode when snapdir is visible Given how zfs_getattr() is implemented, zfs_getattr_fast() (used by ->getattr() of zpl inodes) also needs to consider an additional link count if "snapdir" property is set to "visible". Without this, # of directories in root inode of each dataset doesn't match the link count when snapdir is visible. Reviewed-by: Richard Yao Reviewed-by: Brian Behlendorf Signed-off-by: Tomohiro Kusumi Closes #8727 --- module/zfs/zfs_vnops.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/module/zfs/zfs_vnops.c b/module/zfs/zfs_vnops.c index 27f179d82..41c1bd255 100644 --- a/module/zfs/zfs_vnops.c +++ b/module/zfs/zfs_vnops.c @@ -2657,6 +2657,12 @@ zfs_getattr_fast(struct inode *ip, struct kstat *sp) mutex_enter(&zp->z_lock); generic_fillattr(ip, sp); + /* + * +1 link count for root inode with visible '.zfs' directory. + */ + if ((zp->z_id == zfsvfs->z_root) && zfs_show_ctldir(zp)) + if (sp->nlink < ZFS_LINK_MAX) + sp->nlink++; sa_object_size(zp->z_sa_hdl, &blksize, &nblocks); sp->blksize = blksize; -- 2.40.0