Alexey Asemov (Alex/AT)
2022-Nov-27 06:46 UTC
[Ocfs2-devel] [PATCH] ocfs2: always read both high and low parts of dinode link count
When filesystem is using indexed-dirs feature, maximum link count values can spill over to i_links_count_hi, up to OCFS2_DX_LINK_MAX links. ocfs2_read_links_count() checks for OCFS2_INDEXED_DIR_FL flag in dinode, but this flag is only valid for directories so for files the check causes high part of the link count not being read back from file dinodes resulting in wrong link count value when file has >65535 links. As ocfs2_set_links_count() always writes both high and low parts of link count, the flag check on reading may be removed. Signed-off-by: Alexey Asemov <alex at alex-at.net> --- fs/ocfs2/ocfs2.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h index 740b64238312..a503c553bab2 100644 --- a/fs/ocfs2/ocfs2.h +++ b/fs/ocfs2/ocfs2.h @@ -560,8 +560,7 @@ static inline unsigned int ocfs2_read_links_count(struct ocfs2_dinode *di) u32 nlink = le16_to_cpu(di->i_links_count); u32 hi = le16_to_cpu(di->i_links_count_hi); - if (di->i_dyn_features & cpu_to_le16(OCFS2_INDEXED_DIR_FL)) - nlink |= (hi << OCFS2_LINKS_HI_SHIFT); + nlink |= (hi << OCFS2_LINKS_HI_SHIFT); return nlink; }
Joseph Qi
2022-Nov-27 12:57 UTC
[Ocfs2-devel] [PATCH] ocfs2: always read both high and low parts of dinode link count
On 11/27/22 2:46 PM, Alexey Asemov (Alex/AT) wrote:> When filesystem is using indexed-dirs feature, maximum link count values > can spill over to i_links_count_hi, up to OCFS2_DX_LINK_MAX links. > ocfs2_read_links_count() checks for OCFS2_INDEXED_DIR_FL flag in dinode, > but this flag is only valid for directories so for files the check > causes high part of the link count not being read back from file > dinodes resulting in wrong link count value when file has >65535 links. > > As ocfs2_set_links_count() always writes both high and low parts of link > count, the flag check on reading may be removed. > > Signed-off-by: Alexey Asemov <alex at alex-at.net>Reviewed-by: Joseph Qi <joseph.qi at linux.alibaba.com>> --- > > ?fs/ocfs2/ocfs2.h | 3 +-- > ?1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h > index 740b64238312..a503c553bab2 100644 > --- a/fs/ocfs2/ocfs2.h > +++ b/fs/ocfs2/ocfs2.h > @@ -560,8 +560,7 @@ static inline unsigned int ocfs2_read_links_count(struct ocfs2_dinode *di) > ??????? u32 nlink = le16_to_cpu(di->i_links_count); > ??????? u32 hi = le16_to_cpu(di->i_links_count_hi); > > -?????? if (di->i_dyn_features & cpu_to_le16(OCFS2_INDEXED_DIR_FL)) > -?????????????? nlink |= (hi << OCFS2_LINKS_HI_SHIFT); > +?????? nlink |= (hi << OCFS2_LINKS_HI_SHIFT); > > ??????? return nlink; > ?}