From: Johannes Thumshirn <jth@kernel.org>
To: linux-btrfs@vger.kernel.org
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: [PATCH] btrfs: don't BUG_ON() in btrfs_drop_extents()
Date: Thu, 28 Nov 2024 10:34:28 +0100 [thread overview]
Message-ID: <20241128093428.21485-1-jth@kernel.org> (raw)
From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
btrfs_drop_extents() calls BUG_ON() in case the counter of to be deleted
extents is greater than 0 in two code paths. But both of these code paths
can handle errors, so there's no need to crash the kernel, but gracefully
bail out.
For developer builds with CONFIG_BTRFS_ASSERT turned on, ASSERT() that
this conditon is never met.
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
fs/btrfs/file.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index fbb753300071..33f0de10df5b 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -245,7 +245,11 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans,
next_slot:
leaf = path->nodes[0];
if (path->slots[0] >= btrfs_header_nritems(leaf)) {
- BUG_ON(del_nr > 0);
+ ASSERT(del_nr == 0);
+ if (del_nr > 0) {
+ ret = -EINVAL;
+ break;
+ }
ret = btrfs_next_leaf(root, path);
if (ret < 0)
break;
@@ -321,7 +325,11 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans,
* | -------- extent -------- |
*/
if (args->start > key.offset && args->end < extent_end) {
- BUG_ON(del_nr > 0);
+ ASSERT(del_nr == 0);
+ if (del_nr > 0) {
+ ret = -EINVAL;
+ break;
+ }
if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
ret = -EOPNOTSUPP;
break;
--
2.47.0
next reply other threads:[~2024-11-28 9:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-28 9:34 Johannes Thumshirn [this message]
2024-11-28 12:37 ` [PATCH] btrfs: don't BUG_ON() in btrfs_drop_extents() Filipe Manana
2024-11-28 15:42 ` Johannes Thumshirn
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=20241128093428.21485-1-jth@kernel.org \
--to=jth@kernel.org \
--cc=johannes.thumshirn@wdc.com \
--cc=linux-btrfs@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.