]> git.hungrycats.org Git - linux/commit
btrfs: stripe_alloc: release open stripe runs when a mount fails or an aborted filesy...
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 16 Sep 2026 10:19:44 +0000 (06:19 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Fri, 18 Sep 2026 21:36:31 +0000 (17:36 -0400)
commit25aed8545d67e0e0c2e011d9981c04eefb490370
treecd50e6e89298c41d63bc9a893ace3a2bef6951d6
parent28672f350b5c9abfd2c428efd5417372079998cd
btrfs: stripe_alloc: release open stripe runs when a mount fails or an aborted filesystem unmounts

A block group with open stripe runs holds a reference for as long as it
is on fs_info->open_stripe_bgs, and only the commit-time retirement,
having released the group's last run, drops it.  Two paths never commit
again: a mount whose log replay fails after it has already allocated
tree blocks (each allocation opened a metadata run), and the unmount of
a filesystem whose transaction aborted.  btrfs_free_block_groups() then
finds the leftover references and asserts:

  BTRFS: error (device loop0 state EAO) in btrfs_replay_log:2072:
  errno=-5 IO failure (Failed to recover log tree)
  assertion failed: refcount_read(&block_group->refs) == 1 :: 0, in
  fs/btrfs/block-group.c:7479
  kernel BUG at fs/btrfs/block-group.c:7479!
  RIP: btrfs_free_block_groups.cold
  open_ctree
  btrfs_get_tree.cold

Hit by the raid56-metadata fsync-window characterization: a degraded
mount whose log replay got as far as allocating before it met the torn
log block, where an earlier run of the same case had failed while
walking the log and never allocated.  The mount task died holding the
superblock lock and the next mount of the same devices hung on it.

Release every open run and the references before the block groups are
freed, on both paths.  Nothing is in flight there: workers are stopped
and the roots dropped; a run that still counts bytes in flight is
reported and released anyway.

Assisted-by: Claude:claude-fable-5-1
fs/btrfs/block-group.c
fs/btrfs/block-group.h
fs/btrfs/disk-io.c