public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: "Dominique Martinet" <asmadeus@codewreck.org>,
	"Marek Behún" <kabel@kernel.org>, "Qu Wenruo" <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org, u-boot@lists.denx.de,
	Dominique Martinet <dominique.martinet@atmark-techno.com>
Subject: Re: [PATCH U-BOOT 3/3] btrfs: btfs_file_read: zero trailing data if no extent was found
Date: Tue, 18 Apr 2023 10:04:56 +0800	[thread overview]
Message-ID: <ef27f8e9-df8f-316a-eb90-e2227572c910@gmx.com> (raw)
In-Reply-To: <20230418-btrfs-extent-reads-v1-3-47ba9839f0cc@codewreck.org>



On 2023/4/18 09:17, Dominique Martinet wrote:
> From: Dominique Martinet <dominique.martinet@atmark-techno.com>
> 
> btfs_file_read's truncate path has a comment noting '>0 means no extent'
> and bailing out immediately, but the buffer has not been written so
> probably needs zeroing out.
> 
> This is a theorical fix only and hasn't been tested on a file that
> actually runs this code path.

IIRC there is a memset() at the very beginning of btrfs_file_read() to 
set the whole dest memory to zero.

This is to handle cases like NO_HOLE cases, which we can skip hole extents.

Thanks,
Qu
> 
> Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
> ---
>   fs/btrfs/inode.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index efffec0f2e68..23c006c98c3b 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -756,9 +756,12 @@ int btrfs_file_read(struct btrfs_root *root, u64 ino, u64 file_offset, u64 len,
>   		btrfs_release_path(&path);
>   		ret = lookup_data_extent(root, &path, ino, cur,
>   					 &next_offset);
> -		/* <0 is error, >0 means no extent */
> -		if (ret)
> +		/* <0 is error, >0 means no extent: zero end of buffer */
> +		if (ret) {
> +			if (ret > 0)
> +				memset(dest + cur, 0, end - cur);
>   			goto out;
> +		}
>   		fi = btrfs_item_ptr(path.nodes[0], path.slots[0],
>   				    struct btrfs_file_extent_item);
>   		ret = read_and_truncate_page(&path, fi, cur,
> 

  reply	other threads:[~2023-04-18  2:05 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
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 [this message]
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=ef27f8e9-df8f-316a-eb90-e2227572c910@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=asmadeus@codewreck.org \
    --cc=dominique.martinet@atmark-techno.com \
    --cc=kabel@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --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