ocfs2: fix stale extent map cache during COW operations
PATCH 1/1 ocfs2: fix stale extent map cache during COW operations
The extent map cache can become stale during COW operations, causing ocfs2_refcount_cal_cow_clusters() to see an outdated extent state.
The problem occurs when:
1. ocfs2_get_clusters() reads and caches an extent with OCFS2_EXT_REFCOUNTED
2. ocfs2_refcount_cow_hunk() performs COW, clearing the REFCOUNTED flag
3. The extent map cache still contains the stale REFCOUNTED flag
4. Subsequent access on the same extent via the cache gets incorrect flags, triggering BUG_ON(!(rec->e_flags & OCFS2_EXT_REFCOUNTED))
Fix by clearing the extent map cache at the start of COW operations. This ensures that ocfs2_get_clusters() always reads fresh extent data from disk during COW instead of using stale cached data.
--- fs/ocfs2/refcounttree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ocfs2/refcounttree.c +2 -1
@@ -3451,7 +3451,8 @@ int ocfs2_refcount_cow(struct inode *inode,int ret =0 ;u32 p_cluster, num_clusters;unsigned int ext_flags; - +/* Clear extent map cache before COW operations to avoid stale data */ +ocfs2_extent_map_trunc (inode,0 );while (write_len) { ret =ocfs2_get_clusters (inode, cpos, &p_cluster, &num_clusters, &ext_flags);
Signature · 1 line
2.43.0
Joseph Qi
maintainerHi,
Quoted 10 lines · Deepanshu Kartikey
The extent map cache can become stale during COW operations, causing
ocfs2_refcount_cal_cow_clusters()to see an outdated extent state.The problem occurs when:
1.ocfs2_get_clusters()reads and caches an extent withOCFS2_EXT_REFCOUNTED
2.ocfs2_refcount_cow_hunk()performs COW, clearing the REFCOUNTED flag
3. The extent map cache still contains the stale REFCOUNTED flag
4. Subsequent access on the same extent via the cache gets incorrect flags, triggeringBUG_ON(!(rec->e_flags & OCFS2_EXT_REFCOUNTED))
At the end of ocfs2_refcount_cow_hunk(), it has:
/* * truncate the extent map here since no matter whether we meet with * any error during the action, we shouldn't trust cached extent map * any more. */ ocfs2_extent_map_trunc(inode, cow_start);
It seems the cached extent record has already been forgotten. So how does the above step 3 happen?
Thanks,
Joseph
Quoted 25 lines
Fix by clearing the extent map cache at the start of COW operations. This ensures that
ocfs2_get_clusters()always reads fresh extent data from disk during COW instead of using stale cached data.Reported-by [email protected]Tested-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>--- fs/ocfs2/refcounttree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/ocfs2/refcounttree.c +2
-1@@ -3451,7 +3451,8 @@ int ocfs2_refcount_cow(struct inode *inode,int ret =0 ;u32 p_cluster, num_clusters;unsigned int ext_flags; - +/* Clear extent map cache before COW operations to avoid stale data */ +ocfs2_extent_map_trunc (inode,0 );while (write_len) { ret =ocfs2_get_clusters (inode, cpos, &p_cluster, &num_clusters, &ext_flags);