Commit 28cb13f2 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: don't BUG_ON() when 0 reference count at btrfs_lookup_extent_info()

Instead of doing a BUG_ON() handle the error by returning -EUCLEAN,
aborting the transaction and logging an error message.
Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 5c83b3be
...@@ -164,9 +164,16 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, ...@@ -164,9 +164,16 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item); ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
num_refs = btrfs_extent_refs(leaf, ei); num_refs = btrfs_extent_refs(leaf, ei);
if (unlikely(num_refs == 0)) {
ret = -EUCLEAN;
btrfs_err(fs_info,
"unexpected zero reference count for extent item (%llu %u %llu)",
key.objectid, key.type, key.offset);
btrfs_abort_transaction(trans, ret);
goto out_free;
}
extent_flags = btrfs_extent_flags(leaf, ei); extent_flags = btrfs_extent_flags(leaf, ei);
owner = btrfs_get_extent_owner_root(fs_info, leaf, path->slots[0]); owner = btrfs_get_extent_owner_root(fs_info, leaf, path->slots[0]);
BUG_ON(num_refs == 0);
} else { } else {
num_refs = 0; num_refs = 0;
extent_flags = 0; extent_flags = 0;
...@@ -193,10 +200,19 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, ...@@ -193,10 +200,19 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
goto search_again; goto search_again;
} }
spin_lock(&head->lock); spin_lock(&head->lock);
if (head->extent_op && head->extent_op->update_flags) if (head->extent_op && head->extent_op->update_flags) {
extent_flags |= head->extent_op->flags_to_set; extent_flags |= head->extent_op->flags_to_set;
else } else if (unlikely(num_refs == 0)) {
BUG_ON(num_refs == 0); spin_unlock(&head->lock);
mutex_unlock(&head->mutex);
spin_unlock(&delayed_refs->lock);
ret = -EUCLEAN;
btrfs_err(fs_info,
"unexpected zero reference count for extent %llu (%s)",
bytenr, metadata ? "metadata" : "data");
btrfs_abort_transaction(trans, ret);
goto out_free;
}
num_refs += head->ref_mod; num_refs += head->ref_mod;
spin_unlock(&head->lock); spin_unlock(&head->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment