From: Filipe Manana <fdmanana@kernel.org>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/2] btrfs: simplify the inline extent map creation
Date: Tue, 2 Apr 2024 15:50:52 +0000 [thread overview]
Message-ID: <CAL3q7H7V2tzJP3udgEO2zQw=G_yu=M9mKNwO9y_-sybMQTqtOQ@mail.gmail.com> (raw)
In-Reply-To: <da18eebca4fdff1e0be286c18aee0359c074d3f8.1712038308.git.wqu@suse.com>
On Tue, Apr 2, 2024 at 7:24 AM Qu Wenruo <wqu@suse.com> wrote:
>
> With the tree-checker ensuring all inline file extents starts at file
> offset 0 and has a length no larger than sectorsize, we can simplify the
> calculation to assigned those fixes values directly.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> fs/btrfs/file-item.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
> index e58fb5347e65..de3ccee38572 100644
> --- a/fs/btrfs/file-item.c
> +++ b/fs/btrfs/file-item.c
> @@ -1265,18 +1265,19 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
> struct extent_buffer *leaf = path->nodes[0];
> const int slot = path->slots[0];
> struct btrfs_key key;
> - u64 extent_start, extent_end;
> + u64 extent_start;
> u64 bytenr;
> u8 type = btrfs_file_extent_type(leaf, fi);
> int compress_type = btrfs_file_extent_compression(leaf, fi);
>
> btrfs_item_key_to_cpu(leaf, &key, slot);
> extent_start = key.offset;
> - extent_end = btrfs_file_extent_end(path);
> em->ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi);
> em->generation = btrfs_file_extent_generation(leaf, fi);
> if (type == BTRFS_FILE_EXTENT_REG ||
> type == BTRFS_FILE_EXTENT_PREALLOC) {
> + u64 extent_end = btrfs_file_extent_end(path);
> +
This can be made const or better, since it's only used in one place
now and fits within 80 characters, just use the expression directly
instead of using a variable.
> em->start = extent_start;
> em->len = extent_end - extent_start;
Which is here: em->len = btrfs_file_extent_end(path) - extent_start;
> em->orig_start = extent_start -
> @@ -1299,9 +1300,12 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
> em->flags |= EXTENT_FLAG_PREALLOC;
> }
> } else if (type == BTRFS_FILE_EXTENT_INLINE) {
> + /* Tree-checker has ensured this. */
> + ASSERT(extent_start == 0);
> +
> em->block_start = EXTENT_MAP_INLINE;
> - em->start = extent_start;
> - em->len = extent_end - extent_start;
> + em->start = 0;
> + em->len = fs_info->sectorsize;
> /*
> * Initialize orig_start and block_len with the same values
> * as in inode.c:btrfs_get_extent().
> @@ -1336,7 +1340,7 @@ u64 btrfs_file_extent_end(const struct btrfs_path *path)
>
> if (btrfs_file_extent_type(leaf, fi) == BTRFS_FILE_EXTENT_INLINE) {
> end = btrfs_file_extent_ram_bytes(leaf, fi);
> - end = ALIGN(key.offset + end, leaf->fs_info->sectorsize);
> + end = leaf->fs_info->sectorsize;
So both assignments to "end" should be removed, not just the second
one, as the new one doesn't need the previous and makes it pointless.
Thanks.
> } else {
> end = key.offset + btrfs_file_extent_num_bytes(leaf, fi);
> }
> --
> 2.44.0
>
>
prev parent reply other threads:[~2024-04-02 15:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-02 6:23 [PATCH 0/2] btrfs: more explaination on extent_map members Qu Wenruo
2024-04-02 6:23 ` [PATCH 1/2] btrfs: add extra comments " Qu Wenruo
2024-04-02 7:33 ` Andrea Gelmini
2024-04-02 8:25 ` Qu Wenruo
2024-04-02 15:45 ` Filipe Manana
2024-04-02 6:23 ` [PATCH 2/2] btrfs: simplify the inline extent map creation Qu Wenruo
2024-04-02 15:50 ` Filipe Manana [this message]
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='CAL3q7H7V2tzJP3udgEO2zQw=G_yu=M9mKNwO9y_-sybMQTqtOQ@mail.gmail.com' \
--to=fdmanana@kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).