[PATCH] ext4: add logging to debug issue
From: Ojaswin Mujoo
Date: Tue Feb 10 2026 - 07:29:17 EST
---
fs/ext4/extents.c | 28 ++++++++++++++++++++++++++++
fs/ext4/extents_status.c | 20 ++++++++++++++++++++
fs/ext4/mballoc.c | 27 +++++++++++++++++++++++++++
3 files changed, 75 insertions(+)
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 3630b27e4fd7..89a681f6e5ca 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -529,6 +529,7 @@ static void ext4_cache_extents(struct inode *inode,
int i;
KUNIT_STATIC_STUB_REDIRECT(ext4_cache_extents, inode, eh);
+ ext4_warning_inode(inode, "%s: caching extents\n", __func__);
for (i = le16_to_cpu(eh->eh_entries); i > 0; i--, ex++) {
unsigned int status = EXTENT_STATUS_WRITTEN;
@@ -2006,6 +2007,22 @@ ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
goto errout;
}
+ ext4_warning_inode(
+ inode,
+ "%s: add newext [%u, %u, %llu, unwrit:%d] to extent tree.\n",
+ __func__, le32_to_cpu(newext->ee_block),
+ ext4_ext_get_actual_len(newext), ext4_ext_pblock(newext),
+ ext4_ext_is_unwritten(newext));
+
+ if (ex) {
+ ext4_warning_inode(
+ inode,
+ "%s: ext at current path: [%u, %u, %llu, unwrit:%d]\n",
+ __func__, le32_to_cpu(ex->ee_block),
+ ext4_ext_get_actual_len(ex), ext4_ext_pblock(ex),
+ ext4_ext_is_unwritten(ex));
+ }
+
/* try to insert block into found extent and return */
if (ex && !(gb_flags & EXT4_GET_BLOCKS_SPLIT_NOMERGE)) {
@@ -2832,6 +2849,11 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start,
int i = 0, err = 0;
int flags = EXT4_EX_NOCACHE | EXT4_EX_NOFAIL;
+ ext4_warning_inode(
+ inode,
+ "%s: remove range [%u, %u] from extent tree\n",
+ __func__, start, end);
+
partial.pclu = 0;
partial.lblk = 0;
partial.state = initial;
@@ -4456,6 +4478,12 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
map->m_flags |= EXT4_MAP_UNWRITTEN;
}
+ ext4_warning_inode(
+ inode,
+ "%s: add newext [%u, %u, %llu, unwrit:%d] to extent tree.\n",
+ __func__, le32_to_cpu(newex.ee_block),
+ ext4_ext_get_actual_len(&newex), ext4_ext_pblock(&newex),
+ ext4_ext_is_unwritten(&newex));
path = ext4_ext_insert_extent(handle, inode, path, &newex, flags);
if (IS_ERR(path)) {
err = PTR_ERR(path);
diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index a1538bac51c6..009c22108a7f 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -847,6 +847,10 @@ static int __es_insert_extent(struct inode *inode, struct extent_status *newes,
struct rb_node *parent = NULL;
struct extent_status *es;
+ ext4_warning_inode(inode, "%s: add lblk:%u len:%u pblk:%llu status:0x%x]\n", __func__,
+ newes->es_lblk, newes->es_len, ext4_es_pblock(newes),
+ ext4_es_status(newes));
+
while (*p) {
parent = *p;
es = rb_entry(parent, struct extent_status, rb_node);
@@ -921,6 +925,10 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
es_debug("add [%u/%u) %llu %x %d to extent status tree of inode %lu\n",
lblk, len, pblk, status, delalloc_reserve_used, inode->i_ino);
+ ext4_warning_inode(
+ inode,
+ "%s: add lblk:%u len:%u pblk:%llu 0x%x to es\n",
+ __func__, lblk, len, pblk, status);
if (!len)
return;
@@ -1031,6 +1039,11 @@ void ext4_es_cache_extent(struct inode *inode, ext4_lblk_t lblk,
bool conflict = false;
int err;
+ ext4_warning_inode(
+ inode,
+ "%s: cache extent lblk:%u len:%u pblk:%llu status:0x%x\n",
+ __func__, lblk, len, pblk, status);
+
if (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY)
return;
@@ -1493,6 +1506,11 @@ static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
bool count_reserved = true;
struct rsvd_count rc;
+ ext4_warning_inode(
+ inode,
+ "%s: remove [%u,%u] range from extent status tree of inode %lu\n",
+ __func__, lblk, end, inode->i_ino);
+
if (reserved == NULL || !test_opt(inode->i_sb, DELALLOC))
count_reserved = false;
if (status == 0)
@@ -1633,6 +1651,8 @@ void ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
es_debug("remove [%u/%u) from extent status tree of inode %lu\n",
lblk, len, inode->i_ino);
+ ext4_warning_inode(inode, "%s: remove lblk:%u len:%u from es\n",
+ __func__, lblk, len);
if (!len)
return;
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index dbc82b65f810..a37d6e3e004d 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2004,6 +2004,18 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,
int last = first + count - 1;
struct super_block *sb = e4b->bd_sb;
+ ext4_fsblk_t pblk =
+ ext4_group_first_block_no(e4b->bd_sb, e4b->bd_group) +
+ (first << EXT4_SB(e4b->bd_sb)->s_cluster_bits);
+
+ if (inode)
+ ext4_warning_inode(inode, "%s: trying to free pblk:%llu count:%d\n",
+ __func__, pblk, count);
+ else
+ ext4_warning(sb, "%s: trying to free pblk:%llu count:%d\n",
+ __func__, pblk, count);
+
+
if (WARN_ON(count == 0))
return;
BUG_ON(last >= (sb->s_blocksize << 3));
@@ -3101,6 +3113,12 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
if (!err && ac->ac_status != AC_STATUS_FOUND && ac->ac_first_err)
err = ac->ac_first_err;
+ ext4_warning_inode(
+ ac->ac_inode,
+ "%s: Best len %d, origin len %d, ac_status %u, ac_flags 0x%x, cr %d ret %d\n",
+ __func__, ac->ac_b_ex.fe_len, ac->ac_o_ex.fe_len, ac->ac_status,
+ ac->ac_flags, ac->ac_criteria, err);
+
mb_debug(sb, "Best len %d, origin len %d, ac_status %u, ac_flags 0x%x, cr %d ret %d\n",
ac->ac_b_ex.fe_len, ac->ac_o_ex.fe_len, ac->ac_status,
ac->ac_flags, ac->ac_criteria, err);
@@ -6251,6 +6269,10 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
sb = ar->inode->i_sb;
sbi = EXT4_SB(sb);
+ ext4_warning_inode(ar->inode,
+ "%s: Allocation requested for: lblk:%u len:%d\n",
+ __func__, ar->logical, ar->len);
+
trace_ext4_request_blocks(ar);
if (sbi->s_mount_state & EXT4_FC_REPLAY)
return ext4_mb_new_blocks_simple(ar, errp);
@@ -6334,6 +6356,11 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
ext4_mb_pa_put_free(ac);
}
if (likely(ac->ac_status == AC_STATUS_FOUND)) {
+ ext4_warning_inode(
+ ar->inode,
+ "%s: Allocation found: lblk:%u, len:%d, pblk:%llu\n",
+ __func__, ar->logical, ac->ac_b_ex.fe_len,
+ ext4_grp_offs_to_block(sb, &ac->ac_b_ex));
*errp = ext4_mb_mark_diskspace_used(ac, handle);
if (*errp) {
ext4_discard_allocated_blocks(ac);
--
2.52.0
--lUyFTQojouXCY1ux--