Skip to contentSkip to conversation

Patch "btrfs: reduce nesting for extent processing at btrfs_lookup_extent_info()" has been added to the 6.10-stable tree

DISCUSSION Filipe Manana 1 participant 1 message Aug 11, 2024 1 message not in the archive Stable branch

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 8 lines · Sasha Levin

This is a note to let you know that I've just added the patch titled

btrfs: reduce nesting for extent processing at btrfs_lookup_extent_info()

to the 6.10-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

Quoted 6 lines

The filename of the patch is:
btrfs-reduce-nesting-for-extent-processing-at-btrfs_.patch
and it can be found in the queue-6.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Why is this being added to stable releases?
It's just a cleanup, it doesn't fix any bug or compiler warning, etc.

Quoted 72 lines

commit 5a0873e18421183cf695cc5f2c851aac4e1d832c

Author: Filipe Manana <[email protected]>
Date:   Tue Jun 18 11:52:19 2024 +0100

btrfs: reduce nesting for extent processing at btrfs_lookup_extent_info()

[ Upstream commit 5c83b3beaee06aa88d4015408ac2d8bb35380b06 ]

Instead of using an if-else statement when processing the extent item at btrfs_lookup_extent_info(), use a single if statement for the error case since it does a goto at the end and leave the success (expected) case following the if statement, reducing indentation and making the logic a bit easier to follow. Also make the if statement's condition as unlikely since it's not expected to ever happen, as it signals some corruption, making it clear and hint the compiler to generate more efficient code.

fs/btrfs/extent-tree.c +9 -13
index 153297cb97a4a..844b677d054ec 100644
@@ -104,10 +104,7 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
        struct btrfs_delayed_ref_head *head;
        struct btrfs_delayed_ref_root *delayed_refs;
        struct btrfs_path *path;
-       struct btrfs_extent_item *ei;
-       struct extent_buffer *leaf;
        struct btrfs_key key;
-       u32 item_size;
        u64 num_refs;
        u64 extent_flags;
        u64 owner = 0;
@@ -157,16 +154,11 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
        }
 
        if (ret == 0) {
-               leaf = path->nodes[0];
-               item_size = btrfs_item_size(leaf, path->slots[0]);
-               if (item_size >= sizeof(*ei)) {
-                       ei = btrfs_item_ptr(leaf, path->slots[0],
-                                           struct btrfs_extent_item);
-                       num_refs = btrfs_extent_refs(leaf, ei);
-                       extent_flags = btrfs_extent_flags(leaf, ei);
-                       owner = btrfs_get_extent_owner_root(fs_info, leaf,
-                                                           path->slots[0]);
-               } else {
+               struct extent_buffer *leaf = path->nodes[0];
+               struct btrfs_extent_item *ei;
+               const u32 item_size = btrfs_item_size(leaf, path->slots[0]);
+
+               if (unlikely(item_size < sizeof(*ei))) {
                        ret = -EUCLEAN;
                        btrfs_err(fs_info,
                        "unexpected extent item size, has %u expect >= %zu",
@@ -179,6 +171,10 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
                        goto out_free;
                }
 
+               ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
+               num_refs = btrfs_extent_refs(leaf, ei);
+               extent_flags = btrfs_extent_flags(leaf, ei);
+               owner = btrfs_get_extent_owner_root(fs_info, leaf, path->slots[0]);
                BUG_ON(num_refs == 0);
        } else {
                num_refs = 0;