From: Siddharth Mishra <smish149@asu.edu>
To: dsterba@suse.com
Cc: wqu@suse.com, boris@bur.io, josef@toxicpanda.com,
fdmanana@suse.com, mason@kernel.org, linux-btrfs@vger.kernel.org,
linux-kernel@vger.kernel.org, Siddharth Mishra <smish149@asu.edu>
Subject: [PATCH 5/5] btrfs-progs: tune: do not remove owner refs from tree blocks
Date: Wed, 4 Nov 2026 03:23:23 -0700 [thread overview]
Message-ID: <20261104102323.4090290-6-smish149@asu.edu> (raw)
In-Reply-To: <20261104102323.4090290-1-smish149@asu.edu>
[BUG]
On a filesystem without skinny-metadata, "btrfstune --remove-simple-quota"
can corrupt the extent items of tree blocks:
before:
item 31 key (30756864 EXTENT_ITEM 4096) itemoff 2363 itemsize 51
refs 1 gen 6 flags TREE_BLOCK
tree block key (940 INODE_ITEM 0) level 0
(176 0x5) tree block backref root FS_TREE
after:
item 31 key (30756864 EXTENT_ITEM 4096) itemoff 2372 itemsize 42
refs 1 gen 6 flags TREE_BLOCK
tree block key (0 UNKNOWN.0 1456) level 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
and "btrfs check" then reports "backpointer mismatch" for each of them.
[CAUSE]
remove_owner_refs() takes the first inline ref right after the
btrfs_extent_item of every EXTENT_ITEM. For a tree block without
skinny-metadata that is the btrfs_tree_block_info. If the lowest byte of
its first key objectid is BTRFS_EXTENT_OWNER_REF_KEY (172, here inode
940 = 0x3ac), the tree block info is taken as an owner ref and 9 bytes of
it are removed.
The check for an extent item without inline refs is also off by one: it
reads the type byte when ptr == item_end.
[FIX]
Owner refs are only added to data extents, so skip extent items with the
TREE_BLOCK flag, and skip the item when ptr >= item_end.
Fixes: 2336a7b921ff ("btrfs-progs: btrfstune: add ability to remove squotas")
Signed-off-by: Siddharth Mishra <smish149@asu.edu>
---
tune/quota.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tune/quota.c b/tune/quota.c
index a5f7fb40..187ba4f6 100644
--- a/tune/quota.c
+++ b/tune/quota.c
@@ -132,10 +132,12 @@ search_slot:
if (found_key.type != BTRFS_EXTENT_ITEM_KEY)
goto next;
ei = btrfs_item_ptr(leaf, slot, struct btrfs_extent_item);
+ if (btrfs_extent_flags(leaf, ei) & BTRFS_EXTENT_FLAG_TREE_BLOCK)
+ goto next;
ptr = (unsigned long)(ei + 1);
item_end = (unsigned long)ei + btrfs_item_size(leaf, slot);
/* No inline extent references; accessing type is invalid. */
- if (ptr > item_end)
+ if (ptr >= item_end)
goto next;
iref = (struct btrfs_extent_inline_ref *)ptr;
type = btrfs_extent_inline_ref_type(leaf, iref);
--
2.54.0
next prev parent reply other threads:[~2026-11-04 10:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 10:23 [PATCH 0/5] btrfs: owner refs and " Siddharth Mishra
2026-11-04 10:23 ` [PATCH 1/5] btrfs: skip tree blocks in btrfs_get_extent_owner_root() Siddharth Mishra
2026-11-04 19:13 ` Boris Burkov
2026-11-04 10:23 ` [PATCH 2/5] btrfs: tree-checker: reject inline refs not matching the extent type Siddharth Mishra
2026-11-04 19:24 ` Boris Burkov
2026-11-04 19:56 ` Siddharth Mishra
2026-11-04 10:23 ` [PATCH 3/5] btrfs: tree-checker: reject keyed " Siddharth Mishra
2026-11-04 19:29 ` Boris Burkov
2026-11-04 10:23 ` [PATCH 4/5] btrfs-progs: check: count non-skinny tree blocks in simple quotas Siddharth Mishra
2026-11-04 19:21 ` Boris Burkov
2026-11-04 21:30 ` [PATCH v2] " Siddharth Mishra
2026-11-04 10:23 ` Siddharth Mishra [this message]
2026-11-04 19:18 ` [PATCH 5/5] btrfs-progs: tune: do not remove owner refs from tree blocks Boris Burkov
2026-11-04 22:50 ` [PATCH 0/5] btrfs: owner refs and " Qu Wenruo
2026-11-04 23:16 ` Siddharth Mishra
2026-11-04 23:17 ` Qu Wenruo
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=20261104102323.4090290-6-smish149@asu.edu \
--to=smish149@asu.edu \
--cc=boris@bur.io \
--cc=dsterba@suse.com \
--cc=fdmanana@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@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
all inboxes | Powered by JetHome®