]> git.hungrycats.org Git - linux/commit
btrfs: always use the second newest slot for rescue=usebackuproot
authorQu Wenruo <wqu@suse.com>
Sun, 6 Sep 2026 07:03:37 +0000 (16:33 +0930)
committerDavid Sterba <dsterba@suse.com>
Mon, 12 Oct 2026 17:16:24 +0000 (19:16 +0200)
commitc73eb6f727414a0a78ee993eccd6c2d2065e9571
tree9ac1c394e007314f813d2e2aa1ca2d8d65dc7ac2
parentd00b85308abee300dfb7e1ac642f38bab9ec7492
btrfs: always use the second newest slot for rescue=usebackuproot

[RESCUE FAILURE]
There is a bug report that "rescue=usebackuproot" failed to properly
mount the fs, but if using btrfs-mod-sb to use the second newest slot,
then the fs can even pass the full "btrfs check" and be mounted RW.

[CAUSE]
During init_tree_roots(), "rescue=usebackuproot" only makes a difference
if the tree and chunk roots failed to be load.

The loading only requires the root node/leaf to be properly loaded:

- tree root
- extent tree
- block group tree
- device tree
- data reloc tree
- quota tree (optional)
- uuid tree
- raid stripe tree (for RST feature)

And it doesn't really check any child tree blocks, thus for a lot of
cases, "rescue=usebackuproot" won't make a difference.

[ENHANCEMENT]
Instead of trying every slot and settling down on the first passing
backup slot, always use the second newest slot.

The newest slot should always match the root info in the super block,
and if it worked the end user should not even need to bother to use
backup root.

Older backup slots normally have a very low chance to work.

Link: https://github.com/kdave/btrfs-progs/issues/1162#issuecomment-5475477108
Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c