提交 f624d976 编写于 作者: Q Qu Wenruo 提交者: David Sterba

btrfs: ctree: Reduce one indent level for btrfs_search_slot()

In btrfs_search_slot(), we something like:

	if (level != 0) {
		/* Do search inside tree nodes*/
	} else {
		/* Do search inside tree leaves */
		goto done;
	}

This caused extra indent for tree node search code.  Change it to
something like:

	if (level == 0) {
		/* Do search inside tree leaves */
		goto done'
	}
	/* Do search inside tree nodes */

So we have more space to maneuver our code, this is especially useful as
the tree nodes search code is more complex than the leaves search code.
Reviewed-by: NAnand Jain <anand.jain@oracle.com>
Signed-off-by: NQu Wenruo <wqu@suse.com>
Reviewed-by: NDavid Sterba <dsterba@suse.com>
Signed-off-by: NDavid Sterba <dsterba@suse.com>
上级 71bf92a9
...@@ -2785,6 +2785,8 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, ...@@ -2785,6 +2785,8 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
} }
while (b) { while (b) {
int dec = 0;
level = btrfs_header_level(b); level = btrfs_header_level(b);
/* /*
...@@ -2861,15 +2863,38 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, ...@@ -2861,15 +2863,38 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
if (ret < 0) if (ret < 0)
goto done; goto done;
if (level != 0) { if (level == 0) {
int dec = 0; p->slots[level] = slot;
if (ins_len > 0 &&
btrfs_leaf_free_space(b) < ins_len) {
if (write_lock_level < 1) {
write_lock_level = 1;
btrfs_release_path(p);
goto again;
}
btrfs_set_path_blocking(p);
err = split_leaf(trans, root, key,
p, ins_len, ret == 0);
BUG_ON(err > 0);
if (err) {
ret = err;
goto done;
}
}
if (!p->search_for_split)
unlock_up(p, level, lowest_unlock,
min_write_lock_level, NULL);
goto done;
}
if (ret && slot > 0) { if (ret && slot > 0) {
dec = 1; dec = 1;
slot -= 1; slot--;
} }
p->slots[level] = slot; p->slots[level] = slot;
err = setup_nodes_for_search(trans, root, p, b, level, err = setup_nodes_for_search(trans, root, p, b, level, ins_len,
ins_len, &write_lock_level); &write_lock_level);
if (err == -EAGAIN) if (err == -EAGAIN)
goto again; goto again;
if (err) { if (err) {
...@@ -2880,20 +2905,18 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, ...@@ -2880,20 +2905,18 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
slot = p->slots[level]; slot = p->slots[level];
/* /*
* slot 0 is special, if we change the key * Slot 0 is special, if we change the key we have to update
* we have to update the parent pointer * the parent pointer which means we must have a write lock on
* which means we must have a write lock * the parent
* on the parent
*/ */
if (slot == 0 && ins_len && if (slot == 0 && ins_len && write_lock_level < level + 1) {
write_lock_level < level + 1) {
write_lock_level = level + 1; write_lock_level = level + 1;
btrfs_release_path(p); btrfs_release_path(p);
goto again; goto again;
} }
unlock_up(p, level, lowest_unlock, unlock_up(p, level, lowest_unlock, min_write_lock_level,
min_write_lock_level, &write_lock_level); &write_lock_level);
if (level == lowest_level) { if (level == lowest_level) {
if (dec) if (dec)
...@@ -2901,8 +2924,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, ...@@ -2901,8 +2924,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
goto done; goto done;
} }
err = read_block_for_search(root, p, &b, level, err = read_block_for_search(root, p, &b, level, slot, key);
slot, key);
if (err == -EAGAIN) if (err == -EAGAIN)
goto again; goto again;
if (err) { if (err) {
...@@ -2927,31 +2949,6 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, ...@@ -2927,31 +2949,6 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
} }
p->nodes[level] = b; p->nodes[level] = b;
} }
} else {
p->slots[level] = slot;
if (ins_len > 0 &&
btrfs_leaf_free_space(b) < ins_len) {
if (write_lock_level < 1) {
write_lock_level = 1;
btrfs_release_path(p);
goto again;
}
btrfs_set_path_blocking(p);
err = split_leaf(trans, root, key,
p, ins_len, ret == 0);
BUG_ON(err > 0);
if (err) {
ret = err;
goto done;
}
}
if (!p->search_for_split)
unlock_up(p, level, lowest_unlock,
min_write_lock_level, NULL);
goto done;
}
} }
ret = 1; ret = 1;
done: done:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册