]> git.hungrycats.org Git - linux/commitdiff
btrfs: don't cache rbio if an error is hit
authorQu Wenruo <wqu@suse.com>
Wed, 28 Oct 2026 06:30:47 +0000 (17:00 +1030)
committerDavid Sterba <dsterba@suse.com>
Fri, 30 Oct 2026 20:36:19 +0000 (21:36 +0100)
If rmw_rbio() hit an error after cache_rbio_pages() call, the rbio still
have RBIO_CACHE_READY_BIT set, thus can be utilized for future page
stealing.

But that rbio didn't really reach the disk, thus using the pages for
future steal can cause data inconsistency between in-memory cache and
on-disk data.

Fix the problem by clearing the RBIO_CACHE_READY_BIT on the error path
of rmw_rbio().

Fixes: 5eb30ee26fa4 ("btrfs: raid56: introduce the main entrance for RMW path")
Assisted-by: LLM (find the bug)
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/raid56.c

index b24ec362909bb74a5826ccbccbef148cb75a425e..a8a8004bb14c7bbf18394695d537c8f1a09a32fa 100644 (file)
@@ -2471,6 +2471,9 @@ out:
                spin_lock(&rbio->bio_list_lock);
                set_bit(RBIO_RMW_LOCKED_BIT, &rbio->flags);
                spin_unlock(&rbio->bio_list_lock);
+
+               /* Failed write, don't cache for page stealing. */
+               clear_bit(RBIO_CACHE_READY_BIT, &rbio->flags);
        }
        rbio_orig_end_io(rbio, errno_to_blk_status(ret));
 }