Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Marek Behun <marek.behun@nic.cz>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: u-boot@lists.denx.de, linux-btrfs@vger.kernel.org,
	David Sterba <dsterba@suse.com>, Qu Wenruo <wqu@suse.com>,
	Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH u-boot] fs: btrfs: do not fail when offset of a ROOT_ITEM is not -1
Date: Wed, 10 Feb 2021 02:05:49 +0100	[thread overview]
Message-ID: <20210210020549.6881d90a@nic.cz> (raw)
In-Reply-To: <40e38323-0013-6799-1527-02cbac8dc93e@gmx.com>

On Wed, 10 Feb 2021 08:09:14 +0800
Qu Wenruo <quwenruo.btrfs@gmx.com> wrote:

> On 2021/2/10 上午1:33, Marek Behún wrote:
> > When the btrfs_read_fs_root() function is searching a ROOT_ITEM with
> > location key offset other than -1, it currently fails via BUG_ON.
> >
> > The offset can have other value than -1, though. This can happen for
> > example if a subvolume is renamed:
> >
> >    $ btrfs subvolume create X && sync
> >    Create subvolume './X'
> >    $ btrfs inspect-internal dump-tree /dev/root | grep -B 2 'name: X$
> >          location key (270 ROOT_ITEM 18446744073709551615) type DIR
> >          transid 283 data_len 0 name_len 1
> >          name: X
> >    $ mv X Y && sync
> >    $ btrfs inspect-internal dump-tree /dev/root | grep -B 2 'name: Y$
> >          location key (270 ROOT_ITEM 0) type DIR
> >          transid 285 data_len 0 name_len 1
> >          name: Y
> >
> > As can be seen the offset changed from -1ULL to 0.  
> 
> 
> Offset for subvolume ROOT_ITEM can be other values, especially for
> snapshot that offset is the transid when it get created.
> 
> But the problem is, if we call btrfs_read_fs_root() for subvolume tree,
> the offset of the key really doesn't matter, the only important thing is
> the objectid.
> 
> Thus we use that BUG_ON() to catch careless callers.
> 
> Would you please provide a case where we wrongly call
> btrfs_read_fs_root() with incorrect offset inside btrfs-progs/uboot?
> 
> I believe that would be the proper way to fix.

Qu,

this can be triggered in U-Boot when listing a directory containing a
subvolume that was renamed:
  - create a subvolume && sync
  - rename subvolume && sync
  - umount, reboot, list the directory containing the subvolume in
    u-boot
It will also break when you want to read a file that has a subvolume in
it's path (e.g. `read mmc 0 0x10000000 /renamed-subvol/file`).

I found out this btrfs-progs commit:
  https://github.com/kdave/btrfs-progs/commit/10f1af0fe7de5a0310657993c7c21a1d78087e56
This commit ensures that while searching a directory recursively, when
a ROOT_ITEM is encountered, the offset of its location is changed to -1
before passing the location to btrfs_read_fs_root().

So maybe we could do this in u-boot as well, but why do this? Linux'
btrfs driver does not check whether the offset is -1. So why do it here?

BTW, Qu, I think we have to change the BUG_ON code in U-Boot's btrfs
driver. BUG_ON in U-Boot calls a complete SOC reset. We can't break
whole U-Boot simply because btrfs partition contains broken data.
U-Boot commands must fail in such a case, not reset the SOC.

Marek

  reply	other threads:[~2021-02-10  1:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09 17:33 [PATCH u-boot] fs: btrfs: do not fail when offset of a ROOT_ITEM is not -1 Marek Behún
2021-02-10  0:09 ` Qu Wenruo
2021-02-10  1:05   ` Marek Behun [this message]
2021-02-10  1:20     ` Qu Wenruo
2021-02-10 16:21       ` Marek Behun
2021-02-10 23:24         ` Qu Wenruo
2021-03-02  3:47 ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210210020549.6881d90a@nic.cz \
    --to=marek.behun@nic.cz \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=wqu@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox