public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Dominique Martinet <dominique.martinet@atmark-techno.com>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: "Dominique Martinet" <asmadeus@codewreck.org>,
	"Marek Behún" <kabel@kernel.org>, "Qu Wenruo" <wqu@suse.com>,
	linux-btrfs@vger.kernel.org, u-boot@lists.denx.de
Subject: Re: [PATCH U-BOOT 1/3] btrfs: fix offset within btrfs_read_extent_reg()
Date: Tue, 18 Apr 2023 11:05:23 +0900	[thread overview]
Message-ID: <ZD364ycA71hLmmOK@atmark-techno.com> (raw)
In-Reply-To: <ad41862c-e7fb-acd7-7657-85b76cb302ee@gmx.com>

Qu Wenruo wrote on Tue, Apr 18, 2023 at 09:58:37AM +0800:
> The subject can be changed to "btrfs: fix offset when reading compressed
> extents".
> The original one is a little too generic.

Ok.

> > btrfs_file_read()
> >   -> btrfs_read_extent_reg
> >      (aligned part loop from 0x40480000 to 0x40ba0000, 128KB at a time)
> >       last read had 0x4000 bytes in extent, but aligned_end - cur limited
> >       the read to 0x3000 (offset 0x720000)
> >   -> read_and_truncate_page
> >     -> btrfs_read_extent_reg
> >        reading the last 0x1000 bytes from offset 0x73000 (end of the
> >        previous 0x4000) into 0x40ba3000
> >        here key.offset = 0x70000 so we need to use it to recover the
> >        0x3000 offset.
> 
> You can use "btrfs ins dump-tree" to provide a much easier to read on-disk
> data layout.

key.offset is the offset within the read call, not the offset on disk.
The file on disk looks perfectly normal, the condition to trigger the
bug is to have a file which size is not sector-aligned and where the
last extent is bigger than a sector.

I had a look at dump-tree early on and couldn't actually find my file in
there, now the problem is understood it should be easy to make a
reproducer so I'll add this info and commands needed to reproduce (+ a
link to a fs image just in case) in v2
 
> >   	/* Preallocated or hole , fill @dest with zero */
> >   	if (btrfs_file_extent_type(leaf, fi) == BTRFS_FILE_EXTENT_PREALLOC ||
> > @@ -454,9 +456,7 @@ int btrfs_read_extent_reg(struct btrfs_path *path,
> >   	if (btrfs_file_extent_compression(leaf, fi) == BTRFS_COMPRESS_NONE) {
> >   		u64 logical;
> > -		logical = btrfs_file_extent_disk_bytenr(leaf, fi) +
> > -			  btrfs_file_extent_offset(leaf, fi) +
> > -			  offset - key.offset;
> > +		logical = btrfs_file_extent_disk_bytenr(leaf, fi) + offset;
> 
> This is touching non-compressed path, which is very weird as your commit
> message said this part is correct.

my rationale is that since this was considered once but forgotten the
other time it'll be easy to add yet another code path that forgets it
later, but I guess it won't change much anyway -- I'll fix the patch
making it explicit again.


Thanks,
-- 
Dominique

  reply	other threads:[~2023-04-18 14:39 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18  1:17 [PATCH U-BOOT 0/3] btrfs: fix and improve read code Dominique Martinet
2023-04-18  1:17 ` [PATCH U-BOOT 1/3] btrfs: fix offset within btrfs_read_extent_reg() Dominique Martinet
2023-04-18  1:58   ` Qu Wenruo
2023-04-18  2:05     ` Dominique Martinet [this message]
2023-04-18  2:16       ` Qu Wenruo
2023-04-18  2:20       ` Qu Wenruo
2023-04-18  1:17 ` [PATCH U-BOOT 2/3] btrfs: btrfs_file_read: allow opportunistic read until the end Dominique Martinet
2023-04-18  2:02   ` Qu Wenruo
2023-04-18  2:41     ` Dominique Martinet
2023-04-18  2:53       ` Qu Wenruo
2023-04-18  3:07         ` Dominique Martinet
2023-04-18  3:21           ` Qu Wenruo
2023-04-18  3:53             ` Dominique Martinet
2023-04-18  5:17               ` Dominique Martinet
2023-04-18  7:15               ` Qu Wenruo
2023-04-18  1:17 ` [PATCH U-BOOT 3/3] btrfs: btfs_file_read: zero trailing data if no extent was found Dominique Martinet
2023-04-18  2:04   ` Qu Wenruo
2023-04-18  2:43     ` Dominique Martinet

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=ZD364ycA71hLmmOK@atmark-techno.com \
    --to=dominique.martinet@atmark-techno.com \
    --cc=asmadeus@codewreck.org \
    --cc=kabel@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.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