mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] btrfs: remove "rescue=usebackuproot" from "rescue=all" shortcut
@ 2026-11-17  3:03 Hengyu Liang
  2026-11-17  4:23 ` Qu Wenruo
  0 siblings, 1 reply; 4+ messages in thread
From: Hengyu Liang @ 2026-11-17  3:03 UTC (permalink / raw)
  To: linux-btrfs
  Cc: Qu Wenruo, Boris Burkov, David Sterba, Chris Mason, linux-kernel

[BUG]
Since commit c73eb6f72741 ("btrfs: always use the second newest slot for
rescue=usebackuproot"), "mount -o ro,rescue=all" mounts the second
newest backup root even when the newest roots are fine. As of now, the
changes of the last transaction are not visible with "rescue=all".

The issue can be reproduced with a healthy filesystem:

    mkfs.btrfs -q -f /dev/vda
    mount /dev/vda /mnt
    echo old > /mnt/A
    echo old > /mnt/C
    sync
    echo new > /mnt/A
    echo new > /mnt/B
    rm /mnt/C
    umount /mnt
    mount -o ro,rescue=all /dev/vda /mnt
    ls /mnt
    cat /mnt/A

Before that commit, the result is "A B" and "new". After that commit,
the result is "A C" and "old".

[CAUSE]
Commit 2fd3f6a2711b ("btrfs: add "rescue=usebackuproot" into
"rescue=all" shortcut") added USEBACKUPROOT to "rescue=all". At that
time the option only fell back to a backup root when the newest roots
failed to load. Now btrfs_parse_param() sets USEBACKUPROOT and
use_backup_slot = 1 for "rescue=all", and init_tree_roots() calls
read_backup_root(fs_info, 1) before it loads the tree root.

[FIX]
"rescue=usebackuproot" now selects a root instead of tolerating an
error, so remove it from "rescue=all". With this change "rescue=all"
never uses a backup root by itself. When the newest roots are damaged,
"rescue=usebackuproot" has to be given in addition.

Fixes: c73eb6f72741 ("btrfs: always use the second newest slot for rescue=usebackuproot")
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
---
This is new in 7.4-rc (v7.3 mounts the newest roots with "rescue=all"),
so it can be judged before the release.

On a copy of a disk taken while the next transaction was running,
"rescue=all" on v7.4-rc2 showed 30 of 60 files with the data of other
files and no read error, as the space freed by the newest transaction
was reused and data checksums are ignored.

If "rescue=all" should keep every rescue option, as btrfs-progs
documents it, using slot 0 for it also shows the newest state, and I
can send that instead.

Tested on btrfs for-next (26eb4d70f96d) with clean mkfs.btrfs images:
healthy, a damaged data block, a damaged extent, csum, fs or tree root
block, and the disk copy above.

 fs/btrfs/super.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index b424cc836bd4..d67d678451f6 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -624,8 +624,6 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
 			btrfs_set_opt(ctx->mount_opt, IGNORESUPERFLAGS);
 			btrfs_set_opt(ctx->mount_opt, IGNOREBADROOTS);
 			btrfs_set_opt(ctx->mount_opt, NOLOGREPLAY);
-			btrfs_set_opt(ctx->mount_opt, USEBACKUPROOT);
-			ctx->use_backup_slot = 1;
 			break;
 		default:
 			btrfs_info(NULL, "unrecognized rescue option '%s'",

base-commit: 26eb4d70f96d9bf99e87c2565d6234eb652f9c26
-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: remove "rescue=usebackuproot" from "rescue=all" shortcut
  2026-11-17  3:03 [PATCH] btrfs: remove "rescue=usebackuproot" from "rescue=all" shortcut Hengyu Liang
@ 2026-11-17  4:23 ` Qu Wenruo
  2026-11-25 17:17   ` Hengyu Liang
  0 siblings, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2026-11-17  4:23 UTC (permalink / raw)
  To: Hengyu Liang, linux-btrfs
  Cc: Qu Wenruo, Boris Burkov, David Sterba, Chris Mason, linux-kernel



在 2026/11/17 13:33, Hengyu Liang 写道:
> [BUG]

Don't use [BUG][CAUSE][FIX] sections for a very simple behavior change.

You should not use this detailed method for such a simple behavior.

> Since commit c73eb6f72741 ("btrfs: always use the second newest slot for
> rescue=usebackuproot"), "mount -o ro,rescue=all" mounts the second
> newest backup root even when the newest roots are fine. As of now, the
> changes of the last transaction are not visible with "rescue=all".

Furthermore, one can even argue that this behavior gives a higher chance 
to mount the fs.

Thus counting this as a bug is very weak argument, thus the whole point 
of your patch may not even stand.

> 
> The issue can be reproduced with a healthy filesystem:
> 
>      mkfs.btrfs -q -f /dev/vda
>      mount /dev/vda /mnt
>      echo old > /mnt/A
>      echo old > /mnt/C
>      sync
>      echo new > /mnt/A
>      echo new > /mnt/B
>      rm /mnt/C
>      umount /mnt
>      mount -o ro,rescue=all /dev/vda /mnt
>      ls /mnt
>      cat /mnt/A
> 
> Before that commit, the result is "A B" and "new". After that commit,
> the result is "A C" and "old".
> 
> [CAUSE]
> Commit 2fd3f6a2711b ("btrfs: add "rescue=usebackuproot" into
> "rescue=all" shortcut") added USEBACKUPROOT to "rescue=all". At that
> time the option only fell back to a backup root when the newest roots
> failed to load. Now btrfs_parse_param() sets USEBACKUPROOT and
> use_backup_slot = 1 for "rescue=all", and init_tree_roots() calls
> read_backup_root(fs_info, 1) before it loads the tree root.
> 
> [FIX]
> "rescue=usebackuproot" now selects a root instead of tolerating an
> error, so remove it from "rescue=all". With this change "rescue=all"
> never uses a backup root by itself. When the newest roots are damaged,
> "rescue=usebackuproot" has to be given in addition.
> 
> Fixes: c73eb6f72741 ("btrfs: always use the second newest slot for rescue=usebackuproot")
> Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
> ---
> This is new in 7.4-rc (v7.3 mounts the newest roots with "rescue=all"),
> so it can be judged before the release.
> 
> On a copy of a disk taken while the next transaction was running,
> "rescue=all" on v7.4-rc2 showed 30 of 60 files with the data of other
> files and no read error, as the space freed by the newest transaction
> was reused and data checksums are ignored.
> 
> If "rescue=all" should keep every rescue option, as btrfs-progs
> documents it, using slot 0 for it also shows the newest state, and I
> can send that instead.
> 
> Tested on btrfs for-next (26eb4d70f96d) with clean mkfs.btrfs images:
> healthy, a damaged data block, a damaged extent, csum, fs or tree root
> block, and the disk copy above.

Remove ChatGPT garbage next time.
Or use your human brain cells to determine whether this makes any sense, 
and check all the patches from known developers for the styles to 
follow, other than blindly accept whatever chatGPT generated.

No one cares how your stupid agent tested the patch.

If you explained the patch well enough, no one need to waste his/her 
time on this BS testing steps.
If not explained well, then the testing part is totally BS.


Furthermore, you should not just change this without a doc update.

> 
>   fs/btrfs/super.c | 2 --
>   1 file changed, 2 deletions(-)
> 
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index b424cc836bd4..d67d678451f6 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -624,8 +624,6 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
>   			btrfs_set_opt(ctx->mount_opt, IGNORESUPERFLAGS);
>   			btrfs_set_opt(ctx->mount_opt, IGNOREBADROOTS);
>   			btrfs_set_opt(ctx->mount_opt, NOLOGREPLAY);
> -			btrfs_set_opt(ctx->mount_opt, USEBACKUPROOT);
> -			ctx->use_backup_slot = 1;
>   			break;
>   		default:
>   			btrfs_info(NULL, "unrecognized rescue option '%s'",
> 
> base-commit: 26eb4d70f96d9bf99e87c2565d6234eb652f9c26


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: remove "rescue=usebackuproot" from "rescue=all" shortcut
  2026-11-17  4:23 ` Qu Wenruo
@ 2026-11-25 17:17   ` Hengyu Liang
  2026-11-25 20:25     ` Qu Wenruo
  0 siblings, 1 reply; 4+ messages in thread
From: Hengyu Liang @ 2026-11-25 17:17 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs
  Cc: Qu Wenruo, Boris Burkov, David Sterba, Chris Mason, linux-kernel

Hi Qu,

I found this while comparing the behaviour of different kernel versions.
I used an LLM to analyse the problem and to draft the patch and this
message, and I analyzed the result myself.

On 2026/11/17 14:53, Qu Wenruo wrote:
> Furthermore, one can even argue that this behavior gives a higher chance
> to mount the fs.
>
> Thus counting this as a bug is very weak argument, thus the whole point
> of your patch may not even stand.

I agree that slot 1 helps when the newest tree root is damaged. But
"rescue=all" is also what people use to copy data off after an unclean
shutdown, and there slot 1 can be worse than the newest roots:

1. The data extents freed by the last committed transaction can already
   hold data of the transaction that did not commit, while slot 1 still
   points to them, and ignoredatacsums reads them without an error. In
   my test, user A deleted 30 of 60 files in the last transaction, then
   user B wrote and fsynced 60 private (0600) files before a power cut
   (I used a copy of the disk taken at that point). With
   "ro,rescue=all", A's deleted files are back, and 30 of A's files,
   owned by A, contain B's data. Copying the data off with the owners
   kept hands B's data to A. With the newest roots (v7.3, or
   "rescue=all,rescue=usebackuproot_0" now), A sees only the 30 current
   files with A's own data.

2. On the same disk, "ro,rescue=usebackuproot" fails with "chunk ...
   has missing dev extent" (-EUCLEAN), while the newest roots mount
   without errors. I also have a syzkaller image that mounts with
   ignorebadroots and usebackuproot (plus some unrelated options) on
   the parent of c73eb6f72741 and fails with -EIO on that commit: slot 1
   has a bad checksum, the newest roots load. So slot 1 does not always
   give a better chance to mount.

I have two suggestions, but in the end it is your call:

a) "rescue=all" tries the newest roots first and falls back to slot 1
   only when the mount fails with them (similar to the retry Boris
   suggested in his review of your series).

b) Keep slot 1 for "rescue=all", and document in btrfs-progs that an
   older slot can point to reused data blocks, which ignoredatacsums
   then reads without errors.

Thanks,
Hengyu

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: remove "rescue=usebackuproot" from "rescue=all" shortcut
  2026-11-25 17:17   ` Hengyu Liang
@ 2026-11-25 20:25     ` Qu Wenruo
  0 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2026-11-25 20:25 UTC (permalink / raw)
  To: Hengyu Liang, Qu Wenruo, linux-btrfs
  Cc: Boris Burkov, David Sterba, Chris Mason, linux-kernel



在 2026/11/26 03:47, Hengyu Liang 写道:
> Hi Qu,
> 
> I found this while comparing the behaviour of different kernel versions.
> I used an LLM to analyse the problem and to draft the patch and this
> message, and I analyzed the result myself.

Then you should also stop waste human time on reading such long word salads.

> 
> On 2026/11/17 14:53, Qu Wenruo wrote:
>> Furthermore, one can even argue that this behavior gives a higher chance
>> to mount the fs.
>>
>> Thus counting this as a bug is very weak argument, thus the whole point
>> of your patch may not even stand.
> 
> I agree that slot 1 helps when the newest tree root is damaged. But
> "rescue=all" is also what people use to copy data off after an unclean
> shutdown, and there slot 1 can be worse than the newest roots:
> 
> 1. The data extents freed by the last committed transaction can already
>     hold data of the transaction that did not commit,

That's not a problem, COW makes sure the old data can still be reached.

> while slot 1 still
>     points to them, and ignoredatacsums reads them without an error. In
>     my test, user A deleted 30 of 60 files in the last transaction, then
>     user B wrote and fsynced 60 private (0600) files before a power cut
>     (I used a copy of the disk taken at that point).

And fsync is a different behavior. Fsynced data are only in log tree.
No matter if you use the newest slot or not, as long as you ignore the 
log tree, those new deletion will not be seen anyway.

> With
>     "ro,rescue=all", A's deleted files are back, and 30 of A's files,
>     owned by A, contain B's data. Copying the data off with the owners
>     kept hands B's data to A. With the newest roots (v7.3, or
>     "rescue=all,rescue=usebackuproot_0" now), A sees only the 30 current
>     files with A's own data.
> 
> 2. On the same disk, "ro,rescue=usebackuproot" fails with "chunk ...
>     has missing dev extent" (-EUCLEAN), while the newest roots mount
>     without errors. I also have a syzkaller image that mounts with
>     ignorebadroots and usebackuproot (plus some unrelated options) on
>     the parent of c73eb6f72741 and fails with -EIO on that commit: slot 1
>     has a bad checksum,

That's the problem, and users always have the solution to choose which 
slot to use.

> the newest roots load. So slot 1 does not always
>     give a better chance to mount.
> 
> I have two suggestions, but in the end it is your call:
> 
> a) "rescue=all" tries the newest roots first and falls back to slot 1
>     only when the mount fails with them (similar to the retry Boris
>     suggested in his review of your series).
> 
> b) Keep slot 1 for "rescue=all", and document in btrfs-progs that an
>     older slot can point to reused data blocks, which ignoredatacsums
>     then reads without errors.

Nope, not for slot 1 at least.

Data COW ensures it won't write data into an extent just released in the 
current transaction.

> 
> Thanks,
> Hengyu


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-25 20:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17  3:03 [PATCH] btrfs: remove "rescue=usebackuproot" from "rescue=all" shortcut Hengyu Liang
2026-11-17  4:23 ` Qu Wenruo
2026-11-25 17:17   ` Hengyu Liang
2026-11-25 20:25     ` Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®