[PATCH v2 13/31] ocfs2: abstract the fast symlink dinode guard and size check
From: Joseph Qi
Date: Fri Nov 06 2026 - 06:21:37 EST
Introduce ocfs2_dinode_is_fast_symlink() for the S_ISLNK with no
allocated clusters test that selects the id2.i_symlink union arm, and
ocfs2_dinode_has_oversized_fast_symlink() for the i_size bound.
The guard is deliberately not shared with the similar test inside
ocfs2_dinode_has_extents(), which additionally requires a non-zero
i_size. A zero-length, zero-cluster symlink currently falls through to
the extent list checks, and reusing one predicate for both would change
that.
No functional change intended.
Signed-off-by: Joseph Qi <joseph.qi@xxxxxxxxxxxxxxxxx>
---
fs/ocfs2/inode.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index 8e867f6f394a..bf27925dd5c8 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -192,6 +192,21 @@ static bool ocfs2_dinode_has_inline_size_over_count(struct ocfs2_dinode *di)
return le64_to_cpu(di->i_size) > le16_to_cpu(di->id2.i_data.id_count);
}
+/*
+ * Unlike the similar test in ocfs2_dinode_has_extents(), this does not require
+ * a non-zero i_size: a zero-length fast symlink is still validated here.
+ */
+static bool ocfs2_dinode_is_fast_symlink(struct ocfs2_dinode *di)
+{
+ return S_ISLNK(le16_to_cpu(di->i_mode)) && !le32_to_cpu(di->i_clusters);
+}
+
+static bool ocfs2_dinode_has_oversized_fast_symlink(struct super_block *sb,
+ struct ocfs2_dinode *di)
+{
+ return le64_to_cpu(di->i_size) >= ocfs2_fast_symlink_chars(sb);
+}
+
void ocfs2_set_inode_flags(struct inode *inode)
{
unsigned int flags = OCFS2_I(inode)->ip_attr;
@@ -1784,12 +1799,11 @@ int ocfs2_validate_inode_block(struct super_block *sb,
}
}
- if (S_ISLNK(le16_to_cpu(di->i_mode)) &&
- !le32_to_cpu(di->i_clusters)) {
+ if (ocfs2_dinode_is_fast_symlink(di)) {
int max_inline = ocfs2_fast_symlink_chars(sb);
u64 i_size = le64_to_cpu(di->i_size);
- if (i_size >= max_inline) {
+ if (ocfs2_dinode_has_oversized_fast_symlink(sb, di)) {
rc = ocfs2_error(sb,
"Invalid dinode #%llu: fast symlink i_size %llu exceeds max %d\n",
(unsigned long long)bh->b_blocknr,
--
2.39.3