Commit cc925b96 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: use a single variable for return value at lookup_inline_extent_backref()

At lookup_inline_extent_backref(), instead of using a 'ret' and an 'err'
variable for tracking the return value, use a single one ('ret'). This
simplifies the code, makes it comply with most of the existing code and
it's less prone for logic errors as time has proven over and over in the
btrfs code.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 20fb05a6
...@@ -789,7 +789,6 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, ...@@ -789,7 +789,6 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
int type; int type;
int want; int want;
int ret; int ret;
int err = 0;
bool skinny_metadata = btrfs_fs_incompat(fs_info, SKINNY_METADATA); bool skinny_metadata = btrfs_fs_incompat(fs_info, SKINNY_METADATA);
int needed; int needed;
...@@ -816,10 +815,8 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, ...@@ -816,10 +815,8 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
again: again:
ret = btrfs_search_slot(trans, root, &key, path, extra_size, 1); ret = btrfs_search_slot(trans, root, &key, path, extra_size, 1);
if (ret < 0) { if (ret < 0)
err = ret;
goto out; goto out;
}
/* /*
* We may be a newly converted file system which still has the old fat * We may be a newly converted file system which still has the old fat
...@@ -846,7 +843,7 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, ...@@ -846,7 +843,7 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
} }
if (ret && !insert) { if (ret && !insert) {
err = -ENOENT; ret = -ENOENT;
goto out; goto out;
} else if (WARN_ON(ret)) { } else if (WARN_ON(ret)) {
btrfs_print_leaf(path->nodes[0]); btrfs_print_leaf(path->nodes[0]);
...@@ -854,18 +851,18 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, ...@@ -854,18 +851,18 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
"extent item not found for insert, bytenr %llu num_bytes %llu parent %llu root_objectid %llu owner %llu offset %llu", "extent item not found for insert, bytenr %llu num_bytes %llu parent %llu root_objectid %llu owner %llu offset %llu",
bytenr, num_bytes, parent, root_objectid, owner, bytenr, num_bytes, parent, root_objectid, owner,
offset); offset);
err = -EIO; ret = -EIO;
goto out; goto out;
} }
leaf = path->nodes[0]; leaf = path->nodes[0];
item_size = btrfs_item_size(leaf, path->slots[0]); item_size = btrfs_item_size(leaf, path->slots[0]);
if (unlikely(item_size < sizeof(*ei))) { if (unlikely(item_size < sizeof(*ei))) {
err = -EUCLEAN; ret = -EUCLEAN;
btrfs_err(fs_info, btrfs_err(fs_info,
"unexpected extent item size, has %llu expect >= %zu", "unexpected extent item size, has %llu expect >= %zu",
item_size, sizeof(*ei)); item_size, sizeof(*ei));
btrfs_abort_transaction(trans, err); btrfs_abort_transaction(trans, ret);
goto out; goto out;
} }
...@@ -885,11 +882,11 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, ...@@ -885,11 +882,11 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
else else
needed = BTRFS_REF_TYPE_BLOCK; needed = BTRFS_REF_TYPE_BLOCK;
err = -ENOENT; ret = -ENOENT;
while (1) { while (1) {
if (ptr >= end) { if (ptr >= end) {
if (ptr > end) { if (ptr > end) {
err = -EUCLEAN; ret = -EUCLEAN;
btrfs_print_leaf(path->nodes[0]); btrfs_print_leaf(path->nodes[0]);
btrfs_crit(fs_info, btrfs_crit(fs_info,
"overrun extent record at slot %d while looking for inline extent for root %llu owner %llu offset %llu parent %llu", "overrun extent record at slot %d while looking for inline extent for root %llu owner %llu offset %llu parent %llu",
...@@ -900,7 +897,7 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, ...@@ -900,7 +897,7 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
iref = (struct btrfs_extent_inline_ref *)ptr; iref = (struct btrfs_extent_inline_ref *)ptr;
type = btrfs_get_extent_inline_ref_type(leaf, iref, needed); type = btrfs_get_extent_inline_ref_type(leaf, iref, needed);
if (type == BTRFS_REF_TYPE_INVALID) { if (type == BTRFS_REF_TYPE_INVALID) {
err = -EUCLEAN; ret = -EUCLEAN;
goto out; goto out;
} }
...@@ -916,7 +913,7 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, ...@@ -916,7 +913,7 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
dref = (struct btrfs_extent_data_ref *)(&iref->offset); dref = (struct btrfs_extent_data_ref *)(&iref->offset);
if (match_extent_data_ref(leaf, dref, root_objectid, if (match_extent_data_ref(leaf, dref, root_objectid,
owner, offset)) { owner, offset)) {
err = 0; ret = 0;
break; break;
} }
if (hash_extent_data_ref_item(leaf, dref) < if (hash_extent_data_ref_item(leaf, dref) <
...@@ -927,14 +924,14 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, ...@@ -927,14 +924,14 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
ref_offset = btrfs_extent_inline_ref_offset(leaf, iref); ref_offset = btrfs_extent_inline_ref_offset(leaf, iref);
if (parent > 0) { if (parent > 0) {
if (parent == ref_offset) { if (parent == ref_offset) {
err = 0; ret = 0;
break; break;
} }
if (ref_offset < parent) if (ref_offset < parent)
break; break;
} else { } else {
if (root_objectid == ref_offset) { if (root_objectid == ref_offset) {
err = 0; ret = 0;
break; break;
} }
if (ref_offset < root_objectid) if (ref_offset < root_objectid)
...@@ -943,10 +940,10 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, ...@@ -943,10 +940,10 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
} }
ptr += btrfs_extent_inline_ref_size(type); ptr += btrfs_extent_inline_ref_size(type);
} }
if (err == -ENOENT && insert) { if (ret == -ENOENT && insert) {
if (item_size + extra_size >= if (item_size + extra_size >=
BTRFS_MAX_EXTENT_ITEM_SIZE(root)) { BTRFS_MAX_EXTENT_ITEM_SIZE(root)) {
err = -EAGAIN; ret = -EAGAIN;
goto out; goto out;
} }
/* /*
...@@ -958,7 +955,7 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, ...@@ -958,7 +955,7 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
if (find_next_key(path, 0, &key) == 0 && if (find_next_key(path, 0, &key) == 0 &&
key.objectid == bytenr && key.objectid == bytenr &&
key.type < BTRFS_BLOCK_GROUP_ITEM_KEY) { key.type < BTRFS_BLOCK_GROUP_ITEM_KEY) {
err = -EAGAIN; ret = -EAGAIN;
goto out; goto out;
} }
} }
...@@ -969,7 +966,7 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, ...@@ -969,7 +966,7 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
path->search_for_extension = 0; path->search_for_extension = 0;
btrfs_unlock_up_safe(path, 1); btrfs_unlock_up_safe(path, 1);
} }
return err; return ret;
} }
/* /*
......
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