Re: [PATCH v2] ocfs2: clear extent cache after moving/defragmenting extents
From: Andrew Morton
Date: Thu Oct 09 2025 - 21:37:31 EST
On Thu, 9 Oct 2025 21:19:03 +0530 Deepanshu Kartikey <kartikey406@xxxxxxxxx> wrote:
> The extent map cache can become stale when extents are moved or
> defragmented, causing subsequent operations to see outdated extent
> flags. This triggers a BUG_ON in ocfs2_refcount_cal_cow_clusters().
We try to avoid BUG_ONs ;)
>
> ...
>
> The problem occurs when:
>
> ...
>
> --- a/fs/ocfs2/move_extents.c
> +++ b/fs/ocfs2/move_extents.c
> @@ -867,6 +867,11 @@ static int __ocfs2_move_extents_range(struct buffer_head *di_bh,
> mlog_errno(ret);
> goto out;
> }
> + /*
> + * Invalidate extent cache after moving/defragging to prevent
> + * stale cached data with outdated extent flags.
> + */
> + ocfs2_extent_map_trunc(inode, cpos);
>
> context->clusters_moved += alloc_size;
> next:
I assume we should backport this into earlier kernels, so I'll add a
cc:stable to the changelog.
It's very nice (but not essential) to add a Fixes: as well, so -stable
maintainers know how far back in time to backport the fix.